diff --git a/resources/manuals/diary.xml b/resources/manuals/diary.xml index daccf486..431d79e2 100644 --- a/resources/manuals/diary.xml +++ b/resources/manuals/diary.xml @@ -145,4 +145,19 @@ Tinker's Log #26: I have all these tools laying around with little notes on what each one does. Instead of leaving them scattered about, I think I will create one place to store them. +Tinker's Log #27: + +I went exploring and found some new ores today. They're colors I've never seen before, and they don't shatter on impact like iron does. I wonder what I can do with these? + +Tinker's Log #27: + +I went exploring and found some new ores today. They're colors I've never seen before, and they don't shatter on impact like iron does. I wonder what I can do with these? + +Tinker's Log #28: +The normal furnace is nice for keeping warm, but it leaves something to be desired for processing metal. I've dug a pit and lined it with some clay, gathered lava nearby, and put ore in the center in an attempt to improve on the design. The results were quite interesting. + +The more lava I fed into the pit the hotter the material became. Eventually the whole thing liquified. I broke open the side of the pit with a cauldron in an attempt to catch the material, but it went everywhere. There were some remnants left in the pit as well. + +Raw ore still has parts of stone in it. There must be a way to remove the excess. + \ No newline at end of file diff --git a/resources/tinkertextures/ConstructBlocks.png b/resources/tinkertextures/ConstructBlocks.png index 2b74b63a..ca9839d1 100644 Binary files a/resources/tinkertextures/ConstructBlocks.png and b/resources/tinkertextures/ConstructBlocks.png differ diff --git a/resources/tinkertextures/mob/skyla.png b/resources/tinkertextures/mob/skyla.png index 264d6ef3..fa4f5f68 100644 Binary files a/resources/tinkertextures/mob/skyla.png and b/resources/tinkertextures/mob/skyla.png differ diff --git a/tinker/common/CoordTuple.java b/tinker/common/CoordTuple.java new file mode 100644 index 00000000..96eba678 --- /dev/null +++ b/tinker/common/CoordTuple.java @@ -0,0 +1,27 @@ +package tinker.common; + +public class CoordTuple +{ + public final int x; + public final int y; + public final int z; + + public CoordTuple(int posX, int posY, int posZ) + { + x = posX; + y = posY; + z = posZ; + } + + public boolean equals(CoordTuple coord) + { + if (coord == null) + return false; + else if (coord == this) + return true; + else if (coord.x == this.x && coord.y == this.y && coord.z == this.z) + return true; + else + return false; + } +} diff --git a/tinker/common/IMechanicalLogic.java b/tinker/common/IMechanicalLogic.java deleted file mode 100644 index 2b9136a9..00000000 --- a/tinker/common/IMechanicalLogic.java +++ /dev/null @@ -1,6 +0,0 @@ -package tinker.common; - -public interface IMechanicalLogic -{ - -} \ No newline at end of file diff --git a/tinker/tconstruct/PHConstruct.java b/tinker/tconstruct/PHConstruct.java index 51b6c794..f617cd17 100644 --- a/tinker/tconstruct/PHConstruct.java +++ b/tinker/tconstruct/PHConstruct.java @@ -109,6 +109,38 @@ public class PHConstruct { mattock = config.getItem("Tools", "Mattock", 14060).getInt(14060); lumberaxe = config.getItem("Tools", "Lumber Axe", 14061).getInt(14061); longbow = config.getItem("Tools", "Longbow", 14062).getInt(14062); + + boolean ic2 = true; + boolean xycraft = true; + try + { + Class c = Class.forName("ic2.core.IC2"); + ic2 = false; + } + catch (Exception e) {} + try + { + Class c = Class.forName("soaryn.xycraft.XyCraft"); + xycraft = false; + } + catch (Exception e) {} + + generateCopper = config.get("Worldgen", "Generate Copper", ic2).getBoolean(ic2); + generateTin = config.get("Worldgen", "Generate Tin", ic2).getBoolean(ic2); + generateAluminum = config.get("Worldgen", "Generate Aluminum", xycraft).getBoolean(xycraft); + generateCobalt = config.get("Worldgen", "Generate Cobalt", true).getBoolean(true); + generateArdite = config.get("Worldgen", "Generate Ardite", true).getBoolean(true); + + copperDensity = config.get("Worldgen", "Copper Density", 8).getInt(8); + copperHeight = config.get("Worldgen", "Copper Height", 20).getInt(20); + copperRange = config.get("Worldgen", "Copper Range", 40).getInt(40); + tinDensity = config.get("Worldgen", "Tin Density", 8).getInt(8); + tinHeight = config.get("Worldgen", "Tin Height", 0).getInt(0); + tinRange = config.get("Worldgen", "Tin Range", 40).getInt(40); + aluminumDensity = config.get("Worldgen", "Aluminum Density", 9).getInt(9); + aluminumHeight = config.get("Worldgen", "Aluminum Height", 0).getInt(0); + aluminumRange = config.get("Worldgen", "Aluminum Range", 64).getInt(64); + netherDensity = config.get("Worldgen", "Nether Ores Density", 8).getInt(8); /* Save the configuration file */ config.save(); @@ -194,4 +226,22 @@ public class PHConstruct { public static int lumberHead; public static int binding; + + //Ore values + public static boolean generateCopper; + public static boolean generateTin; + public static boolean generateAluminum; + public static boolean generateCobalt; + public static boolean generateArdite; + + public static int copperDensity; + public static int copperHeight; + public static int copperRange; + public static int tinDensity; + public static int tinHeight; + public static int tinRange; + public static int aluminumDensity; + public static int aluminumHeight; + public static int aluminumRange; + public static int netherDensity; } \ No newline at end of file diff --git a/tinker/tconstruct/TConstruct.java b/tinker/tconstruct/TConstruct.java index acda22b6..b5f24ee5 100644 --- a/tinker/tconstruct/TConstruct.java +++ b/tinker/tconstruct/TConstruct.java @@ -8,9 +8,8 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; -import tinker.tconstruct.client.gui.ToolGuiElement; import tinker.tconstruct.crafting.PatternBuilder; -import tinker.tconstruct.tools.ToolCore; +import tinker.tconstruct.worldgen.TBaseWorldGenerator; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; @@ -22,13 +21,14 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.registry.GameRegistry; /** TConstruct, the tool mod. * Craft your tools with style, then modify until the original is gone! * @author: mDiyo */ -@Mod(modid = "TConstruct", name = "TConstruct", version = "1.4.7_1.1.4") +@Mod(modid = "TConstruct", name = "TConstruct", version = "1.4.7_1.1.5") @NetworkMod(serverSideRequired = false, clientSideRequired = true, channels={"TConstruct"}, packetHandler = tinker.tconstruct.TPacketHandler.class) public class TConstruct { @@ -55,7 +55,8 @@ public class TConstruct @Init public void load(FMLInitializationEvent evt) { - //GameRegistry.registerWorldGenerator(new TBaseWorldGenerator()); + GameRegistry.registerWorldGenerator(new TBaseWorldGenerator()); + content.oreRegistry(); } @PostInit diff --git a/tinker/tconstruct/TContent.java b/tinker/tconstruct/TContent.java index de16ffd3..25ec66e8 100644 --- a/tinker/tconstruct/TContent.java +++ b/tinker/tconstruct/TContent.java @@ -7,17 +7,41 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapedOreRecipe; - import tinker.common.IPattern; -import tinker.tconstruct.blocks.*; -import tinker.tconstruct.blocks.liquids.*; -import tinker.tconstruct.client.gui.*; -import tinker.tconstruct.crafting.*; -import tinker.tconstruct.items.*; -import tinker.tconstruct.modifiers.*; -import tinker.tconstruct.tools.*; - +import tinker.tconstruct.blocks.EquipBlock; +import tinker.tconstruct.blocks.SearedBrick; +import tinker.tconstruct.blocks.TConstructBlock; +import tinker.tconstruct.blocks.ToolStationBlock; +import tinker.tconstruct.client.gui.ToolGuiElement; +import tinker.tconstruct.crafting.PatternBuilder; +import tinker.tconstruct.crafting.ToolBuilder; +import tinker.tconstruct.items.CraftingItem; +import tinker.tconstruct.items.Materials; +import tinker.tconstruct.items.Pattern; +import tinker.tconstruct.items.PatternManual; +import tinker.tconstruct.items.ToolPart; +import tinker.tconstruct.items.ToolShard; +import tinker.tconstruct.modifiers.ModBlaze; +import tinker.tconstruct.modifiers.ModBoolean; +import tinker.tconstruct.modifiers.ModDurability; +import tinker.tconstruct.modifiers.ModElectric; +import tinker.tconstruct.modifiers.ModInteger; +import tinker.tconstruct.modifiers.ModLapisBase; +import tinker.tconstruct.modifiers.ModLapisIncrease; +import tinker.tconstruct.modifiers.ModRedstone; +import tinker.tconstruct.modifiers.ModRepair; +import tinker.tconstruct.tools.Axe; +import tinker.tconstruct.tools.BattleSign; +import tinker.tconstruct.tools.Broadsword; +import tinker.tconstruct.tools.FryingPan; +import tinker.tconstruct.tools.Longsword; +import tinker.tconstruct.tools.Mattock; +import tinker.tconstruct.tools.Pickaxe; +import tinker.tconstruct.tools.Rapier; +import tinker.tconstruct.tools.Shovel; +import tinker.tconstruct.tools.ToolCore; import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; @@ -70,7 +94,6 @@ public class TContent implements IFuelHandler public static Block smeltery; public static Block heldItemBlock; - public static Block ores; public static Block lavaTank; public static Block craftedSoil; public static Block searedBrick; @@ -143,70 +166,75 @@ public class TContent implements IFuelHandler //ores = new TBaseOre(PHTools.ores, 48); //GameRegistry.registerBlock(ores, tinker.toolconstruct.blocks.TBaseOreItem.class, "TConstruct.ores"); - lavaTank = new LavaTankBlock(PHConstruct.lavaTank); + /*lavaTank = new LavaTankBlock(PHConstruct.lavaTank); GameRegistry.registerBlock(lavaTank, "LavaTank"); GameRegistry.registerTileEntity(tinker.tconstruct.logic.LavaTankLogic.class, "TConstruct.LavaTank"); smeltery = new SmelteryBlock(PHConstruct.smeltery); GameRegistry.registerBlock(smeltery, "Smeltery"); - GameRegistry.registerTileEntity(tinker.tconstruct.logic.SmelteryLogic.class, "TConstruct.Smeltery"); + GameRegistry.registerTileEntity(tinker.tconstruct.logic.SmelteryLogic.class, "TConstruct.Smeltery");*/ craftedSoil = new TConstructBlock(PHConstruct.craftedSoil, 96, Material.sand, 3.0F, 2); craftedSoil.stepSound = Block.soundGravelFootstep; GameRegistry.registerBlock(craftedSoil, tinker.tconstruct.blocks.CraftedSoilItemBlock.class, "CraftedSoil"); - searedBrick = new TConstructBlock(PHConstruct.searedBrick, 80, Material.iron, 10.0F, 1); + searedBrick = new SearedBrick(PHConstruct.searedBrick, 80, Material.iron, 10.0F, 6); GameRegistry.registerBlock(searedBrick, tinker.tconstruct.blocks.SearedBrickItemBlock.class, "SearedBrick"); MinecraftForge.setBlockHarvestLevel(searedBrick, 0, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(searedBrick, 1, "pickaxe", 4); + MinecraftForge.setBlockHarvestLevel(searedBrick, 2, "pickaxe", 4); + MinecraftForge.setBlockHarvestLevel(searedBrick, 3, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(searedBrick, 4, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(searedBrick, 5, "pickaxe", 1); - ironFlowing = new IronFlowing(PHConstruct.ironFlowing).setBlockName("liquid.ironFlow"); + /*ironFlowing = new IronFlowing(PHConstruct.ironFlowing).setBlockName("liquid.ironFlow"); GameRegistry.registerBlock(ironFlowing, "Liquid Iron Flowing"); ironStill = new IronStill(PHConstruct.ironStill).setBlockName("liquid.ironStill"); GameRegistry.registerBlock(ironStill, "Liquid Iron Still"); - goldFlowing = new GoldStill(PHConstruct.goldFlowing).setBlockName("liquid.goldFlow"); + goldFlowing = new GoldFlowing(PHConstruct.goldFlowing).setBlockName("liquid.goldFlow"); GameRegistry.registerBlock(goldFlowing, "Liquid Gold Flowing"); - goldStill = new GoldFlowing(PHConstruct.goldStill).setBlockName("liquid.goldStill"); + goldStill = new GoldStill(PHConstruct.goldStill).setBlockName("liquid.goldStill"); GameRegistry.registerBlock(goldStill, "Liquid Gold Still"); - copperFlowing = new CopperStill(PHConstruct.copperFlowing).setBlockName("liquid.copperFlow"); + copperFlowing = new CopperFlowing(PHConstruct.copperFlowing).setBlockName("liquid.copperFlow"); GameRegistry.registerBlock(copperFlowing, "Liquid copper Flowing"); - copperStill = new CopperFlowing(PHConstruct.copperStill).setBlockName("liquid.copperStill"); + copperStill = new CopperStill(PHConstruct.copperStill).setBlockName("liquid.copperStill"); GameRegistry.registerBlock(copperStill, "Liquid copper Still"); - tinFlowing = new TinStill(PHConstruct.tinFlowing).setBlockName("liquid.tinFlow"); + tinFlowing = new TinFlowing(PHConstruct.tinFlowing).setBlockName("liquid.tinFlow"); GameRegistry.registerBlock(tinFlowing, "Liquid tin Flowing"); - tinStill = new TinFlowing(PHConstruct.tinStill).setBlockName("liquid.tinStill"); + tinStill = new TinStill(PHConstruct.tinStill).setBlockName("liquid.tinStill"); GameRegistry.registerBlock(tinStill, "Liquid tin Still"); - aluminumFlowing = new AluminumStill(PHConstruct.aluminumFlowing).setBlockName("liquid.aluminumFlow"); + aluminumFlowing = new AluminumFlowing(PHConstruct.aluminumFlowing).setBlockName("liquid.aluminumFlow"); GameRegistry.registerBlock(aluminumFlowing, "Liquid aluminum Flowing"); - aluminumStill = new AluminumFlowing(PHConstruct.aluminumStill).setBlockName("liquid.aluminumStill"); + aluminumStill = new AluminumStill(PHConstruct.aluminumStill).setBlockName("liquid.aluminumStill"); GameRegistry.registerBlock(aluminumStill, "Liquid aluminum Still"); - cobaltFlowing = new CobaltStill(PHConstruct.cobaltFlowing).setBlockName("liquid.cobaltFlow"); + cobaltFlowing = new CobaltFlowing(PHConstruct.cobaltFlowing).setBlockName("liquid.cobaltFlow"); GameRegistry.registerBlock(cobaltFlowing, "Liquid cobalt Flowing"); - cobaltStill = new CobaltFlowing(PHConstruct.cobaltStill).setBlockName("liquid.cobaltStill"); + cobaltStill = new CobaltStill(PHConstruct.cobaltStill).setBlockName("liquid.cobaltStill"); GameRegistry.registerBlock(cobaltStill, "Liquid cobalt Still"); - arditeFlowing = new ArditeStill(PHConstruct.arditeFlowing).setBlockName("liquid.arditeFlow"); + arditeFlowing = new ArditeFlowing(PHConstruct.arditeFlowing).setBlockName("liquid.arditeFlow"); GameRegistry.registerBlock(arditeFlowing, "Liquid ardite Flowing"); - arditeStill = new ArditeFlowing(PHConstruct.arditeStill).setBlockName("liquid.arditeStill"); + arditeStill = new ArditeStill(PHConstruct.arditeStill).setBlockName("liquid.arditeStill"); GameRegistry.registerBlock(arditeStill, "Liquid ardite Still"); - bronzeFlowing = new BronzeStill(PHConstruct.bronzeFlowing).setBlockName("liquid.bronzeFlow"); + bronzeFlowing = new BronzeFlowing(PHConstruct.bronzeFlowing).setBlockName("liquid.bronzeFlow"); GameRegistry.registerBlock(bronzeFlowing, "Liquid bronze Flowing"); - bronzeStill = new BronzeFlowing(PHConstruct.bronzeStill).setBlockName("liquid.bronzeStill"); + bronzeStill = new BronzeStill(PHConstruct.bronzeStill).setBlockName("liquid.bronzeStill"); GameRegistry.registerBlock(bronzeStill, "Liquid bronze Still"); - brassFlowing = new BrassStill(PHConstruct.brassFlowing).setBlockName("liquid.brassFlow"); + brassFlowing = new BrassFlowing(PHConstruct.brassFlowing).setBlockName("liquid.brassFlow"); GameRegistry.registerBlock(brassFlowing, "Liquid brass Flowing"); - brassStill = new BrassFlowing(PHConstruct.brassStill).setBlockName("liquid.brassStill"); + brassStill = new BrassStill(PHConstruct.brassStill).setBlockName("liquid.brassStill"); GameRegistry.registerBlock(brassStill, "Liquid brass Still"); - manyullynFlowing = new ManyullynStill(PHConstruct.manyullynFlowing).setBlockName("liquid.manyullynFlow"); + manyullynFlowing = new ManyullynFlowing(PHConstruct.manyullynFlowing).setBlockName("liquid.manyullynFlow"); GameRegistry.registerBlock(manyullynFlowing, "Liquid manyullyn Flowing"); - manyullynStill = new ManyullynFlowing(PHConstruct.manyullynStill).setBlockName("liquid.manyullynStill"); + manyullynStill = new ManyullynStill(PHConstruct.manyullynStill).setBlockName("liquid.manyullynStill"); GameRegistry.registerBlock(manyullynStill, "Liquid manyullun Still"); - alumiteFlowing = new AlumiteStill(PHConstruct.alumiteFlowing).setBlockName("liquid.alumiteFlow"); + alumiteFlowing = new AlumiteFlowing(PHConstruct.alumiteFlowing).setBlockName("liquid.alumiteFlow"); GameRegistry.registerBlock(alumiteFlowing, "Liquid alumite Flowing"); - alumiteStill = new AlumiteFlowing(PHConstruct.alumiteStill).setBlockName("liquid.alumiteStill"); + alumiteStill = new AlumiteStill(PHConstruct.alumiteStill).setBlockName("liquid.alumiteStill"); GameRegistry.registerBlock(alumiteStill, "Liquid alumite Still"); - obsidianFlowing = new ObsidianStill(PHConstruct.obsidianFlowing).setBlockName("liquid.obsidianFlow"); + obsidianFlowing = new ObsidianFlowing(PHConstruct.obsidianFlowing).setBlockName("liquid.obsidianFlow"); GameRegistry.registerBlock(obsidianFlowing, "Liquid obsidian Flowing"); - obsidianStill = new ObsidianFlowing(PHConstruct.obsidianStill).setBlockName("liquid.obsidianStill"); - GameRegistry.registerBlock(obsidianStill, "Liquid obsidian Still"); + obsidianStill = new ObsidianStill(PHConstruct.obsidianStill).setBlockName("liquid.obsidianStill"); + GameRegistry.registerBlock(obsidianStill, "Liquid obsidian Still");*/ } void createItems () @@ -232,7 +260,7 @@ public class TContent implements IFuelHandler battlesign = new BattleSign(PHConstruct.battlesign, signTexture); //longbow = new RangedWeapon(PHConstruct.longbow, bowTexture); mattock = new Mattock(PHConstruct.mattock, mattockTexture); - lumberaxe = new LumberAxe(PHConstruct.lumberaxe, lumberaxeTexture); + //lumberaxe = new LumberAxe(PHConstruct.lumberaxe, lumberaxeTexture); pickaxeHead = new ToolPart(PHConstruct.pickaxeHead, 0, baseHeads).setItemName("tconstruct.PickaxeHead"); shovelHead = new ToolPart(PHConstruct.shovelHead, 64, baseHeads).setItemName("tconstruct.ShovelHead"); @@ -382,7 +410,7 @@ public class TContent implements IFuelHandler void addSmelteryRecipes() { - Smeltery.instance.addSmelting(Block.oreIron.blockID, 0, 35, new ItemStack(Item.ingotIron, 1, 0)); + //Smeltery.instance.addSmelting(Block.oreIron.blockID, 0, 450, new ItemStack(ironStill, 1, 0)); } void addCraftingRecipes () @@ -418,6 +446,12 @@ public class TContent implements IFuelHandler FurnaceRecipes.smelting().addSmelting(craftedSoil.blockID, 0, new ItemStack(materials, 1, 1), 2f); //Slime FurnaceRecipes.smelting().addSmelting(craftedSoil.blockID, 1, new ItemStack(materials, 1, 2), 2f); //Seared brick item GameRegistry.addRecipe(new ItemStack(searedBrick, 1, 0), "pp", "pp", 'p', new ItemStack(materials, 1, 2)); //Seared brick block + + FurnaceRecipes.smelting().addSmelting(searedBrick.blockID, 1, new ItemStack(materials, 1, 3), 3f); + FurnaceRecipes.smelting().addSmelting(searedBrick.blockID, 2, new ItemStack(materials, 1, 4), 3f); + FurnaceRecipes.smelting().addSmelting(searedBrick.blockID, 3, new ItemStack(materials, 1, 9), 0.5f); + FurnaceRecipes.smelting().addSmelting(searedBrick.blockID, 4, new ItemStack(materials, 1, 10), 0.5f); + FurnaceRecipes.smelting().addSmelting(searedBrick.blockID, 5, new ItemStack(materials, 1, 12), 0.5f); /*for (int i = 0; i < 12; i++) { @@ -493,6 +527,23 @@ public class TContent implements IFuelHandler { TConstructRegistry.toolButtons.add(new ToolGuiElement(slotType, xButton, yButton, xIcons, yIcons, title, body)); } + + public void oreRegistry () + { + OreDictionary.registerOre("oreCobalt", new ItemStack(searedBrick, 1, 1)); + OreDictionary.registerOre("oreArdite", new ItemStack(searedBrick, 1, 2)); + OreDictionary.registerOre("oreCopper", new ItemStack(searedBrick, 1, 3)); + OreDictionary.registerOre("oreTin", new ItemStack(searedBrick, 1, 4)); + OreDictionary.registerOre("oreAluminum", new ItemStack(searedBrick, 1, 5)); + + OreDictionary.registerOre("ingotCobalt", new ItemStack(materials, 1, 3)); + OreDictionary.registerOre("ingotArdite", new ItemStack(materials, 1, 4)); + OreDictionary.registerOre("ingotManyullyn", new ItemStack(materials, 1, 5)); + OreDictionary.registerOre("ingotCopper", new ItemStack(materials, 1, 9)); + OreDictionary.registerOre("ingotTin", new ItemStack(materials, 1, 10)); + OreDictionary.registerOre("ingotAluminum", new ItemStack(materials, 1, 11)); + OreDictionary.registerOre("rawAluminum", new ItemStack(materials, 1, 12)); + } public void modIntegration () { diff --git a/tinker/tconstruct/blocks/SearedBrick.java b/tinker/tconstruct/blocks/SearedBrick.java new file mode 100644 index 00000000..325044ef --- /dev/null +++ b/tinker/tconstruct/blocks/SearedBrick.java @@ -0,0 +1,22 @@ +package tinker.tconstruct.blocks; + +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +public class SearedBrick extends TConstructBlock +{ + public SearedBrick(int id, int tex, Material material, float hardness, int sub) + { + super(id, tex, material, hardness, sub); + } + + public float getBlockHardness (World world, int x, int y, int z) + { + int meta = world.getBlockMetadata(x, y, z); + if (meta <= 2) + return 10f; + else + return 3f; + //return this.blockHardness; + } +} diff --git a/tinker/tconstruct/blocks/SearedBrickItemBlock.java b/tinker/tconstruct/blocks/SearedBrickItemBlock.java index ce5cf137..88bd3f50 100644 --- a/tinker/tconstruct/blocks/SearedBrickItemBlock.java +++ b/tinker/tconstruct/blocks/SearedBrickItemBlock.java @@ -7,7 +7,7 @@ public class SearedBrickItemBlock extends ItemBlock { public static final String blockType[] = { - "Brick" + "Brick", "Cobalt", "Ardite", "Copper", "Tin", "Aluminum", "Slag" }; public SearedBrickItemBlock(int id) diff --git a/tinker/tconstruct/blocks/SmelteryBlock.java b/tinker/tconstruct/blocks/SmelteryBlock.java index 047361db..e42069fe 100644 --- a/tinker/tconstruct/blocks/SmelteryBlock.java +++ b/tinker/tconstruct/blocks/SmelteryBlock.java @@ -14,6 +14,7 @@ import tinker.common.InventoryLogic; import tinker.tconstruct.TConstruct; import tinker.tconstruct.TContent; import tinker.tconstruct.TGuiHandler; +import tinker.tconstruct.client.SmelteryRender; import tinker.tconstruct.logic.SmelteryLogic; public class SmelteryBlock extends InventoryBlock @@ -30,6 +31,12 @@ public class SmelteryBlock extends InventoryBlock this.setCreativeTab(TConstruct.blockTab); this.setBlockName("tconstruct.Smeltery"); } + + @Override + public int getRenderType () + { + return SmelteryRender.smelteryModel; + } public String getTextureFile () { diff --git a/tinker/tconstruct/blocks/liquids/IronStill.java b/tinker/tconstruct/blocks/liquids/IronStill.java index f7a560c2..a0f8de8b 100644 --- a/tinker/tconstruct/blocks/liquids/IronStill.java +++ b/tinker/tconstruct/blocks/liquids/IronStill.java @@ -8,7 +8,6 @@ public class IronStill extends LiquidMetalStill public IronStill(int id) { super(id); - //blockIndexInTexture = 128; } @Override diff --git a/tinker/tconstruct/blocks/liquids/LiquidMetalFlowing.java b/tinker/tconstruct/blocks/liquids/LiquidMetalFlowing.java index 96751d61..fa78cc7f 100644 --- a/tinker/tconstruct/blocks/liquids/LiquidMetalFlowing.java +++ b/tinker/tconstruct/blocks/liquids/LiquidMetalFlowing.java @@ -13,15 +13,12 @@ import net.minecraftforge.liquids.ILiquid; public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid { - - int numAdjacentSources = 0; boolean isOptimalFlowDirection[] = new boolean[4]; int flowCost[] = new int[4]; public LiquidMetalFlowing(int id) { super(id, Material.lava); - setHardness(100F); } @Override @@ -38,34 +35,35 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid private void updateFlow (World world, int x, int y, int z) { - int l = world.getBlockMetadata(x, y, z); - world.setBlockAndMetadata(x, y, z, stillLiquidId(), l); + //System.out.println("x: "+x+", y: "+y+", z: "+z); + int meta = world.getBlockMetadata(x, y, z); + world.setBlockAndMetadata(x, y, z, stillLiquidId(), meta); world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); world.markBlockForUpdate(x, y, z); } @Override - public void updateTick (World world, int i, int j, int k, Random random) + public void updateTick (World world, int x, int y, int z, Random random) { - int l = getFlowDecay(world, i, j, k); + //System.out.println("x: "+x+", y: "+y+", z: "+z); + int l = getFlowDecay(world, x, y, z); byte byte0 = 1; boolean flag = true; if (l > 0) { int i1 = -100; - numAdjacentSources = 0; - i1 = getSmallestFlowDecay(world, i - 1, j, k, i1); - i1 = getSmallestFlowDecay(world, i + 1, j, k, i1); - i1 = getSmallestFlowDecay(world, i, j, k - 1, i1); - i1 = getSmallestFlowDecay(world, i, j, k + 1, i1); + i1 = getSmallestFlowDecay(world, x - 1, y, z, i1); + i1 = getSmallestFlowDecay(world, x + 1, y, z, i1); + i1 = getSmallestFlowDecay(world, x, y, z - 1, i1); + i1 = getSmallestFlowDecay(world, x, y, z + 1, i1); int j1 = i1 + byte0; if (j1 >= 8 || i1 < 0) { j1 = -1; } - if (getFlowDecay(world, i, j + 1, k) >= 0) + if (getFlowDecay(world, x, y + 1, z) >= 0) { - int l1 = getFlowDecay(world, i, j + 1, k); + int l1 = getFlowDecay(world, x, y + 1, z); if (l1 >= 8) { j1 = l1; @@ -80,38 +78,38 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid l = j1; if (l < 0) { - world.setBlockWithNotify(i, j, k, 0); + world.setBlockWithNotify(x, y, z, 0); } else { - world.setBlockMetadataWithNotify(i, j, k, l); - world.scheduleBlockUpdate(i, j, k, blockID, tickRate()); - world.notifyBlocksOfNeighborChange(i, j, k, blockID); + world.setBlockMetadataWithNotify(x, y, z, l); + world.scheduleBlockUpdate(x, y, z, blockID, tickRate()); + world.notifyBlocksOfNeighborChange(x, y, z, blockID); } } else if (flag) { - updateFlow(world, i, j, k); + updateFlow(world, x, y, z); } } else { - updateFlow(world, i, j, k); + updateFlow(world, x, y, z); } - if (liquidCanDisplaceBlock(world, i, j - 1, k)) + if (liquidCanDisplaceBlock(world, x, y - 1, z)) { if (l >= 8) { - world.setBlockAndMetadataWithNotify(i, j - 1, k, blockID, l); + world.setBlockAndMetadataWithNotify(x, y - 1, z, blockID, l); } else { - world.setBlockAndMetadataWithNotify(i, j - 1, k, blockID, l + 8); + world.setBlockAndMetadataWithNotify(x, y - 1, z, blockID, l + 8); } } - else if (l >= 0 && (l == 0 || blockBlocksFlow(world, i, j - 1, k))) + else if (l >= 0 && (l == 0 || blockBlocksFlow(world, x, y - 1, z))) { - boolean aflag[] = getOptimalFlowDirections(world, i, j, k); + boolean aflag[] = getOptimalFlowDirections(world, x, y, z); int k1 = l + byte0; if (l >= 8) { @@ -121,37 +119,37 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid return; if (aflag[0]) { - flowIntoBlock(world, i - 1, j, k, k1); + flowIntoBlock(world, x - 1, y, z, k1); } if (aflag[1]) { - flowIntoBlock(world, i + 1, j, k, k1); + flowIntoBlock(world, x + 1, y, z, k1); } if (aflag[2]) { - flowIntoBlock(world, i, j, k - 1, k1); + flowIntoBlock(world, x, y, z - 1, k1); } if (aflag[3]) { - flowIntoBlock(world, i, j, k + 1, k1); + flowIntoBlock(world, x, y, z + 1, k1); } } } - private void flowIntoBlock (World world, int i, int j, int k, int l) + private void flowIntoBlock (World world, int x, int y, int z, int meta) { - if (liquidCanDisplaceBlock(world, i, j, k)) + if (liquidCanDisplaceBlock(world, x, y, z)) { - int i1 = world.getBlockId(i, j, k); - if (i1 > 0) + int bID = world.getBlockId(x, y, z); + if (bID > 0) { - Block.blocksList[i1].dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0); + Block.blocksList[bID].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); } - world.setBlockAndMetadataWithNotify(i, j, k, blockID, l); + world.setBlockAndMetadataWithNotify(x, y, z, blockID, meta); } } - private int calculateFlowCost (World world, int i, int j, int k, int l, int i1) + private int calculateFlowCost (World world, int x, int y, int z, int l, int i1) { int j1 = 1000; for (int k1 = 0; k1 < 4; k1++) @@ -160,36 +158,36 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid { continue; } - int l1 = i; - int i2 = j; - int j2 = k; + int posX = x; + int posY = y; + int posZ = z; if (k1 == 0) { - l1--; + posX--; } if (k1 == 1) { - l1++; + posX++; } if (k1 == 2) { - j2--; + posZ--; } if (k1 == 3) { - j2++; + posZ++; } - if (blockBlocksFlow(world, l1, i2, j2) || world.getBlockMaterial(l1, i2, j2) == blockMaterial && world.getBlockMetadata(l1, i2, j2) == 0) + if (blockBlocksFlow(world, posX, posY, posZ) || world.getBlockMaterial(posX, posY, posZ) == blockMaterial && world.getBlockMetadata(posX, posY, posZ) == 0) { continue; } - if (!blockBlocksFlow(world, l1, i2 - 1, j2)) + if (!blockBlocksFlow(world, posX, posY - 1, posZ)) return l; if (l >= 4) { continue; } - int k2 = calculateFlowCost(world, l1, i2, j2, l + 1, k1); + int k2 = calculateFlowCost(world, posX, posY, posZ, l + 1, k1); if (k2 < j1) { j1 = k2; @@ -201,54 +199,54 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid private boolean[] getOptimalFlowDirections (World world, int x, int y, int z) { - for (int l = 0; l < 4; l++) + for (int iter = 0; iter < 4; iter++) { - flowCost[l] = 1000; - int j1 = x; - int i2 = y; - int j2 = z; - if (l == 0) + flowCost[iter] = 1000; + int posX = x; + int posY = y; + int posZ = z; + if (iter == 0) { - j1--; + posX--; } - if (l == 1) + if (iter == 1) { - j1++; + posX++; } - if (l == 2) + if (iter == 2) { - j2--; + posZ--; } - if (l == 3) + if (iter == 3) { - j2++; + posZ++; } - if (blockBlocksFlow(world, j1, i2, j2) || world.getBlockMaterial(j1, i2, j2) == blockMaterial && world.getBlockMetadata(j1, i2, j2) == 0) + if (blockBlocksFlow(world, posX, posY, posZ) || world.getBlockMaterial(posX, posY, posZ) == blockMaterial && world.getBlockMetadata(posX, posY, posZ) == 0) { continue; } - if (!blockBlocksFlow(world, j1, i2 - 1, j2)) + if (!blockBlocksFlow(world, posX, posY - 1, posZ)) { - flowCost[l] = 0; + flowCost[iter] = 0; } else { - flowCost[l] = calculateFlowCost(world, j1, i2, j2, 1, l); + flowCost[iter] = calculateFlowCost(world, posX, posY, posZ, 1, iter); } } - int i1 = flowCost[0]; + int cost = flowCost[0]; for (int k1 = 1; k1 < 4; k1++) { - if (flowCost[k1] < i1) + if (flowCost[k1] < cost) { - i1 = flowCost[k1]; + cost = flowCost[k1]; } } for (int l1 = 0; l1 < 4; l1++) { - isOptimalFlowDirection[l1] = flowCost[l1] == i1; + isOptimalFlowDirection[l1] = flowCost[l1] == cost; } return isOptimalFlowDirection; @@ -265,9 +263,9 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid return material.isSolid(); } - protected int getSmallestFlowDecay (World world, int i, int j, int k, int l) + protected int getSmallestFlowDecay (World world, int x, int y, int z, int l) { - int i1 = getFlowDecay(world, i, j, k); + int i1 = getFlowDecay(world, x, y, z); if (i1 < 0) return l; if (i1 >= 8) @@ -277,22 +275,23 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid return l >= 0 && i1 >= l ? l : i1; } - private boolean liquidCanDisplaceBlock (World world, int i, int j, int k) + private boolean liquidCanDisplaceBlock (World world, int x, int y, int z) { - Material material = world.getBlockMaterial(i, j, k); + Material material = world.getBlockMaterial(x, y, z); if (material == blockMaterial) return false; else - return !blockBlocksFlow(world, i, j, k); + return !blockBlocksFlow(world, x, y, z); } @Override - public void onBlockAdded (World world, int i, int j, int k) + public void onBlockAdded (World world, int x, int y, int z) { - super.onBlockAdded(world, i, j, k); - if (world.getBlockId(i, j, k) == blockID) + //System.out.println("x: "+x+", y: "+y+", z: "+z); + super.onBlockAdded(world, x, y, z); + if (world.getBlockId(x, y, z) == blockID) { - world.scheduleBlockUpdate(i, j, k, blockID, tickRate()); + world.scheduleBlockUpdate(x, y, z, blockID, tickRate()); } } @@ -307,11 +306,4 @@ public abstract class LiquidMetalFlowing extends BlockFluid implements ILiquid { return false; } - - @Override - public boolean isBlockReplaceable (World world, int i, int j, int k) - { - return true; - } - } diff --git a/tinker/tconstruct/blocks/liquids/LiquidMetalStill.java b/tinker/tconstruct/blocks/liquids/LiquidMetalStill.java index b7c9fee5..d17052b8 100644 --- a/tinker/tconstruct/blocks/liquids/LiquidMetalStill.java +++ b/tinker/tconstruct/blocks/liquids/LiquidMetalStill.java @@ -131,15 +131,14 @@ public abstract class LiquidMetalStill extends BlockStationary implements ILiqui } } - private void unsetStationary(World par1World, int par2, int par3, int par4) + private void unsetStationary(World world, int x, int y, int z) { - System.out.println("unsetStationary"); - int var5 = par1World.getBlockMetadata(par2, par3, par4); - par1World.editingBlocks = true; - par1World.setBlockAndMetadata(par2, par3, par4, flowingLiquidID(), var5); - par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); - par1World.scheduleBlockUpdate(par2, par3, par4, flowingLiquidID(), this.tickRate()); - par1World.editingBlocks = false; + int meta = world.getBlockMetadata(x, y, z); + world.editingBlocks = true; + world.setBlockAndMetadata(x, y, z, flowingLiquidID(), meta); + world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); + world.scheduleBlockUpdate(x, y, z, flowingLiquidID(), this.tickRate()); + world.editingBlocks = false; } /*@Override diff --git a/tinker/tconstruct/client/SmelteryRender.java b/tinker/tconstruct/client/SmelteryRender.java new file mode 100644 index 00000000..491fbe5e --- /dev/null +++ b/tinker/tconstruct/client/SmelteryRender.java @@ -0,0 +1,93 @@ +package tinker.tconstruct.client; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.client.ForgeHooksClient; + +import org.lwjgl.opengl.GL11; + +import tinker.tconstruct.logic.SmelteryLogic; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; + +public class SmelteryRender implements ISimpleBlockRenderingHandler +{ + public static int smelteryModel = RenderingRegistry.getNextAvailableRenderId(); + @Override + public void renderInventoryBlock (Block block, int metadata, int modelID, RenderBlocks renderer) + { + if (modelID == smelteryModel) + { + renderDo(renderer, block, metadata); + } + } + + @Override + public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block block, int modelID, RenderBlocks renderer) + { + if (modelID == smelteryModel) + { + renderer.renderStandardBlock(block, x, y, z); + SmelteryLogic logic = (SmelteryLogic) world.getBlockTileEntity(x, y, z); + if (logic.validStructure) + { + int posX = logic.centerPos.x - 1, posY = logic.centerPos.y, posZ = logic.centerPos.z - 1; + for (int i = 0; i < 9; i++) + { + if (logic.isStackInSlot(i)) + { + Block invBlock = Block.blocksList[logic.getStackInSlot(i).itemID]; + ForgeHooksClient.bindTexture(invBlock.getTextureFile(), 0); + renderer.renderStandardBlock(invBlock, posX + i % 3, posY, posZ + i / 3); + } + } + } + } + return false; + } + + @Override + public boolean shouldRender3DInInventory () + { + return true; + } + + @Override + public int getRenderId () + { + return smelteryModel; + } + + private void renderDo(RenderBlocks renderblocks, Block block, int meta) + { + Tessellator tessellator = Tessellator.instance; + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1F, 0.0F); + renderblocks.renderBottomFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(0, meta)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + renderblocks.renderTopFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(1, meta)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1F); + renderblocks.renderEastFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(2, meta)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + renderblocks.renderWestFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(3, meta)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(-1F, 0.0F, 0.0F); + renderblocks.renderNorthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(4, meta)); + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + renderblocks.renderSouthFace(block, 0.0D, 0.0D, 0.0D, block.getBlockTextureFromSideAndMetadata(5, meta)); + tessellator.draw(); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } +} diff --git a/tinker/tconstruct/client/TProxyClient.java b/tinker/tconstruct/client/TProxyClient.java index 595aee13..be1a1e91 100644 --- a/tinker/tconstruct/client/TProxyClient.java +++ b/tinker/tconstruct/client/TProxyClient.java @@ -31,12 +31,13 @@ public class TProxyClient extends TProxyCommon Minecraft mc = Minecraft.getMinecraft(); smallFontRenderer = new SmallFontRenderer(mc.gameSettings, "/font/default.png", mc.renderEngine, false); RenderingRegistry.registerBlockHandler(new TableRender()); + RenderingRegistry.registerBlockHandler(new SmelteryRender()); RenderingRegistry.registerBlockHandler(new TankRender()); RenderingRegistry.registerBlockHandler(new FrypanRender()); RenderingRegistry.registerBlockHandler(new RenderLiquidMetal()); //RenderingRegistry.registerBlockHandler(new AxleRender()); - RenderEngine renderEngine = FMLClientHandler.instance().getClient().renderEngine; + /*RenderEngine renderEngine = FMLClientHandler.instance().getClient().renderEngine; renderEngine.registerTextureFX(new LiquidIronFX()); renderEngine.registerTextureFX(new LiquidIronFlowFX()); renderEngine.registerTextureFX(new LiquidGoldFX()); @@ -60,7 +61,7 @@ public class TProxyClient extends TProxyCommon renderEngine.registerTextureFX(new LiquidAlumiteFX()); renderEngine.registerTextureFX(new LiquidAlumiteFlowFX()); renderEngine.registerTextureFX(new LiquidObsidianFX()); - renderEngine.registerTextureFX(new LiquidObsidianFlowFX()); + renderEngine.registerTextureFX(new LiquidObsidianFlowFX());*/ //Tools MinecraftForgeClient.preloadTexture(TContent.blockTexture); @@ -79,7 +80,7 @@ public class TProxyClient extends TProxyCommon /* Ties an internal name to a visible one. */ public void addNames() { - LanguageRegistry.addName(TContent.lavaTank, "Lava Tank"); + //LanguageRegistry.addName(TContent.lavaTank, "Lava Tank"); LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructTools", "TConstruct Tools"); LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructMaterials", "TConstruct Materials"); LanguageRegistry.instance().addStringLocalization("itemGroup.TConstructBlocks", "TConstruct Blocks"); @@ -99,6 +100,12 @@ public class TProxyClient extends TProxyCommon LanguageRegistry.instance().addStringLocalization("CraftedSoil.Slime.name", "Slimy Mud"); LanguageRegistry.instance().addStringLocalization("CraftedSoil.Grout.name", "Grout"); LanguageRegistry.instance().addStringLocalization("SearedBrick.Brick.name", "Seared Bricks"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Cobalt.name", "Cobalt Ore"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Ardite.name", "Ardite Ore"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Copper.name", "Copper Ore"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Tin.name", "Tin Ore"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Aluminum.name", "Aluminum Ore"); + LanguageRegistry.instance().addStringLocalization("SearedBrick.Slag.name", "Slag"); for (int mat = 0; mat < materialTypes.length; mat++) { @@ -131,7 +138,7 @@ public class TProxyClient extends TProxyCommon LanguageRegistry.instance().addStringLocalization(internalName, "en_US", visibleName); } - LanguageRegistry.addName(TContent.smeltery, "Smeltery"); + //LanguageRegistry.addName(TContent.smeltery, "Smeltery"); LanguageRegistry.addName(TContent.manualBook, "Tinker's Log"); LanguageRegistry.addName(TContent.blankPattern, "Blank Pattern"); LanguageRegistry.addName(TContent.pickaxe, "Pickaxe"); @@ -143,9 +150,9 @@ public class TProxyClient extends TProxyCommon LanguageRegistry.addName(TContent.frypan, "Frying Pan"); LanguageRegistry.addName(TContent.battlesign, "Battlesign"); LanguageRegistry.addName(TContent.mattock, "Mattock"); - LanguageRegistry.addName(TContent.lumberaxe, "Lumber Axe"); + //LanguageRegistry.addName(TContent.lumberaxe, "Lumber Axe"); - LanguageRegistry.addName(TContent.ironFlowing, "Liquid Iron"); + /*LanguageRegistry.addName(TContent.ironFlowing, "Liquid Iron"); LanguageRegistry.addName(TContent.ironStill, "Liquid Iron"); LanguageRegistry.addName(TContent.goldFlowing, "Liquid Gold"); LanguageRegistry.addName(TContent.goldStill, "Liquid Gold"); @@ -169,7 +176,7 @@ public class TProxyClient extends TProxyCommon LanguageRegistry.addName(TContent.manyullynFlowing, "Liquid Manyullyn"); LanguageRegistry.addName(TContent.manyullynStill, "Liquid Manyullyn"); LanguageRegistry.addName(TContent.obsidianFlowing, "Liquid Obsidian"); - LanguageRegistry.addName(TContent.obsidianStill, "Liquid Obsidian"); + LanguageRegistry.addName(TContent.obsidianStill, "Liquid Obsidian");*/ } @@ -178,10 +185,12 @@ public class TProxyClient extends TProxyCommon "Cobalt Chunk", "Ardite Chunk", "Manyullyn Chunk", "Copper Chunk", "Bronze Chunk" }; public static final String[] materialItemInternalNames = new String[] { - "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot", "Mossball", "LavaCrystal", "NecroticBone" }; + "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot", "Mossball", "LavaCrystal", "NecroticBone", + "CopperIngot", "TinIngot", "AluminumIngot", "RawAluminum" }; public static final String[] materialItemNames = new String[] { - "Paper Stack", "Slime Crystal", "Seared Brick", "Cobalt Ingot", "Ardite Ingot", "Manyullyn Ingot", "Ball of Moss", "Lava Crystal", "Necrotic Bone" }; + "Paper Stack", "Slime Crystal", "Seared Brick", "Cobalt Ingot", "Ardite Ingot", "Manyullyn Ingot", "Ball of Moss", "Lava Crystal", "Necrotic Bone", + "Copper Ingot", "Tin Ingot", "Aluminum Ingot", "Raw Aluminum"}; public static final String[] toolMaterialNames = new String[] { "Wood", "Stone", "Iron", "Flint", "Cactus", "Bone", "Obsidian", "Netherrack", "Slime", "Paper", "Cobalt", "Ardite", "Manyullyn", "Copper", "Bronze" }; @@ -229,8 +238,8 @@ public class TProxyClient extends TProxyCommon { switch (stack.getItemDamage()) { - case 1: return diary; - case 0: return volume1; + case 0: return diary; + case 1: return volume1; } return null; diff --git a/tinker/tconstruct/client/entityrender/SkylaModel.java b/tinker/tconstruct/client/entityrender/SkylaModel.java index e20b20a6..cc2dcd9c 100644 --- a/tinker/tconstruct/client/entityrender/SkylaModel.java +++ b/tinker/tconstruct/client/entityrender/SkylaModel.java @@ -3,6 +3,7 @@ package tinker.tconstruct.client.entityrender; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; +import tinker.tconstruct.client.tmt.ModelRendererTurbo; public class SkylaModel extends ModelBase { @@ -39,6 +40,7 @@ public class SkylaModel extends ModelBase Head = new ModelRenderer(this, 0, 0); Head.addBox(-4F, -8F, -4F, 8, 8, 8); + //Head.addCylinder(0, 0, 0, 8, 16, 24, 0, ModelRendererTurbo.MR_BOTTOM); Head.setRotationPoint(0F, -3F, 0F); setRotation(Head, 0F, 0F, 0F); @@ -194,24 +196,10 @@ public class SkylaModel extends ModelBase Breast.render(f5); RightArm.render(f5); LeftArm.render(f5); - //RightHand.render(f5); - //LeftHand.render(f5); RightLeg.render(f5); LeftLeg.render(f5); - //RightFoot.render(f5); - //LeftFoot.render(f5); WingBaseRight.render(f5); - //WingEdgeRight.render(f5); - //WingInsetRight.render(f5); - //WingCenterRight.render(f5); - //WingFlangeRight.render(f5); - //WingAuxRight.render(f5); WingBaseLeft.render(f5); - //WingEdgeLeft.render(f5); - //WingInsetLeft.render(f5); - //WingCenterLeft.render(f5); - //WingFlangeLeft.render(f5); - //WingAuxLeft.render(f5); } private void setRotation (ModelRenderer model, float x, float y, float z) diff --git a/tinker/tconstruct/client/liquidrender/LiquidAluminumFX.java b/tinker/tconstruct/client/liquidrender/LiquidAluminumFX.java index 095734d4..aa61e8a0 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidAluminumFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidAluminumFX.java @@ -6,6 +6,6 @@ public class LiquidAluminumFX extends TextureLiquidStillFX { public LiquidAluminumFX() { - super(140, 255, 70, 150, 70, 150, TContent.aluminumStill.blockIndexInTexture, TContent.aluminumStill.getTextureFile()); + super(140, 255, 30, 190, 30, 190, TContent.aluminumStill.blockIndexInTexture, TContent.aluminumStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidAluminumFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidAluminumFlowFX.java index 4ea72ff9..2964925f 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidAluminumFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidAluminumFlowFX.java @@ -6,6 +6,6 @@ public class LiquidAluminumFlowFX extends TextureLiquidFlowingFX { public LiquidAluminumFlowFX() { - super(140, 255, 70, 150, 70, 150, TContent.aluminumFlowing.blockIndexInTexture+1, TContent.aluminumFlowing.getTextureFile()); + super(140, 255, 30, 190, 30, 190, TContent.aluminumFlowing.blockIndexInTexture+1, TContent.aluminumFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidArditeFX.java b/tinker/tconstruct/client/liquidrender/LiquidArditeFX.java index b693621d..dde763d6 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidArditeFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidArditeFX.java @@ -6,6 +6,6 @@ public class LiquidArditeFX extends TextureLiquidStillFX { public LiquidArditeFX() { - super(0, 180, 0, 140, 0, 50, TContent.arditeStill.blockIndexInTexture, TContent.arditeStill.getTextureFile()); + super(10, 250, 10, 150, 10, 50, TContent.arditeStill.blockIndexInTexture, TContent.arditeStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidArditeFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidArditeFlowFX.java index ed6a8761..ce1e16f8 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidArditeFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidArditeFlowFX.java @@ -6,6 +6,6 @@ public class LiquidArditeFlowFX extends TextureLiquidFlowingFX { public LiquidArditeFlowFX() { - super(0, 180, 0, 140, 0, 50, TContent.arditeFlowing.blockIndexInTexture+1, TContent.arditeFlowing.getTextureFile()); + super(10, 250, 10, 150, 10, 50, TContent.arditeFlowing.blockIndexInTexture+1, TContent.arditeFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidBronzeFX.java b/tinker/tconstruct/client/liquidrender/LiquidBronzeFX.java index e74e81ed..00ef890f 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidBronzeFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidBronzeFX.java @@ -6,6 +6,6 @@ public class LiquidBronzeFX extends TextureLiquidStillFX { public LiquidBronzeFX() { - super(140, 220, 70, 220, 10, 40, TContent.bronzeStill.blockIndexInTexture, TContent.arditeStill.getTextureFile()); + super(0, 180, 0, 140, 0, 50, TContent.bronzeStill.blockIndexInTexture, TContent.arditeStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidBronzeFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidBronzeFlowFX.java index d614270b..edff362e 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidBronzeFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidBronzeFlowFX.java @@ -6,6 +6,6 @@ public class LiquidBronzeFlowFX extends TextureLiquidFlowingFX { public LiquidBronzeFlowFX() { - super(140, 220, 70, 220, 10, 40, TContent.bronzeFlowing.blockIndexInTexture+1, TContent.arditeFlowing.getTextureFile()); + super(0, 180, 0, 140, 0, 50, TContent.bronzeFlowing.blockIndexInTexture+1, TContent.arditeFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidCopperFX.java b/tinker/tconstruct/client/liquidrender/LiquidCopperFX.java index a1d3de5c..8d090e25 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidCopperFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidCopperFX.java @@ -6,6 +6,6 @@ public class LiquidCopperFX extends TextureLiquidStillFX { public LiquidCopperFX() { - super(180, 255, 100, 255, 10, 40, TContent.copperStill.blockIndexInTexture, TContent.copperStill.getTextureFile()); + super(220, 255, 130, 220, 0, 120, TContent.copperStill.blockIndexInTexture, TContent.copperStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidCopperFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidCopperFlowFX.java index 5da4dbfb..6fe88db0 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidCopperFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidCopperFlowFX.java @@ -6,6 +6,6 @@ public class LiquidCopperFlowFX extends TextureLiquidFlowingFX { public LiquidCopperFlowFX() { - super(180, 255, 100, 255, 10, 40, TContent.copperFlowing.blockIndexInTexture+1, TContent.copperFlowing.getTextureFile()); + super(220, 255, 130, 220, 0, 120, TContent.copperFlowing.blockIndexInTexture+1, TContent.copperFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidManyullynFX.java b/tinker/tconstruct/client/liquidrender/LiquidManyullynFX.java index e2e7c3f1..42f2e31d 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidManyullynFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidManyullynFX.java @@ -6,6 +6,6 @@ public class LiquidManyullynFX extends TextureLiquidStillFX { public LiquidManyullynFX() { - super(150, 250, 50, 120, 150, 250, TContent.manyullynStill.blockIndexInTexture, TContent.manyullynStill.getTextureFile()); + super(50, 200, 0, 40, 50, 200, TContent.manyullynStill.blockIndexInTexture, TContent.manyullynStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidManyullynFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidManyullynFlowFX.java index e71889c1..d41733c7 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidManyullynFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidManyullynFlowFX.java @@ -6,6 +6,6 @@ public class LiquidManyullynFlowFX extends TextureLiquidFlowingFX { public LiquidManyullynFlowFX() { - super(150, 250, 50, 120, 150, 250, TContent.manyullynFlowing.blockIndexInTexture+1, TContent.manyullynFlowing.getTextureFile()); + super(50, 200, 0, 40, 50, 200, TContent.manyullynFlowing.blockIndexInTexture+1, TContent.manyullynFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidObsidianFX.java b/tinker/tconstruct/client/liquidrender/LiquidObsidianFX.java index 061047c1..b098fa8f 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidObsidianFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidObsidianFX.java @@ -6,6 +6,6 @@ public class LiquidObsidianFX extends TextureLiquidStillFX { public LiquidObsidianFX() { - super(50, 200, 0, 40, 50, 200, TContent.obsidianStill.blockIndexInTexture, TContent.obsidianStill.getTextureFile()); + super(0, 120, 0, 40, 0, 120, TContent.obsidianStill.blockIndexInTexture, TContent.obsidianStill.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/LiquidObsidianFlowFX.java b/tinker/tconstruct/client/liquidrender/LiquidObsidianFlowFX.java index bdee1564..1aeb125a 100644 --- a/tinker/tconstruct/client/liquidrender/LiquidObsidianFlowFX.java +++ b/tinker/tconstruct/client/liquidrender/LiquidObsidianFlowFX.java @@ -6,6 +6,6 @@ public class LiquidObsidianFlowFX extends TextureLiquidFlowingFX { public LiquidObsidianFlowFX() { - super(50, 200, 0, 40, 50, 200, TContent.obsidianFlowing.blockIndexInTexture+1, TContent.obsidianFlowing.getTextureFile()); + super(0, 120, 0, 40, 0, 120, TContent.obsidianFlowing.blockIndexInTexture+1, TContent.obsidianFlowing.getTextureFile()); } } \ No newline at end of file diff --git a/tinker/tconstruct/client/liquidrender/TextureLiquidFlowingFX.java b/tinker/tconstruct/client/liquidrender/TextureLiquidFlowingFX.java index 2d3b2ac3..70802f3a 100644 --- a/tinker/tconstruct/client/liquidrender/TextureLiquidFlowingFX.java +++ b/tinker/tconstruct/client/liquidrender/TextureLiquidFlowingFX.java @@ -2,6 +2,7 @@ package tinker.tconstruct.client.liquidrender; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderEngine; +import net.minecraft.util.MathHelper; import org.lwjgl.opengl.GL11; @@ -11,6 +12,12 @@ public class TextureLiquidFlowingFX extends FMLTextureFX { private final int redMin, redMax, greenMin, greenMax, blueMin, blueMax; private final String texture; + + protected float red[]; + protected float blue[]; + protected float green[]; + protected float alpha[]; + private int animFrame; public TextureLiquidFlowingFX(int redMin, int redMax, int greenMin, int greenMax, int blueMin, int blueMax, int spriteIndex, String texture) { @@ -46,7 +53,91 @@ public class TextureLiquidFlowingFX extends FMLTextureFX @Override public void onTick () { - animFrame++; + ++this.animFrame; + int var2; + float var3; + int r; + int g; + int b; + int var8; + int var9; + + for (int var1 = 0; var1 < tileSizeBase; ++var1) + { + for (var2 = 0; var2 < tileSizeBase; ++var2) + { + var3 = 0.0F; + int var4 = (int)(MathHelper.sin((float)var2 * (float)Math.PI * 2.0F / 16.0F) * 1.2F); + r = (int)(MathHelper.sin((float)var1 * (float)Math.PI * 2.0F / 16.0F) * 1.2F); + + for (g = var1 - 1; g <= var1 + 1; ++g) + { + for (b = var2 - 1; b <= var2 + 1; ++b) + { + var8 = g + var4 & tileSizeMask; + var9 = b + r & tileSizeMask; + var3 += this.red[var8 + var9 * tileSizeBase]; + } + } + + this.blue[var1 + var2 * tileSizeBase] = var3 / 10.0F + (this.green[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.green[(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.green[(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase] + this.green[(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]) / 4.0F * 0.8F; + this.green[var1 + var2 * tileSizeBase] += this.alpha[var1 + var2 * tileSizeBase] * 0.01F; + + if (this.green[var1 + var2 * tileSizeBase] < 0.0F) + { + this.green[var1 + var2 * tileSizeBase] = 0.0F; + } + + this.alpha[var1 + var2 * tileSizeBase] -= 0.06F; + + if (Math.random() < 0.005D) + { + this.alpha[var1 + var2 * tileSizeBase] = 1.5F; + } + } + } + + float[] var11 = this.blue; + this.blue = this.red; + this.red = var11; + + for (var2 = 0; var2 < tileSizeSquare; ++var2) + { + var3 = this.red[(var2 - this.animFrame / 3 * tileSizeBase) & tileSizeSquareMask] * 2.0F; + + if (var3 > 1.0F) + { + var3 = 1.0F; + } + + if (var3 < 0.0F) + { + var3 = 0.0F; + } + + //r = (int)(var3 * 100.0F + 155.0F); + //g = (int)(var3 * var3 * 255.0F); + //b = (int)(var3 * var3 * var3 * var3 * 128.0F); + r = (int) (redMin + var3 * (redMax - redMin)); + g = (int) (greenMin + var3 * (greenMax - greenMin)); + b = (int) (blueMin + var3 * (blueMax - blueMin)); + + if (this.anaglyphEnabled) + { + var8 = (r * 30 + g * 59 + b * 11) / 100; + var9 = (r * 30 + g * 70) / 100; + int var10 = (r * 30 + b * 70) / 100; + r = var8; + g = var9; + b = var10; + } + + this.imageData[var2 * 4 + 0] = (byte)r; + this.imageData[var2 * 4 + 1] = (byte)g; + this.imageData[var2 * 4 + 2] = (byte)b; + this.imageData[var2 * 4 + 3] = -1; + } + /*animFrame++; for (int i = 0; i < tileSizeBase; i++) { for (int k = 0; k < tileSizeBase; k++) @@ -95,9 +186,9 @@ public class TextureLiquidFlowingFX extends FMLTextureFX f1 = 0.0F; } float f2 = f1 * f1; - /*int r = (int) (10F + f2 * 22F); - int g = (int) (50F + f2 * 64F); - int b = 255;*/ + //int r = (int) (10F + f2 * 22F); + //int g = (int) (50F + f2 * 64F); + //int b = 255; int r = (int) (redMin + f2 * (redMax - redMin)); int g = (int) (greenMin + f2 * (greenMax - greenMin)); @@ -114,19 +205,13 @@ public class TextureLiquidFlowingFX extends FMLTextureFX imageData[i1 * 4 + 0] = (byte) r; imageData[i1 * 4 + 1] = (byte) g; imageData[i1 * 4 + 2] = (byte) b; - imageData[i1 * 4 + 3] = /*(byte)l2*/(byte) 255; + imageData[i1 * 4 + 3] = (byte)l2(byte) 255; //imageData[i1 * 4 + 0] = (byte) l1; //imageData[i1 * 4 + 1] = (byte) l1; //imageData[i1 * 4 + 2] = (byte) l1; - //imageData[i1 * 4 + 3] = /* (byte)l2 */(byte) 255; - } + //imageData[i1 * 4 + 3] = (byte)l2 (byte) 255; + }*/ } - - protected float red[]; - protected float blue[]; - protected float green[]; - protected float alpha[]; - private int animFrame; } diff --git a/tinker/tconstruct/client/liquidrender/TextureLiquidStillFX.java b/tinker/tconstruct/client/liquidrender/TextureLiquidStillFX.java index 5274cfb3..c1180ed6 100644 --- a/tinker/tconstruct/client/liquidrender/TextureLiquidStillFX.java +++ b/tinker/tconstruct/client/liquidrender/TextureLiquidStillFX.java @@ -1,24 +1,20 @@ -/** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ - package tinker.tconstruct.client.liquidrender; import net.minecraft.client.renderer.RenderEngine; +import net.minecraft.util.MathHelper; import net.minecraftforge.client.ForgeHooksClient; import cpw.mods.fml.client.FMLTextureFX; public class TextureLiquidStillFX extends FMLTextureFX { - private final int redMin, redMax, greenMin, greenMax, blueMin, blueMax; private final String texture; + protected float red[]; + protected float green[]; + protected float blue[]; + protected float alpha[]; + public TextureLiquidStillFX(int redMin, int redMax, int greenMin, int greenMax, int blueMin, int blueMax, int spriteIndex, String texture) { super(spriteIndex); @@ -53,8 +49,91 @@ public class TextureLiquidStillFX extends FMLTextureFX @Override public void onTick () { + int var2; + float var3; + int r; + int g; + int b; + int var8; + int var9; - for (int i = 0; i < tileSizeBase; ++i) + for (int var1 = 0; var1 < tileSizeBase; ++var1) + { + for (var2 = 0; var2 < tileSizeBase; ++var2) + { + var3 = 0.0F; + int var4 = (int)(MathHelper.sin((float)var2 * (float)Math.PI * 2.0F / 16.0F) * 1.2F); + r = (int)(MathHelper.sin((float)var1 * (float)Math.PI * 2.0F / 16.0F) * 1.2F); + + for (g = var1 - 1; g <= var1 + 1; ++g) + { + for (b = var2 - 1; b <= var2 + 1; ++b) + { + var8 = g + var4 & tileSizeMask; + var9 = b + r & tileSizeMask; + var3 += this.red[var8 + var9 * tileSizeBase]; + } + } + + this.green[var1 + var2 * tileSizeBase] = var3 / 10.0F + (this.blue[(var1 + 0 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.blue[(var1 + 1 & tileSizeMask) + (var2 + 0 & tileSizeMask) * tileSizeBase] + this.blue[(var1 + 1 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase] + this.blue[(var1 + 0 & tileSizeMask) + (var2 + 1 & tileSizeMask) * tileSizeBase]) / 4.0F * 0.8F; + this.blue[var1 + var2 * tileSizeBase] += this.alpha[var1 + var2 * tileSizeBase] * 0.01F; + + if (this.blue[var1 + var2 * tileSizeBase] < 0.0F) + { + this.blue[var1 + var2 * tileSizeBase] = 0.0F; + } + + this.alpha[var1 + var2 * tileSizeBase] -= 0.06F; + + if (Math.random() < 0.005D) + { + this.alpha[var1 + var2 * tileSizeBase] = 1.5F; + } + } + } + + float[] var11 = this.green; + this.green = this.red; + this.red = var11; + + for (var2 = 0; var2 < tileSizeSquare; ++var2) + { + var3 = this.red[var2] * 2.0F; + + if (var3 > 1.0F) + { + var3 = 1.0F; + } + + if (var3 < 0.0F) + { + var3 = 0.0F; + } + + /*r = (int)(var3 * 100.0F + 155.0F); + g = (int)(var3 * var3 * 255.0F); + b = (int)(var3 * var3 * var3 * var3 * 128.0F);*/ + r = (int) (redMin + var3 * (redMax - redMin)); + g = (int) (greenMin + var3 * (greenMax - greenMin)); + b = (int) (blueMin + var3 * (blueMax - blueMin)); + + if (this.anaglyphEnabled) + { + var8 = (r * 30 + g * 59 + b * 11) / 100; + var9 = (r * 30 + g * 70) / 100; + int var10 = (r * 30 + b * 70) / 100; + r = var8; + g = var9; + b = var10; + } + + this.imageData[var2 * 4 + 0] = (byte)r; + this.imageData[var2 * 4 + 1] = (byte)g; + this.imageData[var2 * 4 + 2] = (byte)b; + this.imageData[var2 * 4 + 3] = -1; + } + + /*for (int i = 0; i < tileSizeBase; ++i) { for (int j = 0; j < tileSizeBase; ++j) { @@ -123,12 +202,7 @@ public class TextureLiquidStillFX extends FMLTextureFX imageData[i1 * 4 + 1] = (byte) g; imageData[i1 * 4 + 2] = (byte) b; imageData[i1 * 4 + 3] = (byte) 255; - } + }*/ } - - protected float red[]; - protected float green[]; - protected float blue[]; - protected float alpha[]; } diff --git a/tinker/tconstruct/client/tmt/Angle3D.java b/tinker/tconstruct/client/tmt/Angle3D.java new file mode 100644 index 00000000..692c6586 --- /dev/null +++ b/tinker/tconstruct/client/tmt/Angle3D.java @@ -0,0 +1,99 @@ +package tinker.tconstruct.client.tmt; + +/** + * This class handles angles. Basically all it does it store angles. You can + * directly alter the angles. + * @author GaryCXJk + * + */ +public class Angle3D +{ + /** + * The constructor to create a new Angle3D. + * @param x the x-rotation + * @param y the y-rotation + * @param z the z-rotation + */ + public Angle3D(float x, float y, float z) + { + angleX = x; + angleY = y; + angleZ = z; + } + + /** + * Adds the given angles to the current angles. + * @param x the x-rotation + * @param y the y-rotation + * @param z the z-rotation + */ + public void addAngles(float x, float y, float z) + { + angleX+= x; + angleY+= y; + angleZ+= z; + } + + /** + * Adds the angles of another Angle3D to the current angles. + * @param angles the Angle3D + */ + public void addAngles(Angle3D angles) + { + angleX+= angles.angleX; + angleY+= angles.angleY; + angleZ+= angles.angleZ; + } + + /** + * Multiplies the angles with the given angles. + * @param x the x-rotation + * @param y the y-rotation + * @param z the z-rotation + */ + public void multiplyAngles(float x, float y, float z) + { + angleX*= x; + angleY*= y; + angleZ*= z; + } + + /** + * Multiplies the angles with a given Angle3D. + * @param angles the Angle3D + */ + public void multiplyAngles(Angle3D angles) + { + angleX*= angles.angleX; + angleY*= angles.angleY; + angleZ*= angles.angleZ; + } + + /** + * Gets the center angle between two angles. + * @param angles1 the first Angle3D + * @param angles2 the second Angle3D + * @return the center Angle3D + */ + public static Angle3D getCenter(Angle3D angles1, Angle3D angles2) + { + Angle3D angles = new Angle3D(0, 0, 0); + angles.addAngles(angles1); + angles.addAngles(angles2); + angles.multiplyAngles(0.5F, 0.5F, 0.5F); + return angles; + } + + /** + * Copies the current Angle3D over to a new Angle3D instance. + * @return a copy of the Angle3D instance + */ + public Angle3D copy() + { + return new Angle3D(angleX, angleY, angleZ); + } + + public float angleX; + public float angleY; + public float angleZ; +} diff --git a/tinker/tconstruct/client/tmt/Bone.java b/tinker/tconstruct/client/tmt/Bone.java new file mode 100644 index 00000000..99973160 --- /dev/null +++ b/tinker/tconstruct/client/tmt/Bone.java @@ -0,0 +1,550 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; + +/** + * The Bone class makes it possible to create skeletons, which should help you out in + * animating your mobs a little bit more easy. However, since you won't work with a + * graphical interface, creating bones will be different from what you are probably + * used to. + *

