From bdd2701368054ae9e4e9029f64b046b454992a0f Mon Sep 17 00:00:00 2001 From: mDiyo Date: Sun, 29 Sep 2013 09:05:08 -0700 Subject: [PATCH] Fix version check for structures, begin AdaptiveSmelteryLogic --- src/tconstruct/TConstruct.java | 11 ++- .../blocks/logic/AdaptiveSmelteryLogic.java | 63 ++++++++++++++++ .../blocks/AdaptiveInventoryLogic.java | 55 ++++++++------ src/tconstruct/util/DozenalConverter.java | 73 +++++++++++++++++++ 4 files changed, 177 insertions(+), 25 deletions(-) create mode 100644 src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java create mode 100644 src/tconstruct/util/DozenalConverter.java diff --git a/src/tconstruct/TConstruct.java b/src/tconstruct/TConstruct.java index f5073819..04c7d417 100644 --- a/src/tconstruct/TConstruct.java +++ b/src/tconstruct/TConstruct.java @@ -1,6 +1,6 @@ package tconstruct; -import net.minecraft.server.MinecraftServer; +import net.minecraft.crash.CallableMinecraftVersion; import net.minecraft.world.gen.structure.MapGenStructureIO; import net.minecraftforge.common.MinecraftForge; import tconstruct.client.event.EventCloakRender; @@ -39,6 +39,7 @@ import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; +import cpw.mods.fml.common.versioning.ComparableVersion; import cpw.mods.fml.relauncher.Side; /** TConstruct, the tool mod. @@ -127,7 +128,11 @@ public class TConstruct VillagerRegistry.instance().registerVillageCreationHandler(new VillageSmelteryHandler()); try { - if (MinecraftServer.getServer().getMinecraftVersion().equals("1.6.4")) + //if (MinecraftServer.getServer().getMinecraftVersion().equals("1.6.4")) + /*ComparableVersion cv = new ComparableVersion(new CallableMinecraftVersion(null).minecraftVersion()); + ComparableVersion compare = new ComparableVersion("1.6.4"); + if (compare.compareTo(cv) > 0)*/ //<-- Probably not right + if (new CallableMinecraftVersion(null).minecraftVersion().equals("1.6.4")) { MapGenStructureIO.func_143031_a(ComponentToolWorkshop.class, "TConstruct:ToolWorkshopStructure"); MapGenStructureIO.func_143031_a(ComponentSmeltery.class, "TConstruct:SmelteryStructure"); @@ -138,7 +143,7 @@ public class TConstruct } } - + playerTracker = new TPlayerHandler(); GameRegistry.registerPlayerTracker(playerTracker); MinecraftForge.EVENT_BUS.register(playerTracker); diff --git a/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java new file mode 100644 index 00000000..e49ce4db --- /dev/null +++ b/src/tconstruct/blocks/logic/AdaptiveSmelteryLogic.java @@ -0,0 +1,63 @@ +package tconstruct.blocks.logic; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import tconstruct.library.blocks.AdaptiveInventoryLogic; + +public class AdaptiveSmelteryLogic extends AdaptiveInventoryLogic +{ + + @Override + public byte getRenderDirection () + { + return 0; + } + + @Override + public ForgeDirection getForgeDirection () + { + // TODO Auto-generated method stub + return null; + } + + @Override + @Deprecated + public void setDirection (int side) + { + // TODO Auto-generated method stub + + } + + @Override + @Deprecated + public void setDirection (float yaw, float pitch, EntityLivingBase player) + { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isValidBlock (int x, int y, int z) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public Container getGuiContainer (InventoryPlayer inventoryplayer, World world, int x, int y, int z) + { + // TODO Auto-generated method stub + return null; + } + + @Override + protected String getDefaultName () + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java b/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java index f82a8576..a6cec5c9 100644 --- a/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java +++ b/src/tconstruct/library/blocks/AdaptiveInventoryLogic.java @@ -173,10 +173,9 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I break; } - //Check for at least two connected blocks + //Recurse the structure boolean validBlocks = false; - //Recurse the structure int xPos = 0, zPos = 0; if (dir == 2) xPos = 1; @@ -309,9 +308,8 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I { if (checkAir(x + offset[0], y, z + offset[1])) { - airBlocks++; airCoords.add(coord); - //worldObj.setBlock(x + offset[0], y, z + offset[1], Block.leaves.blockID); + addAirBlock(coord.x, y, coord.z); floodTest(x + offset[0], y, z + offset[1]); } else if (!blockCoords.contains(coord) && checkServant(x + offset[0], y, z + offset[1])) @@ -337,8 +335,10 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I { coord = (CoordTuple) i.next(); if (checkAir(coord.x, y, coord.z)) + { airCoords.add(new CoordTuple(coord.x, y, coord.z)); - + addAirBlock(coord.x, y, coord.z); + } else { valid = false; @@ -389,28 +389,13 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I public void recurseStructureUp (int y) { - Iterator i = tempAirCoords.iterator(); + Iterator i = tempBlockCoords.iterator(); CoordTuple coord = (CoordTuple) i.next(); - if (checkAir(coord.x, y, coord.z)) + if (checkServant(coord.x, y, coord.z)) { boolean valid = true; - //Air blocks - while (i.hasNext()) - { - coord = (CoordTuple) i.next(); - if (checkAir(coord.x, y, coord.z)) - airCoords.add(new CoordTuple(coord.x, y, coord.z)); - - else - { - valid = false; - break; - } - } - //Bricks - i = tempBlockCoords.iterator(); while (i.hasNext()) { coord = (CoordTuple) i.next(); @@ -424,10 +409,36 @@ public abstract class AdaptiveInventoryLogic extends InventoryLogic implements I } } + //Air blocks + if (valid) + { + i = tempAirCoords.iterator(); + while (i.hasNext()) + { + coord = (CoordTuple) i.next(); + if (checkAir(coord.x, y, coord.z)) + { + airCoords.add(new CoordTuple(coord.x, y, coord.z)); + addAirBlock(coord.x, y, coord.z); + } + else + { + valid = false; + break; + } + } + } + if (valid) recurseStructureUp(y + 1); } } + + protected void addAirBlock(int x, int y, int z) + { + airBlocks++; + //worldObj.setBlock(x + offset[0], y, z + offset[1], Block.leaves.blockID); + } public void cleanup () { diff --git a/src/tconstruct/util/DozenalConverter.java b/src/tconstruct/util/DozenalConverter.java new file mode 100644 index 00000000..a1f37466 --- /dev/null +++ b/src/tconstruct/util/DozenalConverter.java @@ -0,0 +1,73 @@ +package tconstruct.util; + +import java.util.LinkedList; + +public class DozenalConverter +{ + public static String convertToDozenal (byte i) + { + return convertDecimal(i); + } + + public static String convertToDozenal (short i) + { + return convertDecimal(i); + } + + public static String convertToDozenal (int i) + { + return convertDecimal(i); + } + + public static String convertDecimal (int i) + { + int num = i; + LinkedList list = new LinkedList(); + while (num > 0) + { + list.add(getDozenalCharacter(num % 12)); + num /= 12; + } + StringBuilder builder = new StringBuilder(); + for (int iter = list.size() - 1; iter > 0; iter--) + { + builder.append(list.get(iter)); + } + return builder.toString(); + } + + public static char getDozenalCharacter (int i) + { + assert i < 12 : "Base 10 number should be less than 12"; + + switch (i) + { + case 0: + return '0'; //Zero + case 1: + return '1'; //One + case 2: + return '2'; //Two + case 3: + return '3'; //Three + case 4: + return '4'; //Four + case 5: + return '5'; //Five + case 6: + return '6'; //Six + case 7: + return '7'; //Seven + case 8: + return '8'; //Eight + case 9: + return '9'; //Nine + case 10: + return 'X'; //Dec + case 11: + return 'E'; //El + } + + return 'Q'; + } +}