diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-05-21 18:48:35 +0300 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-05-21 18:48:35 +0300 |
| commit | 27b6d250ba6005bfa9cdd9d291e0656f5e02fa65 (patch) | |
| tree | 89fd6b927e3cdd9391a2479cfa08dee2bda1c15e /src/main/java/darkknight/jewelrycraft/block | |
| parent | 2b4aedb9fb90e02c8ec89130919fb9cfae82770c (diff) | |
Liquids!
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/block')
3 files changed, 161 insertions, 21 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockMolder.java b/src/main/java/darkknight/jewelrycraft/block/BlockMolder.java index 1ed58d7..4b26044 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockMolder.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockMolder.java @@ -57,8 +57,6 @@ public class BlockMolder extends BlockContainer if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.molder.addedmold", te.mold.getDisplayName()))); te.isDirty = true; - te.markDirty(); - world.markTileEntityChunkModified(i, j, k, te); } if (te.hasMold && entityPlayer.isSneaking() && !te.hasMoltenMetal) { @@ -66,7 +64,6 @@ public class BlockMolder extends BlockContainer te.mold = new ItemStack(Item.getItemById(0), 0, 0); te.hasMold = false; te.isDirty = true; - te.markDirty(); } else if(te.hasMoltenMetal) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.hasmoltenmetal"))); } @@ -122,7 +119,6 @@ public class BlockMolder extends BlockContainer else if (me.mold.getItem() != ItemList.molds) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.moldismissing"))); me.isDirty = true; - me.markDirty(); } } diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java index 9adbf59..b6d10c1 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java @@ -2,13 +2,16 @@ package darkknight.jewelrycraft.block; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Random; import javax.imageio.ImageIO; +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.client.resources.IResourceManager; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -20,6 +23,7 @@ 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.util.JewelryNBT; import darkknight.jewelrycraft.util.JewelrycraftUtil; @@ -34,6 +38,7 @@ public class BlockMoltenMetal extends BlockFluidClassic { super(fluid, material); setBlockName("Jewelrycraft.moltenMetal"); this.setQuantaPerBlock(100); + setLightLevel(15f); } @Override @@ -59,24 +64,166 @@ public class BlockMoltenMetal extends BlockFluidClassic { return super.displaceIfPossible(world, x, y, z); } + @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; + } + } + @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess world, int i, int j, int k) { -// try { -// return color(world, i, j, k); -// } catch (IOException e) { -// e.printStackTrace(); -// } + try { + return color(world, i, j, k, false, null); + } catch (IOException e) { + e.printStackTrace(); + } return 0; } - public static int color(IBlockAccess world, int i, int j, int k) throws IOException + @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.getInteger(coords(x, y2, z)) == JewelrycraftMod.saveData.getInteger(coords(x, y, z)))|| + (world.getBlock(x - 1, y2, z ) == this && JewelrycraftMod.saveData.getInteger(coords(x - 1, y2, z)) == JewelrycraftMod.saveData.getInteger(coords(x, y, z)))|| + (world.getBlock(x + 1, y2, z ) == this && JewelrycraftMod.saveData.getInteger(coords(x + 1, y2, z)) == JewelrycraftMod.saveData.getInteger(coords(x, y, z)))|| + (world.getBlock(x, y2, z - 1) == this && JewelrycraftMod.saveData.getInteger(coords(x, y2, z - 1)) == JewelrycraftMod.saveData.getInteger(coords(x, y, z)))|| + (world.getBlock(x, y2, z + 1) == this && JewelrycraftMod.saveData.getInteger(coords(x, y2, z + 1)) == JewelrycraftMod.saveData.getInteger(coords(x, y, z)))) + { + expQuanta = quantaPerBlock - 1; + } + else + { + int maxQuanta = -100; + maxQuanta = getLargerQuanta(world, x - 1, y, z, maxQuanta); + maxQuanta = getLargerQuanta(world, x + 1, y, z, maxQuanta); + maxQuanta = getLargerQuanta(world, x, y, z - 1, maxQuanta); + 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); + } + + // Flow vertically if possible + if (canDisplace(world, x, y + densityDir, z)) + { + JewelrycraftMod.saveData.setInteger(coords(x, y + densityDir, z), JewelrycraftMod.saveData.getInteger(coords(x, y, z))); + flowIntoBlock(world, x, y + densityDir, z, 1); + 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) + { + flowMeta = 1; + } + boolean flowTo[] = getOptimalFlowDirections(world, x, y, z); + + if (flowTo[0]){ + if(JewelrycraftMod.saveData.getTag(coords(x - 1, y, z)) == null || world.getBlock(x - 1, y, z).isAir(world, x - 1, y, z)) + JewelrycraftMod.saveData.setInteger(coords(x - 1, y, z), JewelrycraftMod.saveData.getInteger(coords(x, y, z))); + flowIntoBlock(world, x - 1, y, z, flowMeta); + } + if (flowTo[1]){ + if(JewelrycraftMod.saveData.getTag(coords(x + 1, y, z)) == null || world.getBlock(x + 1, y, z).isAir(world, x + 1, y, z)) + JewelrycraftMod.saveData.setInteger(coords(x + 1, y, z), JewelrycraftMod.saveData.getInteger(coords(x, y, z))); + flowIntoBlock(world, x + 1, y, z, flowMeta); + } + if (flowTo[2]){ + if(JewelrycraftMod.saveData.getTag(coords(x, y, z - 1)) == null || world.getBlock(x, y, z - 1).isAir(world, x, y, z - 1)) + JewelrycraftMod.saveData.setInteger(coords(x, y, z - 1), JewelrycraftMod.saveData.getInteger(coords(x, y, z))); + flowIntoBlock(world, x, y, z - 1, flowMeta); + } + if (flowTo[3]){ + if(JewelrycraftMod.saveData.getTag(coords(x, y, z + 1)) == null || world.getBlock(x, y, z + 1).isAir(world, x, y, z + 1)) + JewelrycraftMod.saveData.setInteger(coords(x, y, z + 1), JewelrycraftMod.saveData.getInteger(coords(x, y, z))); + flowIntoBlock(world, x, y, z + 1, flowMeta); + } + } + } + + public static int color(IBlockAccess world, int i, int j, int k, boolean forcecolor, Item itemC) throws IOException { String domain = "", texture; IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); BufferedImage icon; ItemStack item = new ItemStack(BlockList.moltenMetal); - JewelryNBT.addMetal(item, new ItemStack(JewelrycraftUtil.liquids.get(String.valueOf(i) + " " + String.valueOf(j) + " " + String.valueOf(k)))); + if(JewelrycraftMod.saveData.getInteger(String.valueOf(i) + " " + String.valueOf(j) + " " + String.valueOf(k)) > 0) + JewelryNBT.addMetal(item, new ItemStack(Item.getItemById(JewelrycraftMod.saveData.getInteger(coords(i, j, k))))); + if(forcecolor) JewelryNBT.addMetal(item, new ItemStack(itemC)); int x=0, y=0, ok = 0, red, green, blue; if (JewelryNBT.ingot(item) != null && JewelryNBT.ingot(item).getIconIndex() != null && JewelryNBT.ingotColor(item) == 16777215) { @@ -114,4 +261,9 @@ public class BlockMoltenMetal extends BlockFluidClassic { if(JewelryNBT.ingot(item) != null) return JewelryNBT.ingotColor(item); return 16777215; } + + public static String coords(int x, int y, int z) + { + return String.valueOf(x) + " " + String.valueOf(y) + " " + String.valueOf(z); + } } diff --git a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java index 176a6f2..1f04bce 100644 --- a/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java +++ b/src/main/java/darkknight/jewelrycraft/block/BlockSmelter.java @@ -71,7 +71,7 @@ public class BlockSmelter extends BlockContainer { int index = -1; for(int a = 0; a < JewelrycraftUtil.jamcraftPlayers.size(); a++) if(entityPlayer.getDisplayName().equals(JewelrycraftUtil.jamcraftPlayers.get(a))) index = a; - if (!te.hasMetal && !te.hasMoltenMetal && item != null && (item.getUnlocalizedName().toLowerCase().contains("ingot") || index != -1) && !item.getUnlocalizedName().toLowerCase().contains("mold")) + if (!te.hasMetal && !te.hasMoltenMetal && !te.pouring && item != null && (item.getUnlocalizedName().toLowerCase().contains("ingot") || index != -1) && !item.getUnlocalizedName().toLowerCase().contains("mold")) { entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.smelter.nowsmeltingingot", item.getDisplayName()))); te.metal = item.copy(); @@ -80,7 +80,6 @@ public class BlockSmelter extends BlockContainer te.melting = ConfigHandler.ingotMeltingTime; if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; te.isDirty = true; - te.markDirty(); } else if (te.hasMetal && !te.hasMoltenMetal && item != null && item.getDisplayName().contains("Ingot") && !item.getDisplayName().contains("Mold")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.smelter.alreadyhasingot", te.metal.getDisplayName()))); @@ -96,8 +95,6 @@ public class BlockSmelter extends BlockContainer dropItem(world, (double)te.xCoord, (double)te.yCoord, (double)te.zCoord, te.metal.copy()); te.hasMetal = false; te.melting = -1; - te.isDirty = true; - te.markDirty(); world.markBlockForUpdate(i, j, k); world.setTileEntity(i, j, k, te); } @@ -124,13 +121,8 @@ public class BlockSmelter extends BlockContainer { if (te.hasMoltenMetal && isConnectedToMolder(world, i, j, k) && me != null && me.hasMold && !me.hasMoltenMetal && !me.hasJewelBase) { - me.moltenMetal = te.moltenMetal; - me.hasMoltenMetal = true; - me.cooling = ConfigHandler.ingotCoolingTime; - te.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); - te.hasMoltenMetal = false; + te.pouring = true; te.isDirty = true; - te.markDirty(); world.markBlockForUpdate(i, j, k); world.setTileEntity(i, j, k, te); } |