+ * First, you will need to instantiate every Bone in the constructor of your model + * file. The default orientation, when all angles are set to zero, will be in the + * vector (0, 0, length), meaning it will always point backwards on a regular model. + * You can also set what its parent node is. If a Bone does not have a parent node, + * it is assumed it is the root node. Each Bone can only have one parent, but several + * children. Also, all children will inherit the offset position of the root node. + *

+ * The neutral position basically defines in what direction the Bone normally faces + * when in rest. This will not affect the rotation of any model currently attached + * to it or the rotation of the child nodes, but will affect the position of the + * child nodes when recalculating their positions. The length always defines how far + * each child Bone will be placed, since child Bones are always placed at the end of + * their parent Bone. + *

+ * Once you're ready to render, you can call the prepareDraw method. You only need + * to apply it to one Bone, since it will always search for the root node to execute + * the code there. It will then automatically rotate every child Bone and places + * them at the right position. Finally, use the setAnglesToModels method to rotate + * each model and place them at the correct spot. Note that if you also apply custom + * rotation for the individual models that you should apply that after you've run + * setAnglesToModels, since this will override the settings the model originally had. + * The best way to solve this is to make a separate method to rotate the Bones. + *

+ * The following would be an example of a biped with a skeleton. It takes ModelBiped + * as an example and extends it with a skeleton. First, we have the part that goes + * in the constructor. + *
+ * // First, the origin will be placed. This is where the rest is attached to.
+ * skeletonOrigin = new Bone(0, 0, 0, 0);
+ * 
+ * // Next, the entire skeleton is built up.
+ * skeletonHead = new Bone(-3.141593F / 2, 0, 0, 0, skeletonOrigin);
+ * skeletonBody = new Bone(3.141593F / 2, 0, 0, 12, skeletonOrigin);
+ * skeletonShoulderRight = new Bone(0, -3.141593F / 2, 0, 5, skeletonOrigin);
+ * skeletonShoulderLeft = new Bone(0, 3.141593F / 2, 0, 5, skeletonOrigin);
+ * skeletonArmRight = new Bone(3.141593F / 2, 0, 0, 12, skeletonShoulderRight);
+ * skeletonArmLeft = new Bone(3.141593F / 2, 0, 0, 12, skeletonShoulderLeft);
+ * skeletonPelvisRight = new Bone(0, -3.141593F / 2, 0, 2, skeletonBody);
+ * skeletonPelvisLeft = new Bone(0, 3.141593F / 2, 0, 2, skeletonBody);
+ * skeletonLegRight = new Bone(3.141593F / 2, 0, 0, 12, skeletonPelvisRight);
+ * skeletonLegLeft = new Bone(3.141593F / 2, 0, 0, 12, skeletonPelvisLeft);
+ * 
+ * // Finally, all models will be attached to the skeletons.
+ * skeletonHead.addModel(bipedHead);
+ * skeletonHead.addModel(bipedHeadwear);
+ * skeletonBody.addModel(bipedBody);
+ * skeletonArmRight.addModel(bipedRightArm);
+ * skeletonArmLeft.addModel(bipedLeftArm);
+ * skeletonLegRight.addModel(bipedRightLeg);
+ * skeletonLegLeft.addModel(bipedRightLeg);
+ * 
+ *

