Fixed #924 - "TileCable should avoid being ticked"
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- Fixed Crafting Tweaks buttons positioned wrongly (blay09)
|
- Fixed Crafting Tweaks buttons positioned wrongly (blay09)
|
||||||
- Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09)
|
- Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09)
|
||||||
- Fixed crash when updating storages (raoulvdberge)
|
- Fixed crash when updating storages (raoulvdberge)
|
||||||
|
- Removed ticking tile entities, every tile entity in RS is non-ticking now (raoulvdberge)
|
||||||
|
|
||||||
### 1.4.4
|
### 1.4.4
|
||||||
- Updated Forge to 2284 (raoulvdberge)
|
- Updated Forge to 2284 (raoulvdberge)
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ repositories {
|
|||||||
name "Cyclops Repo"
|
name "Cyclops Repo"
|
||||||
url "https://dl.bintray.com/cyclopsmc/dev/"
|
url "https://dl.bintray.com/cyclopsmc/dev/"
|
||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
name = "oc"
|
name "oc"
|
||||||
url = "http://maven.cil.li/"
|
url "http://maven.cil.li/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ dependencies {
|
|||||||
deobfCompile "org.cyclops.cyclopscore:CyclopsCore:1.11.2-0.10.2-542"
|
deobfCompile "org.cyclops.cyclopscore:CyclopsCore:1.11.2-0.10.2-542"
|
||||||
deobfCompile "org.cyclops.commoncapabilities:CommonCapabilities:1.11.2-1.3.2-107"
|
deobfCompile "org.cyclops.commoncapabilities:CommonCapabilities:1.11.2-1.3.2-107"
|
||||||
deobfCompile "MCMultiPart2:MCMultiPart-exp:2.0.0_19"
|
deobfCompile "MCMultiPart2:MCMultiPart-exp:2.0.0_19"
|
||||||
deobfCompile "li.cil.oc:OpenComputers:MC1.11.2-1.7.0.14:api"
|
deobfCompile "li.cil.oc:OpenComputers:MC1.11.2-1.7.0.14:api"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|||||||
@@ -12,8 +12,24 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
|
|
||||||
public class NetworkNodeListener {
|
public class NetworkNodeListener {
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onWorldTick(TickEvent.WorldTickEvent e) {
|
||||||
|
e.world.profiler.startSection("network node ticking");
|
||||||
|
|
||||||
|
if (e.phase == TickEvent.Phase.END) {
|
||||||
|
for (INetworkNode node : API.instance().getNetworkNodeManager(e.world.provider.getDimension()).all()) {
|
||||||
|
if (e.world.isBlockLoaded(node.getPos())) {
|
||||||
|
node.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.world.profiler.endSection();
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onBlockPlace(BlockEvent.PlaceEvent e) {
|
public void onBlockPlace(BlockEvent.PlaceEvent e) {
|
||||||
if (!e.getWorld().isRemote) {
|
if (!e.getWorld().isRemote) {
|
||||||
|
|||||||
@@ -8,29 +8,18 @@ import net.minecraft.network.NetworkManager;
|
|||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ITickable;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public abstract class TileBase extends TileEntity implements ITickable {
|
public abstract class TileBase extends TileEntity {
|
||||||
protected static final String NBT_DIRECTION = "Direction";
|
protected static final String NBT_DIRECTION = "Direction";
|
||||||
|
|
||||||
private EnumFacing direction = EnumFacing.NORTH;
|
private EnumFacing direction = EnumFacing.NORTH;
|
||||||
|
|
||||||
protected TileDataManager dataManager = new TileDataManager(this);
|
protected TileDataManager dataManager = new TileDataManager(this);
|
||||||
protected int ticks = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
if (!getWorld().isRemote) {
|
|
||||||
++ticks;
|
|
||||||
|
|
||||||
dataManager.detectAndSendChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDirection(EnumFacing direction) {
|
public void setDirection(EnumFacing direction) {
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
@@ -65,16 +54,16 @@ public abstract class TileBase extends TileEntity implements ITickable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readUpdate(NBTTagCompound tag) {
|
public void readUpdate(NBTTagCompound tag) {
|
||||||
boolean doRerender = canUpdateCauseRerender(tag);
|
boolean doRender = canCauseRenderUpdate(tag);
|
||||||
|
|
||||||
direction = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
direction = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
||||||
|
|
||||||
if (doRerender) {
|
if (doRender) {
|
||||||
RSUtils.updateBlock(getWorld(), pos);
|
RSUtils.updateBlock(getWorld(), pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean canUpdateCauseRerender(NBTTagCompound tag) {
|
protected boolean canCauseRenderUpdate(NBTTagCompound tag) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.datasync.DataSerializers;
|
import net.minecraft.network.datasync.DataSerializers;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
@@ -69,7 +70,7 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class TileController extends TileBase implements INetworkMaster, IRedstoneConfigurable, INetworkNode, INetworkNodeProxy<TileController> {
|
public class TileController extends TileBase implements ITickable, INetworkMaster, IRedstoneConfigurable, INetworkNode, INetworkNodeProxy<TileController> {
|
||||||
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||||
|
|
||||||
public static final TileDataParameter<Integer> ENERGY_USAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileController>() {
|
public static final TileDataParameter<Integer> ENERGY_USAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, new ITileDataProducer<Integer, TileController>() {
|
||||||
@@ -262,8 +263,6 @@ public class TileController extends TileBase implements INetworkMaster, IRedston
|
|||||||
RSUtils.updateBlock(world, pos);
|
RSUtils.updateBlock(world, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,31 +23,14 @@ import javax.annotation.Nullable;
|
|||||||
public abstract class TileNode<N extends NetworkNode> extends TileBase implements INetworkNodeProxy<N>, INetworkNodeHolder, IRedstoneConfigurable, IWrenchable {
|
public abstract class TileNode<N extends NetworkNode> extends TileBase implements INetworkNodeProxy<N>, INetworkNodeHolder, IRedstoneConfigurable, IWrenchable {
|
||||||
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||||
|
|
||||||
private NBTTagCompound legacyTagToRead;
|
private NBTTagCompound legacyTag;
|
||||||
|
|
||||||
protected static final String NBT_ACTIVE = "Active";
|
protected static final String NBT_ACTIVE = "Active";
|
||||||
|
|
||||||
public TileNode() {
|
public TileNode() {
|
||||||
dataManager.addWatchedParameter(REDSTONE_MODE);
|
dataManager.addWatchedParameter(REDSTONE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
if (!getWorld().isRemote) {
|
|
||||||
if (legacyTagToRead != null) {
|
|
||||||
getNode().read(legacyTagToRead);
|
|
||||||
getNode().markDirty();
|
|
||||||
|
|
||||||
legacyTagToRead = null;
|
|
||||||
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
getNode().update();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World world() {
|
public World world() {
|
||||||
return getWorld();
|
return getWorld();
|
||||||
@@ -82,21 +65,7 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
|
|||||||
public void read(NBTTagCompound tag) {
|
public void read(NBTTagCompound tag) {
|
||||||
super.read(tag);
|
super.read(tag);
|
||||||
|
|
||||||
// Ugly code for checking if this is a legacy tile. Sue me.
|
this.legacyTag = tag;
|
||||||
boolean hasMeta = tag.hasKey("x") && tag.hasKey("y") && tag.hasKey("z") && tag.hasKey("id");
|
|
||||||
boolean hasForgeData = tag.hasKey("ForgeData");
|
|
||||||
boolean hasForgeCaps = tag.hasKey("ForgeCaps");
|
|
||||||
|
|
||||||
// + 1 because of "Direction".
|
|
||||||
if (tag.getSize() == 4 + 1 && hasMeta) {
|
|
||||||
// NO OP
|
|
||||||
} else if (tag.getSize() == 5 + 1 && hasMeta && (hasForgeData || hasForgeCaps)) {
|
|
||||||
// NO OP
|
|
||||||
} else if (tag.getSize() == 6 + 1 && hasMeta && hasForgeData && hasForgeCaps) {
|
|
||||||
// NO OP
|
|
||||||
} else {
|
|
||||||
legacyTagToRead = tag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
public NBTTagCompound writeUpdate(NBTTagCompound tag) {
|
||||||
@@ -135,9 +104,36 @@ public abstract class TileNode<N extends NetworkNode> extends TileBase implement
|
|||||||
node.setHolder(this);
|
node.setHolder(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (legacyTag != null) {
|
||||||
|
doLegacyCheck(node);
|
||||||
|
}
|
||||||
|
|
||||||
return (N) node;
|
return (N) node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doLegacyCheck(NetworkNode node) {
|
||||||
|
// Ugly code for checking if this is a legacy tile. Sue me.
|
||||||
|
boolean hasMeta = legacyTag.hasKey("x") && legacyTag.hasKey("y") && legacyTag.hasKey("z") && legacyTag.hasKey("id");
|
||||||
|
boolean hasForgeData = legacyTag.hasKey("ForgeData");
|
||||||
|
boolean hasForgeCaps = legacyTag.hasKey("ForgeCaps");
|
||||||
|
|
||||||
|
// + 1 because of "Direction".
|
||||||
|
if (legacyTag.getSize() == 4 + 1 && hasMeta) {
|
||||||
|
// NO OP
|
||||||
|
} else if (legacyTag.getSize() == 5 + 1 && hasMeta && (hasForgeData || hasForgeCaps)) {
|
||||||
|
// NO OP
|
||||||
|
} else if (legacyTag.getSize() == 6 + 1 && hasMeta && hasForgeData && hasForgeCaps) {
|
||||||
|
// NO OP
|
||||||
|
} else {
|
||||||
|
node.read(legacyTag);
|
||||||
|
node.markDirty();
|
||||||
|
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.legacyTag = null;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract N createNode();
|
public abstract N createNode();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class TileSolderer extends TileNode<NetworkNodeSolderer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canUpdateCauseRerender(NBTTagCompound tag) {
|
protected boolean canCauseRenderUpdate(NBTTagCompound tag) {
|
||||||
EnumFacing receivedDirection = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
EnumFacing receivedDirection = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
||||||
|
|
||||||
return receivedDirection != getDirection();
|
return receivedDirection != getDirection();
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class TileStorageMonitor extends TileNode<NetworkNodeStorageMonitor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canUpdateCauseRerender(NBTTagCompound tag) {
|
protected boolean canCauseRenderUpdate(NBTTagCompound tag) {
|
||||||
EnumFacing receivedDirection = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
EnumFacing receivedDirection = EnumFacing.getFront(tag.getInteger(NBT_DIRECTION));
|
||||||
boolean receivedActive = tag.getBoolean(NBT_ACTIVE);
|
boolean receivedActive = tag.getBoolean(NBT_ACTIVE);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,36 @@ public class ContainerListener {
|
|||||||
TileBase tile = ((ContainerBase) container).getTile();
|
TileBase tile = ((ContainerBase) container).getTile();
|
||||||
|
|
||||||
if (tile != null && !tile.getWorld().isRemote) {
|
if (tile != null && !tile.getWorld().isRemote) {
|
||||||
tile.getDataManager().sendParametersTo((EntityPlayerMP) e.getEntityPlayer());
|
TileDataManager manager = tile.getDataManager();
|
||||||
|
|
||||||
|
manager.sendParametersTo((EntityPlayerMP) e.getEntityPlayer());
|
||||||
|
|
||||||
|
int watchers = manager.getWatchers();
|
||||||
|
|
||||||
|
manager.setWatchers(watchers + 1);
|
||||||
|
|
||||||
|
if (watchers == 0) {
|
||||||
|
Thread listenerThread = new Thread(() -> {
|
||||||
|
while (manager.getWatchers() > 0) {
|
||||||
|
manager.detectAndSendChanges();
|
||||||
|
}
|
||||||
|
}, "RS tile listener " + tile.getPos().getX() + ", " + tile.getPos().getY() + ", " + tile.getPos().getZ());
|
||||||
|
|
||||||
|
listenerThread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onContainerClose(PlayerContainerEvent.Close e) {
|
||||||
|
Container container = e.getContainer();
|
||||||
|
|
||||||
|
if (container instanceof ContainerBase) {
|
||||||
|
TileBase tile = ((ContainerBase) container).getTile();
|
||||||
|
|
||||||
|
if (tile != null && !tile.getWorld().isRemote) {
|
||||||
|
tile.getDataManager().setWatchers(tile.getDataManager().getWatchers() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public class TileDataManager {
|
|||||||
private List<TileDataParameter> watchedParameters = new ArrayList<>();
|
private List<TileDataParameter> watchedParameters = new ArrayList<>();
|
||||||
private List<Object> watchedParametersCache = new ArrayList<>();
|
private List<Object> watchedParametersCache = new ArrayList<>();
|
||||||
|
|
||||||
|
private int watchers = 0;
|
||||||
|
|
||||||
public static void registerParameter(TileDataParameter<?> parameter) {
|
public static void registerParameter(TileDataParameter<?> parameter) {
|
||||||
parameter.setId(LAST_ID);
|
parameter.setId(LAST_ID);
|
||||||
|
|
||||||
@@ -44,6 +46,14 @@ public class TileDataManager {
|
|||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWatchers() {
|
||||||
|
return watchers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWatchers(int watchers) {
|
||||||
|
this.watchers = Math.max(0, watchers);
|
||||||
|
}
|
||||||
|
|
||||||
public void addParameter(TileDataParameter<?> parameter) {
|
public void addParameter(TileDataParameter<?> parameter) {
|
||||||
parameters.add(parameter);
|
parameters.add(parameter);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user