diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-06-05 01:53:14 +0100 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-06-05 01:53:14 +0100 |
| commit | a6a3bfa6f313adba5afe6eb4a0da049a8d641cfc (patch) | |
| tree | 56da97ba430232a7d0da51a3b8b9f444d96325c7 /src/main/java/darkknight/jewelrycraft/block | |
| parent | 40487f07fa5ef31fde99713c0b842d34a0ba3622 (diff) | |
Stuff!
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/block')
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java | 545 | ||||
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java | 531 |
2 files changed, 540 insertions, 536 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java index 017c459..fd7c264 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java @@ -1,270 +1,275 @@ -package darkknight.jewelrycraft.block; - -import java.io.IOException; -import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.fluids.BlockFluidClassic; -import net.minecraftforge.fluids.Fluid; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.network.PacketRequestLiquidData; -import darkknight.jewelrycraft.network.PacketSendLiquidData; -import darkknight.jewelrycraft.util.Variables; - -public class BlockMoltenMetal extends BlockFluidClassic -{ - @SideOnly (Side.CLIENT) - protected IIcon stillIcon; - @SideOnly (Side.CLIENT) - protected IIcon flowingIcon; - - /** - * @param fluid - * @param material - */ - public BlockMoltenMetal(Fluid fluid, Material material) - { - super(fluid, material); - setBlockName(Variables.MODID + ".moltenMetal"); - setQuantaPerBlock(5); - setRenderPass(1); - setLightLevel(15f); - } - - /** - * @param side - * @param meta - * @return - */ - @Override - public IIcon getIcon(int side, int meta) - { - return side == 0 || side == 1 ? stillIcon : flowingIcon; - } - - /** - * @param register - */ - @Override - @SideOnly (Side.CLIENT) - public void registerBlockIcons(IIconRegister register) - { - stillIcon = register.registerIcon(Variables.MODID + ":moltenMetalStill"); - flowingIcon = register.registerIcon(Variables.MODID + ":moltenMetalFlow"); - } - - /** - * @param world - * @param x - * @param y - * @param z - * @return - */ - @Override - public boolean canDisplace(IBlockAccess world, int x, int y, int z) - { - if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false; - return super.canDisplace(world, x, y, z); - } - - /** - * @param world - * @param x - * @param y - * @param z - * @return - */ - @Override - public boolean displaceIfPossible(World world, int x, int y, int z) - { - if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false; - return super.displaceIfPossible(world, x, y, z); - } - - /** - * @param world - * @param x - * @param y - * @param z - * @return - */ - @Override - protected boolean canFlowInto(IBlockAccess world, int x, int y, int z) - { - if (world.getBlock(x, y, z).isAir(world, x, y, z)) return true; - Block block = world.getBlock(x, y, z); - if (block == this) return false; - if (displacements.containsKey(block)) return displacements.get(block); - Material material = block.getMaterial(); - if (material.blocksMovement() || material == Material.water || material == Material.lava || material == Material.portal) return false; - int density = getDensity(world, x, y, z); - if (density == Integer.MAX_VALUE) return true; - if (this.density > density) return true; - else return false; - } - - /** - * @param world - * @param i - * @param j - * @param k - * @return - */ - @Override - @SideOnly (Side.CLIENT) - public int colorMultiplier(IBlockAccess world, int i, int j, int k) - { - try{ - return color(world, i, j, k, false, null); - } - catch(IOException e){ - e.printStackTrace(); - } - return 0; - } - - /** - * @param world - * @param x - * @param y - * @param z - * @param rand - */ - @Override - public void updateTick(World world, int x, int y, int z, Random rand) - { - int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z); - int expQuanta = -101; - // check adjacent block levels if non-source - if (quantaRemaining < quantaPerBlock){ - int y2 = y - densityDir; - if (world.getBlock(x, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x - 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x + 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z - 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z + 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) expQuanta = quantaPerBlock - 1; - else{ - int maxQuanta = -100; - if (JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta); - if (JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta); - if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta); - if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta); - expQuanta = maxQuanta - 1; - } - // decay calculation - if (expQuanta != quantaRemaining){ - quantaRemaining = expQuanta; - if (expQuanta <= 0) world.setBlock(x, y, z, Blocks.air); - else{ - world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3); - world.scheduleBlockUpdate(x, y, z, this, tickRate); - world.notifyBlocksOfNeighborChange(x, y, z, this); - } - } - } - // This is a "source" block, set meta to zero, and send a server only - // update - else if (quantaRemaining >= quantaPerBlock) world.setBlockMetadataWithNotify(x, y, z, 0, 2); - String originData = JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)); - // Flow vertically if possible - if (canDisplace(world, x, y + densityDir, z)){ - JewelrycraftMod.saveData.setString(stringFromLocation(x, y + densityDir, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))); - flowIntoBlock(world, x, y + densityDir, z, 1, originData); - return; - } - // Flow outward if possible - int flowMeta = quantaPerBlock - quantaRemaining + 1; - if (flowMeta >= quantaPerBlock) return; - if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)){ - if (world.getBlock(x, y - densityDir, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y - densityDir, z, world.provider.dimensionId)))) flowMeta = 1; - boolean flowTo[] = getOptimalFlowDirections(world, x, y, z); - if (flowTo[0]){ - if (JewelrycraftMod.saveData.getTag(stringFromLocation(x - 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x - 1, y, z).isAir(world, x - 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x - 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))); - flowIntoBlock(world, x - 1, y, z, flowMeta, originData); - } - if (flowTo[1]){ - if (JewelrycraftMod.saveData.getTag(stringFromLocation(x + 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x + 1, y, z).isAir(world, x + 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x + 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))); - flowIntoBlock(world, x + 1, y, z, flowMeta, originData); - } - if (flowTo[2]){ - if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z - 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z - 1).isAir(world, x, y, z - 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z - 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))); - flowIntoBlock(world, x, y, z - 1, flowMeta, originData); - } - if (flowTo[3]){ - if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z + 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z + 1).isAir(world, x, y, z + 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z + 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))); - flowIntoBlock(world, x, y, z + 1, flowMeta, originData); - } - } - } - - /** - * @param world - * @param x - * @param y - * @param z - * @param meta - * @param originData - */ - public void flowIntoBlock(World world, int x, int y, int z, int meta, String originData) - { - if (meta < 0 || world.isRemote) return; - if (displaceIfPossible(world, x, y, z)){ - world.setBlock(x, y, z, this, meta, 3); - JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z, world.provider.dimensionId), originData); - String[] data = originData.split(":"); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2]))); - } - } - - /** - * @param world - * @param i - * @param j - * @param k - * @param forcecolor - * @param itemC - * @return - * @throws IOException - */ - @SideOnly (Side.CLIENT) - public static int color(IBlockAccess world, int i, int j, int k, boolean forcecolor, Item itemC) throws IOException - { - String ingotData = JewelrycraftMod.clientData.getString(String.valueOf(i) + " " + String.valueOf(j) + " " + String.valueOf(k) + " " + Minecraft.getMinecraft().theWorld.provider.dimensionId); - if (ingotData == ""){ - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestLiquidData(Minecraft.getMinecraft().theWorld.provider.dimensionId, i, j, k)); - return 0xFFFFFF; - }else{ - String[] splitData = ingotData.split(":"); - if (splitData.length == 3){ - int color; - try{ - Integer.parseInt(splitData[0]); - Integer.parseInt(splitData[1]); - color = Integer.parseInt(splitData[2]); - return color; - } - catch(Exception e){ - e.printStackTrace(); - } - } - } - return 16777215; - } - - /** - * @param x - * @param y - * @param z - * @param dimID - * @return - */ - public static String stringFromLocation(int x, int y, int z, int dimID) - { - return x + " " + y + " " + z + " " + dimID; - } -} +package darkknight.jewelrycraft.block;
+
+import java.io.IOException;
+import java.util.Random;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.fluids.BlockFluidClassic;
+import net.minecraftforge.fluids.Fluid;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import darkknight.jewelrycraft.JewelrycraftMod;
+import darkknight.jewelrycraft.network.PacketRequestLiquidData;
+import darkknight.jewelrycraft.network.PacketSendLiquidData;
+import darkknight.jewelrycraft.util.Variables;
+
+public class BlockMoltenMetal extends BlockFluidClassic
+{
+ @SideOnly (Side.CLIENT)
+ protected IIcon stillIcon;
+ @SideOnly (Side.CLIENT)
+ protected IIcon flowingIcon;
+
+ /**
+ * @param fluid
+ * @param material
+ */
+ public BlockMoltenMetal(Fluid fluid, Material material)
+ {
+ super(fluid, material);
+ setBlockName(Variables.MODID + ".moltenMetal");
+ setQuantaPerBlock(5);
+ setRenderPass(1);
+ setLightLevel(15f);
+ }
+
+ /**
+ * @param side
+ * @param meta
+ * @return
+ */
+ @Override
+ public IIcon getIcon(int side, int meta)
+ {
+ return side == 0 || side == 1 ? stillIcon : flowingIcon;
+ }
+
+ /**
+ * @param register
+ */
+ @Override
+ @SideOnly (Side.CLIENT)
+ public void registerBlockIcons(IIconRegister register)
+ {
+ stillIcon = register.registerIcon(Variables.MODID + ":moltenMetalStill");
+ flowingIcon = register.registerIcon(Variables.MODID + ":moltenMetalFlow");
+ }
+
+ /**
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ @Override
+ public boolean canDisplace(IBlockAccess world, int x, int y, int z)
+ {
+ if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
+ return super.canDisplace(world, x, y, z);
+ }
+
+ /**
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ @Override
+ public boolean displaceIfPossible(World world, int x, int y, int z)
+ {
+ if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false;
+ return super.displaceIfPossible(world, x, y, z);
+ }
+
+ /**
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ @Override
+ protected boolean canFlowInto(IBlockAccess world, int x, int y, int z)
+ {
+ if (world.getBlock(x, y, z).isAir(world, x, y, z)) return true;
+ Block block = world.getBlock(x, y, z);
+ if (block == this) return false;
+ if (displacements.containsKey(block)) return displacements.get(block);
+ Material material = block.getMaterial();
+ if (material.blocksMovement() || material == Material.water || material == Material.lava || material == Material.portal) return false;
+ int density = getDensity(world, x, y, z);
+ if (density == Integer.MAX_VALUE) return true;
+ if (this.density > density) return true;
+ else return false;
+ }
+
+ /**
+ * @param world
+ * @param i
+ * @param j
+ * @param k
+ * @return
+ */
+ @Override
+ @SideOnly (Side.CLIENT)
+ public int colorMultiplier(IBlockAccess world, int i, int j, int k)
+ {
+ try{
+ return color(world, i, j, k, false, null);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ /**
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param rand
+ */
+ @Override
+ public void updateTick(World world, int x, int y, int z, Random rand)
+ {
+ int quantaRemaining = quantaPerBlock - world.getBlockMetadata(x, y, z);
+ int expQuanta = -101;
+ // check adjacent block levels if non-source
+ if (quantaRemaining < quantaPerBlock){
+ int y2 = y - densityDir;
+ if (world.getBlock(x, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x - 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x + 1, y2, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y2, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z - 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId))) || world.getBlock(x, y2, z + 1) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y2, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) expQuanta = quantaPerBlock - 1;
+ else{
+ int maxQuanta = -100;
+ if (JewelrycraftMod.saveData.getString(stringFromLocation(x - 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta);
+ if (JewelrycraftMod.saveData.getString(stringFromLocation(x + 1, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta);
+ if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z - 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta);
+ if (JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z + 1, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)))) maxQuanta = getLargerQuanta(world, x, y, z + 1, maxQuanta);
+ expQuanta = maxQuanta - 1;
+ }
+ // decay calculation
+ if (expQuanta != quantaRemaining){
+ quantaRemaining = expQuanta;
+ if (expQuanta <= 0) world.setBlock(x, y, z, Blocks.air);
+ else{
+ world.setBlockMetadataWithNotify(x, y, z, quantaPerBlock - expQuanta, 3);
+ world.scheduleBlockUpdate(x, y, z, this, tickRate);
+ world.notifyBlocksOfNeighborChange(x, y, z, this);
+ }
+ }
+ }
+ // This is a "source" block, set meta to zero, and send a server only
+ // update
+ else if (quantaRemaining >= quantaPerBlock) world.setBlockMetadataWithNotify(x, y, z, 0, 2);
+ String originData = JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId));
+ // Flow vertically if possible
+ if (canDisplace(world, x, y + densityDir, z)){
+ JewelrycraftMod.saveData.setString(stringFromLocation(x, y + densityDir, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
+ flowIntoBlock(world, x, y + densityDir, z, 1, originData);
+ return;
+ }
+ // Flow outward if possible
+ int flowMeta = quantaPerBlock - quantaRemaining + 1;
+ if (flowMeta >= quantaPerBlock) return;
+ if (isSourceBlock(world, x, y, z) || !isFlowingVertically(world, x, y, z)){
+ if (world.getBlock(x, y - densityDir, z) == this && JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)).equals(JewelrycraftMod.saveData.getString(stringFromLocation(x, y - densityDir, z, world.provider.dimensionId)))) flowMeta = 1;
+ boolean flowTo[] = getOptimalFlowDirections(world, x, y, z);
+ if (flowTo[0]){
+ if (JewelrycraftMod.saveData.getTag(stringFromLocation(x - 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x - 1, y, z).isAir(world, x - 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x - 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
+ flowIntoBlock(world, x - 1, y, z, flowMeta, originData);
+ }
+ if (flowTo[1]){
+ if (JewelrycraftMod.saveData.getTag(stringFromLocation(x + 1, y, z, world.provider.dimensionId)) == null || world.getBlock(x + 1, y, z).isAir(world, x + 1, y, z)) JewelrycraftMod.saveData.setString(stringFromLocation(x + 1, y, z, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
+ flowIntoBlock(world, x + 1, y, z, flowMeta, originData);
+ }
+ if (flowTo[2]){
+ if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z - 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z - 1).isAir(world, x, y, z - 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z - 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
+ flowIntoBlock(world, x, y, z - 1, flowMeta, originData);
+ }
+ if (flowTo[3]){
+ if (JewelrycraftMod.saveData.getTag(stringFromLocation(x, y, z + 1, world.provider.dimensionId)) == null || world.getBlock(x, y, z + 1).isAir(world, x, y, z + 1)) JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z + 1, world.provider.dimensionId), JewelrycraftMod.saveData.getString(stringFromLocation(x, y, z, world.provider.dimensionId)));
+ flowIntoBlock(world, x, y, z + 1, flowMeta, originData);
+ }
+ }
+ }
+
+ /**
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param meta
+ * @param originData
+ */
+ public void flowIntoBlock(World world, int x, int y, int z, int meta, String originData)
+ {
+ if (meta < 0 || world.isRemote) return;
+ if (displaceIfPossible(world, x, y, z)){
+ world.setBlock(x, y, z, this, meta, 3);
+ JewelrycraftMod.saveData.setString(stringFromLocation(x, y, z, world.provider.dimensionId), originData);
+ String[] data = originData.split(":");
+ try{
+ JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2])));
+ }
+ catch(Exception e){
+ System.out.println("The liquids file is either corrupt, missing or the metal for the liquid simply doesn't exist!");
+ }
+ }
+ }
+
+ /**
+ * @param world
+ * @param i
+ * @param j
+ * @param k
+ * @param forcecolor
+ * @param itemC
+ * @return
+ * @throws IOException
+ */
+ @SideOnly (Side.CLIENT)
+ public static int color(IBlockAccess world, int i, int j, int k, boolean forcecolor, Item itemC) throws IOException
+ {
+ String ingotData = JewelrycraftMod.clientData.getString(String.valueOf(i) + " " + String.valueOf(j) + " " + String.valueOf(k) + " " + Minecraft.getMinecraft().theWorld.provider.dimensionId);
+ if (ingotData == ""){
+ JewelrycraftMod.netWrapper.sendToServer(new PacketRequestLiquidData(Minecraft.getMinecraft().theWorld.provider.dimensionId, i, j, k));
+ return 0xFFFFFF;
+ }else{
+ String[] splitData = ingotData.split(":");
+ if (splitData.length == 3){
+ int color;
+ try{
+ Integer.parseInt(splitData[0]);
+ Integer.parseInt(splitData[1]);
+ color = Integer.parseInt(splitData[2]);
+ return color;
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+ return 16777215;
+ }
+
+ /**
+ * @param x
+ * @param y
+ * @param z
+ * @param dimID
+ * @return
+ */
+ public static String stringFromLocation(int x, int y, int z, int dimID)
+ {
+ return x + " " + y + " " + z + " " + dimID;
+ }
+}
diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java index e6e74cc..4e20a43 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java @@ -1,266 +1,265 @@ -package darkknight.jewelrycraft.block; - -import java.io.IOException; -import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.MathHelper; -import net.minecraft.util.StatCollector; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.config.ConfigHandler; -import darkknight.jewelrycraft.item.ItemList; -import darkknight.jewelrycraft.item.ItemMoltenMetalBucket; -import darkknight.jewelrycraft.network.PacketSendLiquidData; -import darkknight.jewelrycraft.tileentity.TileEntityMolder; -import darkknight.jewelrycraft.tileentity.TileEntitySmelter; -import darkknight.jewelrycraft.util.JewelryNBT; -import darkknight.jewelrycraft.util.JewelrycraftUtil; -import darkknight.jewelrycraft.util.Variables; - -public class BlockSmelter extends BlockContainer -{ - Random rand = new Random(); - - public BlockSmelter() - { - super(Material.rock); - } - - @Override - public TileEntity createNewTileEntity(World world, int var2) - { - return new TileEntitySmelter(); - } - - @Override - public boolean renderAsNormalBlock() - { - return false; - } - - /** - * Spawns an item in the world at the specified location - * - * @param world - * @param x - * @param y - * @param z - * @param stack - */ - public void dropItem(World world, double x, double y, double z, ItemStack stack) - { - EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 1.3D, z + 0.5D, stack); - entityitem.motionX = 0; - entityitem.motionZ = 0; - entityitem.motionY = 0.11000000298023224D; - entityitem.delayBeforeCanPickup = 0; - world.spawnEntityInWorld(entityitem); - } - - @Override - public void breakBlock(World world, int i, int j, int k, Block par5, int par6) - { - TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k); - if (te != null){ - if (te.hasMetal) dropItem(world, te.xCoord, te.yCoord, te.zCoord, te.metal.copy()); - if (te.hasMoltenMetal && te.moltenMetal != null && Item.getIdFromItem(te.moltenMetal.getItem()) > 0){ - ItemStack metal = te.moltenMetal; - ItemStack item = te.moltenMetal; - if (Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.carpet)) metal.setItemDamage(15 - metal.getItemDamage()); - int color = 16777215; - JewelryNBT.addMetal(item, metal); - try{ - color = ItemMoltenMetalBucket.color(item, 1); - System.out.println(color); - } - catch(IOException e){ - e.printStackTrace(); - } - JewelrycraftMod.saveData.setString(i + " " + j + " " + k + " " + world.provider.dimensionId, Item.getIdFromItem(metal.getItem()) + ":" + metal.getItemDamage() + ":" + color); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, i, j, k, Item.getIdFromItem(metal.getItem()), metal.getItemDamage(), color)); - world.setBlock(i, j, k, BlockList.moltenMetal, 0, 3); - int quant = (int)(te.quantity * 10); - if (quant == 1) world.setBlockMetadataWithNotify(i, j, k, 4, 3); - if (quant == 2) world.setBlockMetadataWithNotify(i, j, k, 4, 3); - if (quant == 3) world.setBlockMetadataWithNotify(i, j, k, 3, 3); - if (quant == 4) world.setBlockMetadataWithNotify(i, j, k, 3, 3); - if (quant == 5) world.setBlockMetadataWithNotify(i, j, k, 2, 3); - if (quant == 6) world.setBlockMetadataWithNotify(i, j, k, 2, 3); - if (quant == 7) world.setBlockMetadataWithNotify(i, j, k, 1, 3); - if (quant == 8) world.setBlockMetadataWithNotify(i, j, k, 1, 3); - if (quant == 9) world.setBlockMetadataWithNotify(i, j, k, 0, 3); - } - world.removeTileEntity(i, j, k); - } - super.breakBlock(world, i, j, k, par5, par6); - } - - @Override - public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) - { - TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k); - ItemStack item = entityPlayer.inventory.getCurrentItem(); - if (te != null && te.hasMoltenMetal && te.quantity >= .9f && !te.pouring && item != null && item.getItem() == Items.bucket){ - te.quantity = 0f; - te.hasMoltenMetal = false; - ItemStack metalBucket = new ItemStack(ItemList.bucket, 1); - ItemStack ingot = te.moltenMetal.copy(); - if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage()); - JewelryNBT.addMetal(metalBucket, ingot); - --item.stackSize; - entityPlayer.inventory.addItemStackToInventory(metalBucket); - te.isDirty = true; - return true; - } - if (te != null && !world.isRemote){ - if (te.hasMetal && entityPlayer.isSneaking()){ - dropItem(world, te.xCoord, te.yCoord, te.zCoord, te.metal.copy()); - te.hasMetal = false; - te.melting = -1; - te.isDirty = true; - } - if (item != null && item.getItem() != null && !(item.getItem() instanceof ItemMoltenMetalBucket)){ - int index = -1; - for(int a = 0; a < JewelrycraftUtil.jamcraftPlayers.size(); a++) - if (entityPlayer.getUniqueID().toString().equals(JewelrycraftUtil.jamcraftPlayers.get(a))) index = a; - if(entityPlayer.capabilities.isCreativeMode) index = 1; - boolean canPlace = item != null && (JewelrycraftUtil.isMetal(item) || JewelrycraftUtil.isOre(item) || index >= 0 || JewelryNBT.ingot(item) != null); - boolean isOre = false, oreCoincidesWithMetal = false, itemCoincidesWithMetal = false, itemCoincidesWithMoltenMetal = false, overflow = false; - isOre = JewelrycraftUtil.isOre(item); - if (te.metal != null && te.metal.getItem() != null) { - if(JewelryNBT.ingot(item) == null) itemCoincidesWithMetal = item.getItem().equals(te.metal.getItem()) && item.getItemDamage() == te.metal.getItemDamage(); - else itemCoincidesWithMetal = item.getItem().equals(te.metal.getItem()) && item.getItemDamage() == te.metal.getItemDamage() && JewelryNBT.ingot(item).getItem().equals(JewelryNBT.ingot(te.metal).getItem()) && JewelryNBT.ingot(item).getItemDamage() == JewelryNBT.ingot(te.metal).getItemDamage(); - } - if (te.moltenMetal != null && te.moltenMetal.getItem() != null){ - if(JewelryNBT.ingot(item) == null) itemCoincidesWithMoltenMetal = item.getItem().equals(te.moltenMetal.getItem()) && item.getItemDamage() == te.moltenMetal.getItemDamage(); - else itemCoincidesWithMoltenMetal = JewelryNBT.ingot(item).getItem().equals(te.moltenMetal.getItem()) && JewelryNBT.ingot(item).getItemDamage() == te.moltenMetal.getItemDamage(); - if (isOre) oreCoincidesWithMetal = te.moltenMetal.getItem().equals(JewelrycraftUtil.getIngotFromOre(item).getItem()) && te.moltenMetal.getItemDamage() == JewelrycraftUtil.getIngotFromOre(item).getItemDamage(); - } - overflow = isOre ? te.metal.stackSize * 0.2f + te.quantity < 0.8f : te.metal.stackSize*0.1f + te.quantity < 0.9f; - boolean isValid = te.hasMoltenMetal ? isOre ? oreCoincidesWithMetal : itemCoincidesWithMoltenMetal : true; - if (te.quantity < 0.9f && !te.pouring && canPlace && isValid){ - boolean check = isOre ? oreCoincidesWithMetal && te.quantity < 0.8f : itemCoincidesWithMoltenMetal; - boolean check2 = isOre ? oreCoincidesWithMetal : itemCoincidesWithMetal; - if (!te.hasMetal && !te.hasMoltenMetal || !te.hasMetal && te.hasMoltenMetal && check){ - entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.nowsmeltingingot", item.getDisplayName()))); - te.metal = item.copy(); - // if (Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.carpet)) te.metal.setItemDamage(15 - te.metal.getItemDamage()); - te.metal.stackSize = 1; - te.hasMetal = true; - te.melting = ConfigHandler.INGOT_MELTING_TIME; - if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; - te.isDirty = true; - }else if (te.hasMetal && te.hasMoltenMetal && check2 && overflow || te.hasMetal && !te.hasMoltenMetal && itemCoincidesWithMetal && overflow){ - entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("Smelting extra " + (isOre ? "ores" : "ingots") + " (" + (te.metal.stackSize + 1) + ")"))); - te.metal.stackSize++; - te.hasMetal = true; - te.melting += ConfigHandler.INGOT_MELTING_TIME; - if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; - te.isDirty = true; - } - te.isDirty = true; - }else if (item != null && (te.hasMetal || te.hasMoltenMetal) && !itemCoincidesWithMoltenMetal && te.quantity < .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.contentdoesnotmatch"))); - else if (item != null && !item.getUnlocalizedName().toLowerCase().contains("ingot") && item.getDisplayName().toLowerCase().contains("ingot") && te.quantity < .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.itemrenamedtoingot"))); - else if (item != null && te.quantity >= .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.full"))); - else entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.cannotsmelt"))); - }else if (item != null && item.getItem() != null && item.getItem() instanceof ItemMoltenMetalBucket && !te.hasMoltenMetal && !te.hasMetal){ - te.hasMoltenMetal = true; - ItemStack ingot = JewelryNBT.ingot(item); - if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage()); - te.moltenMetal = ingot; - te.quantity = .9f; - te.isDirty = true; - if (!entityPlayer.capabilities.isCreativeMode){ - --item.stackSize; - dropItem(world, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, new ItemStack(Items.bucket)); - } - } - else if (item == null && te.hasMoltenMetal && te.moltenMetal.getItem() != null) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.hasmolteningot", te.moltenMetal.getDisplayName().replace(" Ingot","")))); - world.setTileEntity(i, j, k, te); - } - return true; - } - - @Override - public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) - { - TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k); - TileEntityMolder me = null; - if (world.getBlockMetadata(i, j, k) == 0 && world.getTileEntity(i, j, k - 1) != null && world.getTileEntity(i, j, k - 1) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i, j, k - 1); - else if (world.getBlockMetadata(i, j, k) == 1 && world.getTileEntity(i + 1, j, k) != null && world.getTileEntity(i + 1, j, k) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i + 1, j, k); - else if (world.getBlockMetadata(i, j, k) == 2 && world.getTileEntity(i, j, k + 1) != null && world.getTileEntity(i, j, k + 1) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i, j, k + 1); - else if (world.getBlockMetadata(i, j, k) == 3 && world.getTileEntity(i - 1, j, k) != null && world.getTileEntity(i - 1, j, k) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i - 1, j, k); - if (te != null && me != null && !world.isRemote) if (te.hasMoltenMetal && isConnectedToMolder(world, i, j, k) && me != null && me.hasMold && !me.hasMoltenMetal && !me.hasJewelBase){ - te.pouring = true; - te.isDirty = true; - }else if (te.hasMetal && te.melting > 0) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.metalismelting", te.metal.getDisplayName()) + " (" + (ConfigHandler.INGOT_MELTING_TIME * te.metal.stackSize - te.melting) * 100 / (ConfigHandler.INGOT_MELTING_TIME * te.metal.stackSize) + "%)")); - else if (te.hasMoltenMetal && !isConnectedToMolder(world, i, j, k)) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderismissing"))); - else if (!me.hasMold && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderhasnomold"))); - else if (me.hasMoltenMetal && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderhasmoltenmetal"))); - else if (me.hasJewelBase && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.modlerhasitem"))); - else player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.empty"))); - } - - /** - * Determines if a molder is placed in front of this - * - * @param world - * @param i - * @param j - * @param k - * @return true if a molder is attached, false otherwise - */ - public boolean isConnectedToMolder(World world, int i, int j, int k) - { - int blockMeta = world.getBlockMetadata(i, j, k); - if (blockMeta == 0 && world.getBlock(i, j, k - 1) instanceof BlockMolder) return true; - else if (blockMeta == 1 && world.getBlock(i + 1, j, k) instanceof BlockMolder) return true; - else if (blockMeta == 2 && world.getBlock(i, j, k + 1) instanceof BlockMolder) return true; - else if (blockMeta == 3 && world.getBlock(i - 1, j, k) instanceof BlockMolder) return true; - return false; - } - - @Override - public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityLiving, ItemStack par6ItemStack) - { - int rotation = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; - world.setBlockMetadataWithNotify(i, j, k, rotation, 2); - } - - @Override - public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l) - { - return false; - } - - @Override - public boolean isOpaqueCube() - { - return false; - } - - @Override - public int getRenderType() - { - return -1; - } - - @Override - public void registerBlockIcons(IIconRegister icon) - { - blockIcon = icon.registerIcon(Variables.MODID + ":smelter"); - } -} +package darkknight.jewelrycraft.block;
+
+import java.io.IOException;
+import java.util.Random;
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockContainer;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ChatComponentText;
+import net.minecraft.util.MathHelper;
+import net.minecraft.util.StatCollector;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import darkknight.jewelrycraft.JewelrycraftMod;
+import darkknight.jewelrycraft.config.ConfigHandler;
+import darkknight.jewelrycraft.item.ItemList;
+import darkknight.jewelrycraft.item.ItemMoltenMetalBucket;
+import darkknight.jewelrycraft.network.PacketSendLiquidData;
+import darkknight.jewelrycraft.tileentity.TileEntityMolder;
+import darkknight.jewelrycraft.tileentity.TileEntitySmelter;
+import darkknight.jewelrycraft.util.JewelryNBT;
+import darkknight.jewelrycraft.util.JewelrycraftUtil;
+import darkknight.jewelrycraft.util.Variables;
+
+public class BlockSmelter extends BlockContainer
+{
+ Random rand = new Random();
+
+ public BlockSmelter()
+ {
+ super(Material.rock);
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world, int var2)
+ {
+ return new TileEntitySmelter();
+ }
+
+ @Override
+ public boolean renderAsNormalBlock()
+ {
+ return false;
+ }
+
+ /**
+ * Spawns an item in the world at the specified location
+ *
+ * @param world
+ * @param x
+ * @param y
+ * @param z
+ * @param stack
+ */
+ public void dropItem(World world, double x, double y, double z, ItemStack stack)
+ {
+ EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 1.3D, z + 0.5D, stack);
+ entityitem.motionX = 0;
+ entityitem.motionZ = 0;
+ entityitem.motionY = 0.11000000298023224D;
+ entityitem.delayBeforeCanPickup = 0;
+ world.spawnEntityInWorld(entityitem);
+ }
+
+ @Override
+ public void breakBlock(World world, int i, int j, int k, Block par5, int par6)
+ {
+ TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k);
+ if (te != null){
+ if (te.hasMetal) dropItem(world, te.xCoord, te.yCoord, te.zCoord, te.metal.copy());
+ if (te.hasMoltenMetal && te.moltenMetal != null && Item.getIdFromItem(te.moltenMetal.getItem()) > 0){
+ ItemStack metal = te.moltenMetal;
+ ItemStack item = te.moltenMetal;
+ if (Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(metal.getItem()) == Block.getIdFromBlock(Blocks.carpet)) metal.setItemDamage(15 - metal.getItemDamage());
+ int color = 16777215;
+ JewelryNBT.addMetal(item, metal);
+ try{
+ color = ItemMoltenMetalBucket.color(item, 1);
+ }
+ catch(IOException e){
+ e.printStackTrace();
+ }
+ JewelrycraftMod.saveData.setString(i + " " + j + " " + k + " " + world.provider.dimensionId, Item.getIdFromItem(metal.getItem()) + ":" + metal.getItemDamage() + ":" + color);
+ JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, i, j, k, Item.getIdFromItem(metal.getItem()), metal.getItemDamage(), color));
+ world.setBlock(i, j, k, BlockList.moltenMetal, 0, 3);
+ int quant = (int)(te.quantity * 10);
+ if (quant == 1) world.setBlockMetadataWithNotify(i, j, k, 4, 3);
+ if (quant == 2) world.setBlockMetadataWithNotify(i, j, k, 4, 3);
+ if (quant == 3) world.setBlockMetadataWithNotify(i, j, k, 3, 3);
+ if (quant == 4) world.setBlockMetadataWithNotify(i, j, k, 3, 3);
+ if (quant == 5) world.setBlockMetadataWithNotify(i, j, k, 2, 3);
+ if (quant == 6) world.setBlockMetadataWithNotify(i, j, k, 2, 3);
+ if (quant == 7) world.setBlockMetadataWithNotify(i, j, k, 1, 3);
+ if (quant == 8) world.setBlockMetadataWithNotify(i, j, k, 1, 3);
+ if (quant == 9) world.setBlockMetadataWithNotify(i, j, k, 0, 3);
+ }
+ world.removeTileEntity(i, j, k);
+ }
+ super.breakBlock(world, i, j, k, par5, par6);
+ }
+
+ @Override
+ public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9)
+ {
+ TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k);
+ ItemStack item = entityPlayer.inventory.getCurrentItem();
+ if (te != null && te.hasMoltenMetal && te.quantity >= .9f && !te.pouring && item != null && item.getItem() == Items.bucket){
+ te.quantity = 0f;
+ te.hasMoltenMetal = false;
+ ItemStack metalBucket = new ItemStack(ItemList.bucket, 1);
+ ItemStack ingot = te.moltenMetal.copy();
+ if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage());
+ JewelryNBT.addMetal(metalBucket, ingot);
+ --item.stackSize;
+ entityPlayer.inventory.addItemStackToInventory(metalBucket);
+ te.isDirty = true;
+ return true;
+ }
+ if (te != null && !world.isRemote){
+ if (te.hasMetal && entityPlayer.isSneaking()){
+ dropItem(world, te.xCoord, te.yCoord, te.zCoord, te.metal.copy());
+ te.hasMetal = false;
+ te.melting = -1;
+ te.isDirty = true;
+ }
+ if (item != null && item.getItem() != null && !(item.getItem() instanceof ItemMoltenMetalBucket)){
+ int index = -1;
+ for(int a = 0; a < JewelrycraftUtil.jamcraftPlayers.size(); a++)
+ if (entityPlayer.getUniqueID().toString().equals(JewelrycraftUtil.jamcraftPlayers.get(a))) index = a;
+ if(entityPlayer.capabilities.isCreativeMode) index = 1;
+ boolean canPlace = item != null && (JewelrycraftUtil.isMetal(item) || JewelrycraftUtil.isOre(item) || index >= 0 || JewelryNBT.ingot(item) != null);
+ boolean isOre = false, oreCoincidesWithMetal = false, itemCoincidesWithMetal = false, itemCoincidesWithMoltenMetal = false, overflow = false;
+ isOre = JewelrycraftUtil.isOre(item);
+ if (te.metal != null && te.metal.getItem() != null) {
+ if(JewelryNBT.ingot(item) == null) itemCoincidesWithMetal = item.getItem().equals(te.metal.getItem()) && item.getItemDamage() == te.metal.getItemDamage();
+ else itemCoincidesWithMetal = item.getItem().equals(te.metal.getItem()) && item.getItemDamage() == te.metal.getItemDamage() && JewelryNBT.ingot(item).getItem().equals(JewelryNBT.ingot(te.metal).getItem()) && JewelryNBT.ingot(item).getItemDamage() == JewelryNBT.ingot(te.metal).getItemDamage();
+ }
+ if (te.moltenMetal != null && te.moltenMetal.getItem() != null){
+ if(JewelryNBT.ingot(item) == null) itemCoincidesWithMoltenMetal = item.getItem().equals(te.moltenMetal.getItem()) && item.getItemDamage() == te.moltenMetal.getItemDamage();
+ else itemCoincidesWithMoltenMetal = JewelryNBT.ingot(item).getItem().equals(te.moltenMetal.getItem()) && JewelryNBT.ingot(item).getItemDamage() == te.moltenMetal.getItemDamage();
+ if (isOre) oreCoincidesWithMetal = te.moltenMetal.getItem().equals(JewelrycraftUtil.getIngotFromOre(item).getItem()) && te.moltenMetal.getItemDamage() == JewelrycraftUtil.getIngotFromOre(item).getItemDamage();
+ }
+ overflow = isOre ? te.metal.stackSize * 0.2f + te.quantity < 0.8f : te.metal.stackSize*0.1f + te.quantity < 0.9f;
+ boolean isValid = te.hasMoltenMetal ? isOre ? oreCoincidesWithMetal : itemCoincidesWithMoltenMetal : true;
+ if (te.quantity < 0.9f && !te.pouring && canPlace && isValid){
+ boolean check = isOre ? oreCoincidesWithMetal && te.quantity < 0.8f : itemCoincidesWithMoltenMetal;
+ boolean check2 = isOre ? oreCoincidesWithMetal : itemCoincidesWithMetal;
+ if (!te.hasMetal && !te.hasMoltenMetal || !te.hasMetal && te.hasMoltenMetal && check){
+ entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.nowsmeltingingot", item.getDisplayName())));
+ te.metal = item.copy();
+ // if (Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(te.metal.getItem()) == Block.getIdFromBlock(Blocks.carpet)) te.metal.setItemDamage(15 - te.metal.getItemDamage());
+ te.metal.stackSize = 1;
+ te.hasMetal = true;
+ te.melting = ConfigHandler.INGOT_MELTING_TIME;
+ if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize;
+ te.isDirty = true;
+ }else if (te.hasMetal && te.hasMoltenMetal && check2 && overflow || te.hasMetal && !te.hasMoltenMetal && itemCoincidesWithMetal && overflow){
+ entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("Smelting extra " + (isOre ? "ores" : "ingots") + " (" + (te.metal.stackSize + 1) + ")")));
+ te.metal.stackSize++;
+ te.hasMetal = true;
+ te.melting += ConfigHandler.INGOT_MELTING_TIME;
+ if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize;
+ te.isDirty = true;
+ }
+ te.isDirty = true;
+ }else if (item != null && (te.hasMetal || te.hasMoltenMetal) && !itemCoincidesWithMoltenMetal && te.quantity < .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.contentdoesnotmatch")));
+ else if (item != null && !item.getUnlocalizedName().toLowerCase().contains("ingot") && item.getDisplayName().toLowerCase().contains("ingot") && te.quantity < .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.itemrenamedtoingot")));
+ else if (item != null && te.quantity >= .9f) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.full")));
+ else entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.cannotsmelt")));
+ }else if (item != null && item.getItem() != null && item.getItem() instanceof ItemMoltenMetalBucket && !te.hasMoltenMetal && !te.hasMetal){
+ te.hasMoltenMetal = true;
+ ItemStack ingot = JewelryNBT.ingot(item);
+ if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage());
+ te.moltenMetal = ingot;
+ te.quantity = .9f;
+ te.isDirty = true;
+ if (!entityPlayer.capabilities.isCreativeMode){
+ --item.stackSize;
+ dropItem(world, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, new ItemStack(Items.bucket));
+ }
+ }
+ else if (item == null && te.hasMoltenMetal && te.moltenMetal.getItem() != null) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.hasmolteningot", te.moltenMetal.getDisplayName().replace(" Ingot",""))));
+ world.setTileEntity(i, j, k, te);
+ }
+ return true;
+ }
+
+ @Override
+ public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player)
+ {
+ TileEntitySmelter te = (TileEntitySmelter)world.getTileEntity(i, j, k);
+ TileEntityMolder me = null;
+ if (world.getBlockMetadata(i, j, k) == 0 && world.getTileEntity(i, j, k - 1) != null && world.getTileEntity(i, j, k - 1) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i, j, k - 1);
+ else if (world.getBlockMetadata(i, j, k) == 1 && world.getTileEntity(i + 1, j, k) != null && world.getTileEntity(i + 1, j, k) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i + 1, j, k);
+ else if (world.getBlockMetadata(i, j, k) == 2 && world.getTileEntity(i, j, k + 1) != null && world.getTileEntity(i, j, k + 1) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i, j, k + 1);
+ else if (world.getBlockMetadata(i, j, k) == 3 && world.getTileEntity(i - 1, j, k) != null && world.getTileEntity(i - 1, j, k) instanceof TileEntityMolder) me = (TileEntityMolder)world.getTileEntity(i - 1, j, k);
+ if (te != null && me != null && !world.isRemote) if (te.hasMoltenMetal && isConnectedToMolder(world, i, j, k) && me != null && me.hasMold && !me.hasMoltenMetal && !me.hasJewelBase){
+ te.pouring = true;
+ te.isDirty = true;
+ }else if (te.hasMetal && te.melting > 0) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage." + Variables.MODID + ".smelter.metalismelting", te.metal.getDisplayName()) + " (" + (ConfigHandler.INGOT_MELTING_TIME * te.metal.stackSize - te.melting) * 100 / (ConfigHandler.INGOT_MELTING_TIME * te.metal.stackSize) + "%)"));
+ else if (te.hasMoltenMetal && !isConnectedToMolder(world, i, j, k)) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderismissing")));
+ else if (!me.hasMold && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderhasnomold")));
+ else if (me.hasMoltenMetal && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.molderhasmoltenmetal")));
+ else if (me.hasJewelBase && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.modlerhasitem")));
+ else player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage." + Variables.MODID + ".smelter.empty")));
+ }
+
+ /**
+ * Determines if a molder is placed in front of this
+ *
+ * @param world
+ * @param i
+ * @param j
+ * @param k
+ * @return true if a molder is attached, false otherwise
+ */
+ public boolean isConnectedToMolder(World world, int i, int j, int k)
+ {
+ int blockMeta = world.getBlockMetadata(i, j, k);
+ if (blockMeta == 0 && world.getBlock(i, j, k - 1) instanceof BlockMolder) return true;
+ else if (blockMeta == 1 && world.getBlock(i + 1, j, k) instanceof BlockMolder) return true;
+ else if (blockMeta == 2 && world.getBlock(i, j, k + 1) instanceof BlockMolder) return true;
+ else if (blockMeta == 3 && world.getBlock(i - 1, j, k) instanceof BlockMolder) return true;
+ return false;
+ }
+
+ @Override
+ public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityLiving, ItemStack par6ItemStack)
+ {
+ int rotation = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
+ world.setBlockMetadataWithNotify(i, j, k, rotation, 2);
+ }
+
+ @Override
+ public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isOpaqueCube()
+ {
+ return false;
+ }
+
+ @Override
+ public int getRenderType()
+ {
+ return -1;
+ }
+
+ @Override
+ public void registerBlockIcons(IIconRegister icon)
+ {
+ blockIcon = icon.registerIcon(Variables.MODID + ":smelter");
+ }
+}
|