+ * After that, you could replace anything in the setRotationAngles method with + * the following code. It's not a complete code, but you'll get the basics. + *

+ *
+ * skeletonHead.relativeAngles.angleY = f3 / 57.29578F;
+ * skeletonHead.relativeAngles.angleX = f4 / 57.29578F;
+ * skeletonArmRight.relativeAngles.angleX = MathHelper.cos(f * 0.6662F + 3.141593F) * 2.0F * f1 * 0.5F;
+ * skeletonArmRight.relativeAngles.angleZ = 0.0F;
+ * skeletonArmLeft.relativeAngles.angleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F;
+ * skeletonArmLeft.relativeAngles.angleZ = 0.0F;
+ * skeletonLegRight.relativeAngles.angleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
+ * skeletonLegRight.relativeAngles.angleY = 0.0F;
+ * skeletonLegLeft.relativeAngles.angleX = MathHelper.cos(f * 0.6662F + 3.141593F) * 1.4F * f1;
+ * skeletonLegLeft.relativeAngles.angleY = 0.0F;
+ * 
+ *

+ * Finally, in the render method, you could use the following code. + *

+ *
+ * setRotationAngles(f, f1, f2, f3, f4, f5);
+ * skeletonOrigin.prepareDraw();
+ * skeletonOrigin.setAnglesToModels();
+ * 
+ *

