From e3cf1575010ef4f6d1962065ec6d5071972da49c Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+BallOfEnergy1@users.noreply.github.com> Date: Sun, 13 Oct 2024 00:27:55 -0500 Subject: [PATCH] bug fixes part 1 (thank you radium) --- .../com/hbm/blocks/generic/BlockEmitter.java | 42 ++++----- .../com/hbm/main/ModEventHandlerRenderer.java | 76 +++++++-------- .../hbm/tileentity/TileEntityMachineBase.java | 2 +- .../machine/TileEntityConveyorPress.java | 80 ++++++++-------- .../machine/TileEntityHeatBoiler.java | 93 ++++++++++--------- .../machine/TileEntityHeaterHeatex.java | 52 +++++------ .../machine/TileEntityMachinePress.java | 84 ++++++++--------- 7 files changed, 214 insertions(+), 215 deletions(-) diff --git a/src/main/java/com/hbm/blocks/generic/BlockEmitter.java b/src/main/java/com/hbm/blocks/generic/BlockEmitter.java index c6d8d59f6..365343e26 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockEmitter.java +++ b/src/main/java/com/hbm/blocks/generic/BlockEmitter.java @@ -42,7 +42,7 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityEmitter(); } - + @Override public boolean isOpaqueCube() { return false; @@ -57,12 +57,12 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int i, float fx, float fy, float fz) { - + if(world.isRemote) return true; - + TileEntityEmitter te = (TileEntityEmitter)world.getTileEntity(x, y, z); - + if(player.getHeldItem() != null) { if(player.getHeldItem().getItem() instanceof ItemDye) { @@ -73,7 +73,7 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP return true; } } - + return false; } @@ -81,31 +81,31 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) { TileEntityEmitter te = (TileEntityEmitter)world.getTileEntity(x, y, z); - + if(tool == ToolType.SCREWDRIVER) { te.girth += 0.125F; te.markDirty(); return true; } - + if(tool == ToolType.DEFUSER) { te.girth -= 0.125F; if(te.girth < 0.125F) te.girth = 0.125F; te.markDirty(); return true; } - + if(tool == ToolType.HAND_DRILL) { te.effect = (te.effect + 1) % te.effectCount; te.markDirty(); return true; } - + return false; } public static class TileEntityEmitter extends TileEntityLoadedBase implements IBufPacketReceiver { - + public static final int range = 100; public int color; public int beam; @@ -115,34 +115,34 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()); - + if(worldObj.getTotalWorldTime() % 20 == 0) { for(int i = 1; i <= range; i++) { - + beam = i; - + int x = xCoord + dir.offsetX * i; int y = yCoord + dir.offsetY * i; int z = zCoord + dir.offsetZ * i; - + Block b = worldObj.getBlock(x, y, z); if(b.isBlockSolid(worldObj, x, y, z, dir.ordinal())) { break; } } } - + if(effect == 4 && beam > 0) { if(worldObj.getTotalWorldTime() % 5 == 0) { double x = (int) (xCoord + dir.offsetX * (worldObj.getTotalWorldTime() / 5L) % beam) + 0.5; double y = (int) (yCoord + dir.offsetY * (worldObj.getTotalWorldTime() / 5L) % beam) + 0.5; double z = (int) (zCoord + dir.offsetZ * (worldObj.getTotalWorldTime() / 5L) % beam) + 0.5; - + int prevColor = color; if(color == 0) { color = Color.HSBtoRGB(worldObj.getTotalWorldTime() / 50.0F, 0.5F, 0.25F) & 16777215; @@ -172,7 +172,7 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, x, y, z), new TargetPoint(worldObj.provider.dimensionId, x, y, z, 100)); - + color = prevColor; } } @@ -188,7 +188,7 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP this.writeToNBT(nbt); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbt); } - + @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); @@ -209,7 +209,7 @@ public class BlockEmitter extends BlockContainer implements IToolable, ITooltipP nbt.setFloat("girth", this.girth); nbt.setInteger("effect", this.effect); } - + @Override public AxisAlignedBB getRenderBoundingBox() { return TileEntity.INFINITE_EXTENT_AABB; diff --git a/src/main/java/com/hbm/main/ModEventHandlerRenderer.java b/src/main/java/com/hbm/main/ModEventHandlerRenderer.java index f5745092d..853709009 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerRenderer.java +++ b/src/main/java/com/hbm/main/ModEventHandlerRenderer.java @@ -115,11 +115,11 @@ public class ModEventHandlerRenderer { EntityPlayer player = event.entityPlayer; RenderPlayer renderer = event.renderer; - + boolean akimbo = false; ItemStack held = player.getHeldItem(); - + if(held != null) { IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(held, IItemRenderer.ItemRenderType.EQUIPPED); if(customRenderer instanceof ItemRenderWeaponBase) { @@ -131,7 +131,7 @@ public class ModEventHandlerRenderer { } boolean isManly = PermaSyncHandler.boykissers.contains(player.getEntityId()); - + if(akimbo) { ModelBiped biped = renderer.modelBipedMain; biped.bipedLeftArm.rotateAngleY = 0.1F + biped.bipedHead.rotateAngleY; @@ -157,7 +157,7 @@ public class ModEventHandlerRenderer { if(f6 > 1.0F) { f6 = 1.0F; } - + manlyModel.render(event.entityPlayer, f7, f6, yawWrapped, yaw, pitch, 0.0625F, renderer); } } @@ -174,13 +174,13 @@ public class ModEventHandlerRenderer { } } } - + @SubscribeEvent public void onRenderHeldGun(RenderPlayerEvent.Pre event) { EntityPlayer player = event.entityPlayer; RenderPlayer renderer = event.renderer; - + if(player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemGunBaseNT) { renderer.modelBipedMain.aimedBow = true; renderer.modelArmor.aimedBow = true; @@ -197,7 +197,7 @@ public class ModEventHandlerRenderer { if(held == null) return; IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(held, IItemRenderer.ItemRenderType.EQUIPPED); - + if(customRenderer instanceof ItemRenderWeaponBase) { ItemRenderWeaponBase renderWeapon = (ItemRenderWeaponBase) customRenderer; if(renderWeapon.isAkimbo()) { @@ -238,16 +238,16 @@ public class ModEventHandlerRenderer { if(manlyModel == null) manlyModel = new ModelMan(); - + event.renderItem = false; float f2 = 1.3333334F; ItemStack held = player.getHeldItem(); - + if(held == null) return; - + GL11.glPushMatrix(); manlyModel.rightArm.postRender(0.0625F); GL11.glTranslatef(-0.0625F, 0.4375F, 0.0625F); @@ -345,16 +345,16 @@ public class ModEventHandlerRenderer { default: return null; } } - + @SubscribeEvent public void onDrawHighlight(DrawBlockHighlightEvent event) { MovingObjectPosition mop = event.target; - + if(mop != null && mop.typeOfHit == mop.typeOfHit.BLOCK) { Block b = event.player.worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ); if(b instanceof ICustomBlockHighlight) { ICustomBlockHighlight cus = (ICustomBlockHighlight) b; - + if(cus.shouldDrawHighlight(event.player.worldObj, mop.blockX, mop.blockY, mop.blockZ)) { cus.drawHighlight(event, event.player.worldObj, mop.blockX, mop.blockY, mop.blockZ); event.setCanceled(true); @@ -432,17 +432,17 @@ public class ModEventHandlerRenderer { GL11.glPopMatrix(); } }*/ - + float renderSoot = 0; - + @SubscribeEvent public void worldTick(WorldTickEvent event) { - + if(event.phase == event.phase.START && RadiationConfig.enableSootFog) { float step = 0.05F; float soot = PermaSyncHandler.pollution[PollutionType.SOOT.ordinal()]; - + if(Math.abs(renderSoot - soot) < step) { renderSoot = soot; } else if(renderSoot < soot) { @@ -457,7 +457,7 @@ public class ModEventHandlerRenderer { public void thickenFog(FogDensity event) { float soot = (float) (renderSoot - RadiationConfig.sootFogThreshold); if(soot > 0 && RadiationConfig.enableSootFog) { - + float farPlaneDistance = (float) (Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16); float fogDist = farPlaneDistance / (1 + soot * 5F / (float) RadiationConfig.sootFogDivisor); GL11.glFogf(GL11.GL_FOG_START, 0); @@ -471,10 +471,10 @@ public class ModEventHandlerRenderer { event.setCanceled(true); } } - + @SubscribeEvent(priority = EventPriority.LOW) public void tintFog(FogColors event) { - + EntityPlayer player = MainRegistry.proxy.me(); if(player.worldObj.getBlock((int) Math.floor(player.posX), (int) Math.floor(player.posY), (int) Math.floor(player.posZ)).getMaterial() != Material.water) { Vec3 color = getFogBlendColor(player.worldObj, (int) Math.floor(player.posX), (int) Math.floor(player.posZ), event.red, event.green, event.blue, event.renderPartialTicks); @@ -484,7 +484,7 @@ public class ModEventHandlerRenderer { event.blue = (float) color.zCoord; } } - + float soot = (float) (renderSoot - RadiationConfig.sootFogThreshold); float sootColor = 0.15F; float sootReq = (float) RadiationConfig.sootFogDivisor; @@ -495,10 +495,10 @@ public class ModEventHandlerRenderer { event.blue = event.blue * (1 - interp) + sootColor * interp; } } - + @SubscribeEvent public void onRenderHUD(RenderGameOverlayEvent.Pre event) { - + if(event.type == ElementType.HOTBAR && (ModEventHandlerClient.shakeTimestamp + ModEventHandlerClient.shakeDuration - System.currentTimeMillis()) > 0) { double mult = (ModEventHandlerClient.shakeTimestamp + ModEventHandlerClient.shakeDuration - System.currentTimeMillis()) / (double) ModEventHandlerClient.shakeDuration * 2; double horizontal = MathHelper.clamp_double(Math.sin(System.currentTimeMillis() * 0.02), -0.7, 0.7) * 15; @@ -509,13 +509,13 @@ public class ModEventHandlerRenderer { @SubscribeEvent public void onRenderHand(RenderHandEvent event) { - + //can't use plaxer.getHeldItem() here because the item rendering persists for a few frames after hitting the switch key - ItemStack toRender = null; //Minecraft.getMinecraft().entityRenderer.itemRenderer.itemToRender; - + ItemStack toRender = Minecraft.getMinecraft().entityRenderer.itemRenderer.itemToRender; + if(toRender != null) { IItemRenderer renderer = MinecraftForgeClient.getItemRenderer(toRender, ItemRenderType.EQUIPPED_FIRST_PERSON); - + if(renderer instanceof ItemRenderWeaponBase) { ((ItemRenderWeaponBase) renderer).setPerspectiveAndRender(toRender, event.partialTicks); event.setCanceled(true); @@ -529,10 +529,10 @@ public class ModEventHandlerRenderer { private static Vec3 fogRGBMultiplier; private static boolean doesBiomeApply = false; private static long fogTimer = 0; - + /** Same procedure as getting the blended sky color but for fog */ public static Vec3 getFogBlendColor(World world, int playerX, int playerZ, float red, float green, float blue, double partialTicks) { - + long millis = System.currentTimeMillis() - fogTimer; if(playerX == fogX && playerZ == fogZ && fogInit && millis < 3000) return fogRGBMultiplier; @@ -541,7 +541,7 @@ public class ModEventHandlerRenderer { GameSettings settings = Minecraft.getMinecraft().gameSettings; int[] ranges = ForgeModContainer.blendRanges; int distance = 0; - + if(settings.fancyGraphics && settings.renderDistanceChunks >= 0) { distance = ranges[Math.min(settings.renderDistanceChunks, ranges.length - 1)]; } @@ -549,10 +549,10 @@ public class ModEventHandlerRenderer { float r = 0F; float g = 0F; float b = 0F; - + int divider = 0; doesBiomeApply = false; - + for(int x = -distance; x <= distance; x++) { for(int z = -distance; z <= distance; z++) { BiomeGenBase biome = world.getBiomeGenForCoords(playerX + x, playerZ + z); @@ -566,7 +566,7 @@ public class ModEventHandlerRenderer { fogX = playerX; fogZ = playerZ; - + if(doesBiomeApply) { fogRGBMultiplier = Vec3.createVectorHelper(r / divider, g / divider, b / divider); } else { @@ -575,25 +575,25 @@ public class ModEventHandlerRenderer { return fogRGBMultiplier; } - + /** Returns the current biome's fog color adjusted for brightness if in a crater, or the world's cached fog color if not */ public static Vec3 getBiomeFogColors(World world, BiomeGenBase biome, float r, float g, float b, double partialTicks) { - + if(biome instanceof BiomeGenCraterBase) { int color = biome.getSkyColorByTemp(biome.temperature); r = ((color & 0xff0000) >> 16) / 255F; g = ((color & 0x00ff00) >> 8) / 255F; b = (color & 0x0000ff) / 255F; - + float celestialAngle = world.getCelestialAngle((float) partialTicks); float skyBrightness = MathHelper.clamp_float(MathHelper.cos(celestialAngle * (float) Math.PI * 2.0F) * 2.0F + 0.5F, 0F, 1F); r *= skyBrightness; g *= skyBrightness; b *= skyBrightness; - + doesBiomeApply = true; } - + return Vec3.createVectorHelper(r, g, b); } } diff --git a/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java b/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java index 3d623eea3..24231d3ef 100644 --- a/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java +++ b/src/main/java/com/hbm/tileentity/TileEntityMachineBase.java @@ -174,7 +174,7 @@ public abstract class TileEntityMachineBase extends TileEntityLoadedBase impleme // In my testing, this can be reliably reproduced with a full fluid barrel, for instance. // I think it might be fixable by doing something with getDescriptionPacket() and onDataPacket(), // but this sidesteps the problem for the mean time. - if (lastPackedBuf != null && buf.equals(lastPackedBuf) && worldObj.getWorldTime() % 20 != 0) { + if (buf.equals(lastPackedBuf) && worldObj.getWorldTime() % 20 != 0) { return; } this.lastPackedBuf = buf; diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityConveyorPress.java b/src/main/java/com/hbm/tileentity/machine/TileEntityConveyorPress.java index 02ecc68ef..d7a93653e 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityConveyorPress.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityConveyorPress.java @@ -33,7 +33,7 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE private int turnProgress; protected boolean isRetracting = false; private int delay; - + public ItemStack syncStack; public TileEntityConveyorPress() { @@ -47,32 +47,32 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + this.updateConnections(); - + if(delay <= 0) { - + if(isRetracting) { - + if(this.canRetract()) { this.press -= speed; this.power -= this.usage; - + if(press <= 0) { press = 0; this.isRetracting = false; delay = 0; } } - + } else { - + if(this.canExtend()) { this.press += speed; this.power -= this.usage; - + if(press >= 1) { press = 1; this.isRetracting = true; @@ -81,17 +81,17 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE } } } - + } else { delay--; } - + this.networkPackNT(50); } else { - + // approach-based interpolation, GO! this.lastPress = this.renderPress; - + if(this.turnProgress > 0) { this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress); --this.turnProgress; @@ -100,11 +100,11 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE } } } - + protected void updateConnections() { for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } - + protected DirPos[] getConPos() { return new DirPos[] { new DirPos(xCoord + 1, yCoord, zCoord, Library.POS_X), @@ -113,40 +113,40 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE new DirPos(xCoord, yCoord, zCoord - 1, Library.NEG_Z), }; } - + public boolean canExtend() { - + if(this.power < usage) return false; if(slots[0] == null) return false; - + List items = worldObj.getEntitiesWithinAABB(EntityMovingItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 1.5, zCoord + 1)); if(items.isEmpty()) return false; - + for(EntityMovingItem item : items) { ItemStack stack = item.getItemStack(); if(PressRecipes.getOutput(stack, slots[0]) != null && stack.stackSize == 1) { - + double d0 = 0.35; double d1 = 0.65; if(item.posX > xCoord + d0 && item.posX < xCoord + d1 && item.posZ > zCoord + d0 && item.posZ < zCoord + d1) { item.setPosition(xCoord + 0.5, item.posY, zCoord + 0.5); } - + return true; } } - + return false; } - + public void process() { - + List items = worldObj.getEntitiesWithinAABB(EntityMovingItem.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord + 1, zCoord, xCoord + 1, yCoord + 1.5, zCoord + 1)); - + for(EntityMovingItem item : items) { ItemStack stack = item.getItemStack(); ItemStack output = PressRecipes.getOutput(stack, slots[0]); - + if(output != null && stack.stackSize == 1) { item.setDead(); EntityMovingItem out = new EntityMovingItem(worldObj); @@ -155,9 +155,9 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE worldObj.spawnEntityInWorld(out); } } - + this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", getVolume(1.5F), 1.0F); - + if(slots[0].getMaxDamage() != 0) { slots[0].setItemDamage(slots[0].getItemDamage() + 1); if(slots[0].getItemDamage() >= slots[0].getMaxDamage()) { @@ -165,7 +165,7 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE } } } - + public boolean canRetract() { return this.power >= usage; } @@ -175,8 +175,8 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE super.serialize(buf); buf.writeLong(this.power); - buf.writeDouble(this.syncPress); - BufferUtil.writeItemStack(buf, syncStack); + buf.writeDouble(this.press); + BufferUtil.writeItemStack(buf, slots[0]); } @Override @@ -194,7 +194,7 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE public boolean isItemValidForSlot(int i, ItemStack stack) { return stack.getItem() instanceof ItemStamp; } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return new int[] { 0 }; @@ -224,26 +224,26 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE public boolean canConnect(ForgeDirection dir) { return dir != ForgeDirection.DOWN; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); this.power = nbt.getLong("power"); this.press = nbt.getDouble("press"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setLong("power", power); nbt.setDouble("press", press); } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 1, @@ -254,10 +254,10 @@ public class TileEntityConveyorPress extends TileEntityMachineBase implements IE zCoord + 2 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityHeatBoiler.java b/src/main/java/com/hbm/tileentity/machine/TileEntityHeatBoiler.java index 7485772a9..7bd2a4a27 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityHeatBoiler.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityHeatBoiler.java @@ -43,10 +43,10 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa public FluidTank[] tanks; public boolean isOn; public boolean hasExploded = false; - + private AudioWrapper audio; private int audioTime; - + /* CONFIGURABLE */ public static int maxHeat = 3_200_000; public static double diffusion = 0.1D; @@ -66,12 +66,14 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa if(!worldObj.isRemote) { + buf.writeBoolean(this.hasExploded); + if(!this.hasExploded) { this.setupTanks(); this.updateConnections(); this.tryPullHeat(); int lastHeat = this.heat; - + int light = this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, this.xCoord, this.yCoord, this.zCoord); if(light > 7 && TomSaveData.forWorld(worldObj).fire > 1e-5) { this.heat += ((maxHeat - heat) * 0.000005D); //constantly heat up 0.0005% of the remaining heat buffer for rampant but diminishing heating @@ -83,24 +85,23 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa this.isOn = false; this.tryConvert(); tanks[1].serialize(buf); - + if(this.tanks[1].getFill() > 0) { this.sendFluid(); } } - buf.writeBoolean(this.hasExploded); buf.writeBoolean(this.muffled); buf.writeBoolean(this.isOn); sendStandard(25); } else { - + if(this.isOn) audioTime = 20; - + if(audioTime > 0) { - + audioTime--; - + if(audio == null) { audio = createAudioLoop(); audio.startSound(); @@ -110,9 +111,9 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa audio.updateVolume(getVolume(1F)); audio.keepAlive(); - + } else { - + if(audio != null) { audio.stopSound(); audio = null; @@ -120,7 +121,7 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa } } } - + @Override public AudioWrapper createAudioLoop() { return MainRegistry.proxy.getLoopedSound("hbm:block.boiler", xCoord, yCoord, zCoord, 0.125F, 10F, 1.0F, 20); @@ -154,25 +155,27 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa @Override public void deserialize(ByteBuf buf) { - this.heat = buf.readInt(); - this.tanks[0].deserialize(buf); - this.tanks[1].deserialize(buf); this.hasExploded = buf.readBoolean(); - this.muffled = buf.readBoolean(); - this.isOn = buf.readBoolean(); + if (!this.hasExploded) { + this.heat = buf.readInt(); + this.tanks[0].deserialize(buf); + this.tanks[1].deserialize(buf); + this.muffled = buf.readBoolean(); + this.isOn = buf.readBoolean(); + } } - + protected void tryPullHeat() { TileEntity con = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord); - + if(con instanceof IHeatSource) { IHeatSource source = (IHeatSource) con; int diff = source.getHeatStored() - this.heat; - + if(diff == 0) { return; } - + if(diff > 0) { diff = (int) Math.ceil(diff * diffusion); source.useUpHeat(diff); @@ -182,12 +185,12 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa return; } } - + this.heat = Math.max(this.heat - Math.max(this.heat / 1000, 1), 0); } - + protected void setupTanks() { - + if(tanks[0].getTankType().hasTrait(FT_Heatable.class)) { FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class); if(trait.getEfficiency(HeatingType.BOILER) > 0) { @@ -201,32 +204,32 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa tanks[0].setTankType(Fluids.NONE); tanks[1].setTankType(Fluids.NONE); } - + protected void tryConvert() { - + if(tanks[0].getTankType().hasTrait(FT_Heatable.class)) { FT_Heatable trait = tanks[0].getTankType().getTrait(FT_Heatable.class); if(trait.getEfficiency(HeatingType.BOILER) > 0) { - + HeatingStep entry = trait.getFirstStep(); int inputOps = this.tanks[0].getFill() / entry.amountReq; int outputOps = (this.tanks[1].getMaxFill() - this.tanks[1].getFill()) / entry.amountProduced; int heatOps = this.heat / entry.heatReq; - + int ops = Math.min(inputOps, Math.min(outputOps, heatOps)); this.tanks[0].setFill(this.tanks[0].getFill() - entry.amountReq * ops); this.tanks[1].setFill(this.tanks[1].getFill() + entry.amountProduced * ops); this.heat -= entry.heatReq * ops; - + if(ops > 0 && worldObj.rand.nextInt(400) == 0) { worldObj.playSoundEffect(xCoord + 0.5, yCoord + 2, zCoord + 0.5, "hbm:block.boilerGroan", 0.5F, 1.0F); } - + if(ops > 0) { this.isOn = true; } - + if(outputOps == 0 && canExplode) { this.hasExploded = true; BlockDummyable.safeRem = true; @@ -238,33 +241,33 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa } } worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord); - + ExplosionVNT xnt = new ExplosionVNT(worldObj, xCoord + 0.5, yCoord + 2, zCoord + 0.5, 5F); xnt.setEntityProcessor(new EntityProcessorStandard().withRangeMod(3F)); xnt.setPlayerProcessor(new PlayerProcessorStandard()); xnt.setSFX(new ExplosionEffectStandard()); xnt.explode(); - + BlockDummyable.safeRem = false; } } } } - + private void updateConnections() { - + for(DirPos pos : getConPos()) { this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } } - + private void sendFluid() { - + for(DirPos pos : getConPos()) { this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir().getOpposite()); } } - + private DirPos[] getConPos() { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getRotation(ForgeDirection.UP); return new DirPos[] { @@ -273,7 +276,7 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y), }; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -282,7 +285,7 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa heat = nbt.getInteger("heat"); hasExploded = nbt.getBoolean("exploded"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -306,12 +309,12 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa public FluidTank[] getReceivingTanks() { return new FluidTank[] {tanks[0]}; } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 1, @@ -322,10 +325,10 @@ public class TileEntityHeatBoiler extends TileEntityLoadedBase implements IBufPa zCoord + 2 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityHeaterHeatex.java b/src/main/java/com/hbm/tileentity/machine/TileEntityHeaterHeatex.java index ea08a403f..272685e59 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityHeaterHeatex.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityHeaterHeatex.java @@ -19,7 +19,6 @@ import api.hbm.tile.IHeatSource; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; @@ -29,12 +28,12 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHeatSource, IFluidStandardTransceiver, IGUIProvider, IControlReceiver, IFluidCopiable { - + public FluidTank[] tanks; public int amountToCool = 1; public int tickDelay = 1; public int heatEnergy; - + public TileEntityHeaterHeatex() { super(1); this.tanks = new FluidTank[2]; @@ -49,16 +48,16 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe @Override public void updateEntity() { - + if(!worldObj.isRemote) { this.tanks[0].setType(0, slots); this.setupTanks(); this.updateConnections(); - + this.heatEnergy *= 0.999; - + networkPackNT(25); - + for(DirPos pos : getConPos()) { if(this.tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } @@ -68,6 +67,7 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe @Override public void serialize(ByteBuf buf) { tanks[0].serialize(buf); + this.tryConvert(); tanks[1].serialize(buf); buf.writeInt(this.heatEnergy); buf.writeInt(this.amountToCool); @@ -82,9 +82,9 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe this.amountToCool = buf.readInt(); this.tickDelay = buf.readInt(); } - + protected void setupTanks() { - + if(tanks[0].getTankType().hasTrait(FT_Coolable.class)) { FT_Coolable trait = tanks[0].getTankType().getTrait(FT_Coolable.class); if(trait.getEfficiency(CoolingType.HEATEXCHANGER) > 0) { @@ -96,37 +96,37 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe tanks[0].setTankType(Fluids.NONE); tanks[1].setTankType(Fluids.NONE); } - + protected void updateConnections() { - + for(DirPos pos : getConPos()) { this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } } - + protected void tryConvert() { - + if(!tanks[0].getTankType().hasTrait(FT_Coolable.class)) return; if(tickDelay < 1) tickDelay = 1; if(worldObj.getTotalWorldTime() % tickDelay != 0) return; - + FT_Coolable trait = tanks[0].getTankType().getTrait(FT_Coolable.class); - + int inputOps = tanks[0].getFill() / trait.amountReq; int outputOps = (tanks[1].getMaxFill() - tanks[1].getFill()) / trait.amountProduced; int opCap = this.amountToCool; - + int ops = Math.min(inputOps, Math.min(outputOps, opCap)); tanks[0].setFill(tanks[0].getFill() - trait.amountReq * ops); tanks[1].setFill(tanks[1].getFill() + trait.amountProduced * ops); this.heatEnergy += trait.heatEnergy * ops * trait.getEfficiency(CoolingType.HEATEXCHANGER); this.markChanged(); } - + private DirPos[] getConPos() { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection rot = dir.getRotation(ForgeDirection.UP); - + return new DirPos[] { new DirPos(xCoord + dir.offsetX * 2 + rot.offsetX, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX * 2 - rot.offsetX, yCoord, zCoord + dir.offsetZ * 2 - rot.offsetZ, dir), @@ -134,7 +134,7 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite()) }; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -145,7 +145,7 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe this.amountToCool = nbt.getInteger("toCool"); this.tickDelay = nbt.getInteger("delay"); } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -198,12 +198,12 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIHeaterHeatex(player.inventory, this); } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 1, @@ -214,10 +214,10 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe zCoord + 2 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { @@ -233,7 +233,7 @@ public class TileEntityHeaterHeatex extends TileEntityMachineBase implements IHe public void receiveControl(NBTTagCompound data) { if(data.hasKey("toCool")) this.amountToCool = MathHelper.clamp_int(data.getInteger("toCool"), 1, tanks[0].getMaxFill()); if(data.hasKey("delay")) this.tickDelay = Math.max(data.getInteger("delay"), 1); - + this.markChanged(); } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java index 3fadeafdd..c927edc0a 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachinePress.java @@ -36,9 +36,9 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU public final static int maxPress = 200; // max tick count per operation assuming speed is 1 boolean isRetracting = false; // direction the press is currently going private int delay; // delay between direction changes to look a bit more appealing - + public ItemStack syncStack; - + public TileEntityMachinePress() { super(4); } @@ -47,26 +47,26 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU public String getName() { return "container.press"; } - + @Override public void updateEntity() { - + if(!worldObj.isRemote) { - + boolean preheated = false; - + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { if(worldObj.getBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) == ModBlocks.press_preheater) { preheated = true; break; } } - + boolean canProcess = this.canProcess(); - + if((canProcess || this.isRetracting) && this.burnTime >= 200) { this.speed += preheated ? 4 : 1; - + if(this.speed > this.maxSpeed) { this.speed = this.maxSpeed; } @@ -76,21 +76,21 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU this.speed = 0; } } - + if(delay <= 0) { - + int stampSpeed = speed * progressAtMax / maxSpeed; - + if(this.isRetracting) { this.press -= stampSpeed; - + if(this.press <= 0) { this.isRetracting = false; this.delay = 5; } } else if(canProcess) { this.press += stampSpeed; - + if(this.press >= this.maxPress) { this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", getVolume(1.5F), 1.0F); ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); @@ -100,20 +100,20 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU slots[3].stackSize += output.stackSize; } this.decrStackSize(2, 1); - + if(slots[1].getMaxDamage() != 0) { slots[1].setItemDamage(slots[1].getItemDamage() + 1); if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) { slots[1] = null; } } - + this.isRetracting = true; this.delay = 5; if(this.burnTime >= 200) { this.burnTime -= 200; // only subtract fuel if operation was actually successful } - + this.markDirty(); } } else if(this.press > 0){ @@ -122,10 +122,10 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU } else { delay--; } - + if(slots[0] != null && burnTime < 200 && TileEntityFurnace.getItemBurnTime(slots[0]) > 0) { // less than one operation stored? burn more fuel! burnTime += TileEntityFurnace.getItemBurnTime(slots[0]); - + if(slots[0].stackSize == 1 && slots[0].getItem().hasContainerItem(slots[0])) { slots[0] = slots[0].getItem().getContainerItem(slots[0]).copy(); } else { @@ -133,14 +133,14 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU } this.markChanged(); } - + this.networkPackNT(50); - + } else { - + // approach-based interpolation, GO! this.lastPress = this.renderPress; - + if(this.turnProgress > 0) { this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress); --this.turnProgress; @@ -156,10 +156,7 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU buf.writeInt(this.speed); buf.writeInt(this.burnTime); buf.writeInt(this.press); - if (slots[2] == null) - buf.writeShort(-1); // indicate that the NBT doesn't actually exist to avoid null pointer errors. - else - BufferUtil.writeNBT(buf, slots[2].stackTagCompound); + BufferUtil.writeItemStack(buf, slots[2]); } @Override @@ -167,21 +164,20 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU super.deserialize(buf); this.speed = buf.readInt(); this.burnTime = buf.readInt(); - this.press = buf.readInt(); - NBTTagCompound stack = BufferUtil.readNBT(buf); - this.syncStack = ItemStack.loadItemStackFromNBT(stack); + this.syncPress = buf.readInt(); + this.syncStack = BufferUtil.readItemStack(buf); this.turnProgress = 2; } - + public boolean canProcess() { if(burnTime < 200) return false; if(slots[1] == null || slots[2] == null) return false; - + ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); - + if(output == null) return false; - + if(slots[3] == null) return true; if(slots[3].stackSize + output.stackSize <= slots[3].getMaxStackSize() && slots[3].getItem() == output.getItem() && slots[3].getItemDamage() == output.getItemDamage()) return true; return false; @@ -189,16 +185,16 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU @Override public boolean isItemValidForSlot(int i, ItemStack stack) { - + if(stack.getItem() instanceof ItemStamp) return i == 1; - + if(TileEntityFurnace.getItemBurnTime(stack) > 0 && i == 0) return true; - + return i == 2; } - + @Override public int[] getAccessibleSlotsFromSide(int side) { return new int[] { 0, 1, 2, 3 }; @@ -213,7 +209,7 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU public boolean canExtractItem(int i, ItemStack itemStack, int j) { return i == 3; } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -231,19 +227,19 @@ public class TileEntityMachinePress extends TileEntityMachineBase implements IGU nbt.setInteger("speed", speed); nbt.setBoolean("ret", isRetracting); } - + AxisAlignedBB aabb; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(aabb != null) return aabb; - + aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1); return aabb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() {