diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-02-06 21:44:28 +0200 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-02-06 21:44:28 +0200 |
| commit | 9075a22c3e303699db18062ebfc0159cace27c29 (patch) | |
| tree | aa772e1e70074134ce85056aa4b67d3f180fef4a /common | |
| parent | bd524a6dc2bdca6777659287bfcaa235b3362b44 (diff) | |
Weeee! New awesome block!
Diffstat (limited to 'common')
7 files changed, 190 insertions, 5 deletions
diff --git a/common/darkknight/jewelrycraft/block/BlockList.java b/common/darkknight/jewelrycraft/block/BlockList.java index 3a17d9a..66631aa 100644 --- a/common/darkknight/jewelrycraft/block/BlockList.java +++ b/common/darkknight/jewelrycraft/block/BlockList.java @@ -14,6 +14,7 @@ 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; @@ -26,6 +27,7 @@ public class BlockList if (!isInitialized) { shadowOre = new Block(ConfigHandler.idShadowOre, Material.rock).setHardness(3.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setTextureName("jewelrycraft:oreShadow").setUnlocalizedName("Jewelrycraft.oreShadow").setCreativeTab(JewelrycraftMod.jewelrycraft); + glow = new BlockShadow(ConfigHandler.idGlow).setUnlocalizedName("Jewelrycraft.glow").setLightValue(1F); smelter = new BlockSmelter(ConfigHandler.idSmelter, Material.rock).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("Jewelrycraft.smelter").setCreativeTab(JewelrycraftMod.jewelrycraft); molder = new BlockMolder(ConfigHandler.idMolder, Material.rock).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("Jewelrycraft.molder").setCreativeTab(JewelrycraftMod.jewelrycraft); displayer = new BlockDisplayer(ConfigHandler.idDisplayer, Material.iron).setHardness(5.0F).setResistance(6.0F).setStepSound(Block.soundMetalFootstep).setUnlocalizedName("Jewelrycraft.displayer").setCreativeTab(JewelrycraftMod.jewelrycraft); diff --git a/common/darkknight/jewelrycraft/block/BlockShadow.java b/common/darkknight/jewelrycraft/block/BlockShadow.java new file mode 100644 index 0000000..ea811ee --- /dev/null +++ b/common/darkknight/jewelrycraft/block/BlockShadow.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 BlockShadow extends Block +{ + protected BlockShadow(int par1) + { + super(par1, 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/common/darkknight/jewelrycraft/config/ConfigHandler.java b/common/darkknight/jewelrycraft/config/ConfigHandler.java index d23d358..cba8759 100644 --- a/common/darkknight/jewelrycraft/config/ConfigHandler.java +++ b/common/darkknight/jewelrycraft/config/ConfigHandler.java @@ -17,6 +17,7 @@ public class ConfigHandler public static int idDisplayer = 1752; public static int idJewelCraftingTable = 1753; public static int idMolder = 1754; + public static int idGlow = 1755; public static int ingotCoolingTime = 200; public static int ingotMeltingTime = 1500; @@ -43,6 +44,7 @@ public class ConfigHandler idMolder = config.getBlock("Molder", idMolder).getInt(); idDisplayer = config.getBlock("Displayer", idDisplayer).getInt(); idJewelCraftingTable = config.getBlock("Jeweler's Crafting Table", idJewelCraftingTable).getInt(); + idGlow = config.getBlock("Glow", idGlow).getInt(); ingotCoolingTime = config.get("timers", "Molder Ingot Cooling Time", ingotCoolingTime).getInt(); ingotMeltingTime = config.get("timers", "Ingot Melting Time", ingotMeltingTime).getInt(); diff --git a/common/darkknight/jewelrycraft/item/ItemRing.java b/common/darkknight/jewelrycraft/item/ItemRing.java index c420809..730af20 100644 --- a/common/darkknight/jewelrycraft/item/ItemRing.java +++ b/common/darkknight/jewelrycraft/item/ItemRing.java @@ -2,7 +2,10 @@ 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; @@ -10,12 +13,15 @@ import cpw.mods.fml.common.network.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; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.resources.ResourceManager; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -36,7 +42,7 @@ import net.minecraft.world.World; public class ItemRing extends Item { public Icon jewel; - private int amplifier; + private int amplifier, cooldown = 0; int index = 0; public ItemRing(int par1) @@ -147,7 +153,7 @@ public class ItemRing extends Item } else if(JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.bed)) && JewelryNBT.dimension(stack) == -2 && JewelryNBT.playerPosX(stack) == -1 && JewelryNBT.playerPosY(stack) == -1 && JewelryNBT.playerPosZ(stack) == -1){ JewelryNBT.addCoordonatesAndDimension(stack, player.posX, player.posY, player.posZ, world.provider.dimensionId, world.provider.getDimensionName()); - JewelryNBT.addEnchantment(stack); + JewelryNBT.addFakeEnchantment(stack); } else if (JewelryNBT.isJewelX(stack, new ItemStack(Block.obsidian)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.eyeOfEnder))) { @@ -168,7 +174,16 @@ public class ItemRing extends Item } else if (JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.playerPosX(stack) == -1 && JewelryNBT.playerPosY(stack) == -1 && JewelryNBT.playerPosZ(stack) == -1){ JewelryNBT.addCoordonatesAndDimension(stack, player.posX, player.posY, player.posZ, world.provider.dimensionId, world.provider.getDimensionName()); - JewelryNBT.addEnchantment(stack); + JewelryNBT.addFakeEnchantment(stack); + } + else if(player.inventory.getCurrentItem() != null && JewelryNBT.isJewelX(stack, new ItemStack(Item.netherStar)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.book))) + { + String mode = ""; + if(JewelryNBT.isModeX(stack, "Disenchant")) mode = "Transfer"; + else if(JewelryNBT.isModeX(stack, "Transfer")) mode = "Enchant"; + else if(JewelryNBT.isModeX(stack, "Enchant")) mode = "Disenchant"; + player.addChatMessage("Switched to " + mode + " mode"); + JewelryNBT.addMode(stack, mode); } } return stack; @@ -181,7 +196,7 @@ public class ItemRing extends Item JewelryNBT.addEntity(stack, entity); JewelryNBT.addEntityID(stack, entity); entity.setDead(); - JewelryNBT.addEnchantment(stack); + JewelryNBT.addFakeEnchantment(stack); } return true; } @@ -217,6 +232,9 @@ public class ItemRing extends Item EntityLivingBase entity = JewelryNBT.entity(stack, player); if (entity != null) list.add("Entity: " + EnumChatFormatting.GOLD + entity.getEntityName()); + + String modeN = JewelryNBT.modeName(stack); + if(modeN != null) list.add("Mode: " + modeN); } } @@ -236,10 +254,25 @@ public class ItemRing extends Item return true; } + public boolean canDisenchant(EntityPlayer player) + { + if(player.capabilities.isCreativeMode) return true; + else if(player.experienceLevel >= 2) return true; + return false; + } + + public void dynamicLight(World world, EntityPlayer player) + { + world.setBlock((int)player.prevPosX, (int)player.prevPosY, (int)player.prevPosZ, 0); + world.setBlock((int)player.posX, (int)player.posY, (int)player.posZ, BlockList.glow.blockID); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { amplifier = 0; + if(cooldown > 0) cooldown--; if (!world.isRemote){ EntityPlayer entityplayer = (EntityPlayer) entity; if (JewelryNBT.isJewelX(stack, new ItemStack(Item.diamond))) amplifier = 1; @@ -256,6 +289,80 @@ public class ItemRing extends Item } else if (JewelryNBT.isModifierX(stack, new ItemStack(Item.potion, 1, 8270)) && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(Potion.invisibility.id, 4, amplifier, true)); + if(entityplayer.inventory.getCurrentItem() != null && JewelryNBT.isJewelX(stack, new ItemStack(Item.netherStar)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.book)) && entityplayer.inventory.getCurrentItem().equals(stack)) + { + ItemStack item = null; + if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1) != null && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1).isItemEnchanted()) item = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1); + if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1) != null && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1).isItemEnchanted()) item = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1); + if(item != null && JewelryNBT.isModeX(stack, "Disenchant")) + { + ItemStack enchBook = new ItemStack(Item.enchantedBook); + Map enchItem = EnchantmentHelper.getEnchantments(item); + Map book = EnchantmentHelper.getEnchantments(enchBook); + Iterator iterator = enchItem.keySet().iterator(); + int e; + + if (iterator.hasNext() && canDisenchant(entityplayer)) + { + e = ((Integer)iterator.next()).intValue(); + book.put(Integer.valueOf(e), Integer.valueOf(((Integer)enchItem.get(Integer.valueOf(e))).intValue())); + EnchantmentHelper.setEnchantments(book, enchBook); + if(entityplayer.inventory.addItemStackToInventory(enchBook)) + { + if(!entityplayer.capabilities.isCreativeMode) + { + entityplayer.addExperienceLevel(-2); + entityplayer.heal(-1f); + } + enchItem.remove(Integer.valueOf(e)); + if(item.isItemStackDamageable() && (item.getMaxDamage() - item.getItemDamage())/3 > 0) item.damageItem((item.getMaxDamage() - item.getItemDamage())/3, entityplayer); + EnchantmentHelper.setEnchantments(enchItem, item); + } + } + } + if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1) != null && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1) != null && JewelryNBT.isModeX(stack, "Transfer")) + { + if(cooldown > 0) entityplayer.addChatMessage("Ring is currently cooling down (" + cooldown + ")"); + ItemStack enchantedItem = null, enchantableItem = null; + if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1).isItemEnchanted() && entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1) != null) + { + enchantedItem = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1); + enchantableItem = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1); + + } + if(enchantedItem != null && enchantableItem != null) + { + Map enchItem = EnchantmentHelper.getEnchantments(enchantedItem); + Map resultItem = EnchantmentHelper.getEnchantments(enchantableItem); + Iterator iterator = enchItem.keySet().iterator(); + int e; + + if (iterator.hasNext() && cooldown == 0) + { + e = ((Integer)iterator.next()).intValue(); + if(!EnchantmentHelper.getEnchantments(enchantableItem).containsKey(Integer.valueOf(e))) + { + resultItem.put(Integer.valueOf(e), Integer.valueOf(((Integer)enchItem.get(Integer.valueOf(e))).intValue())); + EnchantmentHelper.setEnchantments(resultItem, enchantableItem); + enchItem.remove(Integer.valueOf(e)); + EnchantmentHelper.setEnchantments(enchItem, enchantedItem); + cooldown = 1000; + } + } + } + } + if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1) != null) item = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem + 1); + else if(entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1) != null) item = entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem - 1); + if(item != null && !item.isItemEnchanted() && item.isItemEnchantable() && entityplayer.experienceLevel > 0 && JewelryNBT.isModeX(stack, "Enchant")) + { + Map enchItem = EnchantmentHelper.getEnchantments(item); + int level = entityplayer.experienceLevel; + if(entityplayer.experienceLevel > 6) level = 6; + if(!entityplayer.capabilities.isCreativeMode) entityplayer.addExperienceLevel(-level); + enchItem.put(Enchantment.enchantmentsBookList[new Random().nextInt(Enchantment.enchantmentsBookList.length)].effectId, level); + EnchantmentHelper.setEnchantments(enchItem, item); + } + } } } } diff --git a/common/darkknight/jewelrycraft/tileentity/TileEntityJewelrsCraftingTable.java b/common/darkknight/jewelrycraft/tileentity/TileEntityJewelrsCraftingTable.java index 35457df..935d87b 100644 --- a/common/darkknight/jewelrycraft/tileentity/TileEntityJewelrsCraftingTable.java +++ b/common/darkknight/jewelrycraft/tileentity/TileEntityJewelrsCraftingTable.java @@ -2,6 +2,7 @@ package darkknight.jewelrycraft.tileentity; import darkknight.jewelrycraft.config.ConfigHandler; import darkknight.jewelrycraft.util.JewelryNBT; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; @@ -110,6 +111,7 @@ public class TileEntityJewelrsCraftingTable extends TileEntity this.endItem = jewelry.copy(); if (hasModifier && modifier != new ItemStack(0, 0, 0)) JewelryNBT.addModifier(endItem, modifier); if (hasJewel && jewel != new ItemStack(0, 0, 0)) JewelryNBT.addJewel(endItem, jewel); + if (hasJewel && hasModifier && JewelryNBT.isJewelX(endItem, new ItemStack(Item.netherStar)) && JewelryNBT.isModifierX(endItem, new ItemStack(Item.book))) JewelryNBT.addMode(endItem, "Disenchant"); this.hasJewelry = false; this.jewelry = new ItemStack(0, 0, 0); this.hasModifier = false; diff --git a/common/darkknight/jewelrycraft/util/JewelryNBT.java b/common/darkknight/jewelrycraft/util/JewelryNBT.java index be2f959..aa11e8d 100644 --- a/common/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/common/darkknight/jewelrycraft/util/JewelryNBT.java @@ -146,6 +146,21 @@ public class JewelryNBT itemStackData.setTag("dimension", coords); itemStackData.setTag("dimName", coords); } + + public static void addMode(ItemStack item, String modeN) + { + NBTTagCompound itemStackData; + if (item.hasTagCompound()) + itemStackData = item.getTagCompound(); + else + { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + NBTTagCompound mode = new NBTTagCompound(); + mode.setString("mode", modeN); + itemStackData.setTag("mode", mode); + } public static void removeNBT(ItemStack item, String tag) { @@ -167,7 +182,7 @@ public class JewelryNBT JewelryNBT.removeNBT(item, "ench"); } - public static void addEnchantment(ItemStack item) + public static void addFakeEnchantment(ItemStack item) { NBTTagCompound itemStackData; if (item.hasTagCompound()) @@ -234,6 +249,12 @@ public class JewelryNBT return false; } + public static boolean isModeX(ItemStack stack, String modeN) + { + if(modeName(stack) != null && modeName(stack).equals(modeN)) return true; + return false; + } + public static EntityLivingBase entity(ItemStack stack, EntityPlayer player) { if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity")) @@ -266,6 +287,17 @@ public class JewelryNBT return null; } + public static String modeName(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("mode")) + { + NBTTagCompound dim = (NBTTagCompound) stack.getTagCompound().getTag("mode"); + String name = dim.getString("mode"); + return name; + } + return null; + } + public static boolean isDimNameX(ItemStack stack, String dimName) { if(ingot(stack) != null && dimName(stack).equals(dimName)) return true; diff --git a/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java index ff3fe51..c2c456e 100644 --- a/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -23,6 +23,7 @@ public class JewelrycraftUtil { //Modifiers modifiers.add(new ItemStack(Block.chest)); + modifiers.add(new ItemStack(Item.book)); modifiers.add(new ItemStack(Item.sugar)); modifiers.add(new ItemStack(Item.feather)); modifiers.add(new ItemStack(Item.bed)); |