+ * This should generate the same animation of the regular biped. Don't forget to add + * the individual render methods for each model though, as it won't automatically + * render them. + *

+ * @author GaryCXJk + * + */ +public class Bone +{ + /** + * Constructor to create a bone. + * @param x the x-rotation of the bone + * @param y the y-rotation of the bone + * @param z the z-rotation of the bone + * @param l the length of the bone + */ + public Bone(float x, float y, float z, float l) + { + neutralAngles = new Angle3D(x, y, z); + relativeAngles = new Angle3D(0, 0, 0); + absoluteAngles = new Angle3D(0, 0, 0); + positionVector = Vec3.createVectorHelper(0, 0, 0); + length = l; + childNodes = new ArrayList(); + models = new ArrayList(); + modelBaseRot = new HashMap(); + parentNode = null; + offsetX = 0; + offsetY = 0; + offsetZ = 0; + positionVector = Vec3.createVectorHelper(0, 0, 0); + } + + /** + * Constructor to create a bone. + * @param xOrig the x-offset of the origin + * @param yOrig the y-offset of the origin + * @param zOrig the z-offset of the origin + * @param xRot the x-rotation of the bone + * @param yRot the y-rotation of the bone + * @param zRot the z-rotation of the bone + * @param l the length of the bone + */ + public Bone(float xOrig, float yOrig, float zOrig, float xRot, float yRot, float zRot, float l) + { + this(xRot, yRot, zRot, l); + positionVector = setOffset(xOrig, yOrig, zOrig); + } + + /** + * Constructor to create a bone. This attaches the bone to a parent bone, and will + * calculate its current position relative to the origin. + * @param x the x-rotation of the bone + * @param y the y-rotation of the bone + * @param z the z-rotation of the bone + * @param l the length of the bone + * @param parent the parent Bone node this Bone is attached to + */ + public Bone(float x, float y, float z, float l, Bone parent) + { + this(x, y, z, l); + attachBone(parent); + } + + /** + * Detaches the bone from its parent. + */ + public void detachBone() + { + parentNode.childNodes.remove(this); + parentNode = null; + } + + /** + * Attaches the bone to a parent. If the parent is already set, detaches the bone + * from the previous parent. + * @param parent the parent Bone node this Bone is attached to + */ + public void attachBone(Bone parent) + { + if(parentNode != null) + detachBone(); + parentNode = parent; + parent.addChildBone(this); + offsetX = parent.offsetX; + offsetY = parent.offsetY; + offsetZ = parent.offsetZ; + resetOffset(); + } + + /** + * Sets the current offset of the parent root Bone. Note that this will + * always set the parent root Bone, not the current Bone, as its offset + * is determined by the offset, rotation and length of its parent. + * @param x the x-position + * @param y the y-position + * @param z the z-position + * @return a Vec3 with the new coordinates of the current bone + */ + public Vec3 setOffset(float x, float y, float z) + { + if(parentNode != null) + { + Vec3 vector = parentNode.setOffset(x, y, z); + offsetX = (float)vector.xCoord; + offsetY = (float)vector.yCoord; + offsetZ = (float)vector.zCoord; + return vector; + } + offsetX = x; + offsetY = y; + offsetZ = z; + resetOffset(true); + return Vec3.createVectorHelper(x, y, z); + } + + /** + * Resets the offset. + */ + public void resetOffset() + { + resetOffset(false); + } + + /** + * Resets the offset. + * @param doRecursive + */ + public void resetOffset(boolean doRecursive) + { + if(parentNode != null) + { + positionVector = Vec3.createVectorHelper(0, 0, parentNode.length); + parentNode.setVectorRotations(positionVector); + positionVector.xCoord += parentNode.positionVector.xCoord; + positionVector.yCoord += parentNode.positionVector.yCoord; + positionVector.zCoord += parentNode.positionVector.zCoord; + } + if(doRecursive && !childNodes.isEmpty()) + { + for(int index = 0; index < childNodes.size(); index++) + { + childNodes.get(index).resetOffset(doRecursive); + } + } + } + + /** + * Sets the current neutral rotation of the bone. This is the same rotation as in + * the constructor. + * @param x the x-rotation of the bone + * @param y the y-rotation of the bone + * @param z the z-rotation of the bone + */ + public void setNeutralRotation(float x, float y, float z) + { + neutralAngles.angleX = x; + neutralAngles.angleY = y; + neutralAngles.angleZ = z; + } + + /** + * Gets the root parent bone. + * @return the root parent Bone. + */ + public Bone getRootParent() + { + if(parentNode == null) + return this; + else + return parentNode.getRootParent(); + } + + /** + * Attaches a model to the bone. Its base rotation will be set to the neutral + * rotation of the model. + * @param model the model to attach + */ + public void addModel(ModelRenderer model) + { + addModel(model, false); + } + + /** + * Attaches a model to the bone. If inherit is true, it sets the base rotation + * to the neutral rotation of the Bone, otherwise it's set to the neutral + * rotation of the model. + * @param model the model to attach + * @param inherit whether the model should inherit the Bone's base rotations + */ + public void addModel(ModelRenderer model, boolean inherit) + { + addModel(model, 0F, 0F, 0F, inherit); + } + + /** + * Attaches a model to the bone. If inherit is true, it sets the base rotation + * to the neutral rotation of the Bone, otherwise it's set to the neutral + * rotation of the model. When isUpright is set, the model will be rotated + * (-PI / 2, 0, 0). + * @param model the model to attach + * @param inherit whether the model should inherit the Bone's base rotations + * @param isUpright whether the model is modeled in the upright position + */ + public void addModel(ModelRenderer model, boolean inherit, boolean isUpright) + { + addModel(model, 0F, 0F, 0F, inherit, isUpright); + } + + /** + * Attaches a model to the bone with a given base rotation. + * @param model the model to attach + * @param x the base x-rotation + * @param y the base y-rotation + * @param z the base z-rotation + */ + public void addModel(ModelRenderer model, float x, float y, float z) + { + addModel(model, x, y, z, false); + } + + /** + * Attaches a model to the bone with a given base rotation. When inherit is + * true, it will add the Bone's neutral rotation to the given angles. + * @param model the model to attach + * @param x the base x-rotation + * @param y the base y-rotation + * @param z the base z-rotation + * @param inherit whether the model should inherit the Bone's base rotations + */ + public void addModel(ModelRenderer model, float x, float y, float z, boolean inherit) + { + addModel(model, x, y, z, inherit, false); + } + + /** + * Attaches a model to the bone with a given base rotation. When inherit is + * true, it will add the Bone's neutral rotation to the given angles. + * When isUpright is set, the model will be rotated (-PI / 2, 0, 0). + * @param model the model to attach + * @param x the base x-rotation + * @param y the base y-rotation + * @param z the base z-rotation + * @param inherit whether the model should inherit the Bone's base rotations + * @param isUpright whether the model is modeled in the upright position + */ + public void addModel(ModelRenderer model, float x, float y, float z, boolean inherit, boolean isUpright) + { + if(inherit) + { + x += neutralAngles.angleX + (isUpright ? (float)Math.PI / 2 : 0); + y += neutralAngles.angleY; + z += neutralAngles.angleZ; + } + models.add(model); + modelBaseRot.put(model, new Angle3D(x, y, z)); + } + + /** + * Removes the given model from the Bone. Always detach the model before adding + * it to another Bone. The best thing however is to just keep the model to one + * bone. + * @param model the model to remove from the bone + */ + public void removeModel(ModelRenderer model) + { + models.remove(model); + modelBaseRot.remove(model); + } + + /** + * Gets the current absolute angles. The absolute angle is calculated by getting + * the sum of all parent Bones' relative angles plus the current relative angle. + * This must be called after using the prepareDraw method. + * @return an Angle3D object which holds the current angles of the current node. + */ + public Angle3D getAbsoluteAngle() + { + return new Angle3D(absoluteAngles.angleX, absoluteAngles.angleY, absoluteAngles.angleZ); + } + + /** + * Gets the current position of the bone. You should call this after all rotations + * and positions are applied, e.g. after prepareDraw has been called. + * @return a vector containing the current position relative to the origin. + */ + public Vec3 getPosition() + { + return Vec3.createVectorHelper(positionVector.xCoord, positionVector.yCoord, positionVector.zCoord); + } + + protected void addChildBone(Bone bone) + { + childNodes.add(bone); + } + + /** + * Prepares the bones for rendering. This will automatically take the root Bone + * if it isn't. + */ + public void prepareDraw() + { + if(parentNode != null) + parentNode.prepareDraw(); + else + { + setAbsoluteRotations(); + setVectors(); + } + } + + /** + * Sets the current rotation of the Bone, not calculating any parent bones in. + * @param x + * @param y + * @param z + */ + public void setRotations(float x, float y, float z) + { + relativeAngles.angleX = x; + relativeAngles.angleY = y; + relativeAngles.angleZ = z; + } + + protected void setAbsoluteRotations() + { + absoluteAngles.angleX = relativeAngles.angleX; + absoluteAngles.angleY = relativeAngles.angleY; + absoluteAngles.angleZ = relativeAngles.angleZ; + for(int i = 0; i < childNodes.size(); i++) + { + childNodes.get(i).setAbsoluteRotations(absoluteAngles.angleX, absoluteAngles.angleY, absoluteAngles.angleZ); + } + } + + protected void setAbsoluteRotations(float x, float y, float z) + { + absoluteAngles.angleX = relativeAngles.angleX + x; + absoluteAngles.angleY = relativeAngles.angleY + y; + absoluteAngles.angleZ = relativeAngles.angleZ + z; + for(int i = 0; i < childNodes.size(); i++) + { + childNodes.get(i).setAbsoluteRotations(absoluteAngles.angleX, absoluteAngles.angleY, absoluteAngles.angleZ); + } + + } + + protected void setVectorRotations(Vec3 vector) + { + float x = neutralAngles.angleX + absoluteAngles.angleX; + float y = neutralAngles.angleY + absoluteAngles.angleY; + float z = neutralAngles.angleZ + absoluteAngles.angleZ; + setVectorRotations(vector, x, y, z); + } + + protected void setVectorRotations(Vec3 vector, float xRot, float yRot, float zRot) + { + float x = xRot; + float y = yRot; + float z = zRot; + float xC = MathHelper.cos(x); + float xS = MathHelper.sin(x); + float yC = MathHelper.cos(y); + float yS = MathHelper.sin(y); + float zC = MathHelper.cos(z); + float zS = MathHelper.sin(z); + + double xVec = vector.xCoord; + double yVec = vector.yCoord; + double zVec = vector.zCoord; + + // rotation around x + double xy = xC*yVec - xS*zVec; + double xz = xC*zVec + xS*yVec; + // rotation around y + double yz = yC*xz - yS*xVec; + double yx = yC*xVec + yS*xz; + // rotation around z + double zx = zC*yx - zS*xy; + double zy = zC*xy + zS*yx; + + xVec = zx; + yVec = zy; + zVec = yz; + + vector.xCoord = xVec; + vector.yCoord = yVec; + vector.zCoord = zVec; + } + + protected void addVector(Vec3 destVec, Vec3 srcVec) + { + destVec.xCoord += srcVec.xCoord; + destVec.yCoord += srcVec.yCoord; + destVec.zCoord += srcVec.zCoord; + } + + protected void setVectors() + { + Vec3 tempVec = Vec3.createVectorHelper(0, 0, length); + positionVector = Vec3.createVectorHelper(offsetX, offsetY, offsetZ); + addVector(tempVec, positionVector); + setVectorRotations(tempVec); + for(int i = 0; i < childNodes.size(); i++) + { + childNodes.get(i).setVectors(tempVec); + } + } + + protected void setVectors(Vec3 vector) + { + positionVector = vector; + Vec3 tempVec = Vec3.createVectorHelper(0, 0, length); + setVectorRotations(tempVec); + addVector(tempVec, vector); + for(int i = 0; i < childNodes.size(); i++) + { + childNodes.get(i).setVectors(tempVec); + } + + } + + /** + * Sets the current angles of the Bone to the models attached to it. + */ + public void setAnglesToModels() + { + for(int i = 0; i < models.size(); i++) + { + ModelRenderer currentModel = models.get(i); + Angle3D baseAngles = modelBaseRot.get(currentModel); + currentModel.rotateAngleX = baseAngles.angleX + absoluteAngles.angleX; + currentModel.rotateAngleY = baseAngles.angleY + absoluteAngles.angleY; + currentModel.rotateAngleZ = baseAngles.angleZ + absoluteAngles.angleZ; + currentModel.rotationPointX = (float)positionVector.xCoord; + currentModel.rotationPointY = (float)positionVector.yCoord; + currentModel.rotationPointZ = (float)positionVector.zCoord; + } + + for(int i = 0; i < childNodes.size(); i++) + { + childNodes.get(i).setAnglesToModels(); + } + } + + protected Angle3D neutralAngles; + public Angle3D relativeAngles; + protected Angle3D absoluteAngles; + private Vec3 positionVector; + private float length; + private Bone parentNode; + protected ArrayList childNodes; + private ArrayList models; + private Map modelBaseRot; + private float offsetX; + private float offsetY; + private float offsetZ; +} diff --git a/tinker/tconstruct/client/tmt/Coord2D.java b/tinker/tconstruct/client/tmt/Coord2D.java new file mode 100644 index 00000000..415659d3 --- /dev/null +++ b/tinker/tconstruct/client/tmt/Coord2D.java @@ -0,0 +1,31 @@ +package tinker.tconstruct.client.tmt; + +/** + * This class represents a coordinate space and its UV coordinates. This allows for + * easier flat shape planning. + * @author GaryCXJk + * + */ +public class Coord2D +{ + public Coord2D(double x, double y) + { + xCoord = x; + yCoord = y; + uCoord = (int)Math.floor(x); + vCoord = (int)Math.floor(y); + } + + + public Coord2D(double x, double y, int u, int v) + { + this(x, y); + uCoord = u; + vCoord = v; + } + + public double xCoord; + public double yCoord; + public int uCoord; + public int vCoord; +} diff --git a/tinker/tconstruct/client/tmt/ModelPool.java b/tinker/tconstruct/client/tmt/ModelPool.java new file mode 100644 index 00000000..c431b69d --- /dev/null +++ b/tinker/tconstruct/client/tmt/ModelPool.java @@ -0,0 +1,60 @@ +package tinker.tconstruct.client.tmt; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.client.Minecraft; + +public class ModelPool +{ + public static ModelPoolEntry addFile(String file, Class modelClass, Map group, Map textureGroup) + { + ModelPoolEntry entry = null; + if(modelMap.containsKey(file)) + { + entry = modelMap.get(file); + entry.applyGroups(group, textureGroup); + return entry; + } + try + { + entry = (ModelPoolEntry)modelClass.newInstance(); + } + catch(Exception e) + { + System.out.println("A new " + entry.getClass().getName() + " could not be initialized."); + System.out.println(e.getMessage()); + return null; + } + File modelFile = null; + for(int i = 0; i < resourceDir.length && (modelFile == null || !modelFile.exists()); i++) + { + String absPath = Minecraft.getAppDir(resourceDir[i]).getAbsolutePath(); + if(!absPath.endsWith("/") || !absPath.endsWith("\\")) + absPath+= "/"; + modelFile = entry.checkValidPath(absPath + file); + } + if(modelFile == null || !modelFile.exists()) + { + System.out.println("The model with the name " + file + " does not exist."); + return null; + } + entry.groups = new HashMap(); + entry.textures = new HashMap(); + entry.name = file; + entry.setGroup("0"); + entry.setTextureGroup("0"); + entry.getModel(modelFile); + entry.applyGroups(group, textureGroup); + modelMap.put(file, entry); + return entry; + } + + private static Map modelMap = new HashMap(); + private static String[] resourceDir = new String[] { + "minecraft/resources/models/", + "minecraft/resources/mod/models/" + }; + public static final Class OBJ = ModelPoolObjEntry.class; +} diff --git a/tinker/tconstruct/client/tmt/ModelPoolEntry.java b/tinker/tconstruct/client/tmt/ModelPoolEntry.java new file mode 100644 index 00000000..7542b229 --- /dev/null +++ b/tinker/tconstruct/client/tmt/ModelPoolEntry.java @@ -0,0 +1,118 @@ +package tinker.tconstruct.client.tmt; + +import java.io.File; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public abstract class ModelPoolEntry +{ + public File checkValidPath(String path) + { + File file = null; + + for(int index = 0; index < fileExtensions.length && (file == null || !file.exists()); index++) + { + String absPath = path; + + if(!path.endsWith("." + fileExtensions[index])) + absPath+= "." + fileExtensions[index]; + + file = new File(absPath); + } + if(file == null || !file.exists()) + return null; + return file; + } + + public abstract void getModel(File file); + + /** + * Sets the current transformation group. The transformation group is used + * to allow for vertex transformation. If a transformation group does not exist, + * a new one will be created. + * @param groupName the name of the transformation group you want to switch to + */ + protected void setGroup(String groupName) + { + setGroup(groupName, new Bone(0, 0, 0, 0), 1D); + } + + /** + * Sets the current transformation group. The transformation group is used + * to allow for vertex transformation. If a transformation group does not exist, + * a new one will be created. + * @param groupName the name of the transformation group you want to switch to + * @param bone the Bone this transformation group is attached to + * @param weight the weight of the transformation group + */ + protected void setGroup(String groupName, Bone bone, double weight) + { + if(groups.size() == 0 || !groups.containsKey(groupName)) + groups.put(groupName, new TransformGroupBone(bone, weight)); + group = groups.get(groupName); + } + + /** + * Sets the current texture group, which is used to switch the + * textures on a per-model base. Do note that any model that is + * rendered afterwards will use the same texture. To counter it, + * set a default texture, either at initialization or before + * rendering. + * @param groupName The name of the texture group. If the texture + * group doesn't exist, it creates a new group automatically. + */ + protected void setTextureGroup(String groupName) + { + if(textures.size() == 0 || !textures.containsKey(groupName)) + { + textures.put(groupName, new TextureGroup()); + } + texture = textures.get(groupName); + } + + protected void applyGroups(Map groupsMap, Map texturesMap) + { + Set groupsCol = groups.keySet(); + Collection texturesCol = textures.keySet(); + + Iterator groupsItr = groupsCol.iterator(); + Iterator texturesItr = texturesCol.iterator(); + + while(groupsItr.hasNext()) + { + int nameIdx = 0; + String groupKey = groupsItr.next(); + String currentGroup = name + "_" + nameIdx + ":" + groupKey; + while(groupsMap.size() > 0 && groupsMap.containsKey(currentGroup)) + { + nameIdx++; + currentGroup = name + "_" + nameIdx + ":" + groupKey; + } + groupsMap.put(currentGroup, groups.get(groupKey)); + } + + while(texturesItr.hasNext()) + { + int nameIdx = 0; + String groupKey = texturesItr.next(); + String currentGroup = name + "_" + nameIdx + ":" + groupKey; + while(groupsMap.size() > 0 && texturesMap.containsKey(currentGroup)) + { + nameIdx++; + currentGroup = name + "_" + nameIdx + ":" + groupKey; + } + texturesMap.put(currentGroup, textures.get(groupKey)); + } + } + + public String name; + public PositionTransformVertex[] vertices; + public TexturedPolygon[] faces; + public Map groups; + public Map textures; + protected TransformGroupBone group; + protected TextureGroup texture; + protected String[] fileExtensions; +} diff --git a/tinker/tconstruct/client/tmt/ModelPoolObjEntry.java b/tinker/tconstruct/client/tmt/ModelPoolObjEntry.java new file mode 100644 index 00000000..8765ab99 --- /dev/null +++ b/tinker/tconstruct/client/tmt/ModelPoolObjEntry.java @@ -0,0 +1,223 @@ +package tinker.tconstruct.client.tmt; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; + +import net.minecraft.client.model.PositionTextureVertex; +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; + +public class ModelPoolObjEntry extends ModelPoolEntry +{ + public ModelPoolObjEntry() + { + fileExtensions = new String[] {"obj"}; + } + + public void getModel(File file) + { + try + { + BufferedReader in = new BufferedReader(new FileReader(file)); + + String s; + + ArrayList verts = new ArrayList(); + ArrayList uvs = new ArrayList(); + ArrayList normals = new ArrayList(); + ArrayList face = new ArrayList(); + + while((s = in.readLine()) != null) + { + if(s.indexOf("#") > -1) + { + s = s.substring(0, s.indexOf("#")); + } + + s = s.trim(); + + if(s.equals("")) + continue; + + if(s.startsWith("g ")) + { + setTextureGroup(s.substring(s.indexOf(" ") + 1).trim()); + continue; + } + if(s.startsWith("v ")) + { + s = s.substring(s.indexOf(" ") + 1).trim(); + float[] v = new float[3]; + for(int i = 0; i < 3; i++) + { + int ind = s.indexOf(" "); + if(ind > -1) + v[i] = Float.parseFloat(s.substring(0, ind)); + else + v[i] = Float.parseFloat(s.substring(0)); + s = s.substring(s.indexOf(" ") + 1).trim(); + } + + float flt = v[2]; + v[2] = -v[1]; + v[1] = flt; + + verts.add(new PositionTransformVertex(v[0], v[1], v[2], 0, 0)); + continue; + } + if(s.startsWith("vt ")) + { + s = s.substring(s.indexOf(" ") + 1).trim(); + float[] v = new float[2]; + for(int i = 0; i < 2; i++) + { + int ind = s.indexOf(" "); + if(ind > -1) + v[i] = Float.parseFloat(s.substring(0, ind)); + else + v[i] = Float.parseFloat(s.substring(0)); + s = s.substring(s.indexOf(" ") + 1).trim(); + } + + uvs.add(new float[] {v[0], 1F - v[1]}); + continue; + } + if(s.startsWith("vn ")) + { + s = s.substring(s.indexOf(" ") + 1).trim(); + float[] v = new float[3]; + for(int i = 0; i < 3; i++) + { + int ind = s.indexOf(" "); + if(ind > -1) + v[i] = Float.parseFloat(s.substring(0, ind)); + else + v[i] = Float.parseFloat(s.substring(0)); + s = s.substring(s.indexOf(" ") + 1).trim(); + } + + float flt = v[2]; + v[2] = v[1]; + v[1] = flt; + + normals.add(new float[] {v[0], v[1], v[2]}); + continue; + } + if(s.startsWith("f ")) + { + s = s.substring(s.indexOf(" ") + 1).trim(); + ArrayList v = new ArrayList(); + String s1; + int finalPhase = 0; + float[] normal = new float[] {0F, 0F, 0F}; + ArrayList iNormal = new ArrayList(); + do + { + int vInt; + float[] curUV; + float[] curNormals; + int ind = s.indexOf(" "); + s1 = s; + if(ind > -1) + s1 = s.substring(0, ind); + if(s1.indexOf("/") > -1) + { + String[] f = s1.split("/"); + vInt = Integer.parseInt(f[0]) - 1; + if(f[1].equals("")) + f[1] = f[0]; + int vtInt = Integer.parseInt(f[1]) - 1; + if(uvs.size() > vtInt) + curUV = uvs.get(vtInt); + else + curUV = new float[] {0, 0}; + int vnInt = 0; + if(f.length == 3) + { + if(f[2].equals("")) + f[2] = f[0]; + vnInt = Integer.parseInt(f[2]) - 1; + } + else + vnInt = Integer.parseInt(f[0]) - 1; + if(normals.size() > vnInt) + curNormals = normals.get(vnInt); + else + curNormals = new float[] {0, 0, 0}; + } + else + { + vInt = Integer.parseInt(s1) - 1; + if(uvs.size() > vInt) + curUV = uvs.get(vInt); + else + curUV = new float[] {0, 0}; + if(normals.size() > vInt) + curNormals = normals.get(vInt); + else + curNormals = new float[] {0, 0, 0}; + } + + iNormal.add(Vec3.createVectorHelper(curNormals[0], curNormals[1], curNormals[2])); + + normal[0]+= curNormals[0]; + normal[1]+= curNormals[1]; + normal[2]+= curNormals[2]; + + if(vInt < verts.size()) + { + v.add(verts.get(vInt).setTexturePosition(curUV[0], curUV[1])); + if(verts.get(vInt) instanceof PositionTransformVertex) + { + ((PositionTransformVertex)verts.get(vInt)).addGroup(group); + } + } + if(ind > -1) + s = s.substring(s.indexOf(" ") + 1).trim(); + else + finalPhase++; + } while(finalPhase < 1); + + float d = MathHelper.sqrt_double(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); + + normal[0]/= d; + normal[1]/= d; + normal[2]/= d; + + PositionTextureVertex[] vToArr = new PositionTextureVertex[v.size()]; + + for(int i = 0; i < v.size(); i++) + { + vToArr[i] = v.get(i); + } + + TexturedPolygon poly = new TexturedPolygon(vToArr); + poly.setNormals(normal[0], normal[1], normal[2]); + poly.setNormals(iNormal); + + face.add(poly); + texture.addPoly(poly); + continue; + } + } + + vertices = new PositionTransformVertex[verts.size()]; + for(int i = 0; i < verts.size(); i++) + { + vertices[i] = verts.get(i); + } + faces = new TexturedPolygon[face.size()]; + for(int i = 0; i < face.size(); i++) + { + faces[i] = face.get(i); + } + in.close(); + } + catch(Throwable e) + { + + } + } +} diff --git a/tinker/tconstruct/client/tmt/ModelRendererTurbo.java b/tinker/tconstruct/client/tmt/ModelRendererTurbo.java new file mode 100644 index 00000000..31d6dcc3 --- /dev/null +++ b/tinker/tconstruct/client/tmt/ModelRendererTurbo.java @@ -0,0 +1,1804 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.model.PositionTextureVertex; +import net.minecraft.client.model.TexturedQuad; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.RenderEngine; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.MathHelper; + +import org.lwjgl.opengl.GL11; +/** + * An extension to the ModelRenderer class. It basically is a copy to ModelRenderer, + * however, it contains various new methods to make your models. + *

+ * Since the ModelRendererTurbo class gets loaded during startup, the models made + * can be very complex. This is why I can afford to add, for example, Wavefont OBJ + * support or have the addSprite method, methods that add a lot of vertices and + * polygons. + * @author GaryCXJk + * + */ +public class ModelRendererTurbo extends ModelRenderer +{ + public ModelRendererTurbo(ModelBase modelbase, String s) + { + super(modelbase, s); + flip = false; + compiled = false; + displayList = 0; + mirror = false; + showModel = true; + field_1402_i = false; + vertices = new PositionTextureVertex[0]; + faces = new TexturedPolygon[0]; + forcedRecompile = false; + transformGroup = new HashMap(); + transformGroup.put("0", new TransformGroupBone(new Bone(0, 0, 0, 0), 1D)); + textureGroup = new HashMap(); + textureGroup.put("0", new TextureGroup()); + currentTextureGroup = textureGroup.get("0"); + boxName = s; + + defaultTexture = ""; + + useLegacyCompiler = false; + } + + public ModelRendererTurbo(ModelBase modelbase) + { + this(modelbase, null); + } + + /** + * Creates a new ModelRenderTurbo object. It requires the coordinates of the + * position of the texture. + * @param modelbase + * @param textureX the x-coordinate on the texture + * @param textureY the y-coordinate on the texture + */ + public ModelRendererTurbo(ModelBase modelbase, int textureX, int textureY) + { + this(modelbase, textureX, textureY, 64, 32); + } + + /** + * Creates a new ModelRenderTurbo object. It requires the coordinates of the + * position of the texture, but also allows you to specify the width and height + * of the texture, allowing you to use bigger textures instead. + * @param modelbase + * @param textureX + * @param textureY + * @param textureU + * @param textureV + */ + public ModelRendererTurbo(ModelBase modelbase, int textureX, int textureY, int textureU, int textureV) + { + this(modelbase); + textureOffsetX = textureX; + textureOffsetY = textureY; + textureWidth = textureU; + textureHeight = textureV; + } + + /** + * Creates a new polygon. + * @param verts an array of vertices + */ + public void addPolygon(PositionTextureVertex[] verts) + { + copyTo(verts, new TexturedPolygon[] {new TexturedPolygon(verts)}); + } + + /** + * Creates a new polygon, and adds UV mapping to it. + * @param verts an array of vertices + * @param uv an array of UV coordinates + */ + public void addPolygon(PositionTextureVertex[] verts, int[][] uv) + { + try + { + for(int i = 0; i < verts.length; i++) + { + verts[i] = verts[i].setTexturePosition((float)uv[i][0] / textureWidth, (float)uv[i][1] / textureHeight); + } + } + finally + { + addPolygon(verts); + } + } + + /** + * Creates a new polygon with a given UV. + * @param verts an array of vertices + * @param u1 + * @param v1 + * @param u2 + * @param v2 + */ + public void addPolygon(PositionTextureVertex[] verts, int u1, int v1, int u2, int v2) + { + copyTo(verts, new TexturedPolygon[] {addPolygonReturn(verts, u1, v1, u2, v2)}); + } + + private TexturedPolygon addPolygonReturn(PositionTextureVertex[] verts, int u1, int v1, int u2, int v2) + { + if(verts.length < 3) + return null; + float uOffs = 1.0F / ((float) textureWidth * 10.0F); + float vOffs = 1.0F / ((float) textureHeight * 10.0F); + if(verts.length < 4) + { + float xMin = -1; + float yMin = -1; + float xMax = 0; + float yMax = 0; + + for(int i = 0; i < verts.length; i++) + { + float xPos = verts[i].texturePositionX; + float yPos = verts[i].texturePositionY; + xMax = Math.max(xMax, xPos); + xMin = (xMin < -1 ? xPos : Math.min(xMin, xPos)); + yMax = Math.max(yMax, yPos); + yMin = (yMin < -1 ? yPos : Math.min(yMin, yPos)); + } + float uMin = (float) u1 / (float) textureWidth + uOffs; + float vMin = (float) v1 / (float) textureHeight + vOffs; + float uSize = (float) (u2 - u1) / (float) textureWidth - uOffs * 2; + float vSize = (float) (v2 - v1) / (float) textureHeight - vOffs * 2; + + float xSize = xMax - xMin; + float ySize = yMax - yMin; + for(int i = 0; i < verts.length; i++) + { + float xPos = verts[i].texturePositionX; + float yPos = verts[i].texturePositionY; + xPos = (xPos - xMin) / xSize; + yPos = (yPos - yMin) / ySize; + verts[i] = verts[i].setTexturePosition(uMin + (xPos * uSize), vMin + (yPos * vSize)); + } + } + else + { + verts[0] = verts[0].setTexturePosition((float)u2 / (float) textureWidth - uOffs, (float)v1 / (float)textureHeight + vOffs); + verts[1] = verts[1].setTexturePosition((float)u1 / (float) textureWidth + uOffs, (float)v1 / (float)textureHeight + vOffs); + verts[2] = verts[2].setTexturePosition((float)u1 / (float) textureWidth + uOffs, (float)v2 / (float)textureHeight - vOffs); + verts[3] = verts[3].setTexturePosition((float)u2 / (float) textureWidth - uOffs, (float)v2 / (float)textureHeight - vOffs); + } + return new TexturedPolygon(verts); + } + + /** + * Adds a rectangular shape. Basically, you can make any eight-pointed shape you want, + * as the method requires eight vector coordinates. + * @param v a float array with three values, the x, y and z coordinates of the vertex + * @param v1 a float array with three values, the x, y and z coordinates of the vertex + * @param v2 a float array with three values, the x, y and z coordinates of the vertex + * @param v3 a float array with three values, the x, y and z coordinates of the vertex + * @param v4 a float array with three values, the x, y and z coordinates of the vertex + * @param v5 a float array with three values, the x, y and z coordinates of the vertex + * @param v6 a float array with three values, the x, y and z coordinates of the vertex + * @param v7 a float array with three values, the x, y and z coordinates of the vertex + * @param w the width of the shape, used in determining the texture + * @param h the height of the shape, used in determining the texture + * @param d the depth of the shape, used in determining the texture + */ + public void addRectShape(float[] v, float[] v1, float[] v2, float[] v3, float[] v4, float[] v5, float[] v6, float[] v7, int w, int h, int d) + { + PositionTextureVertex[] verts = new PositionTextureVertex[8]; + TexturedPolygon[] poly = new TexturedPolygon[6]; + PositionTextureVertex positionTexturevertex = new PositionTextureVertex(v[0], v[1], v[2], 0.0F, 0.0F); + PositionTextureVertex positionTexturevertex1 = new PositionTextureVertex(v1[0], v1[1], v1[2], 0.0F, 8F); + PositionTextureVertex positionTexturevertex2 = new PositionTextureVertex(v2[0], v2[1], v2[2], 8F, 8F); + PositionTextureVertex positionTexturevertex3 = new PositionTextureVertex(v3[0], v3[1], v3[2], 8F, 0.0F); + PositionTextureVertex positionTexturevertex4 = new PositionTextureVertex(v4[0], v4[1], v4[2], 0.0F, 0.0F); + PositionTextureVertex positionTexturevertex5 = new PositionTextureVertex(v5[0], v5[1], v5[2], 0.0F, 8F); + PositionTextureVertex positionTexturevertex6 = new PositionTextureVertex(v6[0], v6[1], v6[2], 8F, 8F); + PositionTextureVertex positionTexturevertex7 = new PositionTextureVertex(v7[0], v7[1], v7[2], 8F, 0.0F); + verts[0] = positionTexturevertex; + verts[1] = positionTexturevertex1; + verts[2] = positionTexturevertex2; + verts[3] = positionTexturevertex3; + verts[4] = positionTexturevertex4; + verts[5] = positionTexturevertex5; + verts[6] = positionTexturevertex6; + verts[7] = positionTexturevertex7; + poly[0] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex5, positionTexturevertex1, positionTexturevertex2, positionTexturevertex6 + }, textureOffsetX + d + w, textureOffsetY + d, textureOffsetX + d + w + d, textureOffsetY + d + h); + poly[1] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex, positionTexturevertex4, positionTexturevertex7, positionTexturevertex3 + }, textureOffsetX + 0, textureOffsetY + d, textureOffsetX + d, textureOffsetY + d + h); + poly[2] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex5, positionTexturevertex4, positionTexturevertex, positionTexturevertex1 + }, textureOffsetX + d, textureOffsetY + 0, textureOffsetX + d + w, textureOffsetY + d); + poly[3] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex2, positionTexturevertex3, positionTexturevertex7, positionTexturevertex6 + }, textureOffsetX + d + w, textureOffsetY + 0, textureOffsetX + d + w + w, textureOffsetY + d); + poly[4] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex1, positionTexturevertex, positionTexturevertex3, positionTexturevertex2 + }, textureOffsetX + d, textureOffsetY + d, textureOffsetX + d + w, textureOffsetY + d + h); + poly[5] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex4, positionTexturevertex5, positionTexturevertex6, positionTexturevertex7 + }, textureOffsetX + d + w + d, textureOffsetY + d, textureOffsetX + d + w + d + w, textureOffsetY + d + h); + if(mirror ^ flip) + { + for(int l = 0; l < poly.length; l++) + { + poly[l].flipFace(); + } + + } + + copyTo(verts, poly); + } + + /** + * Adds a new box to the model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width (over the x-direction) + * @param h the height (over the y-direction) + * @param d the depth (over the z-direction) + */ + public ModelRendererTurbo addBox(float x, float y, float z, int w, int h, int d) + { + addBox(x, y, z, w, h, d, 0.0F); + return this; + } + + /** + * Adds a new box to the model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width (over the x-direction) + * @param h the height (over the y-direction) + * @param d the depth (over the z-direction) + * @param expansion the expansion of the box. It increases the size in each direction by that many. + */ + public void addBox(float x, float y, float z, int w, int h, int d, float expansion) + { + addBox(x, y, z, w, h, d, expansion, 1F); + } + + /** + * Adds a new box to the model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width (over the x-direction) + * @param h the height (over the y-direction) + * @param d the depth (over the z-direction) + * @param expansion the expansion of the box. It increases the size in each direction by that many. It's independent from the scale. + * @param scale + */ + public void addBox(float x, float y, float z, int w, int h, int d, float expansion, float scale) + { + float scaleX = (float)w * scale; + float scaleY = (float)h * scale; + float scaleZ = (float)d * scale; + + float x1 = x + scaleX; + float y1 = y + scaleY; + float z1 = z + scaleZ; + + float expX = expansion + scaleX - (float)w; + float expY = expansion + scaleY - (float)h; + float expZ = expansion + scaleZ - (float)d; + + x -= expX; + y -= expY; + z -= expZ; + x1 += expansion; + y1 += expansion; + z1 += expansion; + if(mirror) + { + float xTemp = x1; + x1 = x; + x = xTemp; + } + + float[] v = {x, y, z}; + float[] v1 = {x1, y, z}; + float[] v2 = {x1, y1, z}; + float[] v3 = {x, y1, z}; + float[] v4 = {x, y, z1}; + float[] v5 = {x1, y, z1}; + float[] v6 = {x1, y1, z1}; + float[] v7 = {x, y1, z1}; + addRectShape(v, v1, v2, v3, v4, v5, v6, v7, w, h, d); + } + + /** + * Adds a trapezoid-like shape. It's achieved by expanding the shape on one side. + * You can use the static variables MR_RIGHT, MR_LEFT, + * MR_FRONT, MR_BACK, MR_TOP and + * MR_BOTTOM. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width (over the x-direction) + * @param h the height (over the y-direction) + * @param d the depth (over the z-direction) + * @param scale the "scale" of the box. It only increases the size in each direction by that many. + * @param bottomScale the "scale" of the bottom + * @param dir the side the scaling is applied to + */ + public void addTrapezoid(float x, float y, float z, int w, int h, int d, float scale, float bottomScale, int dir) + { + float f4 = x + (float)w; + float f5 = y + (float)h; + float f6 = z + (float)d; + x -= scale; + y -= scale; + z -= scale; + f4 += scale; + f5 += scale; + f6 += scale; + + int m = (mirror ? -1 : 1); + if(mirror) + { + float f7 = f4; + f4 = x; + x = f7; + } + + float[] v = {x, y, z}; + float[] v1 = {f4, y, z}; + float[] v2 = {f4, f5, z}; + float[] v3 = {x, f5, z}; + float[] v4 = {x, y, f6}; + float[] v5 = {f4, y, f6}; + float[] v6 = {f4, f5, f6}; + float[] v7 = {x, f5, f6}; + + switch(dir) + { + case MR_RIGHT: + v[1] -= bottomScale; + v[2] -= bottomScale; + v3[1] += bottomScale; + v3[2] -= bottomScale; + v4[1] -= bottomScale; + v4[2] += bottomScale; + v7[1] += bottomScale; + v7[2] += bottomScale; + break; + case MR_LEFT: + v1[1] -= bottomScale; + v1[2] -= bottomScale; + v2[1] += bottomScale; + v2[2] -= bottomScale; + v5[1] -= bottomScale; + v5[2] += bottomScale; + v6[1] += bottomScale; + v6[2] += bottomScale; + break; + case MR_FRONT: + v[0] -= m * bottomScale; + v[1] -= bottomScale; + v1[0] += m * bottomScale; + v1[1] -= bottomScale; + v2[0] += m * bottomScale; + v2[1] += bottomScale; + v3[0] -= m * bottomScale; + v3[1] += bottomScale; + break; + case MR_BACK: + v4[0] -= m * bottomScale; + v4[1] -= bottomScale; + v5[0] += m * bottomScale; + v5[1] -= bottomScale; + v6[0] += m * bottomScale; + v6[1] += bottomScale; + v7[0] -= m * bottomScale; + v7[1] += bottomScale; + break; + case MR_TOP: + v[0] -= m * bottomScale; + v[2] -= bottomScale; + v1[0] += m * bottomScale; + v1[2] -= bottomScale; + v4[0] -= m * bottomScale; + v4[2] += bottomScale; + v5[0] += m * bottomScale; + v5[2] += bottomScale; + break; + case MR_BOTTOM: + v2[0] += m * bottomScale; + v2[2] -= bottomScale; + v3[0] -= m * bottomScale; + v3[2] -= bottomScale; + v6[0] += m * bottomScale; + v6[2] += bottomScale; + v7[0] -= m * bottomScale; + v7[2] += bottomScale; + break; + } + + addRectShape(v, v1, v2, v3, v4, v5, v6, v7, w, h, d); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param coordinates an array of coordinates that form the shape + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + */ + public void addShape3D(float x, float y, float z, Coord2D[] coordinates, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction) + { + addShape3D(x, y, z, coordinates, depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, direction, null); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param coordinates an array of coordinates that form the shape + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + * @param faceLengths An array with the length of each face. Used to set + * the texture width of each face on the side manually. + */ + public void addShape3D(float x, float y, float z, Coord2D[] coordinates, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction, float[] faceLengths) + { + addShape3D(x, y, z, new Shape2D(coordinates), depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, direction, faceLengths); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param coordinates an ArrayList of coordinates that form the shape + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + */ + public void addShape3D(float x, float y, float z, ArrayList coordinates, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction) + { + addShape3D(x, y, z, coordinates, depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, direction, null); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param coordinates an ArrayList of coordinates that form the shape + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + * @param faceLengths An array with the length of each face. Used to set + * the texture width of each face on the side manually. + */ + public void addShape3D(float x, float y, float z, ArrayList coordinates, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction, float[] faceLengths) + { + addShape3D(x, y, z, new Shape2D(coordinates), depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, direction, faceLengths); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param shape a Shape2D which contains the coordinates of the shape points + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + */ + public void addShape3D(float x, float y, float z, Shape2D shape, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction) + { + addShape3D(x, y, z, shape, depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, direction, null); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param shape a Shape2D which contains the coordinates of the shape points + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param direction the direction the starting point of the shape is facing + * @param faceLengths An array with the length of each face. Used to set + * the texture width of each face on the side manually. + */ + public void addShape3D(float x, float y, float z, Shape2D shape, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, int direction, float[] faceLengths) + { + float rotX = 0; + float rotY = 0; + float rotZ = 0; + switch(direction) + { + case MR_LEFT: + rotY = pi / 2; + break; + case MR_RIGHT: + rotY = -pi / 2; + break; + case MR_TOP: + rotX = pi / 2; + break; + case MR_BOTTOM: + rotX = -pi / 2; + break; + case MR_FRONT: + rotY = pi; + break; + case MR_BACK: + break; + } + addShape3D(x, y, z, shape, depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, rotX, rotY, rotZ, faceLengths); + } + + /** + * Creates a shape from a 2D vector shape. + * @param x the starting x position + * @param y the starting y position + * @param z the starting z position + * @param shape a Shape2D which contains the coordinates of the shape points + * @param depth the depth of the shape + * @param shapeTextureWidth the width of the texture of one side of the shape + * @param shapeTextureHeight the height of the texture the shape + * @param sideTextureWidth the width of the texture of the side of the shape + * @param sideTextureHeight the height of the texture of the side of the shape + * @param rotX the rotation around the x-axis + * @param rotY the rotation around the y-axis + * @param rotZ the rotation around the z-axis + */ + public void addShape3D(float x, float y, float z, Shape2D shape, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, float rotX, float rotY, float rotZ) + { + addShape3D(x, y, z, shape, depth, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, rotX, rotY, rotZ, null); + } + + public void addShape3D(float x, float y, float z, Shape2D shape, float depth, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, float rotX, float rotY, float rotZ, float[] faceLengths) + { + Shape3D shape3D = shape.extrude(x, y, z, rotX, rotY, rotZ, depth, textureOffsetX, textureOffsetY, textureWidth, textureHeight, shapeTextureWidth, shapeTextureHeight, sideTextureWidth, sideTextureHeight, faceLengths); + + if(flip) + { + for(int idx = 0; idx < shape3D.faces.length; idx++) + { + shape3D.faces[idx].flipFace(); + } + } + + copyTo(shape3D.vertices, shape3D.faces); + } + + /** + * Adds a cube the size of one pixel. It will take a pixel from the texture and + * uses that as the texture of said cube. The accurate name would actually be + * "addVoxel". This method has been added to make it more compatible with Techne, + * and allows for easy single-colored boxes. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param width the width of the box + * @param height the height of the box + * @param length the length of the box + */ + public void addPixel(float x, float y, float z, float width, float height, float length) + { + addPixel(x, y, z, new float[] {width, height, length}, textureOffsetX, textureOffsetY); + } + + /** + * Adds a cube the size of one pixel. It will take a pixel from the texture and + * uses that as the texture of said cube. The accurate name would actually be + * "addVoxel". It will not overwrite the model data, but rather, it will add to + * the model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param scale the "scale" of the cube, where scale is a float integer consisting of three values + * @param w the x-coordinate on the texture + * @param h the y-coordinate on the texture + */ + public void addPixel(float x, float y, float z, float[] scale, int w, int h) + { + PositionTextureVertex[] verts = new PositionTextureVertex[8]; + TexturedPolygon[] poly = new TexturedPolygon[6]; + + float x1 = x + scale[0]; + float y1 = y + scale[1]; + float z1 = z + scale[2]; + + float[] f = {x, y, z}; + float[] f1 = {x1, y, z}; + float[] f2 = {x1, y1, z}; + float[] f3 = {x, y1, z}; + float[] f4 = {x, y, z1}; + float[] f5 = {x1, y, z1}; + float[] f6 = {x1, y1, z1}; + float[] f7 = {x, y1, z1}; + PositionTextureVertex positionTexturevertex = new PositionTextureVertex(f[0], f[1], f[2], 0.0F, 0.0F); + PositionTextureVertex positionTexturevertex1 = new PositionTextureVertex(f1[0], f1[1], f1[2], 0.0F, 8F); + PositionTextureVertex positionTexturevertex2 = new PositionTextureVertex(f2[0], f2[1], f2[2], 8F, 8F); + PositionTextureVertex positionTexturevertex3 = new PositionTextureVertex(f3[0], f3[1], f3[2], 8F, 0.0F); + PositionTextureVertex positionTexturevertex4 = new PositionTextureVertex(f4[0], f4[1], f4[2], 0.0F, 0.0F); + PositionTextureVertex positionTexturevertex5 = new PositionTextureVertex(f5[0], f5[1], f5[2], 0.0F, 8F); + PositionTextureVertex positionTexturevertex6 = new PositionTextureVertex(f6[0], f6[1], f6[2], 8F, 8F); + PositionTextureVertex positionTexturevertex7 = new PositionTextureVertex(f7[0], f7[1], f7[2], 8F, 0.0F); + + verts[0] = positionTexturevertex; + verts[1] = positionTexturevertex1; + verts[2] = positionTexturevertex2; + verts[3] = positionTexturevertex3; + verts[4] = positionTexturevertex4; + verts[5] = positionTexturevertex5; + verts[6] = positionTexturevertex6; + verts[7] = positionTexturevertex7; + + poly[0] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex5, positionTexturevertex1, positionTexturevertex2, positionTexturevertex6 + }, w, h, w + 1, h + 1); + poly[1] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex, positionTexturevertex4, positionTexturevertex7, positionTexturevertex3 + }, w, h, w + 1, h + 1); + poly[2] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex5, positionTexturevertex4, positionTexturevertex, positionTexturevertex1 + }, w, h, w + 1, h + 1); + poly[3] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex2, positionTexturevertex3, positionTexturevertex7, positionTexturevertex6 + }, w, h, w + 1, h + 1); + poly[4] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex1, positionTexturevertex, positionTexturevertex3, positionTexturevertex2 + }, w, h, w + 1, h + 1); + poly[5] = addPolygonReturn(new PositionTextureVertex[] { + positionTexturevertex4, positionTexturevertex5, positionTexturevertex6, positionTexturevertex7 + }, w, h, w + 1, h + 1); + + copyTo(verts, poly); + } + + /** + * Creates a model shaped like the exact image on the texture. Note that this method will + * increase the amount of quads on your model, which could effectively slow down your + * PC, so unless it is really a necessity to use it, I'd suggest you avoid using this + * method to create your model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width of the sprite + * @param h the height of the sprite + * @param expansion the expansion of the sprite. It only increases the size in each direction by that many. + */ + public void addSprite(float x, float y, float z, int w, int h, float expansion) + { + addSprite(x, y, z, w, h, 1, false, false, false, false, false, expansion); + } + + /** + * Creates a model shaped like the exact image on the texture. Note that this method will + * increase the amount of quads on your model, which could effectively slow down your + * PC, so unless it is really a necessity to use it, I'd suggest you avoid using this + * method to create your model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width of the sprite + * @param h the height of the sprite + * @param rotX a boolean to define if it rotates 90 degrees around its yaw-axis + * @param rotY a boolean to define if it rotates 90 degrees around its pitch-axis + * @param rotZ a boolean to define if it rotates 90 degrees around its roll-axis + * @param mirrorX a boolean to define if the sprite should be mirrored + * @param mirrorY a boolean to define if the sprite should be flipped + * @param expansion the expansion of the sprite. It only increases the size in each direction by that many. + */ + public void addSprite(float x, float y, float z, int w, int h, boolean rotX, boolean rotY, boolean rotZ, boolean mirrorX, boolean mirrorY, float expansion) + { + addSprite(x, y, z, w, h, 1, rotX, rotY, rotZ, mirrorX, mirrorY, expansion); + } + + /** + * Creates a model shaped like the exact image on the texture. Note that this method will + * increase the amount of quads on your model, which could effectively slow down your + * PC, so unless it is really a necessity to use it, I'd suggest you avoid using this + * method to create your model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width of the sprite + * @param h the height of the sprite + * @param d the depth of the shape itself + * @param rotX a boolean to define if it rotates 90 degrees around its yaw-axis + * @param rotY a boolean to define if it rotates 90 degrees around its pitch-axis + * @param rotZ a boolean to define if it rotates 90 degrees around its roll-axis + * @param mirrorX a boolean to define if the sprite should be mirrored + * @param mirrorY a boolean to define if the sprite should be flipped + * @param expansion the expansion of the sprite. It only increases the size in each direction by that many. + */ + public void addSprite(float x, float y, float z, int w, int h, int d, boolean rotX, boolean rotY, boolean rotZ, boolean mirrorX, boolean mirrorY, float expansion) + { + addSprite(x, y, z, w, h, d, 1.0F, rotX, rotY, rotZ, mirrorX, mirrorY, expansion); + } + + /** + * Creates a model shaped like the exact image on the texture. Note that this method will + * increase the amount of quads on your model, which could effectively slow down your + * PC, so unless it is really a necessity to use it, I'd suggest you avoid using this + * method to create your model. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param w the width of the sprite + * @param h the height of the sprite + * @param d the depth of the shape itself + * @param pixelScale the scale of each individual pixel + * @param rotX a boolean to define if it rotates 90 degrees around its yaw-axis + * @param rotY a boolean to define if it rotates 90 degrees around its pitch-axis + * @param rotZ a boolean to define if it rotates 90 degrees around its roll-axis + * @param mirrorX a boolean to define if the sprite should be mirrored + * @param mirrorY a boolean to define if the sprite should be flipped + * @param expansion the expansion of the sprite. It only increases the size in each direction by that many. + */ + public void addSprite(float x, float y, float z, int w, int h, int d, float pixelScale, boolean rotX, boolean rotY, boolean rotZ, boolean mirrorX, boolean mirrorY, float expansion) + { + String[] mask = new String[h]; + char[] str = new char[w]; + Arrays.fill(str, '1'); + Arrays.fill(mask, new String(str)); + + addSprite(x, y, z, mask, d, pixelScale, rotX, rotY, rotZ, mirrorX, mirrorY, expansion); + } + + /** + * Creates a model shaped like the exact image on the texture. Note that this method will + * increase the amount of quads on your model, which could effectively slow down your + * PC, so unless it is really a necessity to use it, I'd suggest you avoid using this + * method to create your model. + *

+ * This method uses a mask string. This way you can reduce the amount of quads used. To + * use this, create a String array, where you use a 1 to signify that the pixel will be + * drawn. Any other character will cause that pixel to not be drawn. + * @param x the starting x-position + * @param y the starting y-position + * @param z the starting z-position + * @param mask an array with the mask string + * @param d the depth of the shape itself + * @param pixelScale the scale of each individual pixel + * @param rotX a boolean to define if it rotates 90 degrees around its yaw-axis + * @param rotY a boolean to define if it rotates 90 degrees around its pitch-axis + * @param rotZ a boolean to define if it rotates 90 degrees around its roll-axis + * @param mirrorX a boolean to define if the sprite should be mirrored + * @param mirrorY a boolean to define if the sprite should be flipped + * @param expansion the expansion of the sprite. It only increases the size in each direction by that many. + */ + public void addSprite(float x, float y, float z, String[] mask, int d, float pixelScale, boolean rotX, boolean rotY, boolean rotZ, boolean mirrorX, boolean mirrorY, float expansion) + { + int w = mask[0].length(); + int h = mask.length; + + float x1 = x - expansion; + float y1 = y - expansion; + float z1 = z - expansion; + + int wDir = 0; + int hDir = 0; + int dDir = 0; + + float wScale = 1F + (expansion / ((float) w * pixelScale)); + float hScale = 1F + (expansion / ((float) h * pixelScale)); + + if(!rotX) + { + if(!rotY) + { + if(!rotZ) + { + wDir = 0; + hDir = 1; + dDir = 2; + } + else + { + wDir = 1; + hDir = 0; + dDir = 2; + } + } + else + { + if(!rotZ) + { + wDir = 2; + hDir = 1; + dDir = 0; + } + else + { + wDir = 2; + hDir = 0; + dDir = 1; + } + } + } + else + { + if(!rotY) + { + if(!rotZ) + { + wDir = 0; + hDir = 2; + dDir = 1; + } + else + { + wDir = 1; + hDir = 2; + dDir = 0; + } + } + else + { + if(!rotZ) + { + wDir = 2; + hDir = 0; + dDir = 1; + } + else + { + wDir = 2; + hDir = 1; + dDir = 0; + } + } + } + + int texStartX = textureOffsetX + (mirrorX ? w * 1 - 1 : 0); + int texStartY = textureOffsetY + (mirrorY ? h * 1 - 1 : 0); + int texDirX = (mirrorX ? -1 : 1); + int texDirY = (mirrorY ? -1 : 1); + + float wVoxSize = getPixelSize(wScale, hScale, d * pixelScale + expansion * 2, 0, 1, wDir, 1, 1); + float hVoxSize = getPixelSize(wScale, hScale, d * pixelScale + expansion * 2, 0, 1, hDir, 1, 1); + float dVoxSize = getPixelSize(wScale, hScale, d * pixelScale + expansion * 2, 0, 1, dDir, 1, 1); + + for(int i = 0; i < w; i++) + { + for(int j = 0; j < h; j++) + { + if(mask[j].charAt(i) == '1') + { + addPixel(x1 + getPixelSize(wScale, hScale, 0, wDir, hDir, 0, i, j), + y1 + getPixelSize(wScale, hScale, 0, wDir, hDir, 1, i, j), + z1 + getPixelSize(wScale, hScale, 0, wDir, hDir, 2, i, j), + new float[] {wVoxSize, hVoxSize, dVoxSize}, texStartX + texDirX * i, texStartY + texDirY * j); + } + } + } + } + + private float getPixelSize(float wScale, float hScale, float dScale, int wDir, int hDir, int checkDir, int texPosX, int texPosY) + { + return (wDir == checkDir ? wScale * texPosX : (hDir == checkDir ? hScale * texPosY : dScale)); + } + + /** + * Adds a spherical shape. + * @param x + * @param y + * @param z + * @param r + * @param segs + * @param rings + * @param textureW + * @param textureH + */ + public void addSphere(float x, float y, float z, float r, int segs, int rings, int textureW, int textureH) + { + if(segs < 3) + segs = 3; + rings++; + PositionTextureVertex[] tempVerts = new PositionTextureVertex[segs * (rings - 1) + 2]; + TexturedPolygon[] poly = new TexturedPolygon[segs * rings]; + + tempVerts[0] = new PositionTextureVertex(x, y - r, z, 0, 0); + tempVerts[tempVerts.length - 1] = new PositionTextureVertex(x, y + r, z, 0, 0); + + float uOffs = 1.0F / ((float) textureWidth * 10.0F); + float vOffs = 1.0F / ((float) textureHeight * 10.0F); + float texW = (float) textureW / (float)textureWidth - 2F * uOffs; + float texH = (float) textureH / (float)textureHeight - 2F * vOffs; + float segW = texW / (float) segs; + float segH = texH / (float) rings; + float startU = (float) textureOffsetX / (float) textureWidth; + float startV = (float) textureOffsetY / (float) textureHeight; + + int currentFace = 0; + + for(int j = 1; j < rings; j++) + { + for(int i = 0; i < segs; i++) + { + float yWidth = MathHelper.cos(-pi / 2 + (pi / (float)rings) * (float) j); + float yHeight = MathHelper.sin(-pi / 2 + (pi / (float)rings) * (float) j); + float xSize = MathHelper.sin((pi / (float)segs) * i * 2F + pi) * yWidth; + float zSize = -MathHelper.cos((pi / (float)segs) * i * 2F + pi) * yWidth; + int curVert = 1 + i + segs * (j - 1); + tempVerts[curVert] = new PositionTextureVertex(x + xSize * r, y + yHeight * r, z + zSize * r, 0, 0); + if(i > 0) + { + PositionTextureVertex[] verts; + if(j == 1) + { + verts = new PositionTextureVertex[4]; + verts[0] = tempVerts[curVert].setTexturePosition(startU + segW * i, startV + segH * j); + verts[1] = tempVerts[curVert - 1].setTexturePosition(startU + segW * (i - 1), startV + segH * j); + verts[2] = tempVerts[0].setTexturePosition(startU + segW * (i - 1), startV); + verts[3] = tempVerts[0].setTexturePosition(startU + segW + segW * i, startV); + } + else + { + verts = new PositionTextureVertex[4]; + verts[0] = tempVerts[curVert].setTexturePosition(startU + segW * i, startV + segH * j); + verts[1] = tempVerts[curVert - 1].setTexturePosition(startU + segW * (i - 1), startV + segH * j); + verts[2] = tempVerts[curVert - 1 - segs].setTexturePosition(startU + segW * (i - 1), startV + segH * (j - 1)); + verts[3] = tempVerts[curVert - segs].setTexturePosition(startU + segW * i, startV + segH * (j - 1)); + } + poly[currentFace] = new TexturedPolygon(verts); + currentFace++; + } + } + PositionTextureVertex[] verts; + if(j == 1) + { + verts = new PositionTextureVertex[4]; + verts[0] = tempVerts[1].setTexturePosition(startU + segW * segs, startV + segH * j); + verts[1] = tempVerts[segs].setTexturePosition(startU + segW * (segs - 1), startV + segH * j); + verts[2] = tempVerts[0].setTexturePosition(startU + segW * (segs - 1), startV); + verts[3] = tempVerts[0].setTexturePosition(startU + segW * segs, startV); + } + else + { + verts = new PositionTextureVertex[4]; + verts[0] = tempVerts[1 + segs * (j - 1)].setTexturePosition(startU + texW, startV + segH * j); + verts[1] = tempVerts[segs * (j - 1) + segs].setTexturePosition(startU + texW - segW, startV + segH * j); + verts[2] = tempVerts[segs * (j - 1)].setTexturePosition(startU + texW - segW, startV + segH * (j - 1)); + verts[3] = tempVerts[1 + segs * (j - 1) - segs].setTexturePosition(startU + texW, startV + segH * (j - 1)); + } + poly[currentFace] = new TexturedPolygon(verts); + currentFace++; + } + for(int i = 0; i < segs; i++) + { + PositionTextureVertex[] verts = new PositionTextureVertex[3]; + int curVert = tempVerts.length - (segs + 1); + verts[0] = tempVerts[tempVerts.length - 1].setTexturePosition(startU + segW * (i + 0.5F), startV + texH); + verts[1] = tempVerts[curVert + i].setTexturePosition(startU + segW * i, startV + texH - segH); + verts[2] = tempVerts[curVert + ((i + 1) % segs)].setTexturePosition(startU + segW * (i + 1), startV + texH - segH); + poly[currentFace] = new TexturedPolygon(verts); + currentFace++; + } + + copyTo(tempVerts, poly); + } + + /** + * Adds a cone. + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + */ + public void addCone(float x, float y, float z, float radius, float length, int segments) + { + addCone(x, y, z, radius, length, segments, 1F); + } + + /** + * Adds a cone. + * + * baseScale cannot be zero. If it is, it will automatically be set to 1F. + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + */ + public void addCone(float x, float y, float z, float radius, float length, int segments, float baseScale) + { + addCone(x, y, z, radius, length, segments, baseScale, MR_TOP); + } + + /** + * Adds a cone. + * + * baseScale cannot be zero. If it is, it will automatically be set to 1F. + * + * Setting the baseDirection to either MR_LEFT, MR_BOTTOM or MR_BACK will result in + * the top being placed at the (x,y,z). + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + * @param baseDirection the direction it faces + */ + public void addCone(float x, float y, float z, float radius, float length, int segments, float baseScale, int baseDirection) + { + addCone(x, y, z, radius, length, segments, baseScale, baseDirection, (int)Math.floor(radius * 2F), (int)Math.floor(radius * 2F)); + } + + /** + * Adds a cone. + * + * baseScale cannot be zero. If it is, it will automatically be set to 1F. + * + * Setting the baseDirection to either MR_LEFT, MR_BOTTOM or MR_BACK will result in + * the top being placed at the (x,y,z). + * + * The textures for the sides are placed next to each other. + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + * @param baseDirection the direction it faces + * @param textureCircleDiameterW the diameter width of the circle on the texture + * @param textureCircleDiameterH the diameter height of the circle on the texture + */ + public void addCone(float x, float y, float z, float radius, float length, int segments, float baseScale, int baseDirection, int textureCircleDiameterW, int textureCircleDiameterH) + { + addCylinder(x, y, z, radius, length, segments, baseScale, 0.0F, baseDirection, textureCircleDiameterW, textureCircleDiameterH, 1); + } + + /** + * Adds a cylinder. + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + */ + public void addCylinder(float x, float y, float z, float radius, float length, int segments) + { + addCylinder(x, y, z, radius, length, segments, 1F, 1F); + } + + /** + * Adds a cylinder. + * + * You can make cones by either setting baseScale or topScale to zero. Setting both + * to zero will set the baseScale to 1F. + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + * @param topScale the scaling of the top. Can be negative. + */ + public void addCylinder(float x, float y, float z, float radius, float length, int segments, float baseScale, float topScale) + { + addCylinder(x, y, z, radius, length, segments, baseScale, topScale, MR_TOP); + } + + /** + * Adds a cylinder. + * + * You can make cones by either setting baseScale or topScale to zero. Setting both + * to zero will set the baseScale to 1F. + * + * Setting the baseDirection to either MR_LEFT, MR_BOTTOM or MR_BACK will result in + * the top being placed at the (x,y,z). + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + * @param topScale the scaling of the top. Can be negative. + * @param baseDirection the direction it faces + */ + public void addCylinder(float x, float y, float z, float radius, float length, int segments, float baseScale, float topScale, int baseDirection) + { + addCylinder(x, y, z, radius, length, segments, baseScale, topScale, baseDirection, (int)Math.floor(radius * 2F), (int)Math.floor(radius * 2F), (int)Math.floor(length)); + } + + /** + * Adds a cylinder. + * + * You can make cones by either setting baseScale or topScale to zero. Setting both + * to zero will set the baseScale to 1F. + * + * Setting the baseDirection to either MR_LEFT, MR_BOTTOM or MR_BACK will result in + * the top being placed at the (x,y,z). + * + * The textures for the base and top are placed next to each other, while the body + * will be placed below the circles. + * + * @param x the x-position of the base + * @param y the y-position of the base + * @param z the z-position of the base + * @param radius the radius of the cylinder + * @param length the length of the cylinder + * @param segments the amount of segments the cylinder is made of + * @param baseScale the scaling of the base. Can be negative. + * @param topScale the scaling of the top. Can be negative. + * @param baseDirection the direction it faces + * @param textureCircleDiameterW the diameter width of the circle on the texture + * @param textureCircleDiameterH the diameter height of the circle on the texture + * @param textureH the height of the texture of the body + */ + public void addCylinder(float x, float y, float z, float radius, float length, int segments, float baseScale, float topScale, int baseDirection, int textureCircleDiameterW, int textureCircleDiameterH, int textureH) + { + boolean dirTop = (baseDirection == MR_TOP || baseDirection == MR_BOTTOM); + boolean dirSide = (baseDirection == MR_RIGHT || baseDirection == MR_LEFT); + boolean dirFront = (baseDirection == MR_FRONT || baseDirection == MR_BACK); + boolean dirMirror = (baseDirection == MR_LEFT || baseDirection == MR_BOTTOM || baseDirection == MR_BACK); + + boolean coneBase = (baseScale == 0); + boolean coneTop = (topScale == 0); + + if(coneBase && coneTop) + { + baseScale = 1F; + coneBase = false; + } + + PositionTextureVertex[] tempVerts = new PositionTextureVertex[segments * (coneBase || coneTop ? 1 : 2) + 2]; + TexturedPolygon[] poly = new TexturedPolygon[segments * (coneBase || coneTop ? 2 : 3)]; + + float xLength = (dirSide ? length : 0); + float yLength = (dirTop ? length : 0); + float zLength = (dirFront ? length : 0); + + float xStart = (dirMirror ? x + xLength : x); + float yStart = (dirMirror ? y + yLength : y); + float zStart = (dirMirror ? z + zLength : z); + float xEnd = (!dirMirror ? x + xLength : x); + float yEnd = (!dirMirror ? y + yLength : y); + float zEnd = (!dirMirror ? z + zLength : z); + + tempVerts[0] = new PositionTextureVertex(xStart, yStart, zStart, 0, 0); + tempVerts[tempVerts.length - 1] = new PositionTextureVertex(xEnd, yEnd, zEnd, 0, 0); + + float xCur = xStart; + float yCur = yStart; + float zCur = zStart; + float sCur = (coneBase ? topScale : baseScale); + for(int repeat = 0; repeat < (coneBase || coneTop ? 1 : 2); repeat++) + { + for(int index = 0; index < segments; index++) + { + float xSize = (mirror ^ dirMirror ? -1 : 1) * MathHelper.sin((pi / (float)segments) * index * 2F + pi) * radius * sCur; + float zSize = -MathHelper.cos((pi / (float)segments) * index * 2F + pi) * radius * sCur; + + float xPlace = xCur + (!dirSide ? xSize : 0); + float yPlace = yCur + (!dirTop ? zSize : 0); + float zPlace = zCur + (dirSide ? xSize : (dirTop ? zSize : 0)); + + tempVerts[1 + index + repeat * segments] = new PositionTextureVertex(xPlace, yPlace, zPlace, 0, 0 ); + } + xCur = xEnd; + yCur = yEnd; + zCur = zEnd; + sCur = topScale; + } + + float uScale = 1.0F / (float) textureWidth; + float vScale = 1.0F / (float) textureHeight; + float uOffset = uScale / 20.0F; + float vOffset = vScale / 20.0F; + float uCircle = (float)textureCircleDiameterW * uScale; + float vCircle = (float)textureCircleDiameterH * vScale; + float uWidth = (uCircle * 2F - uOffset * 2F) / (float) segments; + float vHeight = (float)textureH * vScale - uOffset * 2f; + float uStart = (float)textureOffsetX * uScale; + float vStart = (float)textureOffsetY * vScale; + + PositionTextureVertex[] vert; + for(int index = 0; index < segments; index++) + { + int index2 = (index + 1) % segments; + float uSize = MathHelper.sin((pi / (float)segments) * index * 2F + (!dirTop ? 0 : pi)) * (0.5F * uCircle - 2F * uOffset); + float vSize = MathHelper.cos((pi / (float)segments) * index * 2F + (!dirTop ? 0 : pi)) * (0.5F * vCircle - 2F * vOffset); + float uSize1 = MathHelper.sin((pi / (float)segments) * index2 * 2F + (!dirTop ? 0 : pi)) * (0.5F * uCircle - 2F * uOffset); + float vSize1 = MathHelper.cos((pi / (float)segments) * index2 * 2F + (!dirTop ? 0 : pi)) * (0.5F * vCircle - 2F * vOffset); + vert = new PositionTextureVertex[3]; + + vert[0] = tempVerts[0].setTexturePosition(uStart + 0.5F * uCircle, vStart + 0.5F * vCircle); + vert[1] = tempVerts[1 + index2].setTexturePosition(uStart + 0.5F * uCircle + uSize1, vStart + 0.5F * vCircle + vSize1); + vert[2] = tempVerts[1 + index].setTexturePosition(uStart + 0.5F * uCircle + uSize, vStart + 0.5F * vCircle + vSize); + + poly[index] = new TexturedPolygon(vert); + if(mirror ^ flip) + poly[index].flipFace(); + + if(!coneBase && !coneTop) + { + vert = new PositionTextureVertex[4]; + + vert[0] = tempVerts[1 + index].setTexturePosition(uStart + uOffset + uWidth * (float)index, vStart + vOffset + vCircle); + vert[1] = tempVerts[1 + index2].setTexturePosition(uStart + uOffset + uWidth * (float)(index + 1), vStart + vOffset + vCircle); + vert[2] = tempVerts[1 + segments + index2].setTexturePosition(uStart + uOffset + uWidth * (float)(index + 1), vStart + vOffset + vCircle + vHeight); + vert[3] = tempVerts[1 + segments + index].setTexturePosition(uStart + uOffset + uWidth * (float)index, vStart + vOffset + vCircle + vHeight); + poly[index + segments] = new TexturedPolygon(vert); + if(mirror ^ flip) + poly[index + segments].flipFace(); + } + + vert = new PositionTextureVertex[3]; + + vert[0] = tempVerts[tempVerts.length - 1].setTexturePosition(uStart + 1.5F * uCircle, vStart + 0.5F * vCircle); + vert[1] = tempVerts[tempVerts.length - 2 - index].setTexturePosition(uStart + 1.5F * uCircle + uSize1, vStart + 0.5F * vCircle + vSize1); + vert[2] = tempVerts[tempVerts.length - (1 + segments) + ((segments - index) % segments)].setTexturePosition(uStart + 1.5F * uCircle + uSize, vStart + 0.5F * vCircle + vSize); + + poly[poly.length - segments + index] = new TexturedPolygon(vert); + if(mirror ^ flip) + poly[poly.length - segments + index].flipFace(); + } + copyTo(tempVerts, poly); + } + + /** + * Adds a Waveform .obj file as a model. Model files use the entire texture file. + * @param file the location of the .obj file. The location is relative to the base directories, + * which are either resources/models or resources/mods/models. + */ + public void addObj(String file) + { + addModel(file, ModelPool.OBJ); + } + + /** + * Adds model format support. Model files use the entire texture file. + * @param file the location of the model file. The location is relative to the base directories, + * which are either resources/models or resources/mods/models. + * @param modelFormat the class of the model format interpreter + */ + public void addModel(String file, Class modelFormat) + { + ModelPoolEntry entry = ModelPool.addFile(file, modelFormat, transformGroup, textureGroup); + if(entry == null) + return; + PositionTextureVertex[] verts = Arrays.copyOf(entry.vertices, entry.vertices.length); + TexturedPolygon[] poly = Arrays.copyOf(entry.faces, entry.faces.length); + if(flip) + { + for(int l = 0; l < faces.length; l++) + { + faces[l].flipFace(); + } + } + + copyTo(verts, poly, false); + } + + /** + * Sets a new position for the texture offset. + * @param x the x-coordinate of the texture start + * @param y the y-coordinate of the texture start + */ + public ModelRendererTurbo setTextureOffset(int x, int y) + { + textureOffsetX = x; + textureOffsetY = y; + return this; + } + + /** + * Sets the position of the shape, relative to the model's origins. Note that changing + * the offsets will not change the pivot of the model. + * @param x the x-position of the shape + * @param y the y-position of the shape + * @param z the z-position of the shape + */ + public void setPosition(float x, float y, float z) + { + rotationPointX = x; + rotationPointY = y; + rotationPointZ = z; + } + + /** + * Mirrors the model in any direction. + * @param x whether the model should be mirrored in the x-direction + * @param y whether the model should be mirrored in the y-direction + * @param z whether the model should be mirrored in the z-direction + */ + public void doMirror(boolean x, boolean y, boolean z) + { + for(int i = 0; i < faces.length; i++) + { + PositionTextureVertex[] verts = faces[i].vertexPositions; + for(int j = 0; j < verts.length; j++) + { + verts[j].vector3D.xCoord *= (x ? -1 : 1); + verts[j].vector3D.yCoord *= (y ? -1 : 1); + verts[j].vector3D.zCoord *= (z ? -1 : 1); + } + if(x^y^z) + faces[i].flipFace(); + } + } + + /** + * Sets whether the shape is mirrored or not. This has effect on the way the textures + * get displayed. When working with addSprite, addPixel and addObj, it will be ignored. + * @param isMirrored a boolean to define whether the shape is mirrored + */ + public void setMirrored(boolean isMirrored) + { + mirror = isMirrored; + } + + /** + * Sets whether the shape's faces are flipped or not. When GL_CULL_FACE is enabled, + * it won't render the back faces, effectively giving you the possibility to make + * "hollow" shapes. When working with addSprite and addPixel, it will be ignored. + * @param isFlipped a boolean to define whether the shape is flipped + */ + public void setFlipped(boolean isFlipped) + { + flip = isFlipped; + } + + /** + * Clears the current shape. Since all shapes are stacked into one shape, you can't + * just replace a shape by overwriting the shape with another one. In this case you + * would need to clear the shape first. + */ + public void clear() + { + vertices = new PositionTextureVertex[0]; + faces = new TexturedPolygon[0]; + transformGroup.clear(); + transformGroup.put("0", new TransformGroupBone(new Bone(0, 0, 0, 0), 1D)); + currentGroup = transformGroup.get("0"); + } + + /** + * Copies an array of vertices and polygons to the current shape. This mainly is + * used to copy each shape to the main class, but you can just use it to copy + * your own shapes, for example from other classes, into the current class. + * @param verts the array of vertices you want to copy + * @param poly the array of polygons you want to copy + */ + public void copyTo(PositionTextureVertex[] verts, TexturedPolygon[] poly) + { + copyTo(verts, poly, true); + } + + public void copyTo(PositionTextureVertex[] verts, TexturedPolygon[] poly, boolean copyGroup) + { + vertices = Arrays.copyOf(vertices, vertices.length + verts.length); + faces = Arrays.copyOf(faces, faces.length + poly.length); + + for(int idx = 0; idx < verts.length; idx++) + { + vertices[vertices.length - verts.length + idx] = verts[idx]; + if(copyGroup && verts[idx] instanceof PositionTransformVertex) + ((PositionTransformVertex)verts[idx]).addGroup(currentGroup); + } + + for(int idx = 0; idx < poly.length; idx++) + { + faces[faces.length - poly.length + idx] = poly[idx]; + if(copyGroup) + currentTextureGroup.addPoly(poly[idx]); + } + } + + /** + * Copies an array of vertices and quads to the current shape. This method + * converts quads to polygons and then calls the main copyTo method. + * @param verts the array of vertices you want to copy + * @param quad the array of quads you want to copy + */ + public void copyTo(PositionTextureVertex[] verts, TexturedQuad[] quad) + { + TexturedPolygon[] poly = new TexturedPolygon[quad.length]; + for(int idx = 0; idx < quad.length; idx++) + { + poly[idx] = new TexturedPolygon(quad[idx].vertexPositions); + } + + copyTo(verts, poly); + } + + /** + * Sets the current transformation group. The transformation group is used + * to allow for vertex transformation. If a transformation group does not exist, + * a new one will be created. + * @param groupName the name of the transformation group you want to switch to + */ + public void setGroup(String groupName) + { + setGroup(groupName, new Bone(0, 0, 0, 0), 1D); + } + + /** + * Sets the current transformation group. The transformation group is used + * to allow for vertex transformation. If a transformation group does not exist, + * a new one will be created. + * @param groupName the name of the transformation group you want to switch to + * @param bone the Bone this transformation group is attached to + * @param weight the weight of the transformation group + */ + public void setGroup(String groupName, Bone bone, double weight) + { + if(!transformGroup.containsKey(groupName)) + transformGroup.put(groupName, new TransformGroupBone(bone, weight)); + currentGroup = transformGroup.get(groupName); + } + + /** + * Gets the current transformation group. + * @return the current PositionTransformGroup. + */ + public TransformGroup getGroup() + { + return currentGroup; + } + + /** + * Gets the transformation group with a given group name. + * @return the current PositionTransformGroup. + */ + public TransformGroup getGroup(String groupName) + { + if(!transformGroup.containsKey(groupName)) + return null; + return transformGroup.get(groupName); + } + + /** + * Sets the current texture group, which is used to switch the + * textures on a per-model base. Do note that any model that is + * rendered afterwards will use the same texture. To counter it, + * set a default texture, either at initialization or before + * rendering. + * @param groupName The name of the texture group. If the texture + * group doesn't exist, it creates a new group automatically. + */ + public void setTextureGroup(String groupName) + { + if(!textureGroup.containsKey(groupName)) + { + textureGroup.put(groupName, new TextureGroup()); + } + currentTextureGroup = textureGroup.get(groupName); + } + + /** + * Gets the current texture group. + * @return a TextureGroup object. + */ + public TextureGroup getTextureGroup() + { + return currentTextureGroup; + } + + /** + * Gets the texture group with the given name. + * @param groupName the name of the texture group to return + * @return a TextureGroup object. + */ + public TextureGroup getTextureGroup(String groupName) + { + if(!textureGroup.containsKey(groupName)) + return null; + return textureGroup.get(groupName); + } + + /** + * Sets the texture of the current texture group. + * @param s the filename + */ + public void setGroupTexture(String s) + { + currentTextureGroup.texture = s; + } + + /** + * Sets the default texture. When left as an empty string, + * it will use the texture that has been set previously. + * Note that this will also move on to other rendered models + * of the same entity. + * @param s the filename + */ + public void setDefaultTexture(String s) + { + defaultTexture = s; + } + + /** + * Renders the shape. + * @param worldScale the scale of the shape. Usually is 0.0625. + */ + public void render(float worldScale) + { + if(field_1402_i) + { + return; + } + if(!showModel) + { + return; + } + if(!compiled || forcedRecompile) + { + compileDisplayList(worldScale); + } + if(rotateAngleX != 0.0F || rotateAngleY != 0.0F || rotateAngleZ != 0.0F) + { + GL11.glPushMatrix(); + GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ * worldScale); + if(rotateAngleZ != 0.0F) + { + GL11.glRotatef(rotateAngleZ * 57.29578F, 0.0F, 0.0F, 1.0F); + } + if(rotateAngleY != 0.0F) + { + GL11.glRotatef(rotateAngleY * 57.29578F, 0.0F, 1.0F, 0.0F); + } + if(rotateAngleX != 0.0F) + { + GL11.glRotatef(rotateAngleX * 57.29578F, 1.0F, 0.0F, 0.0F); + } + callDisplayList(); + if(childModels != null) + { + for(int i = 0; i < childModels.size(); i++) + { + ((ModelRenderer)childModels.get(i)).render(worldScale); + } + + } + GL11.glPopMatrix(); + } else + if(rotationPointX != 0.0F || rotationPointY != 0.0F || rotationPointZ != 0.0F) + { + GL11.glTranslatef(rotationPointX * worldScale, rotationPointY * worldScale, rotationPointZ * worldScale); + callDisplayList(); + if(childModels != null) + { + for(int i = 0; i < childModels.size(); i++) + { + ((ModelRenderer)childModels.get(i)).render(worldScale); + } + + } + GL11.glTranslatef(-rotationPointX * worldScale, -rotationPointY * worldScale, -rotationPointZ * worldScale); + } else + { + callDisplayList(); + if(childModels != null) + { + for(int i = 0; i < childModels.size(); i++) + { + ((ModelRenderer)childModels.get(i)).render(worldScale); + } + + } + } + } + + public void renderWithRotation(float f) + { + if(field_1402_i) + { + return; + } + if(!showModel) + { + return; + } + if(!compiled) + { + compileDisplayList(f); + } + GL11.glPushMatrix(); + GL11.glTranslatef(rotationPointX * f, rotationPointY * f, rotationPointZ * f); + if(rotateAngleY != 0.0F) + { + GL11.glRotatef(rotateAngleY * 57.29578F, 0.0F, 1.0F, 0.0F); + } + if(rotateAngleX != 0.0F) + { + GL11.glRotatef(rotateAngleX * 57.29578F, 1.0F, 0.0F, 0.0F); + } + if(rotateAngleZ != 0.0F) + { + GL11.glRotatef(rotateAngleZ * 57.29578F, 0.0F, 0.0F, 1.0F); + } + callDisplayList(); + GL11.glPopMatrix(); + } + + public void postRender(float f) + { + if(field_1402_i) + { + return; + } + if(!showModel) + { + return; + } + if(!compiled || forcedRecompile) + { + compileDisplayList(f); + } + if(rotateAngleX != 0.0F || rotateAngleY != 0.0F || rotateAngleZ != 0.0F) + { + GL11.glTranslatef(rotationPointX * f, rotationPointY * f, rotationPointZ * f); + if(rotateAngleZ != 0.0F) + { + GL11.glRotatef(rotateAngleZ * 57.29578F, 0.0F, 0.0F, 1.0F); + } + if(rotateAngleY != 0.0F) + { + GL11.glRotatef(rotateAngleY * 57.29578F, 0.0F, 1.0F, 0.0F); + } + if(rotateAngleX != 0.0F) + { + GL11.glRotatef(rotateAngleX * 57.29578F, 1.0F, 0.0F, 0.0F); + } + } else + if(rotationPointX != 0.0F || rotationPointY != 0.0F || rotationPointZ != 0.0F) + { + GL11.glTranslatef(rotationPointX * f, rotationPointY * f, rotationPointZ * f); + } + } + + private void callDisplayList() + { + if(useLegacyCompiler) + GL11.glCallList(displayList); + else + { + RenderEngine renderEngine = RenderManager.instance.renderEngine; + + Collection textures = textureGroup.values(); + + Iterator itr = textures.iterator(); + for(int i = 0; itr.hasNext(); i++) + { + TextureGroup curTexGroup = (TextureGroup)itr.next(); + curTexGroup.loadTexture(); + GL11.glCallList(displayListArray[i]); + if(!defaultTexture.equals("")) + renderEngine.bindTexture(renderEngine.getTexture(defaultTexture)); + } + } + } + + private void compileDisplayList(float worldScale) + { + if(useLegacyCompiler) + compileLegacyDisplayList(worldScale); + else + { + Collection textures = textureGroup.values(); + + Iterator itr = textures.iterator(); + displayListArray = new int[textureGroup.size()]; + for(int i = 0; itr.hasNext(); i++) + { + displayListArray[i] = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displayListArray[i], 4864); + Tessellator tessellator = Tessellator.instance; + + TextureGroup usedGroup = (TextureGroup)itr.next(); + for(int j = 0; j < usedGroup.poly.size(); j++) + { + usedGroup.poly.get(j).draw(tessellator, worldScale); + } + + GL11.glEndList(); + } + } + + compiled = true; + } + + private void compileLegacyDisplayList(float worldScale) + { + displayList = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displayList, 4864 /*GL_COMPILE*/); + Tessellator tessellator = Tessellator.instance; + for(int i = 0; i < faces.length; i++) + { + faces[i].draw(tessellator, worldScale); + } + + GL11.glEndList(); + } + + private PositionTextureVertex vertices[]; + private TexturedPolygon faces[]; + private int textureOffsetX; + private int textureOffsetY; + private boolean compiled; + private int displayList; + private int displayListArray[]; + private Map transformGroup; + private Map textureGroup; + private TransformGroup currentGroup; + private TextureGroup currentTextureGroup; + public boolean mirror; + public boolean flip; + public boolean showModel; + public boolean field_1402_i; + public boolean forcedRecompile; + public boolean useLegacyCompiler; + public List cubeList; + public List childModels; + public final String boxName; + + private String defaultTexture; + + public static final int MR_FRONT = 0; + public static final int MR_BACK = 1; + public static final int MR_LEFT = 2; + public static final int MR_RIGHT = 3; + public static final int MR_TOP = 4; + public static final int MR_BOTTOM = 5; + + private static final float pi = (float) Math.PI; +} diff --git a/tinker/tconstruct/client/tmt/PositionTransformVertex.java b/tinker/tconstruct/client/tmt/PositionTransformVertex.java new file mode 100644 index 00000000..f03e567e --- /dev/null +++ b/tinker/tconstruct/client/tmt/PositionTransformVertex.java @@ -0,0 +1,78 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; + +import net.minecraft.client.model.PositionTextureVertex; +import net.minecraft.util.Vec3; + +public class PositionTransformVertex extends PositionTextureVertex +{ + public PositionTransformVertex(float x, float y, float z, float u, float v) + { + this(Vec3.createVectorHelper((double)x, (double)y, (double)z), u, v); + } + + public PositionTransformVertex(PositionTextureVertex vertex, float u, float v) + { + super(vertex, u, v); + if(vertex instanceof PositionTransformVertex) + neutralVector = ((PositionTransformVertex)vertex).neutralVector; + else + neutralVector = Vec3.createVectorHelper(vertex.vector3D.xCoord, vertex.vector3D.yCoord, vertex.vector3D.zCoord); + } + + public PositionTransformVertex(PositionTextureVertex vertex) + { + this(vertex, vertex.texturePositionX, vertex.texturePositionY); + } + + public PositionTransformVertex(Vec3 vector, float u, float v) + { + super(vector, u, v); + neutralVector = Vec3.createVectorHelper(vector.xCoord, vector.yCoord, vector.zCoord); + } + + public void setTransformation() + { + if(transformGroups.size() == 0) + { + vector3D.xCoord = neutralVector.xCoord; + vector3D.yCoord = neutralVector.yCoord; + vector3D.zCoord = neutralVector.zCoord; + return; + } + double weight = 0D; + for(int i = 0; i < transformGroups.size(); i++) + { + weight += transformGroups.get(i).getWeight(); + } + vector3D.xCoord = 0; + vector3D.yCoord = 0; + vector3D.zCoord = 0; + + for(int i = 0; i < transformGroups.size(); i++) + { + TransformGroup group = transformGroups.get(i); + double cWeight = group.getWeight() / weight; + Vec3 vector = group.doTransformation(this); + + vector3D.xCoord += cWeight * vector.xCoord; + vector3D.yCoord += cWeight * vector.yCoord; + vector3D.zCoord += cWeight * vector.zCoord; + } + } + + public void addGroup(TransformGroup group) + { + transformGroups.add(group); + } + + public void removeGroup(TransformGroup group) + { + transformGroups.remove(group); + } + + public Vec3 neutralVector; + public ArrayList transformGroups = new ArrayList(); + +} diff --git a/tinker/tconstruct/client/tmt/Shape2D.java b/tinker/tconstruct/client/tmt/Shape2D.java new file mode 100644 index 00000000..2f49aef9 --- /dev/null +++ b/tinker/tconstruct/client/tmt/Shape2D.java @@ -0,0 +1,151 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; + +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; + +public class Shape2D +{ + public Shape2D() + { + coords = new ArrayList(); + } + + public Shape2D(Coord2D[] coordArray) + { + coords = new ArrayList(); + + for(int idx = 0; idx < coordArray.length; idx++) + { + coords.add(coordArray[idx]); + } + } + + public Shape2D(ArrayList coordList) + { + coords = coordList; + } + + public Coord2D[] getCoordArray() + { + return (Coord2D[]) coords.toArray(); + } + + public Shape3D extrude(float x, float y, float z, float rotX, float rotY, float rotZ, float depth, int u, int v, float textureWidth, float textureHeight, int shapeTextureWidth, int shapeTextureHeight, int sideTextureWidth, int sideTextureHeight, float[] faceLengths) + { + PositionTransformVertex[] verts = new PositionTransformVertex[coords.size() * 2]; + PositionTransformVertex[] vertsTop = new PositionTransformVertex[coords.size()]; + PositionTransformVertex[] vertsBottom = new PositionTransformVertex[coords.size()]; + TexturedPolygon[] poly = new TexturedPolygon[coords.size() + 2]; + + Vec3 extrudeVector = Vec3.createVectorHelper(0, 0, depth); + + setVectorRotations(extrudeVector, rotX, rotY, rotZ); + + if(faceLengths != null && faceLengths.length < coords.size()) + faceLengths = null; + + float totalLength = 0; + + for(int idx = 0; idx < coords.size(); idx++) + { + Coord2D curCoord = coords.get(idx); + Coord2D nextCoord = coords.get((idx + 1) % coords.size()); + float texU1 = ((float)(curCoord.uCoord + u) / (float)textureWidth); + float texU2 = ((float)(shapeTextureWidth * 2 - curCoord.uCoord + u) / (float)textureWidth); + float texV = ((float)(curCoord.vCoord + v) / (float)textureHeight); + + Vec3 vecCoord = Vec3.createVectorHelper(curCoord.xCoord, curCoord.yCoord, 0); + + setVectorRotations(vecCoord, rotX, rotY, rotZ); + + verts[idx] = new PositionTransformVertex( + x + (float)vecCoord.xCoord, + y + (float)vecCoord.yCoord, + z + (float)vecCoord.zCoord, texU1, texV); + verts[idx + coords.size()] = new PositionTransformVertex( + x + (float)vecCoord.xCoord - (float)extrudeVector.xCoord, + y + (float)vecCoord.yCoord - (float)extrudeVector.yCoord, + z + (float)vecCoord.zCoord - (float)extrudeVector.zCoord, texU2, texV); + + vertsTop[idx] = new PositionTransformVertex(verts[idx]); + vertsBottom[coords.size() - idx - 1] = new PositionTransformVertex(verts[idx + coords.size()]); + + if(faceLengths != null) + totalLength+= faceLengths[idx]; + else + totalLength+= Math.sqrt(Math.pow(curCoord.xCoord - nextCoord.xCoord, 2) + Math.pow(curCoord.yCoord - nextCoord.yCoord, 2)); + } + + poly[coords.size()] = new TexturedPolygon(vertsTop); + poly[coords.size() + 1] = new TexturedPolygon(vertsBottom); + + float currentLengthPosition = totalLength; + + for(int idx = 0; idx < coords.size(); idx++) + { + Coord2D curCoord = coords.get(idx); + Coord2D nextCoord = coords.get((idx + 1) % coords.size()); + float currentLength = (float)Math.sqrt(Math.pow(curCoord.xCoord - nextCoord.xCoord, 2) + Math.pow(curCoord.yCoord - nextCoord.yCoord, 2)); + if(faceLengths != null) + currentLength = faceLengths[faceLengths.length - idx - 1]; + float ratioPosition = currentLengthPosition / totalLength; + float ratioLength = (currentLengthPosition - currentLength) / totalLength; + + float texU1 = ((float)(ratioLength * (float)sideTextureWidth + u) / (float)textureWidth); + float texU2 = ((float)(ratioPosition * (float)sideTextureWidth + u) / (float)textureWidth); + float texV1 = (((float)v + (float)shapeTextureHeight) / (float)textureHeight); + float texV2 = (((float)v + (float)shapeTextureHeight + (float)sideTextureHeight) / (float)textureHeight); + + PositionTransformVertex[] polySide = new PositionTransformVertex[4]; + + polySide[0] = new PositionTransformVertex(verts[idx], texU2, texV1); + polySide[1] = new PositionTransformVertex(verts[coords.size() + idx], texU2, texV2); + polySide[2] = new PositionTransformVertex(verts[coords.size() + ((idx + 1) % coords.size())], texU1, texV2); + polySide[3] = new PositionTransformVertex(verts[(idx + 1) % coords.size()], texU1, texV1); + + poly[idx] = new TexturedPolygon(polySide); + currentLengthPosition -= currentLength; + } + + return new Shape3D(verts, poly); + } + + protected void setVectorRotations(Vec3 vector, float xRot, float yRot, float zRot) + { + float x = xRot; + float y = yRot; + float z = zRot; + float xC = MathHelper.cos(x); + float xS = MathHelper.sin(x); + float yC = MathHelper.cos(y); + float yS = MathHelper.sin(y); + float zC = MathHelper.cos(z); + float zS = MathHelper.sin(z); + + double xVec = vector.xCoord; + double yVec = vector.yCoord; + double zVec = vector.zCoord; + + // rotation around x + double xy = xC*yVec - xS*zVec; + double xz = xC*zVec + xS*yVec; + // rotation around y + double yz = yC*xz - yS*xVec; + double yx = yC*xVec + yS*xz; + // rotation around z + double zx = zC*yx - zS*xy; + double zy = zC*xy + zS*yx; + + xVec = zx; + yVec = zy; + zVec = yz; + + vector.xCoord = xVec; + vector.yCoord = yVec; + vector.zCoord = zVec; + } + + public ArrayList coords; +} diff --git a/tinker/tconstruct/client/tmt/Shape3D.java b/tinker/tconstruct/client/tmt/Shape3D.java new file mode 100644 index 00000000..a4e2068f --- /dev/null +++ b/tinker/tconstruct/client/tmt/Shape3D.java @@ -0,0 +1,12 @@ +package tinker.tconstruct.client.tmt; + +public class Shape3D +{ + public Shape3D(PositionTransformVertex[] verts, TexturedPolygon[] poly) + { + vertices = verts; + faces = poly; + } + public PositionTransformVertex[] vertices; + public TexturedPolygon[] faces; +} diff --git a/tinker/tconstruct/client/tmt/TextureGroup.java b/tinker/tconstruct/client/tmt/TextureGroup.java new file mode 100644 index 00000000..305ae8dc --- /dev/null +++ b/tinker/tconstruct/client/tmt/TextureGroup.java @@ -0,0 +1,42 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; + +import net.minecraft.client.model.TexturedQuad; +import net.minecraft.client.renderer.RenderEngine; +import net.minecraft.client.renderer.entity.RenderManager; + +public class TextureGroup +{ + public TextureGroup() + { + poly = new ArrayList(); + texture = ""; + } + + public void addPoly(TexturedQuad quad) + { + poly.add(quad); + } + + public void loadTexture() + { + loadTexture(-1); + } + + public void loadTexture(int defaultTexture) + { + if(!texture.equals("")) + { + RenderEngine renderengine = RenderManager.instance.renderEngine; + renderengine.bindTexture(renderengine.getTexture(texture)); + } + else if(defaultTexture > -1) + { + RenderManager.instance.renderEngine.bindTexture(defaultTexture); + } + } + + public ArrayList poly; + public String texture; +} diff --git a/tinker/tconstruct/client/tmt/TexturedPolygon.java b/tinker/tconstruct/client/tmt/TexturedPolygon.java new file mode 100644 index 00000000..68929cf4 --- /dev/null +++ b/tinker/tconstruct/client/tmt/TexturedPolygon.java @@ -0,0 +1,103 @@ +package tinker.tconstruct.client.tmt; + +import java.util.ArrayList; + +import net.minecraft.client.model.PositionTextureVertex; +import net.minecraft.client.model.TexturedQuad; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.Vec3; + +import org.lwjgl.opengl.GL11; + +public class TexturedPolygon extends TexturedQuad +{ + public TexturedPolygon(PositionTextureVertex apositionTexturevertex[]) + { + super(apositionTexturevertex); + invertNormal = false; + normals = new float[0]; + iNormals = new ArrayList(); + } + + public void setInvertNormal(boolean isSet) + { + invertNormal = isSet; + } + + public void setNormals(float x, float y, float z) + { + normals = new float[] {x, y, z}; + } + + public void setNormals(ArrayList vec) + { + iNormals = vec; + } + + public void draw(Tessellator tessellator, float f) + { + + if(nVertices == 3) + tessellator.startDrawing(GL11.GL_TRIANGLES); + else if (nVertices == 4) + tessellator.startDrawingQuads(); + else + tessellator.startDrawing(GL11.GL_POLYGON); + + if(iNormals.size() == 0) + { + if(normals.length == 3) + { + if(invertNormal) + { + tessellator.setNormal(-normals[0], -normals[1], -normals[2]); + } else + { + tessellator.setNormal(normals[0], normals[1], normals[2]); + } + } else + if(vertexPositions.length >= 3) + { + Vec3 Vec3 = vertexPositions[1].vector3D.subtract(vertexPositions[0].vector3D); + Vec3 Vec31 = vertexPositions[1].vector3D.subtract(vertexPositions[2].vector3D); + Vec3 Vec32 = Vec31.crossProduct(Vec3).normalize(); + + if(invertNormal) + { + tessellator.setNormal(-(float)Vec32.xCoord, -(float)Vec32.yCoord, -(float)Vec32.zCoord); + } else + { + tessellator.setNormal((float)Vec32.xCoord, (float)Vec32.yCoord, (float)Vec32.zCoord); + } + } + else + { + return; + } + } + for(int i = 0; i < nVertices; i++) + { + PositionTextureVertex positionTexturevertex = vertexPositions[i]; + if(positionTexturevertex instanceof PositionTransformVertex) + ((PositionTransformVertex)positionTexturevertex).setTransformation(); + if(i < iNormals.size()) + { + if(invertNormal) + { + tessellator.setNormal(-(float)iNormals.get(i).xCoord, -(float)iNormals.get(i).yCoord, -(float)iNormals.get(i).zCoord); + } + else + { + tessellator.setNormal((float)iNormals.get(i).xCoord, (float)iNormals.get(i).yCoord, (float)iNormals.get(i).zCoord); + } + } + tessellator.addVertexWithUV((float)positionTexturevertex.vector3D.xCoord * f, (float)positionTexturevertex.vector3D.yCoord * f, (float)positionTexturevertex.vector3D.zCoord * f, positionTexturevertex.texturePositionX, positionTexturevertex.texturePositionY); + } + + tessellator.draw(); + } + + private boolean invertNormal; + private float[] normals; + private ArrayList iNormals; +} diff --git a/tinker/tconstruct/client/tmt/TransformGroup.java b/tinker/tconstruct/client/tmt/TransformGroup.java new file mode 100644 index 00000000..4e15fdb1 --- /dev/null +++ b/tinker/tconstruct/client/tmt/TransformGroup.java @@ -0,0 +1,9 @@ +package tinker.tconstruct.client.tmt; + +import net.minecraft.util.Vec3; + +public abstract class TransformGroup +{ + public abstract double getWeight(); + public abstract Vec3 doTransformation(PositionTransformVertex vertex); +} diff --git a/tinker/tconstruct/client/tmt/TransformGroupBone.java b/tinker/tconstruct/client/tmt/TransformGroupBone.java new file mode 100644 index 00000000..3faa119e --- /dev/null +++ b/tinker/tconstruct/client/tmt/TransformGroupBone.java @@ -0,0 +1,111 @@ +package tinker.tconstruct.client.tmt; + +import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; + +/** + * The PositionTransformGroup class adds a class which allows for vertex transformations. + * @author GaryCXJk + * + */ +public class TransformGroupBone extends TransformGroup +{ + public TransformGroupBone(Bone bone, double wght) + { + baseVector = bone.getPosition(); + baseAngles = bone.getAbsoluteAngle(); + attachedBone = bone; + weight = wght; + } + + public Angle3D getBaseAngles() + { + return baseAngles.copy(); + } + + public Angle3D getTransformAngle() + { + Angle3D returnAngle = attachedBone.getAbsoluteAngle().copy(); + returnAngle.angleX-= baseAngles.angleX; + returnAngle.angleY-= baseAngles.angleY; + returnAngle.angleZ-= baseAngles.angleZ; + return returnAngle; + } + + public Vec3 getBaseVector() + { + return Vec3.createVectorHelper(baseVector.xCoord, baseVector.yCoord, baseVector.zCoord); + } + + public Vec3 getTransformVector() + { + return baseVector.subtract(attachedBone.getPosition()); + } + + public Vec3 getCurrentVector() + { + return attachedBone.getPosition(); + } + + public double getWeight() + { + return weight; + } + + public void attachBone(Bone bone) + { + baseVector = bone.getPosition(); + baseAngles = bone.getAbsoluteAngle(); + attachedBone = bone; + } + + public Vec3 doTransformation(PositionTransformVertex vertex) + { + Vec3 vector = Vec3.createVectorHelper(vertex.neutralVector.xCoord, vertex.neutralVector.yCoord, vertex.neutralVector.zCoord); + vector = getBaseVector().subtract(vector); + Angle3D angle = getTransformAngle(); + setVectorRotations(vector, angle.angleX, angle.angleY, angle.angleZ); + + return vector; + } + + protected void setVectorRotations(Vec3 vector, float xRot, float yRot, float zRot) + { + float x = xRot; + float y = yRot; + float z = zRot; + float xC = MathHelper.cos(x); + float xS = MathHelper.sin(x); + float yC = MathHelper.cos(y); + float yS = MathHelper.sin(y); + float zC = MathHelper.cos(z); + float zS = MathHelper.sin(z); + + double xVec = vector.xCoord; + double yVec = vector.yCoord; + double zVec = vector.zCoord; + + // rotation around x + double xy = xC*yVec - xS*zVec; + double xz = xC*zVec + xS*yVec; + // rotation around y + double yz = yC*xz - yS*xVec; + double yx = yC*xVec + yS*xz; + // rotation around z + double zx = zC*yx - zS*xy; + double zy = zC*xy + zS*yx; + + xVec = zx; + yVec = zy; + zVec = yz; + + vector.xCoord = xVec; + vector.yCoord = yVec; + vector.zCoord = zVec; + } + + protected Angle3D baseAngles; + protected Vec3 baseVector; + protected Bone attachedBone; + protected double weight; +} diff --git a/tinker/tconstruct/crafting/Smeltery.java b/tinker/tconstruct/crafting/Smeltery.java index b9dce133..82d30c79 100644 --- a/tinker/tconstruct/crafting/Smeltery.java +++ b/tinker/tconstruct/crafting/Smeltery.java @@ -31,11 +31,11 @@ public class Smeltery public static Integer getSmeltingTemperature(ItemStack item) { if (item == null) - return 0; + return 20; Integer temp = instance.temperatureList.get(Arrays.asList(item.itemID, item.getItemDamage())); if (temp == null) - return 0; + return 20; else return temp; //return instance.temperatureList.get(Arrays.asList(item.itemID, item.getItemDamage())); diff --git a/tinker/tconstruct/items/Materials.java b/tinker/tconstruct/items/Materials.java index 27a93d63..94d4caba 100644 --- a/tinker/tconstruct/items/Materials.java +++ b/tinker/tconstruct/items/Materials.java @@ -30,16 +30,17 @@ public class Materials extends Item public String getItemNameIS(ItemStack stack) { - int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, 9); + int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, 13); return getItemName() + "." +materialNames[arr]; } public void getSubItems(int id, CreativeTabs tab, List list) { - for (int i = 0; i < 9; i++) + for (int i = 0; i < 12; i++) list.add(new ItemStack(id, 1, i)); } public static final String[] materialNames = new String[] { - "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot", "Mossball", "LavaCrystal", "NecroticBone" }; + "PaperStack", "SlimeCrystal", "SearedBrick", "CobaltIngot", "ArditeIngot", "ManyullynIngot", "Mossball", "LavaCrystal", "NecroticBone", + "CopperIngot", "TinIngot", "AluminumIngot", "RawAluminum" }; } diff --git a/tinker/tconstruct/logic/SmelteryLogic.java b/tinker/tconstruct/logic/SmelteryLogic.java index 7ce87448..90ee8e5a 100644 --- a/tinker/tconstruct/logic/SmelteryLogic.java +++ b/tinker/tconstruct/logic/SmelteryLogic.java @@ -13,6 +13,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.liquids.ILiquidTank; import net.minecraftforge.liquids.LiquidStack; +import tinker.common.CoordTuple; import tinker.common.IActiveLogic; import tinker.common.IFacingLogic; import tinker.common.InventoryLogic; @@ -23,27 +24,32 @@ import tinker.tconstruct.crafting.Smeltery; /* Simple class for storing items in the block */ -public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFacingLogic +public class SmelteryLogic extends InventoryLogic + implements IActiveLogic, IFacingLogic { - boolean validStructure; + public boolean validStructure; byte direction; int internalTemp; int maxTemp; int useTime; public int fuelGague; - int[] tankCoords; - int[] bottomTemps; + + CoordTuple lavaTank; + CoordTuple drain; + public CoordTuple centerPos; + + public int[] activeTemps; public int[] meltingTemps; int tick; public SmelteryLogic() { super(9); - bottomTemps = new int[9]; + activeTemps = new int[9]; meltingTemps = new int[9]; for (int i = 0; i < 9; i++) { - bottomTemps[i] = 20; + activeTemps[i] = 20; meltingTemps[i] = 0; } } @@ -103,7 +109,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci public int getTempForSlot (int slot) { - return bottomTemps[slot]; + return activeTemps[slot]; } /* Updating */ @@ -111,8 +117,8 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci { //System.out.println("tick"); tick++; - if (tick % 4 == 0) - updateTemperatures(); + if (tick % 4 == 0 && !worldObj.isRemote) + heatItems(); if (tick == 20) { @@ -122,12 +128,12 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci if (useTime > 0) useTime--; - if (!worldObj.isRemote) - matchInventoryToWorld(); + /*if (!worldObj.isRemote) + matchInventoryToWorld();*/ if (validStructure && useTime == 0) { - TileEntity tank = worldObj.getBlockTileEntity(tankCoords[0], tankCoords[1], tankCoords[2]); + TileEntity tank = worldObj.getBlockTileEntity(lavaTank.x, lavaTank.y, lavaTank.z); if (tank instanceof ILiquidTank) { LiquidStack liquid = ((ILiquidTank) tank).drain(10, true); @@ -141,37 +147,45 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci } } - void updateTemperatures () + void heatItems () { for (int i = 0; i < 9; i++) { if (meltingTemps[i] > 20 && this.isStackInSlot(i)) { - if (bottomTemps[i] < internalTemp && bottomTemps[i] < meltingTemps[i]) - bottomTemps[i] += 1; - else if (meltingTemps[i] >= bottomTemps[i]) + if (activeTemps[i] < internalTemp && activeTemps[i] < meltingTemps[i]) + activeTemps[i] += 1; + else if (meltingTemps[i] >= activeTemps[i]) { ItemStack result = getResultFor(inventory[i]); if (result != null) { inventory[i] = result; - setWorldToInventory(); + //setWorldToInventory(); } } } else - bottomTemps[i] = 20; + activeTemps[i] = 20; + } + } + + void updateTemperatures() + { + for (int i = 0; i < 9; i++) + { + meltingTemps[i] = Smeltery.instance.getSmeltingTemperature(inventory[i]); } } void updateFuelGague () { - if (tankCoords == null || tankCoords.length < 3) + if (lavaTank == null) return; - TileEntity tank = worldObj.getBlockTileEntity(tankCoords[0], tankCoords[1], tankCoords[2]); + TileEntity tank = worldObj.getBlockTileEntity(lavaTank.x, lavaTank.y, lavaTank.z); if (tank == null) { fuelGague = 0; @@ -197,8 +211,15 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci { return 1; } + + public void onInventoryChanged() + { + updateTemperatures(); + super.onInventoryChanged(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } - @Override + /*@Override public void setInventorySlotContents (int slot, ItemStack itemstack) { super.setInventorySlotContents(slot, itemstack); @@ -211,10 +232,10 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci ItemStack stack = super.decrStackSize(slot, quantity); setWorldToInventory(); return stack; - } + }*/ /* World-inventory matching */ - void matchInventoryToWorld () + /*void matchInventoryToWorld () { switch (getDirection()) { @@ -231,9 +252,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci grabWorldBlocks(xCoord - 2, yCoord, zCoord); break; } - } + }*/ - void setWorldToInventory () + /*void setWorldToInventory () { switch (getDirection()) { @@ -250,9 +271,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci setWorldToInventory(xCoord - 2, yCoord, zCoord); break; } - } + }*/ - public void grabWorldBlocks (int x, int y, int z) + /*public void grabWorldBlocks (int x, int y, int z) { for (int xPos = 0; xPos <= 2; xPos++) { @@ -271,9 +292,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci } } } - } + }*/ - public void setWorldToInventory (int x, int y, int z) + /*public void setWorldToInventory (int x, int y, int z) { for (int xPos = 0; xPos <= 2; xPos++) { @@ -287,10 +308,12 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci { worldObj.setBlockAndMetadataWithNotify(xPos + x - 1, y, zPos + z - 1, stack.itemID, stack.getItemDamage()); meltingTemps[xPos + zPos * 3] = Smeltery.instance.getSmeltingTemperature(stack); + if (meltingTemps[xPos + zPos * 3] < bottomTemps[xPos + zPos * 3]) + bottomTemps[xPos + zPos * 3] = meltingTemps[xPos + zPos * 3]; } } } - } + }*/ public void checkValidPlacement () { @@ -314,7 +337,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci public void checkValidStructure (int x, int y, int z) { int numBricks = 0; - boolean lavaTank = false; + boolean hasLavaTank = false; //Check outer layer for (int xPos = x - 1; xPos <= x + 1; xPos++) @@ -325,16 +348,16 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci numBricks++; else if (southID == TContent.lavaTank.blockID) { - tankCoords = new int[] { xPos, y, z - 2 }; - lavaTank = true; + lavaTank = new CoordTuple(xPos, y, z - 2); + hasLavaTank = true; } if (northID == TContent.searedBrick.blockID) numBricks++; else if (northID == TContent.lavaTank.blockID) { - tankCoords = new int[] { xPos, y, z + 2 }; - lavaTank = true; + lavaTank = new CoordTuple(xPos, y, z + 2 ); + hasLavaTank = true; } } for (int zPos = z - 1; zPos <= z + 1; zPos++) @@ -345,16 +368,16 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci numBricks++; else if (westID == TContent.lavaTank.blockID) { - tankCoords = new int[] { x - 2, y, zPos }; - lavaTank = true; + lavaTank = new CoordTuple(x - 2, y, zPos); + hasLavaTank = true; } if (eastID == TContent.searedBrick.blockID) numBricks++; else if (eastID == TContent.lavaTank.blockID) { - tankCoords = new int[] { x + 2, y, zPos }; - lavaTank = true; + lavaTank = new CoordTuple( x + 2, y, zPos ); + hasLavaTank = true; } } @@ -368,9 +391,13 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci } } - if (numBricks == 19 && lavaTank) + if (numBricks == 19 && hasLavaTank) { - validStructure = true; + if (!validStructure) + { + centerPos = new CoordTuple(x, y, z); + validStructure = true; + } internalTemp = 550; } else @@ -385,22 +412,20 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci public void readFromNBT (NBTTagCompound tags) { super.readFromNBT(tags); - validStructure = tags.getBoolean("ValidStructure"); direction = tags.getByte("Direction"); useTime = tags.getInteger("UseTime"); - internalTemp = tags.getInteger("Temp"); - tankCoords = tags.getIntArray("TankCoords"); + meltingTemps = tags.getIntArray("MeltingTemps"); + activeTemps = tags.getIntArray("ActiveTemps"); } @Override public void writeToNBT (NBTTagCompound tags) { super.writeToNBT(tags); - tags.setBoolean("ValidStructure", validStructure); tags.setByte("Direction", direction); tags.setInteger("UseTime", useTime); - tags.setInteger("Temp", internalTemp); - tags.setIntArray("TankCoords", tankCoords); + tags.setIntArray("MeltingTemps", meltingTemps); + tags.setIntArray("ActiveTemps", activeTemps); } /* Packets */ @@ -415,7 +440,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci @Override public void onDataPacket (INetworkManager net, Packet132TileEntityData packet) { - worldObj.getBlockTileEntity(xCoord, yCoord, zCoord).readFromNBT(packet.customParam1); + readFromNBT(packet.customParam1); worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); } } diff --git a/tinker/tconstruct/worldgen/ManhattanOreGenerator.java b/tinker/tconstruct/worldgen/ManhattanOreGenerator.java index ef9b9db2..8d44bf19 100644 --- a/tinker/tconstruct/worldgen/ManhattanOreGenerator.java +++ b/tinker/tconstruct/worldgen/ManhattanOreGenerator.java @@ -7,6 +7,7 @@ import java.util.Random; import tinker.tconstruct.util.SortedList; +import net.minecraft.block.Block; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; @@ -16,22 +17,25 @@ import net.minecraft.world.gen.feature.WorldGenerator; public class ManhattanOreGenerator extends WorldGenerator { - private List replaceableBlocks; private int numberOfBlocks; private int sizeVariance; private int metadata; private int minableBlockId; private int density; + private boolean generateLines; + private boolean checkGenMinable; - public ManhattanOreGenerator(int id, int meta, int minSize, int maxSize, int density, Object... replacableIDs) + public ManhattanOreGenerator(int id, int meta, int minSize, int maxSize, int dense, boolean lines, boolean replaceGenMinable, Object... replacableIDs) { minableBlockId = id; metadata = meta; numberOfBlocks = minSize; sizeVariance = maxSize - minSize + 1; - this.density = density; + density = dense; replaceableBlocks = new ArrayList(); + generateLines = lines; + checkGenMinable = replaceGenMinable; for(Object i : replacableIDs) { replaceableBlocks.add((Integer) i); @@ -46,7 +50,16 @@ public class ManhattanOreGenerator extends WorldGenerator public boolean spawnOre(World world, int x, int y, int z) { int currentID = world.getBlockId(x, y, z); - if(replaceableBlocks.contains(currentID)) + if (checkGenMinable) + { + Block block = Block.blocksList[currentID]; + if (block != null && block.isGenMineableReplaceable(world, x, y, z)) + { + world.setBlock(x, y, z, this.minableBlockId); + world.setBlockMetadata(x, y, z, this.metadata); + } + } + else if(replaceableBlocks.contains(currentID)) { world.setBlock(x, y, z, this.minableBlockId); world.setBlockMetadata(x, y, z, this.metadata); @@ -103,7 +116,8 @@ public class ManhattanOreGenerator extends WorldGenerator cpm.add(i); int pickedOre = (int) (((random.nextFloat()*random.nextFloat())) * sortedList.size()); - pickedOre = sortedList.size()-1; //Comment this line to create groups instead of lines + if (!generateLines) + pickedOre = sortedList.size()-1; //Comment this line to create groups instead of lines Integer[] coords = sortedList.get(pickedOre); Integer[] finalCoords = {coords[0], coords[1], coords[2]}; diff --git a/tinker/tconstruct/worldgen/TBaseWorldGenerator.java b/tinker/tconstruct/worldgen/TBaseWorldGenerator.java index 7985f736..7f11e547 100644 --- a/tinker/tconstruct/worldgen/TBaseWorldGenerator.java +++ b/tinker/tconstruct/worldgen/TBaseWorldGenerator.java @@ -2,6 +2,7 @@ package tinker.tconstruct.worldgen; import java.util.Random; +import tinker.tconstruct.PHConstruct; import tinker.tconstruct.TContent; import net.minecraft.block.Block; @@ -15,8 +16,12 @@ public class TBaseWorldGenerator { public TBaseWorldGenerator() { - cobalt = new ManhattanOreGenerator(TContent.ores.blockID, 0, 2, 4, 100, Block.netherrack.blockID); - ardite = new ManhattanOreGenerator(TContent.ores.blockID, 1, 2, 4, 100, Block.netherrack.blockID); + copper = new ManhattanOreGenerator(TContent.searedBrick.blockID, 3, 5, 10, 100, true, true); + tin = new ManhattanOreGenerator(TContent.searedBrick.blockID, 4, 5, 10, 100, true, true); + aluminum = new ManhattanOreGenerator(TContent.searedBrick.blockID, 5, 8, 20, 100, false, true); + + cobalt = new ManhattanOreGenerator(TContent.searedBrick.blockID, 1, 2, 4, 100, true, false, Block.netherrack.blockID); + ardite = new ManhattanOreGenerator(TContent.searedBrick.blockID, 2, 2, 4, 100, true, false, Block.netherrack.blockID); } @Override @@ -24,26 +29,74 @@ public class TBaseWorldGenerator { if (world.provider.dimensionId == -1) generateNether(random, chunkX*16, chunkZ*16, world); + else + generateSurface(random, chunkX*16, chunkZ*16, world); + } + + void generateSurface(Random random, int xChunk, int zChunk, World world) + { + int heightBand; + int xPos, yPos, zPos; + if (PHConstruct.generateCopper) + { + for (int q = 0; q < PHConstruct.copperDensity; q++) + { + xPos = xChunk + random.nextInt(16); yPos = PHConstruct.copperHeight + random.nextInt(PHConstruct.copperRange); zPos = zChunk + random.nextInt(16); + copper.generate(world, random, xPos, yPos, zPos); + } + } + if (PHConstruct.generateTin) + { + for (int q = 0; q < PHConstruct.tinDensity; q++) + { + xPos = xChunk + random.nextInt(16); yPos = PHConstruct.tinHeight + random.nextInt(PHConstruct.tinRange); zPos = zChunk + random.nextInt(16); + tin.generate(world, random, xPos, yPos, zPos); + } + } + if (PHConstruct.generateAluminum) + { + for (int q = 0; q < PHConstruct.aluminumDensity; q++) + { + xPos = xChunk + random.nextInt(16); yPos = PHConstruct.aluminumHeight + random.nextInt(PHConstruct.aluminumRange); zPos = zChunk + random.nextInt(16); + aluminum.generate(world, random, xPos, yPos, zPos); + } + } } void generateNether(Random random, int xChunk, int zChunk, World world) { - for (int i = 0; i < 6; i++) + int xPos, yPos, zPos; + for (int i = 0; i < PHConstruct.netherDensity; i++) { - int xPos = xChunk + random.nextInt(16), yPos = random.nextInt(64), zPos = zChunk + random.nextInt(16); - cobalt.generate(world, random, xPos, yPos, zPos); - xPos = xChunk + random.nextInt(16); yPos = random.nextInt(64)+32; zPos = zChunk + random.nextInt(16); - ardite.generate(world, random, xPos, yPos, zPos); + if (PHConstruct.generateCobalt) + { + xPos = xChunk + random.nextInt(16); yPos = random.nextInt(64); zPos = zChunk + random.nextInt(16); + cobalt.generate(world, random, xPos, yPos, zPos); + } + if (PHConstruct.generateArdite) + { + xPos = xChunk + random.nextInt(16); yPos = random.nextInt(64)+32; zPos = zChunk + random.nextInt(16); + ardite.generate(world, random, xPos, yPos, zPos); + } } - for (int i = 0; i < 6; i++) + for (int i = 0; i < PHConstruct.netherDensity; i++) { - int xPos = xChunk + random.nextInt(16), yPos = random.nextInt(128), zPos = zChunk + random.nextInt(16); - cobalt.generate(world, random, xPos, yPos, zPos); - xPos = xChunk + random.nextInt(16); yPos = random.nextInt(128); zPos = zChunk + random.nextInt(16); - ardite.generate(world, random, xPos, yPos, zPos); + if (PHConstruct.generateCobalt) + { + xPos = xChunk + random.nextInt(16); yPos = random.nextInt(128); zPos = zChunk + random.nextInt(16); + cobalt.generate(world, random, xPos, yPos, zPos); + } + if (PHConstruct.generateArdite) + { + xPos = xChunk + random.nextInt(16); yPos = random.nextInt(128); zPos = zChunk + random.nextInt(16); + ardite.generate(world, random, xPos, yPos, zPos); + } } } - + + ManhattanOreGenerator copper; + ManhattanOreGenerator tin; + ManhattanOreGenerator aluminum; ManhattanOreGenerator cobalt; ManhattanOreGenerator ardite; }