Convenience sided init/dispose in tile entity base class.
This commit is contained in:
@@ -86,11 +86,7 @@ public final class TileEntityDeviceBusElement implements INBTSerializable<Compou
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
final World world = tileEntity.getWorld();
|
||||
if (world == null || world.isRemote()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = Objects.requireNonNull(tileEntity.getWorld());
|
||||
ServerScheduler.schedule(world, () -> {
|
||||
if (tileEntity.isRemoved()) {
|
||||
return;
|
||||
@@ -149,11 +145,7 @@ public final class TileEntityDeviceBusElement implements INBTSerializable<Compou
|
||||
}
|
||||
|
||||
private void scheduleBusScanInAdjacentBusElements() {
|
||||
final World world = tileEntity.getWorld();
|
||||
if (world == null || world.isRemote()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = Objects.requireNonNull(tileEntity.getWorld());
|
||||
final BlockPos pos = tileEntity.getPos();
|
||||
for (final Direction direction : Direction.values()) {
|
||||
final BlockPos neighborPos = pos.offset(direction);
|
||||
|
||||
@@ -3,6 +3,7 @@ package li.cil.oc2.common.tile;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,9 +23,40 @@ public abstract class AbstractTileEntity extends TileEntity {
|
||||
}
|
||||
|
||||
protected void initialize() {
|
||||
final World world = getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.isRemote()) {
|
||||
initializeClient();
|
||||
} else {
|
||||
initializeServer();
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeClient() {
|
||||
}
|
||||
|
||||
protected void initializeServer() {
|
||||
}
|
||||
|
||||
protected void dispose() {
|
||||
final World world = getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
if (world.isRemote()) {
|
||||
disposeClient();
|
||||
} else {
|
||||
disposeServer();
|
||||
}
|
||||
}
|
||||
|
||||
protected void disposeClient() {
|
||||
}
|
||||
|
||||
protected void disposeServer() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,14 +23,14 @@ public class BusCableTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
protected void initializeServer() {
|
||||
super.initializeServer();
|
||||
busElement.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispose() {
|
||||
super.dispose();
|
||||
protected void disposeServer() {
|
||||
super.disposeServer();
|
||||
busElement.dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user