From 06f62473f0622efe6decc32b70516a7c5d3d3572 Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Wed, 17 Sep 2014 19:10:05 +0300 Subject: 1.7.10 --- .../jewelrycraft/block/BlockDisplayer.java | 185 ++++++++++++ java/darkknight/jewelrycraft/block/BlockGlow.java | 39 +++ java/darkknight/jewelrycraft/block/BlockJCOre.java | 15 + .../jewelrycraft/block/BlockJewelAltar.java | 119 ++++++++ .../block/BlockJewelrsCraftingTable.java | 221 +++++++++++++++ java/darkknight/jewelrycraft/block/BlockList.java | 68 +++++ .../darkknight/jewelrycraft/block/BlockMolder.java | 144 ++++++++++ .../jewelrycraft/block/BlockMoltenMetal.java | 310 +++++++++++++++++++++ .../darkknight/jewelrycraft/block/BlockShadow.java | 114 ++++++++ .../jewelrycraft/block/BlockSmelter.java | 239 ++++++++++++++++ 10 files changed, 1454 insertions(+) create mode 100644 java/darkknight/jewelrycraft/block/BlockDisplayer.java create mode 100644 java/darkknight/jewelrycraft/block/BlockGlow.java create mode 100644 java/darkknight/jewelrycraft/block/BlockJCOre.java create mode 100644 java/darkknight/jewelrycraft/block/BlockJewelAltar.java create mode 100644 java/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java create mode 100644 java/darkknight/jewelrycraft/block/BlockList.java create mode 100644 java/darkknight/jewelrycraft/block/BlockMolder.java create mode 100644 java/darkknight/jewelrycraft/block/BlockMoltenMetal.java create mode 100644 java/darkknight/jewelrycraft/block/BlockShadow.java create mode 100644 java/darkknight/jewelrycraft/block/BlockSmelter.java (limited to 'java/darkknight/jewelrycraft/block') diff --git a/java/darkknight/jewelrycraft/block/BlockDisplayer.java b/java/darkknight/jewelrycraft/block/BlockDisplayer.java new file mode 100644 index 0000000..333cc94 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockDisplayer.java @@ -0,0 +1,185 @@ +package darkknight.jewelrycraft.block; + +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.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import darkknight.jewelrycraft.tileentity.TileEntityDisplayer; + +public class BlockDisplayer extends BlockContainer +{ + Random rand = new Random(); + + protected BlockDisplayer(Material par2Material) + { + super(par2Material); + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntityDisplayer(); + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @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 boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + { + TileEntityDisplayer te = (TileEntityDisplayer) world.getTileEntity(i, j, k); + ItemStack item = entityPlayer.inventory.getCurrentItem(); + if (te != null && item != null && item != new ItemStack(Item.getItemById(0), 0, 0) && !world.isRemote) + { + if (!te.hasObject) + { + te.object = item.copy(); + te.object.stackSize = 1; + te.quantity += item.stackSize; + te.hasObject = true; + if (!entityPlayer.capabilities.isCreativeMode) item.stackSize = 0; + te.isDirty = true; + te.markDirty(); + } + else if (te.object.getItem() == item.getItem() && te.object != null && te.object != new ItemStack(Item.getItemById(0), 0, 0) && te.object.getItemDamage() == item.getItemDamage()) + { + if (te.object.hasTagCompound() && item.hasTagCompound() && te.object.getTagCompound().equals(item.getTagCompound())) + { + te.quantity += item.stackSize; + te.object.stackSize = 1; + if (!entityPlayer.capabilities.isCreativeMode) item.stackSize = 0; + te.isDirty = true; + te.markDirty(); + } + else if (!te.object.hasTagCompound() && !item.hasTagCompound()) + { + te.quantity += item.stackSize; + te.object.stackSize = 1; + if (!entityPlayer.capabilities.isCreativeMode) item.stackSize = 0; + te.isDirty = true; + te.markDirty(); + } + } + } + return true; + } + + @Override + public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) + { + TileEntityDisplayer te = (TileEntityDisplayer) world.getTileEntity(i, j, k); + if (te != null && !world.isRemote) + { + if (te.hasObject && te.object != null && te.object != new ItemStack(Item.getItemById(0), 0, 0) && player.inventory.addItemStackToInventory(te.object)) + { + if (player.isSneaking()) + { + if (te.quantity > te.object.getMaxStackSize()) + { + te.object.stackSize = te.object.getMaxStackSize() - 1; + player.inventory.addItemStackToInventory(te.object); + te.object.stackSize = 1; + te.quantity -= te.object.getMaxStackSize(); + } + else + { + te.object.stackSize = te.quantity - 1; + player.inventory.addItemStackToInventory(te.object); + te.hasObject = false; + te.object = new ItemStack(Item.getItemById(0), 0, 0); + te.quantity = 0; + } + te.isDirty = true; + te.markDirty(); + } + else + { + if (te.quantity >= 2) + { + player.inventory.addItemStackToInventory(te.object); + te.object.stackSize = 1; + --te.quantity; + } + else + { + player.inventory.addItemStackToInventory(te.object); + te.object.stackSize = 1; + te.hasObject = false; + te.object = new ItemStack(Item.getItemById(0), 0, 0); + te.quantity = 0; + } + te.isDirty = true; + te.markDirty(); + } + } + } + } + + public void dropItem(World world, double x, double y, double z, ItemStack stack) + { + EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 1.5D, z + 0.5D, stack); + entityitem.motionX = 0; + entityitem.motionZ = 0; + entityitem.motionY = 0.11000000298023224D; + world.spawnEntityInWorld(entityitem); + } + + public void breakBlock(World world, int i, int j, int k, Block block, int par6) + { + TileEntityDisplayer te = (TileEntityDisplayer) world.getTileEntity(i, j, k); + + if (te != null && te.hasObject) + { + te.object.stackSize = te.quantity; + dropItem(te.getWorldObj(), (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.object); + world.removeTileEntity(i, j, k); + } + + super.breakBlock(world, i, j, k, block, par6); + } + + @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 void registerBlockIcons(IIconRegister icon) + { + this.blockIcon = icon.registerIcon("jewelrycraft:displayer"); + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockGlow.java b/java/darkknight/jewelrycraft/block/BlockGlow.java new file mode 100644 index 0000000..39f7b26 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockGlow.java @@ -0,0 +1,39 @@ +package darkknight.jewelrycraft.block; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +public class BlockGlow extends Block +{ + protected BlockGlow() + { + super(Material.air); + } + + public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int i) + { + return null; + } + + public boolean isCollidable() + { + return false; + } + + public boolean isOpaqueCube() + { + return false; + } + + public boolean renderAsNormalBlock() + { + return false; + } + + public int getRenderType() + { + return -1; + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockJCOre.java b/java/darkknight/jewelrycraft/block/BlockJCOre.java new file mode 100644 index 0000000..e6bb31c --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockJCOre.java @@ -0,0 +1,15 @@ +package darkknight.jewelrycraft.block; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +public class BlockJCOre extends Block +{ + protected BlockJCOre() + { + super(Material.rock); + setHarvestLevel("pickaxe", 3); + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockJewelAltar.java b/java/darkknight/jewelrycraft/block/BlockJewelAltar.java new file mode 100644 index 0000000..4e53832 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockJewelAltar.java @@ -0,0 +1,119 @@ +package darkknight.jewelrycraft.block; + +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.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.item.ItemList; +import darkknight.jewelrycraft.tileentity.TileEntityAltar; + +public class BlockJewelAltar extends BlockContainer +{ + @SideOnly(Side.CLIENT) + private IIcon altarSide; + @SideOnly(Side.CLIENT) + private IIcon altarBottom; + @SideOnly(Side.CLIENT) + private IIcon altarTop; + + public BlockJewelAltar() + { + super(Material.iron); + } + + public static boolean isNormalCube(int par0) + { + return true; + } + + public void registerBlockIcons(IIconRegister par1IconRegister) + { + this.altarSide = par1IconRegister.registerIcon(this.getTextureName() + "_" + "side"); + this.altarBottom = par1IconRegister.registerIcon(this.getTextureName() + "_" + "bottom"); + this.altarTop = par1IconRegister.registerIcon(this.getTextureName() + "_" + "top"); + } + + public IIcon getIcon(int par1, int par2) + { + return par1 == 1 ? this.altarTop : (par1 == 0 ? this.altarBottom : this.altarSide); + } + + @Override + public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + { + TileEntityAltar te = (TileEntityAltar) world.getTileEntity(i, j, k); + ItemStack item = entityPlayer.inventory.getCurrentItem(); + if (te != null && !world.isRemote) + { + if (item != null && item != new ItemStack(Item.getItemById(0), 0, 0) && (item.getItem() == ItemList.ring || item.getItem() == ItemList.necklace) && !te.hasObject) + { + te.object = item.copy(); + item.stackSize = 0; + te.playerName = entityPlayer.getDisplayName(); + te.isDirty = true; + te.markDirty(); + te.hasObject = true; + } + + if (te.object != null && te.object != new ItemStack(Item.getItemById(0), 0, 0) && te.hasObject && entityPlayer.isSneaking()) + { + entityPlayer.inventory.addItemStackToInventory(te.object); + te.object = new ItemStack(Item.getItemById(0), 0, 0); + te.playerName = ""; + te.isDirty = true; + te.markDirty(); + te.hasObject = false; + } + } + return true; + } + + @Override + public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) + { + TileEntityAltar te = (TileEntityAltar) world.getTileEntity(i, j, k); + if (te != null && !world.isRemote) + { + if (te.object != null && te.object != new ItemStack(Item.getItemById(0), 0, 0)) + { + } + } + } + + public void dropItem(World world, double x, double y, double z, ItemStack stack) + { + EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 1.5D, z + 0.5D, stack); + entityitem.motionX = 0; + entityitem.motionZ = 0; + entityitem.motionY = 0.11000000298023224D; + world.spawnEntityInWorld(entityitem); + } + + public void breakBlock(World world, int i, int j, int k, Block block, int par6) + { + TileEntityAltar te = (TileEntityAltar) world.getTileEntity(i, j, k); + + if (te != null && te.object != null && te.object != new ItemStack(Item.getItemById(0), 0, 0)) + { + dropItem(te.getWorldObj(), (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.object); + world.removeTileEntity(i, j, k); + } + + super.breakBlock(world, i, j, k, block, par6); + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntityAltar(); + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java b/java/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java new file mode 100644 index 0000000..1c65970 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java @@ -0,0 +1,221 @@ +package darkknight.jewelrycraft.block; + +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.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.config.ConfigHandler; +import darkknight.jewelrycraft.tileentity.TileEntityJewelrsCraftingTable; +import darkknight.jewelrycraft.util.JewelrycraftUtil; + +public class BlockJewelrsCraftingTable extends BlockContainer +{ + Random rand = new Random(); + + protected BlockJewelrsCraftingTable(Material par2Material) + { + super(par2Material); + this.setBlockBounds(0.0F, 0F, 0.0F, 1.0F, 0.8F, 1.0F); + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntityJewelrsCraftingTable(); + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @Override + public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + { + TileEntityJewelrsCraftingTable te = (TileEntityJewelrsCraftingTable) world.getTileEntity(i, j, k); + ItemStack item = entityPlayer.inventory.getCurrentItem(); + if (te != null && !world.isRemote) + { + if (!te.hasEndItem && !te.hasJewelry && item != null && JewelrycraftUtil.isJewelry(item)) + { + if (te.hasModifier && te.hasJewel && item.hasTagCompound() && item.getTagCompound().hasKey("modifier") && item.getTagCompound().hasKey("jewel")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.jewelrymodifiedfull"))); + else if (te.hasJewel && item.hasTagCompound() && item.getTagCompound().hasKey("jewel")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.jewelrycontainsjewel"))); + else if (te.hasModifier && item.hasTagCompound() && item.getTagCompound().hasKey("modifier")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.jewelrycontainsmodifier"))); + else + { + te.jewelry = item.copy(); + te.hasJewelry = true; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + entityPlayer.inventory.markDirty(); + world.setTileEntity(i, j, k, te); + te.isDirty = true; + te.markDirty(); + } + } + if (!te.hasEndItem && !te.hasModifier && item != null && JewelrycraftUtil.isModifier(item)) + { + if (te.hasJewelry && te.jewelry.hasTagCompound() && te.jewelry.getTagCompound().hasKey("modifier")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.jewelrycontainsmodifier"))); + else + { + te.modifier = item.copy(); + te.modifier.stackSize = 1; + te.hasModifier = true; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + entityPlayer.inventory.markDirty(); + world.setTileEntity(i, j, k, te); + te.isDirty = true; + te.markDirty(); + } + } + if (!te.hasEndItem && !te.hasJewel && item != null && JewelrycraftUtil.isJewel(item)) + { + if (te.hasJewelry && te.jewelry.hasTagCompound() && te.jewelry.getTagCompound().hasKey("jewel")) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.jewelrycontainsjewel"))); + else + { + te.jewel = item.copy(); + te.jewel.stackSize = 1; + te.hasJewel = true; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + entityPlayer.inventory.markDirty(); + world.setTileEntity(i, j, k, te); + te.isDirty = true; + te.markDirty(); + } + } + if (te.timer <= 0 && !te.hasEndItem && te.hasJewelry && (te.hasModifier || te.hasJewel)) + { + te.timer = ConfigHandler.jewelryCraftingTime; + te.angle = 0; + } + if (te.hasEndItem && item != null) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.hasenditem"))); + + if (te.hasModifier && entityPlayer.isSneaking()) + { + dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.modifier.copy()); + te.modifier = new ItemStack(Item.getItemById(0), 0, 0); + te.hasModifier = false; + te.timer = 0; + te.angle = 0F; + te.isDirty = true; + te.markDirty(); + world.markBlockForUpdate(i, j, k); + world.setTileEntity(i, j, k, te); + } + if (te.hasJewelry && entityPlayer.isSneaking()) + { + dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewelry.copy()); + te.jewelry = new ItemStack(Item.getItemById(0), 0, 0); + te.hasJewelry = false; + te.timer = 0; + te.angle = 0F; + te.isDirty = true; + te.markDirty(); + world.markBlockForUpdate(i, j, k); + world.setTileEntity(i, j, k, te); + } + if (te.hasJewel && entityPlayer.isSneaking()) + { + dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewel.copy()); + te.jewel = new ItemStack(Item.getItemById(0), 0, 0); + te.hasJewel = false; + te.timer = 0; + te.angle = 0F; + te.isDirty = true; + te.markDirty(); + world.markBlockForUpdate(i, j, k); + world.setTileEntity(i, j, k, te); + } + } + return true; + } + + public void dropItem(World world, double x, double y, double z, ItemStack stack) + { + EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 1D, z + 0.5D, stack); + entityitem.motionX = 0; + entityitem.motionZ = 0; + entityitem.motionY = 0.21000000298023224D; + world.spawnEntityInWorld(entityitem); + } + + public void breakBlock(World world, int i, int j, int k, Block par5, int par6) + { + TileEntityJewelrsCraftingTable te = (TileEntityJewelrsCraftingTable) world.getTileEntity(i, j, k); + if (te != null) + { + if (te.hasModifier) dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.modifier.copy()); + if (te.hasJewelry) dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewelry.copy()); + if (te.hasJewel) dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewel.copy()); + if (te.hasEndItem) dropItem(te.getWorldObj(), (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.endItem.copy()); + world.removeTileEntity(i, j, k); + } + super.breakBlock(world, i, j, k, par5, par6); + } + + @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 void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) + { + TileEntityJewelrsCraftingTable te = (TileEntityJewelrsCraftingTable) world.getTileEntity(i, j, k); + if (te != null && !world.isRemote) + { + if (te.hasEndItem) + { + dropItem(te.getWorldObj(), (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.endItem.copy()); + te.endItem = new ItemStack(Item.getItemById(0), 0, 0); + te.hasEndItem = false; + te.isDirty = true; + te.markDirty(); + world.markBlockForUpdate(i, j, k); + world.setTileEntity(i, j, k, te); + } + else if (te.hasJewelry && (te.hasModifier || te.hasJewel) && te.timer > 0 && te.jewelry != null) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.table.iscrafting", te.jewelry.getDisplayName()) + " (" + ((ConfigHandler.jewelryCraftingTime - te.timer) * 100 / ConfigHandler.jewelryCraftingTime) + "%)")); + else if ((!te.hasModifier || !te.hasJewel) && !te.hasJewelry) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.missingjewelryandmodifierorjewel"))); + else if (!te.hasJewelry) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.missingjewelry"))); + else if (!te.hasModifier || !te.hasJewel) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.table.missingmodifierorjewel"))); + } + } + + @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; + } + + public void registerBlockIcons(IIconRegister icon) + { + this.blockIcon = icon.registerIcon("jewelrycraft:jewelrsCraftingTable"); + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockList.java b/java/darkknight/jewelrycraft/block/BlockList.java new file mode 100644 index 0000000..75efbaa --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockList.java @@ -0,0 +1,68 @@ +package darkknight.jewelrycraft.block; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.tileentity.TileEntityAltar; +import darkknight.jewelrycraft.tileentity.TileEntityBlockShadow; +import darkknight.jewelrycraft.tileentity.TileEntityDisplayer; +import darkknight.jewelrycraft.tileentity.TileEntityJewelrsCraftingTable; +import darkknight.jewelrycraft.tileentity.TileEntityMolder; +import darkknight.jewelrycraft.tileentity.TileEntitySmelter; + +public class BlockList +{ + public static Block shadowOre; + public static Block glow; + public static Block smelter; + public static Block molder; + public static Block displayer; + public static Block jewelCraftingTable; + public static Block shadowBlock; + public static Block jewelAltar; + public static BlockMoltenMetal moltenMetal; + public static Fluid moltenMetalFluid; + + private static boolean isInitialized = false; + + public static void preInit(FMLPreInitializationEvent e) + { + if (!isInitialized) + { + shadowOre = new BlockJCOre().setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockTextureName("jewelrycraft:oreShadow").setBlockName("Jewelrycraft.oreShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); + glow = new BlockGlow().setBlockName("Jewelrycraft.glow").setLightLevel(1F); + smelter = new BlockSmelter(Material.rock).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundTypeStone).setBlockName("Jewelrycraft.smelter").setCreativeTab(JewelrycraftMod.jewelrycraft); + molder = new BlockMolder(Material.rock).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundTypeStone).setBlockName("Jewelrycraft.molder").setCreativeTab(JewelrycraftMod.jewelrycraft); + displayer = new BlockDisplayer(Material.iron).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundTypeMetal).setBlockName("Jewelrycraft.displayer").setCreativeTab(JewelrycraftMod.jewelrycraft); + jewelCraftingTable = new BlockJewelrsCraftingTable(Material.rock).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundTypeStone).setBlockName("Jewelrycraft.jewelCraftingTable").setCreativeTab(JewelrycraftMod.jewelrycraft); + shadowBlock = new BlockShadow().setHardness(5.0F).setResistance(7.0F).setStepSound(Block.soundTypeMetal).setBlockTextureName("jewelrycraft:blockShadow").setBlockName("Jewelrycraft.blockShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); + jewelAltar = new BlockJewelAltar().setHardness(5.0F).setResistance(2.0F).setStepSound(Block.soundTypeMetal).setBlockTextureName("jewelrycraft:altar").setBlockName("Jewelrycraft.altar").setCreativeTab(JewelrycraftMod.jewelrycraft); + + GameRegistry.registerBlock(shadowOre, "shadowOre"); + GameRegistry.registerBlock(shadowBlock, "shadowBlock"); + GameRegistry.registerBlock(smelter, "Smelter"); + GameRegistry.registerBlock(molder, "Molder"); + GameRegistry.registerBlock(jewelCraftingTable, "jewelCraftingTable"); + GameRegistry.registerBlock(displayer, "Displayer"); + GameRegistry.registerBlock(jewelAltar, "Altar"); + + GameRegistry.registerTileEntity(TileEntitySmelter.class, "30"); + GameRegistry.registerTileEntity(TileEntityMolder.class, "31"); + GameRegistry.registerTileEntity(TileEntityJewelrsCraftingTable.class, "32"); + GameRegistry.registerTileEntity(TileEntityDisplayer.class, "33"); + GameRegistry.registerTileEntity(TileEntityBlockShadow.class, "34"); + GameRegistry.registerTileEntity(TileEntityAltar.class, "35"); + + moltenMetalFluid = new Fluid("metal.molten").setLuminosity(15).setDensity(3000).setTemperature(2000).setViscosity(6000); + if (!FluidRegistry.registerFluid(moltenMetalFluid)) moltenMetalFluid = FluidRegistry.getFluid("metal.molten"); + moltenMetal = new BlockMoltenMetal(moltenMetalFluid, Material.lava); + GameRegistry.registerBlock(moltenMetal, "moltenMetalLiquid"); + + isInitialized = true; + } + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockMolder.java b/java/darkknight/jewelrycraft/block/BlockMolder.java new file mode 100644 index 0000000..8b7d47d --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockMolder.java @@ -0,0 +1,144 @@ +package darkknight.jewelrycraft.block; + +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.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.config.ConfigHandler; +import darkknight.jewelrycraft.item.ItemList; +import darkknight.jewelrycraft.tileentity.TileEntityMolder; + +public class BlockMolder extends BlockContainer +{ + Random rand = new Random(); + + protected BlockMolder(Material par2Material) + { + super(par2Material); + this.setBlockBounds(0.1F, 0F, 0.1F, 0.9F, 0.2F, 0.9F); + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntityMolder(); + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @Override + public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) + { + TileEntityMolder te = (TileEntityMolder) world.getTileEntity(i, j, k); + ItemStack item = entityPlayer.inventory.getCurrentItem(); + if (te != null && !world.isRemote) + { + if (item != null && !te.hasMold && item.getItem() == ItemList.molds) + { + te.mold = item.copy(); + te.hasMold = true; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.molder.addedmold", te.mold.getDisplayName()))); + te.isDirty = true; + } + if (te.hasMold && entityPlayer.isSneaking() && !te.hasMoltenMetal) + { + dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.mold.copy()); + te.mold = new ItemStack(Item.getItemById(0), 0, 0); + te.hasMold = false; + te.isDirty = true; + } + else if (te.hasMoltenMetal) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.hasmoltenmetal"))); + } + return true; + } + + public void dropItem(World world, double x, double y, double z, ItemStack stack) + { + EntityItem entityitem = new EntityItem(world, x + 0.5D, y + 0.5D, z + 0.5D, stack); + entityitem.motionX = 0; + entityitem.motionZ = 0; + entityitem.motionY = 0.11000000298023224D; + world.spawnEntityInWorld(entityitem); + } + + public void breakBlock(World world, int i, int j, int k, Block par5, int par6) + { + TileEntityMolder te = (TileEntityMolder) world.getTileEntity(i, j, k); + + if (te != null) + { + if (te.hasJewelBase) dropItem(te.getWorldObj(), (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewelBase.copy()); + if (te.hasMold) dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.mold.copy()); + world.removeTileEntity(i, j, k); + } + + super.breakBlock(world, i, j, k, par5, par6); + } + + @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 void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) + { + TileEntityMolder me = (TileEntityMolder) world.getTileEntity(i, j, k); + if (me != null && !world.isRemote) + { + if (me.hasJewelBase) + { + dropItem(me.getWorldObj(), (double) me.xCoord, (double) me.yCoord, (double) me.zCoord, me.jewelBase.copy()); + me.jewelBase = new ItemStack(Item.getItemById(0), 0, 0); + me.hasJewelBase = false; + } + else if (me.hasMoltenMetal && me.cooling >= 0) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.metaliscooling") + " (" + ((ConfigHandler.ingotCoolingTime - me.cooling) * 100 / ConfigHandler.ingotCoolingTime) + "%)")); + else if (me.mold.getItem() == ItemList.molds && !me.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.moldisempty"))); + else if (me.mold.getItem() != ItemList.molds) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.molder.moldismissing"))); + me.isDirty = true; + } + } + + @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; + } + + public void registerBlockIcons(IIconRegister icon) + { + this.blockIcon = icon.registerIcon("jewelrycraft:molder"); + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java b/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java new file mode 100644 index 0000000..9c1daea --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockMoltenMetal.java @@ -0,0 +1,310 @@ +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.renderer.texture.TextureManager; +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; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +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.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; + +public class BlockMoltenMetal extends BlockFluidClassic +{ + + @SideOnly(Side.CLIENT) + protected IIcon stillIcon; + @SideOnly(Side.CLIENT) + protected IIcon flowingIcon; + + public BlockMoltenMetal(Fluid fluid, Material material) + { + super(fluid, material); + setBlockName("Jewelrycraft.moltenMetal"); + this.setQuantaPerBlock(5); + setLightLevel(15f); + } + + @Override + public IIcon getIcon(int side, int meta) + { + return (side == 0 || side == 1) ? stillIcon : flowingIcon; + } + + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister register) + { + stillIcon = register.registerIcon("jewelrycraft:moltenMetalStill"); + flowingIcon = register.registerIcon("jewelrycraft:moltenMetalFlow"); + } + + @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); + } + + @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); + } + + @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, false, null); + } + catch (IOException e) + { + e.printStackTrace(); + } + return 0; + } + + @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); + } + } + } + + 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]))); + } + } + + @SideOnly(Side.CLIENT) + 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); + 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 == 2) + { + int itemID, itemDamage; + try + { + itemID = Integer.parseInt(splitData[0]); + itemDamage = Integer.parseInt(splitData[1]); + + JewelryNBT.addMetal(item, new ItemStack(Item.getItemById(itemID), 1, itemDamage)); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } + if (forcecolor) JewelryNBT.addMetal(item, new ItemStack(itemC)); + int x = 0, y = 0, ok = 0, red, green, blue; + if (item != null && JewelryNBT.ingot(item) != null && JewelryNBT.ingot(item).getIconIndex() != null && JewelryNBT.ingotColor(item) == 16777215) + { + IIcon itemIcon = JewelryNBT.ingot(item).getItem().getIcon(JewelryNBT.ingot(item), 0); + String ingotIconName = itemIcon.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; + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + + if (texturemanager.getResourceLocation(JewelryNBT.ingot(item).getItemSpriteNumber()).toString().contains("items")) ingot = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture); + else ingot = new ResourceLocation(domain.toLowerCase(), "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 (!isColorPretty(red, green, blue)) + { + if (x < icon.getTileWidth() - 1) x++; + if (x >= icon.getTileWidth() - 1 && y < icon.getTileWidth() - 1) + { + x = 0; + y++; + } + if (x == icon.getTileWidth() - 1 && y == icon.getTileWidth() - 1) ok = 1; + } + else ok = 1; + } + JewelryNBT.addIngotColor(item, icon.getRGB(x, y)); + } + if (JewelryNBT.ingot(item) != null) return JewelryNBT.ingotColor(item); + return 16777215; + } + + public static boolean isColorPretty(int r, int g, int b) + { + if ((r >= 100 && g >= 100 && b >= 100 && r < 200 && b < 200 && g < 200) || ((r >= 100 && (g < 100 || b < 100)) || (g >= 100 && (r < 100 || b < 100)) || (b >= 100 && (g < 100 || r < 100)))) return true; + else return false; + } + + public static String stringFromLocation(int x, int y, int z, int dimID) + { + return x + " " + y + " " + z + " " + dimID; + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockShadow.java b/java/darkknight/jewelrycraft/block/BlockShadow.java new file mode 100644 index 0000000..4e8acf5 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockShadow.java @@ -0,0 +1,114 @@ +package darkknight.jewelrycraft.block; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +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.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Facing; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import darkknight.jewelrycraft.tileentity.TileEntityBlockShadow; + +public class BlockShadow extends BlockContainer +{ + private IIcon[] iconArray; + private static final String __OBFID = "CL_00000312"; + + public BlockShadow() + { + super(Material.iron); + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + + public int getRenderBlockPass() + { + return 1; + } + + public boolean isBeaconBase(World worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ) + { + return true; + } + + public boolean isOpaqueCube() + { + return false; + } + + public boolean renderAsNormalBlock() + { + return false; + } + + public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) + { + return false; + } + + public static boolean isNormalCube(int par0) + { + return true; + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntityBlockShadow(); + } + + public void registerBlockIcons(IIconRegister par1IconRegister) + { + this.iconArray = new IIcon[16]; + + for (int i = 0; i < this.iconArray.length; ++i) + { + this.iconArray[i] = par1IconRegister.registerIcon(this.getTextureName() + (15 - i)); + } + } + + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) + { + if (world.getBlockMetadata(x, y, z) == 15) return null; + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + + public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_) + { + Block block = p_149646_1_.getBlock(p_149646_2_, p_149646_3_, p_149646_4_); + + if (this == BlockList.shadowBlock) + { + if (block == this) { return false; } + } + + return block == this ? false : super.shouldSideBeRendered(p_149646_1_, p_149646_2_, p_149646_3_, p_149646_4_, p_149646_5_); + } + + public boolean hasComparatorInputOverride() + { + return true; + } + + public int getComparatorInputOverride(World world, int x, int y, int z, int meta) + { + return world.getBlockMetadata(x, y, z); + } + + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side, int meta) + { + return this.iconArray[meta]; + } +} diff --git a/java/darkknight/jewelrycraft/block/BlockSmelter.java b/java/darkknight/jewelrycraft/block/BlockSmelter.java new file mode 100644 index 0000000..b64f142 --- /dev/null +++ b/java/darkknight/jewelrycraft/block/BlockSmelter.java @@ -0,0 +1,239 @@ +package darkknight.jewelrycraft.block; + +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.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.network.PacketSendLiquidData; +import darkknight.jewelrycraft.tileentity.TileEntityMolder; +import darkknight.jewelrycraft.tileentity.TileEntitySmelter; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; + +public class BlockSmelter extends BlockContainer +{ + Random rand = new Random(); + + protected BlockSmelter(Material par2Material) + { + super(par2Material); + } + + @Override + public TileEntity createNewTileEntity(World world, int var2) + { + return new TileEntitySmelter(); + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + 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; + world.spawnEntityInWorld(entityitem); + } + + 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, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.metal.copy()); + if (te.hasMoltenMetal && te.moltenMetal != null && Item.getIdFromItem(te.moltenMetal.getItem()) > 0) + { + JewelrycraftMod.saveData.setString(i + " " + j + " " + k + " " + world.provider.dimensionId, Item.getIdFromItem(te.moltenMetal.getItem()) + ":" + te.moltenMetal.getItemDamage()); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, i, j, k, Item.getIdFromItem(te.moltenMetal.getItem()), te.moltenMetal.getItemDamage())); + + 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 >= 0.9f && !te.pouring && item != null && item.getItem() == Items.bucket) + { + te.quantity = 0f; + te.hasMoltenMetal = false; + ItemStack metalBucket = new ItemStack(ItemList.bucket, 1); + JewelryNBT.addMetal(metalBucket, te.moltenMetal); + --item.stackSize; + entityPlayer.inventory.addItemStackToInventory(metalBucket); + te.isDirty = true; + return true; + } + if (te != null && !world.isRemote) + { + int index = -1; + for (int a = 0; a < JewelrycraftUtil.jamcraftPlayers.size(); a++) + if (entityPlayer.getDisplayName().equals(JewelrycraftUtil.jamcraftPlayers.get(a))) index = a; + boolean canPlace = item != null && (JewelrycraftUtil.isMetal(item) || JewelrycraftUtil.isOre(item) || index != -1); + boolean isOre = false; + boolean oreCoincidesWithMetal = false; + if(item != null && Item.getIdFromItem(item.getItem()) != 0) isOre = JewelrycraftUtil.isOre(item); + if(isOre && te.moltenMetal != null && item != null && Item.getIdFromItem(te.moltenMetal.getItem()) != 0) + oreCoincidesWithMetal = te.moltenMetal.getItem().equals(JewelrycraftUtil.getIngotFromOre(item.getItem()).getItem()) && te.moltenMetal.getItemDamage() == JewelrycraftUtil.getIngotFromOre(item.getItem()).getItemDamage(); + if (!te.hasMetal && !te.hasMoltenMetal && !te.pouring && item != null && canPlace) + { + entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.smelter.nowsmeltingingot", item.getDisplayName()))); + te.metal = item.copy(); + te.metal.stackSize = 1; + te.hasMetal = true; + te.melting = ConfigHandler.ingotMeltingTime; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + te.isDirty = true; + } + else if (te.hasMetal && !te.hasMoltenMetal && item != null && canPlace && item.getUnlocalizedName().equals(te.metal.getUnlocalizedName()) && (!isOre && te.metal.stackSize < 9 || isOre && te.metal.stackSize < 4)) + { + entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("Smelting extra " + (isOre ? "ores" : "ingots") + " (" + (te.metal.stackSize + 1) + ")"))); + te.metal.stackSize++; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + te.isDirty = true; + } + else if (!te.hasMetal && te.hasMoltenMetal && item != null && canPlace && ((!isOre && item.getUnlocalizedName().equals(te.moltenMetal.getUnlocalizedName()) && te.moltenMetal.stackSize < 9) || (isOre && oreCoincidesWithMetal && te.moltenMetal.stackSize < 8))) + { + entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("Smelting extra " + (isOre ? "ore" : "ingot") + "."))); + te.metal = item.copy(); + te.metal.stackSize = 1; + te.hasMetal = true; + te.melting = ConfigHandler.ingotMeltingTime; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + te.isDirty = true; + } + else if (te.hasMetal && te.hasMoltenMetal && item != null && canPlace && item.getUnlocalizedName().equals(te.moltenMetal.getUnlocalizedName())) + { + if ((!isOre && te.moltenMetal.stackSize < 9 && te.metal.stackSize < 9 && (te.metal.stackSize + te.moltenMetal.stackSize) < 9) || (isOre && oreCoincidesWithMetal && te.metal.stackSize*2 < 9 && (te.metal.stackSize*2 + te.moltenMetal.stackSize) < 9)) + { + entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("Smelting extra ingots (" + (te.metal.stackSize + 1) + ")"))); + te.metal.stackSize++; + te.hasMetal = true; + te.melting = ConfigHandler.ingotMeltingTime; + if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize; + te.isDirty = true; + } + } + else if ((te.hasMetal || te.hasMoltenMetal) && item != null && canPlace && ((te.moltenMetal != null && te.moltenMetal.stackSize > 0 && item.getUnlocalizedName().equals(te.moltenMetal.getUnlocalizedName())) || (te.metal != null && te.metal.stackSize > 0 && item.getUnlocalizedName().equals(te.metal.getUnlocalizedName()))) && ((te.moltenMetal != null && te.moltenMetal.stackSize >= 9) || (te.metal != null && te.metal.stackSize >= 9))) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("Smelter is at full capacity."))); + else if (te.hasMetal && !te.hasMoltenMetal && item != null && canPlace) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.smelter.alreadyhasingot", te.metal.getDisplayName()))); + else if (te.hasMoltenMetal && Item.getIdFromItem(te.moltenMetal.getItem()) > 0) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("chatmessage.Jewelrycraft.smelter.hasmolteningot", te.moltenMetal.getDisplayName()))); + else if (item != null && !item.getUnlocalizedName().toLowerCase().contains("ingot") && canPlace) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.itemrenamedtoingot"))); + else if (item != null && (!item.getUnlocalizedName().toLowerCase().contains("ingot") || item.getUnlocalizedName().toLowerCase().contains("mold"))) entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.itemneedstobeingot"))); + + if (te.hasMetal && entityPlayer.isSneaking()) + { + dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.metal.copy()); + te.hasMetal = false; + te.melting = -1; + te.isDirty = true; + } + if (te != null) 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.Jewelrycraft.smelter.metalismelting", te.metal.getDisplayName()) + " (" + ((ConfigHandler.ingotMeltingTime - te.melting) * 100 / ConfigHandler.ingotMeltingTime) + "%)")); + else if (te.hasMoltenMetal && !isConnectedToMolder(world, i, j, k)) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.molderismissing"))); + else if (!me.hasMold && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.molderhasnomold"))); + else if (me.hasMoltenMetal && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.molderhasmoltenmetal"))); + else if (me.hasJewelBase && te.hasMoltenMetal) player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.modlerhasitem"))); + else player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("chatmessage.Jewelrycraft.smelter.empty"))); + } + + } + + 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; + } + + public void registerBlockIcons(IIconRegister icon) + { + this.blockIcon = icon.registerIcon("jewelrycraft:smelter"); + } + +} -- cgit v1.2.3