From eddc09c1cbd60bb4f5749de3aa5b50499c9aa196 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 3 Mar 2014 22:35:57 +0800 Subject: [PATCH] Fixed sorter render and packets --- .../mechanical/Mechanical.java | 11 ++- .../mechanical/logistic/belt/TileSorter.java | 78 ++++++++++++++----- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java b/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java index 0a7acf69d..5ae4f4fcc 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/Mechanical.java @@ -90,7 +90,7 @@ public class Mechanical public static Block blockConveyorBelt; public static Block blockManipulator; public static Block blockDetector; - public static Block blockRejector; + // public static Block blockRejector; public static Block blockSorter; // Fluids @@ -122,8 +122,8 @@ public class Mechanical blockConveyorBelt = contentRegistry.createTile(BlockConveyorBelt.class, TileConveyorBelt.class); blockManipulator = contentRegistry.createTile(BlockManipulator.class, TileManipulator.class); blockDetector = contentRegistry.createTile(BlockDetector.class, TileDetector.class); - //blockRejector = contentRegistry.createTile(BlockRejector.class, TileRejector.class); - blockRejector = contentRegistry.newBlock(TileSorter.class); + // blockRejector = contentRegistry.createTile(BlockRejector.class, TileRejector.class); + blockSorter = contentRegistry.newBlock(TileSorter.class); blockPump = contentRegistry.createTile(BlockPump.class, TilePump.class); @@ -142,6 +142,7 @@ public class Mechanical PacketAnnotation.register(TileWindTurbine.class); PacketAnnotation.register(TileWaterTurbine.class); + PacketAnnotation.register(TileSorter.class); } @EventHandler @@ -165,7 +166,9 @@ public class Mechanical GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 4), "III", "GGG", 'I', Item.ingotIron, 'G', itemGear)); GameRegistry.addRecipe(new ShapedOreRecipe(blockManipulator, "SSS", "SRS", "SCS", 'S', Item.ingotIron, 'C', blockConveyorBelt, 'R', Block.blockRedstone)); GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, "SWS", "SRS", "SWS", 'S', Item.ingotIron, 'W', UniversalRecipe.WIRE.get())); - GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, "S S", "SPS", "SRS", 'P', Block.pistonBase, 'S', Item.ingotIron, 'R', Item.redstone)); + // GameRegistry.addRecipe(new ShapedOreRecipe(blockRejector, "S S", "SPS", "SRS", 'P', + // Block.pistonBase, 'S', Item.ingotIron, 'R', Item.redstone)); + GameRegistry.addRecipe(new ShapedOreRecipe(blockSorter, "SSS", "SPS", "SRS", 'P', Block.pistonStickyBase, 'S', Item.ingotIron, 'R', Block.blockRedstone)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockWindTurbine, 1, 0), "CWC", "WGW", "CWC", 'G', itemGear, 'C', Block.cloth, 'W', Item.stick)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockWindTurbine, 1, 1), "CWC", "WGW", "CWC", 'G', new ItemStack(blockWindTurbine, 1, 0), 'C', Block.stone, 'W', Item.stick)); diff --git a/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileSorter.java b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileSorter.java index 83cd95c33..552a081a1 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileSorter.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/logistic/belt/TileSorter.java @@ -3,11 +3,13 @@ package resonantinduction.mechanical.logistic.belt; import java.util.ArrayList; import java.util.List; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.packet.Packet; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; @@ -17,11 +19,14 @@ import org.lwjgl.opengl.GL11; import resonantinduction.api.IFilterable; import resonantinduction.core.Reference; +import resonantinduction.core.ResonantInduction; import resonantinduction.core.prefab.imprint.ItemImprint; import universalelectricity.api.UniversalElectricity; import universalelectricity.api.vector.Vector3; import calclavia.lib.content.module.TileRender; import calclavia.lib.content.module.prefab.TileInventory; +import calclavia.lib.network.Synced.SyncedInput; +import calclavia.lib.network.Synced.SyncedOutput; import calclavia.lib.prefab.vector.Cuboid; import calclavia.lib.render.RenderUtility; import cpw.mods.fml.relauncher.Side; @@ -53,7 +58,7 @@ public class TileSorter extends TileInventory if (world().isRemote) { - player.addChatMessage("Sorter filter inversion: " + isInverted); + player.addChatMessage("Sorter filter inversion: " + !isInverted); } return true; @@ -68,33 +73,42 @@ public class TileSorter extends TileInventory @Override public void collide(Entity entity) { - if (entity instanceof EntityItem) + if (!world().isRemote) { - EntityItem entityItem = (EntityItem) entity; - List possibleDirections = new ArrayList(); - - /** - * Move item to position where a filter allows it. - */ - for (int i = 0; i < getSizeInventory(); i++) + if (entity instanceof EntityItem) { - ItemStack stack = getStackInSlot(i); + EntityItem entityItem = (EntityItem) entity; + List possibleDirections = new ArrayList(); - if (isInverted == ItemImprint.isFiltering(stack, entityItem.getEntityItem())) + /** + * Move item to position where a filter allows it. + */ + for (int i = 0; i < getSizeInventory(); i++) { - possibleDirections.add(ForgeDirection.getOrientation(i)); + ItemStack stack = getStackInSlot(i); + + if (isInverted == ItemImprint.isFiltering(stack, entityItem.getEntityItem())) + { + ForgeDirection dir = ForgeDirection.getOrientation(i); + + int blockID = position().translate(dir).getBlockID(world()); + Block block = Block.blocksList[blockID]; + + if (block == null || block.isNormalCube(blockID)) + { + possibleDirections.add(dir); + } + } } - } - int size = possibleDirections.size(); + int size = possibleDirections.size(); - if (size > 0) - { - ForgeDirection dir = possibleDirections.get(size > 1 ? world().rand.nextInt(size - 1) : 0); - Vector3 set = center().translate(dir, 0.9); - entityItem.posX = set.x; - entityItem.posY = set.y; - entityItem.posZ = set.z; + if (size > 0) + { + ForgeDirection dir = possibleDirections.get(size > 1 ? world().rand.nextInt(size - 1) : 0); + Vector3 set = center().translate(dir, 1); + entityItem.setPosition(set.x, set.y, set.z); + } } } } @@ -105,6 +119,7 @@ public class TileSorter extends TileInventory return Cuboid.full(); } + @SyncedInput @Override public void readFromNBT(NBTTagCompound nbt) { @@ -112,6 +127,7 @@ public class TileSorter extends TileInventory nbt.getBoolean("isInverted"); } + @SyncedOutput @Override public void writeToNBT(NBTTagCompound nbt) { @@ -134,6 +150,26 @@ public class TileSorter extends TileInventory RenderUtility.enableBlending(); GL11.glTranslated(position.x + 0.5, position.y + 0.5, position.z + 0.5); RenderUtility.bind(TEXTURE); + + for (int i = 0; i < TileSorter.this.getSizeInventory(); i++) + { + if (TileSorter.this.getStackInSlot(i) != null) + { + ForgeDirection dir = ForgeDirection.getOrientation(i); + GL11.glPushMatrix(); + + if (dir.ordinal() == 0) + GL11.glRotatef(-90, 0, 0, 1); + + if (dir.ordinal() == 1) + GL11.glRotatef(90, 0, 0, 1); + + RenderUtility.rotateBlockBasedOnDirection(dir); + MODEL.renderOnly("port"); + GL11.glPopMatrix(); + } + } + MODEL.renderAllExcept("port"); RenderUtility.disableBlending(); GL11.glPopMatrix();