summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2013-12-23 22:03:06 +0200
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2013-12-23 22:03:06 +0200
commit198677e5b01009a65d243da1d25a14f879df659c (patch)
tree512da4c4fbccc40fdcfc79a6f6cbf0f4eb0efd50 /common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java
parentb01cf1aa1d3480ad52ee7940f213596bfe6a2090 (diff)
Changed lots of stuff, added new features. Ender Rings!!!
Diffstat (limited to 'common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java')
-rw-r--r--common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java163
1 files changed, 121 insertions, 42 deletions
diff --git a/common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java b/common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java
index c30e78c..c9372a9 100644
--- a/common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java
+++ b/common/darkknight/jewelrycraft/block/BlockJewelrsCraftingTable.java
@@ -1,7 +1,10 @@
package darkknight.jewelrycraft.block;
+import java.util.ArrayList;
+import java.util.Iterator;
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.IconRegister;
@@ -10,7 +13,6 @@ 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.potion.Potion;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
@@ -18,14 +20,15 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import darkknight.jewelrycraft.config.ConfigHandler;
import darkknight.jewelrycraft.item.ItemList;
-import darkknight.jewelrycraft.item.ItemRing;
import darkknight.jewelrycraft.tileentity.TileEntityJewelrsCraftingTable;
public class BlockJewelrsCraftingTable extends BlockContainer
{
- Random rand = new Random();
- ItemStack modifiers[] = new ItemStack[] { new ItemStack(Item.blazePowder), new ItemStack(Item.diamond), new ItemStack(Item.sugar), new ItemStack(Item.slimeBall)};
- int effects[] = new int[] { Potion.fireResistance.id, Potion.digSpeed.id, Potion.moveSpeed.id, Potion.jump.id};
+ Random rand = new Random();
+
+ public static ArrayList<ItemStack> modifiers = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> jewel = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> jewelry = new ArrayList<ItemStack>();
protected BlockJewelrsCraftingTable(int par1, Material par2Material)
{
@@ -33,6 +36,24 @@ public class BlockJewelrsCraftingTable extends BlockContainer
this.setBlockBounds(0.0F, 0F, 0.0F, 1.0F, 0.8F, 1.0F);
}
+ public static void addStuff()
+ {
+ //Modifiers
+ modifiers.add(new ItemStack(Item.blazePowder));
+ modifiers.add(new ItemStack(Item.sugar));
+ modifiers.add(new ItemStack(Block.chest));
+ modifiers.add(new ItemStack(Item.pickaxeIron));
+
+ //Jewels
+ jewel.add(new ItemStack(Item.enderPearl));
+ jewel.add(new ItemStack(Item.diamond));
+ jewel.add(new ItemStack(Item.emerald));
+ jewel.add(new ItemStack(Block.obsidian));
+
+ //Jewelry
+ jewelry.add(new ItemStack(ItemList.ring));
+ }
+
@Override
public TileEntity createNewTileEntity(World world)
{
@@ -53,43 +74,74 @@ public class BlockJewelrsCraftingTable extends BlockContainer
if (te != null && !world.isRemote)
{
te.isDirty = true;
- if (!te.hasEndItem && !te.hasJewel && item != null && item.getItem().itemID == ItemList.ring.itemID)
+ if (!te.hasEndItem && !te.hasJewelry && item != null && isJewelry(item))
{
- te.jewel = item.copy();
- te.hasJewel = true;
- if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize;
- entityPlayer.inventory.onInventoryChanged();
+ if(te.hasModifier && te.hasJewel && item.hasTagCompound() && item.getTagCompound().hasKey("modifier") && item.getTagCompound().hasKey("jewel"))
+ entityPlayer.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.jewelrymodifiedfull"));
+ else if(te.hasJewel && item.hasTagCompound() && item.getTagCompound().hasKey("jewel"))
+ entityPlayer.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.jewelrycontainsjewel"));
+ else if(te.hasModifier && item.hasTagCompound() && item.getTagCompound().hasKey("modifier"))
+ entityPlayer.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.jewelrycontainsmodifier"));
+ else
+ {
+ te.jewelry = item.copy();
+ te.hasJewelry = true;
+ if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize;
+ entityPlayer.inventory.onInventoryChanged();
+ }
}
- if (!te.hasEndItem && !te.hasModifier && item != null)
+ if (!te.hasEndItem && !te.hasModifier && item != null && isModifier(item))
{
- int itemIndex = -1;
- for(int q=0; q < modifiers.length; q++)
- if (item.itemID == modifiers[q].itemID && item.getItemDamage() == modifiers[q].getItemDamage())
- itemIndex = q;
- if(itemIndex != -1)
+ if(te.hasJewelry && te.jewelry.hasTagCompound() && te.jewelry.getTagCompound().hasKey("modifier"))
+ entityPlayer.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.jewelrycontainsmodifier"));
+ else
{
te.modifier = item.copy();
te.modifier.stackSize = 1;
- te.effect = effects[itemIndex];
te.hasModifier = true;
if (!entityPlayer.capabilities.isCreativeMode) --item.stackSize;
entityPlayer.inventory.onInventoryChanged();
}
}
- if(te.timer == 0 && !te.hasEndItem && te.hasJewel && te.hasModifier) te.timer = ConfigHandler.jewelryCraftingTime;
- if(te.hasEndItem && item != null) entityPlayer.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.hasenditem"));
+ if (!te.hasEndItem && !te.hasJewel && item != null && isJewel(item))
+ {
+ if(te.hasJewelry && te.jewelry.hasTagCompound() && te.jewelry.getTagCompound().hasKey("jewel"))
+ entityPlayer.addChatMessage(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.onInventoryChanged();
+ }
+ }
+ 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(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());
+ dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.modifier.copy());
te.modifier = new ItemStack(0, 0, 0);
te.hasModifier = false;
+ te.timer = 0;
+ te.angle = 0F;
+ }
+ if (te.hasJewelry && entityPlayer.isSneaking())
+ {
+ dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewelry.copy());
+ te.jewelry = new ItemStack(0, 0, 0);
+ te.hasJewelry = false;
+ te.timer = 0;
+ te.angle = 0F;
}
if (te.hasJewel && entityPlayer.isSneaking())
{
- dropItem(world, (double)te.xCoord, (double)te.yCoord, (double)te.zCoord, te.jewel.copy());
+ dropItem(world, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.jewel.copy());
te.jewel = new ItemStack(0, 0, 0);
te.hasJewel = false;
+ te.timer = 0;
+ te.angle = 0F;
}
te.isDirty = true;
world.setBlockTileEntity(i, j, k, te);
@@ -97,6 +149,45 @@ public class BlockJewelrsCraftingTable extends BlockContainer
return true;
}
+ public boolean isModifier(ItemStack item)
+ {
+ Iterator<ItemStack> i = modifiers.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isJewel(ItemStack item)
+ {
+ Iterator<ItemStack> i = jewel.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isJewelry(ItemStack item)
+ {
+ Iterator<ItemStack> i = jewelry.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
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);
@@ -111,22 +202,14 @@ public class BlockJewelrsCraftingTable extends BlockContainer
TileEntityJewelrsCraftingTable te = (TileEntityJewelrsCraftingTable) world.getBlockTileEntity(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.hasJewel) dropItem(world, (double)te.xCoord, (double)te.yCoord, (double)te.zCoord, te.jewel.copy());
- if(te.hasEndItem) giveJewelToPlayer(te, te.endItem, te.modifier);
+ 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.worldObj, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.endItem.copy());
}
super.breakBlock(world, i, j, k, par5, par6);
}
- public void giveJewelToPlayer(TileEntityJewelrsCraftingTable cf, ItemStack item, ItemStack modifier)
- {
- if (item != null)
- {
- ItemRing.addEffect(item, cf.effect);
- dropItem(cf.worldObj, (double)cf.xCoord, (double)cf.yCoord, (double)cf.zCoord, item.copy());
- }
- }
-
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityLiving, ItemStack par6ItemStack)
{
@@ -142,18 +225,14 @@ public class BlockJewelrsCraftingTable extends BlockContainer
{
if (te.hasEndItem)
{
- giveJewelToPlayer(te, te.endItem, te.modifier);
+ dropItem(te.worldObj, (double) te.xCoord, (double) te.yCoord, (double) te.zCoord, te.endItem.copy());
te.endItem = new ItemStack(0, 0, 0);
te.hasEndItem = false;
}
- else if (te.hasJewel && te.hasModifier && te.timer > 0 && te.jewel != null)
- player.addChatMessage(StatCollector.translateToLocalFormatted("chatmessage.jewelrycraft.table.iscrafting", te.jewel.getDisplayName()) + " (" + ((ConfigHandler.jewelryCraftingTime - te.timer)*100/ConfigHandler.jewelryCraftingTime) + "%)");
- else if (!te.hasModifier && !te.hasJewel)
- player.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.missingjewelryandmodifier"));
- else if (!te.hasJewel)
- player.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.misingjewelry"));
- else if (!te.hasModifier)
- player.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.missingmodifier"));
+ else if (te.hasJewelry && (te.hasModifier || te.hasJewel) && te.timer > 0 && te.jewelry != null) player.addChatMessage(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(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.missingjewelryandmodifierorjewel"));
+ else if (!te.hasJewelry) player.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.missingjewelry"));
+ else if (!te.hasModifier || !te.hasJewel) player.addChatMessage(StatCollector.translateToLocal("chatmessage.jewelrycraft.table.missingmodifierorjewel"));
te.isDirty = true;
}
}