From 27b6d250ba6005bfa9cdd9d291e0656f5e02fa65 Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Wed, 21 May 2014 18:48:35 +0300 Subject: Liquids! --- .../darkknight/jewelrycraft/JewelrycraftMod.java | 11 +- .../darkknight/jewelrycraft/block/BlockMolder.java | 4 - .../jewelrycraft/block/BlockMoltenMetal.java | 166 +++++++++++++- .../jewelrycraft/block/BlockSmelter.java | 12 +- .../jewelrycraft/events/BucketHandler.java | 7 +- .../jewelrycraft/events/EntityEventHandler.java | 58 ++++- .../jewelrycraft/events/EventHandler.java | 65 ++++++ .../darkknight/jewelrycraft/item/ItemList.java | 3 + .../jewelrycraft/item/ItemMoltenMetal.java | 122 ++++++++++ .../jewelrycraft/item/ItemMoltenMetalBucket.java | 18 +- .../darkknight/jewelrycraft/item/ItemNecklace.java | 2 +- .../darkknight/jewelrycraft/item/ItemRing.java | 2 +- .../darkknight/jewelrycraft/lib/Reference.java | 2 +- .../jewelrycraft/renders/RendererSmelter.java | 67 ++++++ .../renders/TileEntityDisplayerRender.java | 16 +- .../renders/TileEntityMolderRender.java | 23 ++ .../renders/TileEntitySmelterRender.java | 83 +++++-- .../jewelrycraft/tileentity/TileEntityMolder.java | 14 +- .../jewelrycraft/tileentity/TileEntitySmelter.java | 254 ++++++++++++--------- .../jewelrycraft/util/JewelrycraftUtil.java | 1 - .../jewelrycraft/worldGen/Generation.java | 4 +- .../worldGen/village/ComponentJewelry.java | 6 +- .../textures/items/moltenMetalStill.png | Bin 0 -> 9922 bytes .../textures/items/moltenMetalStill.png.mcmeta | 45 ++++ 24 files changed, 786 insertions(+), 199 deletions(-) create mode 100644 src/main/java/darkknight/jewelrycraft/events/EventHandler.java create mode 100644 src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java create mode 100644 src/main/java/darkknight/jewelrycraft/renders/RendererSmelter.java create mode 100644 src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png create mode 100644 src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png.mcmeta (limited to 'src') diff --git a/src/main/java/darkknight/jewelrycraft/JewelrycraftMod.java b/src/main/java/darkknight/jewelrycraft/JewelrycraftMod.java index f6672ee..568591f 100644 --- a/src/main/java/darkknight/jewelrycraft/JewelrycraftMod.java +++ b/src/main/java/darkknight/jewelrycraft/JewelrycraftMod.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; +import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -61,6 +62,7 @@ public class JewelrycraftMod public static CommonProxy proxy; public static final Logger logger = Logger.getLogger("Jewelrycraft"); + public static File dir; public static CreativeTabs jewelrycraft = new CreativeTabs("JewelryCraft") { @@ -73,9 +75,8 @@ public class JewelrycraftMod public static CreativeTabs rings = new CreativeTabRings("Rings"); public static CreativeTabs necklaces = new CreativeTabNecklaces("Necklaces"); public static CreativeTabs liquids = new CreativeTabLiquids("Liquids"); - - public static File liquidsConf; - public static NBTTagCompound saveData; + public static NBTTagCompound saveData = new NBTTagCompound(); + public static File liquidsConf; @EventHandler public void preInit(FMLPreInitializationEvent e) throws IOException @@ -108,13 +109,11 @@ public class JewelrycraftMod List authorList = new ArrayList(); authorList.add("DarkKnight (or sor1n)"); authorList.add("bspkrs"); + dir = e.getModConfigurationDirectory(); metadata.autogenerated = false; metadata.authorList = authorList; metadata.url = "https://github.com/sor1n/Modjam-Mod"; - - liquidsConf = new File(e.getModConfigurationDirectory(), "JLP.cfg"); - if(!liquidsConf.exists() && !liquidsConf.createNewFile()); } @EventHandler 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); } diff --git a/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java b/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java index 64a02c3..cf16847 100644 --- a/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/BucketHandler.java @@ -18,6 +18,9 @@ import net.minecraft.world.World; import net.minecraftforge.event.entity.player.FillBucketEvent; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.block.BlockMoltenMetal; +import darkknight.jewelrycraft.util.JewelryNBT; public class BucketHandler { @@ -47,7 +50,9 @@ public class BucketHandler { Item bucket = buckets.get(block); if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) { world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ); - return new ItemStack(bucket); + ItemStack item = new ItemStack(bucket); + JewelryNBT.addMetal(item, new ItemStack(Item.getItemById(JewelrycraftMod.saveData.getInteger(BlockMoltenMetal.coords(pos.blockX, pos.blockY, pos.blockZ))))); + return item; } else return null; diff --git a/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java b/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java index d8d49a2..957705c 100644 --- a/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java @@ -1,27 +1,31 @@ package darkknight.jewelrycraft.events; +import java.io.EOFException; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.world.WorldEvent; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.item.ItemList; import darkknight.jewelrycraft.util.BlockUtils; import darkknight.jewelrycraft.util.PlayerUtils; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; /** * Code taken from OpenBlocks */ + public class EntityEventHandler { public static final String OPENBLOCKS_PERSIST_TAG = "Jewelrycraft"; @@ -31,10 +35,7 @@ public class EntityEventHandler public void onEntityJoinWorld(EntityJoinWorldEvent event) { final Entity entity = event.entity; - /** - * If the player hasn't been given a manual, we'll give him one! (or - * throw it on the floor..) - */ + if (!event.world.isRemote && entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)entity; @@ -52,4 +53,47 @@ public class EntityEventHandler } } } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) + { + if(!event.world.isRemote) + { + JewelrycraftMod.liquidsConf = new File(JewelrycraftMod.dir, "JLP" + event.world.getWorldInfo().getWorldName() + ".cfg"); + try { + if(!JewelrycraftMod.liquidsConf.exists()) JewelrycraftMod.liquidsConf.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + if(FMLCommonHandler.instance().getEffectiveSide().isServer()) + { + try { + if(JewelrycraftMod.liquidsConf.exists()) + JewelrycraftMod.saveData = CompressedStreamTools.readCompressed(new FileInputStream(JewelrycraftMod.liquidsConf)); + } catch (EOFException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + @SubscribeEvent + public void onWorldSave(WorldEvent.Save event) + { + if(FMLCommonHandler.instance().getEffectiveSide().isServer()) + { + try { + if(JewelrycraftMod.liquidsConf.exists()) + CompressedStreamTools.writeCompressed(JewelrycraftMod.saveData, new FileOutputStream(JewelrycraftMod.liquidsConf)); + } catch (EOFException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } \ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/events/EventHandler.java b/src/main/java/darkknight/jewelrycraft/events/EventHandler.java new file mode 100644 index 0000000..019deab --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/events/EventHandler.java @@ -0,0 +1,65 @@ +package darkknight.jewelrycraft.events; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldServer; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.world.WorldEvent; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.item.ItemList; +import darkknight.jewelrycraft.util.BlockUtils; +import darkknight.jewelrycraft.util.PlayerUtils; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +/** + * Code taken from OpenBlocks + */ +public class EventHandler +{ + public static final String OPENBLOCKS_PERSIST_TAG = "Jewelrycraft"; + public static final String GIVEN_GUIDE_TAG = "givenGuive"; + + @SubscribeEvent + public void onEntityJoinWorld(EntityJoinWorldEvent event) + { + final Entity entity = event.entity; + /** + * If the player hasn't been given a manual, we'll give him one! (or + * throw it on the floor..) + */ + if (!event.world.isRemote && entity instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + + boolean shouldGiveManual = ItemList.guide != null && !persistTag.getBoolean(GIVEN_GUIDE_TAG); + if (shouldGiveManual) + { + ItemStack manual = new ItemStack(ItemList.guide); + if (!player.inventory.addItemStackToInventory(manual)) + { + BlockUtils.dropItemStackInWorld(player.worldObj, player.posX, player.posY, player.posZ, manual); + } + persistTag.setBoolean(GIVEN_GUIDE_TAG, true); + } + } + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) + { + } + + @SubscribeEvent + public void onWorldSave(WorldEvent.Save event) + { + } +} \ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemList.java b/src/main/java/darkknight/jewelrycraft/item/ItemList.java index 3a91c7b..370c1d3 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemList.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemList.java @@ -22,6 +22,7 @@ public class ItemList public static ItemNecklace necklace; public static Item guide; public static ItemMoltenMetalBucket bucket; + public static ItemMoltenMetal metal; private static boolean isInitialized = false; @@ -38,6 +39,7 @@ public class ItemList necklace = (ItemNecklace) new ItemNecklace().setUnlocalizedName("Jewelrycraft.necklace").setTextureName("jewelrycraft:necklace"); guide = new ItemGuide().setUnlocalizedName("Jewelrycraft.guide").setTextureName("jewelrycraft:guide").setCreativeTab(JewelrycraftMod.jewelrycraft); bucket = (ItemMoltenMetalBucket) new ItemMoltenMetalBucket().setUnlocalizedName("Jewelrycraft.bucket"); + metal = (ItemMoltenMetal) new ItemMoltenMetal().setUnlocalizedName("Jewelrycraft.bucket"); GameRegistry.registerItem(thiefGloves, "thiefGloves"); GameRegistry.registerItem(shadowIngot, "shadowIngot"); @@ -48,6 +50,7 @@ public class ItemList GameRegistry.registerItem(crystal, "crystal"); GameRegistry.registerItem(guide, "guide"); GameRegistry.registerItem(bucket, "moltenMetalBucket"); + GameRegistry.registerItem(metal, "moltenMetal"); isInitialized = true; } diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java new file mode 100644 index 0000000..9bf9896 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java @@ -0,0 +1,122 @@ +package darkknight.jewelrycraft.item; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import javax.imageio.ImageIO; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockChest; +import net.minecraft.block.BlockSkull; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.InventoryEnderChest; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.tileentity.TileEntitySkull; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.block.BlockList; +import darkknight.jewelrycraft.util.JewelryNBT; + +public class ItemMoltenMetal extends Item +{ + private int amplifier, cooldown = 0; + int index = 0; + + public ItemMoltenMetal() + { + super(); + this.setMaxStackSize(1); + } + + public void registerIcons(IIconRegister iconRegister) + { + itemIcon = iconRegister.registerIcon("jewelrycraft:moltenMetalStill"); + } + + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack stack, int pass) + { + try + { + return color(stack, pass); + } + catch (IOException e) + { + e.printStackTrace(); + } + return 16777215; + } + + public static int color(ItemStack stack, int pass) throws IOException + { + String domain = "", texture; + IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); + BufferedImage icon; + int x=0, y=0, ok = 0, red, green, blue; + if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && JewelryNBT.ingot(stack) != null && JewelryNBT.ingot(stack) != new ItemStack(Item.getItemById(0), 0, 0) && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215) + { + String ingotIconName = JewelryNBT.ingot(stack).getIconIndex().getIconName(); + + if (ingotIconName.substring(0, ingotIconName.indexOf(":") + 1) != "") domain = ingotIconName.substring(0, ingotIconName.indexOf(":") + 1).replace(":", " ").trim(); + else domain = "minecraft"; + + texture = ingotIconName.substring(ingotIconName.lastIndexOf(":") + 1) + ".png"; + ResourceLocation ingot = null; + + if (JewelryNBT.ingot(stack).getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); + else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); + + icon = ImageIO.read(rm.getResource(ingot).getInputStream()); + while(ok == 0) + { + red = (icon.getRGB(x, y) >> 16) & 0xFF; + green = (icon.getRGB(x, y) >> 8) & 0xFF; + blue = icon.getRGB(x, y) & 0xFF; + if((red <= 80 && green <= 80 && blue <= 80) || (red >= 180 && green >= 180 && blue >= 180)) + { + if(x=icon.getTileWidth()-1 && y 0) - this.cooling--; + if (cooling > 0 && quantity > 0.9f) this.cooling--; if (cooling == 0) { this.hasMoltenMetal = false; @@ -103,8 +105,8 @@ public class TileEntityMolder extends TileEntity this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); this.hasJewelBase = true; cooling = -1; - this.isDirty = true; - this.markDirty(); + quantity = 0f; + isDirty = true; } } } diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java index 53a9f82..5f4be83 100644 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java @@ -2,6 +2,8 @@ package darkknight.jewelrycraft.tileentity; import java.util.Random; +import darkknight.jewelrycraft.config.ConfigHandler; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -12,114 +14,146 @@ import net.minecraft.tileentity.TileEntity; public class TileEntitySmelter extends TileEntity { - public int melting, flow, n = 0, p = 0; - public boolean hasMetal, hasMoltenMetal, isDirty; - public ItemStack metal, moltenMetal; - - public TileEntitySmelter() - { - this.melting = 0; - this.flow = 0; - this.hasMetal = false; - this.hasMoltenMetal = false; - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); - this.isDirty = false; - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setInteger("melting", melting); - nbt.setBoolean("hasMetal", hasMetal); - nbt.setBoolean("hasMoltenMetal", hasMoltenMetal); - NBTTagCompound tag = new NBTTagCompound(); - NBTTagCompound tag1 = new NBTTagCompound(); - this.metal.writeToNBT(tag); - nbt.setTag("metal", tag); - this.moltenMetal.writeToNBT(tag1); - nbt.setTag("moltenMetal", tag1); - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.melting = nbt.getInteger("melting"); - this.hasMetal = nbt.getBoolean("hasMetal"); - this.hasMoltenMetal = nbt.getBoolean("hasMoltenMetal"); - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.metal.readFromNBT(nbt.getCompoundTag("metal")); - this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); - this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal")); - } - - @Override - public void updateEntity() - { - super.updateEntity(); - Random rand = new Random(); - if(isDirty){ - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - isDirty = false; - } - if (p > 0) - --p; - else - p = 5; - if (n == 0 && p == 0) - { - flow += 16; - if (flow >= 16 * 20) - n = 1; - } - if (n == 1 && p == 0) - { - flow -= 16; - if (flow <= 0) - n = 0; - } - if (this.hasMetal) - { - for (int l = 0; l < 2; ++l) - this.worldObj.spawnParticle("flame", xCoord + rand.nextFloat(), (double) yCoord + 0.3F, zCoord + rand.nextFloat(), 0.0D, 0.0D, 0.0D); - } - if (rand.nextInt(65) == 0) - { - double d5 = this.xCoord + rand.nextFloat(); - double d7 = this.yCoord; - double d6 = this.zCoord + rand.nextFloat(); - this.worldObj.playSound(d5, d7, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); - } - if (this.hasMetal) - { - if (melting > 0) - this.melting--; - if (melting == 0) - { - this.hasMetal = false; - this.moltenMetal = metal; - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.hasMoltenMetal = true; - melting = -1; - this.isDirty = true; - this.markDirty(); - } - } - } - - public Packet getDescriptionPacket() - { - NBTTagCompound nbttagcompound = new NBTTagCompound(); - this.writeToNBT(nbttagcompound); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound); - } - - @Override - public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) - { - readFromNBT(packet.func_148857_g()); - worldObj.func_147479_m(xCoord, yCoord, zCoord); - } + public int melting, flow, n = 0, p = 0; + public boolean hasMetal, hasMoltenMetal, isDirty, pouring; + public ItemStack metal, moltenMetal; + public float quantity; + + public TileEntitySmelter() + { + this.melting = 0; + this.pouring = false; + this.flow = 0; + this.quantity = 0f; + this.hasMetal = false; + this.hasMoltenMetal = false; + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + this.isDirty = false; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setInteger("melting", melting); + nbt.setFloat("quantity", quantity); + nbt.setBoolean("hasMetal", hasMetal); + nbt.setBoolean("hasMoltenMetal", hasMoltenMetal); + nbt.setBoolean("pouring", pouring); + NBTTagCompound tag = new NBTTagCompound(); + NBTTagCompound tag1 = new NBTTagCompound(); + this.metal.writeToNBT(tag); + nbt.setTag("metal", tag); + this.moltenMetal.writeToNBT(tag1); + nbt.setTag("moltenMetal", tag1); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + this.melting = nbt.getInteger("melting"); + this.quantity = nbt.getFloat("quantity"); + this.hasMetal = nbt.getBoolean("hasMetal"); + this.hasMoltenMetal = nbt.getBoolean("hasMoltenMetal"); + this.pouring = nbt.getBoolean("pouring"); + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.metal.readFromNBT(nbt.getCompoundTag("metal")); + this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal")); + } + + @Override + public void updateEntity() + { + super.updateEntity(); + Random rand = new Random(); + if(isDirty){ + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + isDirty = false; + } + if (p > 0) + --p; + else + p = 5; + if (n == 0 && p == 0) + { + flow += 16; + if (flow >= 16 * 20) + n = 1; + } + if (n == 1 && p == 0) + { + flow -= 16; + if (flow <= 0) + n = 0; + } + if (this.hasMetal) + { + for (int l = 0; l < 2; ++l) + this.worldObj.spawnParticle("flame", xCoord + rand.nextFloat(), (double) yCoord + 0.3F, zCoord + rand.nextFloat(), 0.0D, 0.0D, 0.0D); + } + if (rand.nextInt(65) == 0) + { + double d5 = this.xCoord + rand.nextFloat(); + double d7 = this.yCoord; + double d6 = this.zCoord + rand.nextFloat(); + this.worldObj.playSound(d5, d7, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); + } + if (this.hasMetal) + { + if (melting > 0) + this.melting--; + if (melting == 0) + { + this.hasMetal = false; + this.moltenMetal = metal; + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.hasMoltenMetal = true; + this.quantity = 1f; + melting = -1; + this.isDirty = true; + } + } + TileEntityMolder me = null; + if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0 && worldObj.getTileEntity(xCoord, yCoord, zCoord - 1) != null && worldObj.getTileEntity(xCoord, yCoord, zCoord - 1) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord, yCoord, zCoord - 1); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 && worldObj.getTileEntity(xCoord + 1, yCoord, zCoord) != null && worldObj.getTileEntity(xCoord + 1, yCoord, zCoord) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord + 1, yCoord, zCoord); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2 && worldObj.getTileEntity(xCoord, yCoord, zCoord + 1) != null && worldObj.getTileEntity(xCoord, yCoord, zCoord + 1) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord, yCoord, zCoord + 1); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 3 && worldObj.getTileEntity(xCoord - 1, yCoord, zCoord) != null && worldObj.getTileEntity(xCoord - 1, yCoord, zCoord) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord - 1, yCoord, zCoord); + if(pouring){ + quantity -= 0.01f; + me.quantity += 0.01f; + if(!me.hasMoltenMetal) + { + me.moltenMetal = moltenMetal; + me.hasMoltenMetal = true; + } + if(quantity < 0){ + quantity = 0f; + hasMoltenMetal = false; + moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + pouring = false; + me.cooling = ConfigHandler.ingotCoolingTime; + } + } + } + + public Packet getDescriptionPacket() + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + this.writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound); + } + + @Override + public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) + { + readFromNBT(packet.func_148857_g()); + worldObj.func_147479_m(xCoord, yCoord, zCoord); + } } diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index 271f6f9..905665e 100644 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -19,7 +19,6 @@ public class JewelrycraftUtil public static ArrayList jewelry = new ArrayList(); public static ArrayList metal = new ArrayList(); public static ArrayList jamcraftPlayers = new ArrayList(); - public static HashMap liquids = new HashMap(); public static Random rand = new Random(); public static void addStuff() diff --git a/src/main/java/darkknight/jewelrycraft/worldGen/Generation.java b/src/main/java/darkknight/jewelrycraft/worldGen/Generation.java index f484c0b..9ff79ab 100644 --- a/src/main/java/darkknight/jewelrycraft/worldGen/Generation.java +++ b/src/main/java/darkknight/jewelrycraft/worldGen/Generation.java @@ -2,6 +2,7 @@ package darkknight.jewelrycraft.worldGen; import java.util.Random; +import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import cpw.mods.fml.common.IWorldGenerator; @@ -37,7 +38,8 @@ public class Generation implements IWorldGenerator int y = 5 + random.nextInt(4); int z = j + random.nextInt(16); world.setBlock(x, y, z, BlockList.shadowOre); - if(random.nextInt(3) == 0) world.setBlock(x + random.nextInt(2), y + random.nextInt(1), z + random.nextInt(2), BlockList.shadowOre); + int randX = random.nextInt(2), randY = random.nextInt(1), randZ = random.nextInt(2); + if(random.nextInt(3) == 0 && world.getBlock(x + randX, y + randY, z + randZ) == Blocks.stone) world.setBlock(x + randX, y + randY, z + randZ, BlockList.shadowOre); } } diff --git a/src/main/java/darkknight/jewelrycraft/worldGen/village/ComponentJewelry.java b/src/main/java/darkknight/jewelrycraft/worldGen/village/ComponentJewelry.java index 6924940..0a79b79 100644 --- a/src/main/java/darkknight/jewelrycraft/worldGen/village/ComponentJewelry.java +++ b/src/main/java/darkknight/jewelrycraft/worldGen/village/ComponentJewelry.java @@ -301,6 +301,7 @@ public class ComponentJewelry extends StructureVillagePieces.House1 { smelter.moltenMetal = JewelrycraftUtil.metal.get(random.nextInt(JewelrycraftUtil.metal.size())); smelter.hasMoltenMetal = true; + smelter.quantity = 1f; } } @@ -320,8 +321,11 @@ public class ComponentJewelry extends StructureVillagePieces.House1 if(hasStuff){ ItemStack ring = new ItemStack(ItemList.ring); JewelryNBT.addMetal(ring, JewelrycraftUtil.metal.get(random.nextInt(JewelrycraftUtil.metal.size()))); + ItemStack necklace = new ItemStack(ItemList.necklace); + JewelryNBT.addMetal(necklace, JewelrycraftUtil.metal.get(random.nextInt(JewelrycraftUtil.metal.size()))); if(meta == 0) molder.jewelBase = JewelrycraftUtil.metal.get(random.nextInt(JewelrycraftUtil.metal.size())); - else molder.jewelBase = ring; + else if(meta == 1) molder.jewelBase = ring; + else molder.jewelBase = necklace; molder.hasJewelBase = true; } } diff --git a/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png b/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png new file mode 100644 index 0000000..1eff844 Binary files /dev/null and b/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png differ diff --git a/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png.mcmeta b/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png.mcmeta new file mode 100644 index 0000000..7ceb363 --- /dev/null +++ b/src/main/resources/assets/jewelrycraft/textures/items/moltenMetalStill.png.mcmeta @@ -0,0 +1,45 @@ +{ + "animation": { + "frametime": 2, + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 18, + 17, + 16, + 15, + 14, + 13, + 12, + 11, + 10, + 9, + 8, + 7, + 6, + 5, + 4, + 3, + 2, + 1 + ] + } +} \ No newline at end of file -- cgit v1.2.3