diff --git a/src/main/java/techreborn/api/recipe/RecipeCrafter.java b/src/main/java/techreborn/api/recipe/RecipeCrafter.java index f3b16a1c5..dce870480 100644 --- a/src/main/java/techreborn/api/recipe/RecipeCrafter.java +++ b/src/main/java/techreborn/api/recipe/RecipeCrafter.java @@ -3,6 +3,9 @@ package techreborn.api.recipe; import ic2.api.energy.prefab.BasicSink; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import techreborn.packets.PacketHandler; import techreborn.tiles.TileMachineBase; import techreborn.util.Inventory; import techreborn.util.ItemUtils; @@ -80,7 +83,7 @@ public class RecipeCrafter { public IBaseRecipeType currentRecipe; public int currentTickTime = 0; - public int currentNeededTicks = 0; + public int currentNeededTicks = 1;//Set to 1 to stop rare crashes double lastEnergy; public boolean isactive = false; @@ -107,7 +110,6 @@ public class RecipeCrafter { * Call this on the tile tick */ public void updateEntity() { - speedMultiplier = 0.9; if(parentTile.getWorldObj().isRemote){ return; } @@ -126,6 +128,7 @@ public class RecipeCrafter { currentRecipe = recipe;//Sets the current recipe then syncs this.currentNeededTicks = (int)(currentRecipe.tickTime() * (1.0 - speedMultiplier)); this.currentTickTime = 0; + syncIsActive(); } else { this.currentTickTime = 0; } @@ -135,6 +138,7 @@ public class RecipeCrafter { if (!hasAllInputs()) {//If it doesn't have all the inputs reset currentRecipe = null; currentTickTime = -1; + syncIsActive(); } if (currentRecipe != null && currentTickTime >= currentNeededTicks) {//If it has reached the recipe tick time boolean canGiveInvAll = true; @@ -154,6 +158,7 @@ public class RecipeCrafter { useAllInputs();//this uses all the inputs currentRecipe = null;//resets currentTickTime = 0; + syncIsActive(); } } else if (currentRecipe != null && currentTickTime < currentNeededTicks) { if (energy.useEnergy(getEuPerTick())) {//This uses the power @@ -246,9 +251,15 @@ public class RecipeCrafter { public void readFromNBT(NBTTagCompound tag) { NBTTagCompound data = tag.getCompoundTag("Crater"); - currentTickTime = data.getInteger("currentTickTime"); + if(data.hasKey("currentTickTime")) + currentTickTime = data.getInteger("currentTickTime"); isactive = data.getBoolean("isActive"); + if(parentTile.getWorldObj().isRemote){ + System.out.println(isactive); + parentTile.getWorldObj().markBlockForUpdate(parentTile.xCoord, parentTile.yCoord, parentTile.zCoord); + parentTile.getWorldObj().markBlockRangeForRenderUpdate(parentTile.xCoord, parentTile.yCoord, parentTile.zCoord, parentTile.xCoord, parentTile.yCoord, parentTile.zCoord); + } } public void writeToNBT(NBTTagCompound tag) { @@ -261,6 +272,7 @@ public class RecipeCrafter { tag.setTag("Crater", data); } + private boolean isActiveServer() { return currentRecipe != null; } @@ -297,4 +309,19 @@ public class RecipeCrafter { public double getEuPerTick(){ return currentRecipe.euPerTick() * powerMultiplier; } + + + public void syncIsActive() { + if (!parentTile.getWorldObj().isRemote) { + PacketHandler.sendPacketToAllPlayers(parentTile.getDescriptionPacket(), + parentTile.getWorldObj()); + } + } + + public Packet getSyncPacket() { + NBTTagCompound nbtTag = new NBTTagCompound(); + writeToNBT(nbtTag); + return new S35PacketUpdateTileEntity(this.parentTile.xCoord, this.parentTile.yCoord, + this.parentTile.zCoord, 1, nbtTag); + } } diff --git a/src/main/java/techreborn/tiles/TileAlloySmelter.java b/src/main/java/techreborn/tiles/TileAlloySmelter.java index 8167e66a9..cfd71ff9d 100644 --- a/src/main/java/techreborn/tiles/TileAlloySmelter.java +++ b/src/main/java/techreborn/tiles/TileAlloySmelter.java @@ -91,13 +91,6 @@ public class TileAlloySmelter extends TileMachineBase implements IWrenchable, IE crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - @Override public void invalidate(){ energy.invalidate(); diff --git a/src/main/java/techreborn/tiles/TileAssemblingMachine.java b/src/main/java/techreborn/tiles/TileAssemblingMachine.java index 738c3a6a2..49f28704f 100644 --- a/src/main/java/techreborn/tiles/TileAssemblingMachine.java +++ b/src/main/java/techreborn/tiles/TileAssemblingMachine.java @@ -102,14 +102,6 @@ public class TileAssemblingMachine extends TileMachineBase implements IWrenchabl crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileCentrifuge.java b/src/main/java/techreborn/tiles/TileCentrifuge.java index 5cbe6f6d0..c34a79df3 100644 --- a/src/main/java/techreborn/tiles/TileCentrifuge.java +++ b/src/main/java/techreborn/tiles/TileCentrifuge.java @@ -109,14 +109,6 @@ public class TileCentrifuge extends TileMachineBase implements IWrenchable, IEn crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileChemicalReactor.java b/src/main/java/techreborn/tiles/TileChemicalReactor.java index 743dbe968..bdcb9f102 100644 --- a/src/main/java/techreborn/tiles/TileChemicalReactor.java +++ b/src/main/java/techreborn/tiles/TileChemicalReactor.java @@ -102,14 +102,6 @@ public class TileChemicalReactor extends TileMachineBase implements IWrenchable, crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileGrinder.java b/src/main/java/techreborn/tiles/TileGrinder.java index 08295f2e2..76fcc4ef4 100644 --- a/src/main/java/techreborn/tiles/TileGrinder.java +++ b/src/main/java/techreborn/tiles/TileGrinder.java @@ -98,16 +98,7 @@ public class TileGrinder extends TileMachineBase implements IWrenchable, IEnergy tank.writeToNBT(tagCompound); crafter.writeToNBT(tagCompound); } - - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - tank.writeToNBT(tagCompound); - } - - + @Override public void invalidate() { energy.invalidate(); diff --git a/src/main/java/techreborn/tiles/TileHeatGenerator.java b/src/main/java/techreborn/tiles/TileHeatGenerator.java index fa7a96258..a03825804 100644 --- a/src/main/java/techreborn/tiles/TileHeatGenerator.java +++ b/src/main/java/techreborn/tiles/TileHeatGenerator.java @@ -123,13 +123,6 @@ public class TileHeatGenerator extends TileMachineBase implements IWrenchable, I energy.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - } - - @Override public void addWailaInfo(List info) { diff --git a/src/main/java/techreborn/tiles/TileImplosionCompressor.java b/src/main/java/techreborn/tiles/TileImplosionCompressor.java index 6fc2cf020..72cf44a5c 100644 --- a/src/main/java/techreborn/tiles/TileImplosionCompressor.java +++ b/src/main/java/techreborn/tiles/TileImplosionCompressor.java @@ -95,14 +95,6 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void addWailaInfo(List info) { diff --git a/src/main/java/techreborn/tiles/TileIndustrialElectrolyzer.java b/src/main/java/techreborn/tiles/TileIndustrialElectrolyzer.java index 30f50d216..9996a5329 100644 --- a/src/main/java/techreborn/tiles/TileIndustrialElectrolyzer.java +++ b/src/main/java/techreborn/tiles/TileIndustrialElectrolyzer.java @@ -100,14 +100,6 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren energy.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileIndustrialSawmill.java b/src/main/java/techreborn/tiles/TileIndustrialSawmill.java index 7686e2d69..e9183818f 100644 --- a/src/main/java/techreborn/tiles/TileIndustrialSawmill.java +++ b/src/main/java/techreborn/tiles/TileIndustrialSawmill.java @@ -104,14 +104,6 @@ public class TileIndustrialSawmill extends TileMachineBase implements IWrenchabl crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileLathe.java b/src/main/java/techreborn/tiles/TileLathe.java index 51e759481..60e427d86 100644 --- a/src/main/java/techreborn/tiles/TileLathe.java +++ b/src/main/java/techreborn/tiles/TileLathe.java @@ -101,14 +101,6 @@ public class TileLathe extends TileMachineBase implements IWrenchable, IEnergyTi crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TileMachineBase.java b/src/main/java/techreborn/tiles/TileMachineBase.java index e5053c77b..151b151a8 100644 --- a/src/main/java/techreborn/tiles/TileMachineBase.java +++ b/src/main/java/techreborn/tiles/TileMachineBase.java @@ -11,42 +11,24 @@ import techreborn.packets.PacketHandler; import java.util.List; -public class TileMachineBase extends TileEntity { +public abstract class TileMachineBase extends TileEntity { - public boolean needsSync = false; - public int ticksSinceLastSync = 0; - - @Override - public void updateEntity() { - super.updateEntity(); - //Force a sync evey 10 seconds - if(needsSync && !worldObj.isRemote){ - syncWithAll(); + @Deprecated + /** + * Try not to use this + */ + public void syncWithAll() { + if (!worldObj.isRemote) { + PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(), + worldObj); } - ticksSinceLastSync ++; - } + } @SideOnly(Side.CLIENT) public void addWailaInfo(List info) { } - public void syncWithAll() { - if (!worldObj.isRemote) { - PacketHandler.sendPacketToAllPlayers(getSyncPacket(), - worldObj); - } - needsSync = false; - ticksSinceLastSync = 0; - } - - public Packet getSyncPacket() { - NBTTagCompound nbtTag = new NBTTagCompound(); - writeSyncToNBT(nbtTag); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, - this.zCoord, 1, nbtTag); - } - public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); writeToNBT(nbtTag); @@ -61,9 +43,4 @@ public class TileMachineBase extends TileEntity { readFromNBT(packet.func_148857_g()); } - public void writeSyncToNBT(NBTTagCompound tagCompound) { - - } - - } diff --git a/src/main/java/techreborn/tiles/TileMatterFabricator.java b/src/main/java/techreborn/tiles/TileMatterFabricator.java index 0c0ccf05a..dcf8334a0 100644 --- a/src/main/java/techreborn/tiles/TileMatterFabricator.java +++ b/src/main/java/techreborn/tiles/TileMatterFabricator.java @@ -83,13 +83,6 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable energy.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - } - - @Override public void invalidate() { diff --git a/src/main/java/techreborn/tiles/TilePlateCuttingMachine.java b/src/main/java/techreborn/tiles/TilePlateCuttingMachine.java index 47a016fa9..c960360f4 100644 --- a/src/main/java/techreborn/tiles/TilePlateCuttingMachine.java +++ b/src/main/java/techreborn/tiles/TilePlateCuttingMachine.java @@ -101,14 +101,6 @@ public class TilePlateCuttingMachine extends TileMachineBase implements IWrencha crafter.writeToNBT(tagCompound); } - @Override - public void writeSyncToNBT(NBTTagCompound tagCompound) { - super.writeSyncToNBT(tagCompound); - energy.writeToNBT(tagCompound); - crafter.writeToNBT(tagCompound); - } - - @Override public void addWailaInfo(List info) {