From de79479944aa48f0a7c868873835be8d0a6e6fe3 Mon Sep 17 00:00:00 2001 From: mDiyo Date: Thu, 10 Oct 2013 00:51:38 -0700 Subject: [PATCH] Render, Sync Smeltery --- src/tconstruct/blocks/RedstoneMachine.java | 70 +++++++++++++++---- src/tconstruct/blocks/TankAirBlock.java | 6 ++ .../blocks/logic/AdaptiveSmelteryLogic.java | 11 +-- .../library/component/TankLayerScan.java | 33 +++++---- 4 files changed, 85 insertions(+), 35 deletions(-) diff --git a/src/tconstruct/blocks/RedstoneMachine.java b/src/tconstruct/blocks/RedstoneMachine.java index 581813f0..c539bf91 100644 --- a/src/tconstruct/blocks/RedstoneMachine.java +++ b/src/tconstruct/blocks/RedstoneMachine.java @@ -1,7 +1,8 @@ package tconstruct.blocks; -import cpw.mods.fml.relauncher.*; +import java.util.ArrayList; import java.util.List; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -13,14 +14,21 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; -import net.minecraft.world.*; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import tconstruct.TConstruct; -import tconstruct.blocks.logic.*; +import tconstruct.blocks.logic.AdvancedDrawbridgeLogic; +import tconstruct.blocks.logic.DrawbridgeLogic; +import tconstruct.blocks.logic.FirestarterLogic; import tconstruct.client.block.MachineRender; import tconstruct.library.TConstructRegistry; import tconstruct.library.blocks.InventoryBlock; -import tconstruct.library.util.*; +import tconstruct.library.util.CoordTuple; +import tconstruct.library.util.IActiveLogic; +import tconstruct.library.util.IFacingLogic; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class RedstoneMachine extends InventoryBlock { @@ -38,7 +46,7 @@ public class RedstoneMachine extends InventoryBlock if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2) { TileEntity logic = world.getBlockTileEntity(x, y, z); - + if (logic != null && logic instanceof DrawbridgeLogic) { if (((DrawbridgeLogic) logic).getStackInSlot(1) != null) @@ -48,7 +56,7 @@ public class RedstoneMachine extends InventoryBlock return lightValue[stack.itemID]; } } - + if (logic != null && logic instanceof AdvancedDrawbridgeLogic) { if (((AdvancedDrawbridgeLogic) logic).camoInventory.getCamoStack() != null) @@ -75,7 +83,8 @@ public class RedstoneMachine extends InventoryBlock ItemStack stack = ((DrawbridgeLogic) logic).getStackInSlot(1); if (stack != null && stack.itemID < 4096 && Block.blocksList[stack.itemID] != null && stack.itemID != this.blockID) return Block.blocksList[stack.itemID].colorMultiplier(world, x, y, z); - }else if (logic != null && logic instanceof AdvancedDrawbridgeLogic) + } + else if (logic != null && logic instanceof AdvancedDrawbridgeLogic) { ItemStack stack = ((AdvancedDrawbridgeLogic) logic).camoInventory.getCamoStack(); if (stack != null && stack.itemID < 4096 && Block.blocksList[stack.itemID] != null && stack.itemID != this.blockID) @@ -96,7 +105,7 @@ public class RedstoneMachine extends InventoryBlock case 1: return new FirestarterLogic(); case 2: - return new AdvancedDrawbridgeLogic(); + return new AdvancedDrawbridgeLogic(); default: return null; } @@ -111,7 +120,7 @@ public class RedstoneMachine extends InventoryBlock case 0: return TConstruct.proxy.drawbridgeID; case 2: - return TConstruct.proxy.advDrawbridgeID; + return TConstruct.proxy.advDrawbridgeID; } return null; } @@ -185,7 +194,7 @@ public class RedstoneMachine extends InventoryBlock return icons[getTextureIndex(side)]; } } - + if (meta == 2) { AdvancedDrawbridgeLogic drawbridge = (AdvancedDrawbridgeLogic) logic; @@ -256,12 +265,35 @@ public class RedstoneMachine extends InventoryBlock public void onNeighborBlockChange (World world, int x, int y, int z, int neighborBlockID) { IActiveLogic logic = (IActiveLogic) world.getBlockTileEntity(x, y, z); - logic.setActive(world.isBlockIndirectlyGettingPowered(x, y, z) || activeNearbyRedstone(world, x, y, z)); + IFacingLogic facing = (IFacingLogic) logic; + int direction = facing.getRenderDirection(); + boolean active = false; + for (int i = 0; i < 6; i++) + { + if (direction == i) + continue; + + CoordTuple coord = directions.get(i); + if (this.getIndirectPowerLevelTo(world, x + coord.x, y + coord.y, z + coord.z, i) > 0 || activeRedstone(world, coord.x, y + coord.y, z + coord.z)) + { + active = true; + break; + } + } + logic.setActive(active); } - boolean activeNearbyRedstone (World world, int x, int y, int z) + public int getIndirectPowerLevelTo (World world, int x, int y, int z, int side) { - return activeRedstone(world, x + 1, y, z) || activeRedstone(world, x - 1, y, z) || activeRedstone(world, x, y, z + 1) || activeRedstone(world, x, y, z - 1); + if (world.isBlockNormalCube(x, y, z)) + { + return world.getBlockPowerInput(x, y, z); + } + else + { + int i1 = world.getBlockId(x, y, z); + return i1 == 0 ? 0 : Block.blocksList[i1].isProvidingWeakPower(world, x, y, z, side); + } } boolean activeRedstone (World world, int x, int y, int z) @@ -373,4 +405,16 @@ public class RedstoneMachine extends InventoryBlock { return true; } + + static ArrayList directions = new ArrayList(6); + + static + { + directions.add(new CoordTuple(0, -1, 0)); + directions.add(new CoordTuple(0, 1, 0)); + directions.add(new CoordTuple(0, 0, -1)); + directions.add(new CoordTuple(0, 0, 1)); + directions.add(new CoordTuple(-1, 0, 0)); + directions.add(new CoordTuple(1, 0, 0)); + } } diff --git a/src/tconstruct/blocks/TankAirBlock.java b/src/tconstruct/blocks/TankAirBlock.java index 252f6165..40af03f5 100644 --- a/src/tconstruct/blocks/TankAirBlock.java +++ b/src/tconstruct/blocks/TankAirBlock.java @@ -90,4 +90,10 @@ public class TankAirBlock extends BlockContainer { return false; } + + @Override + public boolean isAirBlock(World world, int x, int y, int z) + { + return true; + } } diff --git a/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java index 32c7958b..89bd3cee 100644 --- a/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java +++ b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java @@ -125,6 +125,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc smeltery.adjustSize(structure.getAirSize(), true); multitank.setCapacity(structure.getAirSize() * (TConstruct.ingotLiquidValue * 18)); smeltery.setActiveLavaTank(structure.lavaTanks.get(0)); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @Override @@ -244,7 +245,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc void updateWorldBlock (int slot, ItemStack itemstack) { - CoordTuple air = structure.getAirByIndex(slot); + CoordTuple air = structure.airCoords.get(slot);//structure.getAirByIndex(slot); if (air != null) { TileEntity te = worldObj.getBlockTileEntity(air.x, air.y, air.z); @@ -276,7 +277,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc { LiquidDataInstance instance; CoordTuple coord = structure.airCoords.get(i); - int height = 16 * (baseY - coord.y); + int height = 16 * (coord.y - baseY); int position = i % layerSize; if (!blocks.containsKey(coord)) @@ -306,7 +307,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc //Subtract from total data.totalAmount -= newFluid.amount; if (data.totalAmount < 0) - continue; + break; } else if (position == data.blocksWithExtra && data.leftovers > 0) { @@ -329,7 +330,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc //Subtract from total data.totalAmount -= newFluid.amount; if (data.totalAmount < 0) - continue; + break; } else { @@ -346,7 +347,7 @@ public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic implements IAc //Subtract from total data.totalAmount -= newFluid.amount; if (data.totalAmount < 0) - continue; + break; } } } diff --git a/src/tconstruct/library/component/TankLayerScan.java b/src/tconstruct/library/component/TankLayerScan.java index edaa51a5..f4f0bcee 100644 --- a/src/tconstruct/library/component/TankLayerScan.java +++ b/src/tconstruct/library/component/TankLayerScan.java @@ -36,7 +36,7 @@ public class TankLayerScan extends LogicComponent protected ArrayList validAirCoords = new ArrayList(); protected CoordTuple returnStone; - private boolean debug = false; + private boolean debug = true; public TankLayerScan(TileEntity te, Block... ids) { @@ -417,9 +417,15 @@ public class TankLayerScan extends LogicComponent } } - @Override - public void readFromNBT (NBTTagCompound tags) + /* @Override + public void readFromNBT (NBTTagCompound tags) + { + super.readFromNBT(tags); + }*/ + + public void readNetworkNBT (NBTTagCompound tags) { + completeStructure = tags.getBoolean("Complete"); NBTTagList layerAir = tags.getTagList("AirLayer"); if (layerAir != null) { @@ -459,17 +465,17 @@ public class TankLayerScan extends LogicComponent } } - super.readFromNBT(tags); } - public void readNetworkNBT (NBTTagCompound tags) - { - completeStructure = tags.getBoolean("Complete"); - } - - @Override + /*@Override public void writeToNBT (NBTTagCompound tags) { + super.writeToNBT(tags); + }*/ + + public void writeNetworkNBT (NBTTagCompound tags) + { + tags.setBoolean("Complete", completeStructure); NBTTagList layerAir = new NBTTagList(); for (CoordTuple coord : layerAirCoords) { @@ -490,12 +496,5 @@ public class TankLayerScan extends LogicComponent air.appendTag(new NBTTagIntArray("coord", new int[] { coord.x, coord.y, coord.z })); } tags.setTag("Air", air); - - super.writeToNBT(tags); - } - - public void writeNetworkNBT (NBTTagCompound tags) - { - tags.setBoolean("Complete", completeStructure); } }