From 3efdf93073c2fad585b5cd278b6a6281271da0a2 Mon Sep 17 00:00:00 2001 From: nekosune Date: Wed, 30 Apr 2014 16:26:35 +0100 Subject: [PATCH] Changed some items into baubles --- src/api/java/baubles/api/BaubleType.java | 7 + src/api/java/baubles/api/BaublesApi.java | 34 +++++ src/api/java/baubles/api/IBauble.java | 46 ++++++ .../common/item/kami/ItemBlockTalisman.java | 142 +++++++++++------- .../common/item/kami/ItemCatAmulet.java | 77 +++++++--- .../common/item/kami/ItemIchorPouch.java | 34 ++++- .../common/item/kami/armor/ItemGemHelm.java | 4 +- .../assets/ttinkerer/lang/en_US.lang | 10 +- 8 files changed, 266 insertions(+), 88 deletions(-) create mode 100644 src/api/java/baubles/api/BaubleType.java create mode 100644 src/api/java/baubles/api/BaublesApi.java create mode 100644 src/api/java/baubles/api/IBauble.java diff --git a/src/api/java/baubles/api/BaubleType.java b/src/api/java/baubles/api/BaubleType.java new file mode 100644 index 00000000..22349ff7 --- /dev/null +++ b/src/api/java/baubles/api/BaubleType.java @@ -0,0 +1,7 @@ +package baubles.api; + +public enum BaubleType { + RING, + AMULET, + BELT +} diff --git a/src/api/java/baubles/api/BaublesApi.java b/src/api/java/baubles/api/BaublesApi.java new file mode 100644 index 00000000..ca94fcd5 --- /dev/null +++ b/src/api/java/baubles/api/BaublesApi.java @@ -0,0 +1,34 @@ +package baubles.api; + +import java.lang.reflect.Method; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import cpw.mods.fml.common.FMLLog; + + + +/** + * @author Azanor + */ +public class BaublesApi { + + static Method getBaubles; + /** + * Retrieves the baubles inventory for the supplied player + */ + public static IInventory getBaubles(EntityPlayer player) { + IInventory ot = null; + try { + if(getBaubles == null) { + Class fake = Class.forName("baubles.common.lib.PlayerHandler"); + getBaubles = fake.getMethod("getPlayerBaubles", EntityPlayer.class); + } + ot = (IInventory) getBaubles.invoke(null, player); + } catch(Exception ex) { + FMLLog.warning("[Baubles API] Could not invoke baubles.common.lib.PlayerHandler method getPlayerBaubles"); + } + return ot; + } + +} diff --git a/src/api/java/baubles/api/IBauble.java b/src/api/java/baubles/api/IBauble.java new file mode 100644 index 00000000..de85ff10 --- /dev/null +++ b/src/api/java/baubles/api/IBauble.java @@ -0,0 +1,46 @@ +package baubles.api; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * + * @author Azanor + * + * This interface should be extended by items that can be worn in bauble slots + * + */ + +public interface IBauble { + + /** + * This method return the type of bauble this is. + * Type is used to determine the slots it can go into. + */ + public BaubleType getBaubleType(ItemStack itemstack); + + /** + * This method is called once per tick if the bauble is being worn by a player + */ + public void onWornTick(ItemStack itemstack, EntityLivingBase player); + + /** + * This method is called when the bauble is equipped by a player + */ + public void onEquipped(ItemStack itemstack, EntityLivingBase player); + + /** + * This method is called when the bauble is unequipped by a player + */ + public void onUnequipped(ItemStack itemstack, EntityLivingBase player); + + /** + * can this bauble be placed in a bauble slot + */ + public boolean canEquip(ItemStack itemstack, EntityLivingBase player); + + /** + * Can this bauble be removed from a bauble slot + */ + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player); +} diff --git a/src/main/java/vazkii/tinkerer/common/item/kami/ItemBlockTalisman.java b/src/main/java/vazkii/tinkerer/common/item/kami/ItemBlockTalisman.java index 37974948..7325bbfb 100644 --- a/src/main/java/vazkii/tinkerer/common/item/kami/ItemBlockTalisman.java +++ b/src/main/java/vazkii/tinkerer/common/item/kami/ItemBlockTalisman.java @@ -14,11 +14,13 @@ */ package vazkii.tinkerer.common.item.kami; +import baubles.api.BaubleType; +import baubles.api.IBauble; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; @@ -39,7 +41,7 @@ import vazkii.tinkerer.common.item.ItemMod; import java.util.Arrays; import java.util.List; -public class ItemBlockTalisman extends ItemMod { +public class ItemBlockTalisman extends ItemMod implements IBauble{ @Deprecated private static final String TAG_BLOCK_ID = "blockID"; private static final String TAG_BLOCK_NAME = "blockName"; @@ -115,62 +117,6 @@ public class ItemBlockTalisman extends ItemMod { return set; } - @Override - public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) { - Block block=getBlock(par1ItemStack); - if(!par2World.isRemote && par1ItemStack.getItemDamage() == 1 && block!=Blocks.air && par3Entity instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer) par3Entity; - int meta = getBlockMeta(par1ItemStack); - - int highest = -1; - boolean hasFreeSlot = false; - int[] counts = new int[player.inventory.getSizeInventory() - player.inventory.armorInventory.length]; - Arrays.fill(counts, 0); - - for(int i = 0; i < counts.length; i++) { - ItemStack stack = player.inventory.getStackInSlot(i); - if(stack == null) { - hasFreeSlot = true; - continue; - } - - if(Item.getItemFromBlock(block) == stack.getItem() && stack.getItemDamage() == meta) { - counts[i] = stack.stackSize; - if(highest == -1) - highest = i; - else highest = counts[i] > counts[highest] && highest > 8 ? i : highest; - } - } - - if(highest == -1) { - ItemStack heldItem = player.inventory.getItemStack(); - if(hasFreeSlot && (heldItem == null || Item.getItemFromBlock(block) == heldItem.getItem() || heldItem.getItemDamage() != meta)) { - ItemStack stack = new ItemStack(block, remove(par1ItemStack, 64), meta); - if(stack.stackSize != 0) - player.inventory.addItemStackToInventory(stack); - } - } else { - for(int i = 0; i < counts.length; i++) { - int count = counts[i]; - - if(i == highest || count == 0) - continue; - - add(par1ItemStack, count); - player.inventory.setInventorySlotContents(i, null); - } - - int countInHighest = counts[highest]; - int maxSize = new ItemStack(block, 1, meta).getMaxStackSize(); - if(countInHighest < maxSize) { - int missing = maxSize - countInHighest; - ItemStack stackInHighest = player.inventory.getStackInSlot(highest); - stackInHighest.stackSize += remove(par1ItemStack, missing); - } - } - } - } - private boolean setBlock(ItemStack stack, Block block, int meta) { if(getBlock(stack) == Blocks.air || getBlockCount(stack) == 0) { ItemNBTHelper.setString(stack, TAG_BLOCK_NAME,Block.blockRegistry.getNameForObject(block)); @@ -253,4 +199,84 @@ public class ItemBlockTalisman extends ItemMod { return TTClientProxy.kamiRarity; } + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.RING; + } + + @Override + public void onWornTick(ItemStack itemstack, EntityLivingBase entity) { + Block block=getBlock(itemstack); + if(!entity.worldObj.isRemote && itemstack.getItemDamage() == 1 && block!=Blocks.air && entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) entity; + int meta = getBlockMeta(itemstack); + + int highest = -1; + boolean hasFreeSlot = false; + int[] counts = new int[player.inventory.getSizeInventory() - player.inventory.armorInventory.length]; + Arrays.fill(counts, 0); + + for(int i = 0; i < counts.length; i++) { + ItemStack stack = player.inventory.getStackInSlot(i); + if(stack == null) { + hasFreeSlot = true; + continue; + } + + if(Item.getItemFromBlock(block) == stack.getItem() && stack.getItemDamage() == meta) { + counts[i] = stack.stackSize; + if(highest == -1) + highest = i; + else highest = counts[i] > counts[highest] && highest > 8 ? i : highest; + } + } + + if(highest == -1) { + ItemStack heldItem = player.inventory.getItemStack(); + if(hasFreeSlot && (heldItem == null || Item.getItemFromBlock(block) == heldItem.getItem() || heldItem.getItemDamage() != meta)) { + ItemStack stack = new ItemStack(block, remove(itemstack, 64), meta); + if(stack.stackSize != 0) + player.inventory.addItemStackToInventory(stack); + } + } else { + for(int i = 0; i < counts.length; i++) { + int count = counts[i]; + + if(i == highest || count == 0) + continue; + + add(itemstack, count); + player.inventory.setInventorySlotContents(i, null); + } + + int countInHighest = counts[highest]; + int maxSize = new ItemStack(block, 1, meta).getMaxStackSize(); + if(countInHighest < maxSize) { + int missing = maxSize - countInHighest; + ItemStack stackInHighest = player.inventory.getStackInSlot(highest); + stackInHighest.stackSize += remove(itemstack, missing); + } + } + } + } + + @Override + public void onEquipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public void onUnequipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } } diff --git a/src/main/java/vazkii/tinkerer/common/item/kami/ItemCatAmulet.java b/src/main/java/vazkii/tinkerer/common/item/kami/ItemCatAmulet.java index b97fee28..edc3b26c 100644 --- a/src/main/java/vazkii/tinkerer/common/item/kami/ItemCatAmulet.java +++ b/src/main/java/vazkii/tinkerer/common/item/kami/ItemCatAmulet.java @@ -14,8 +14,11 @@ */ package vazkii.tinkerer.common.item.kami; +import baubles.api.BaubleType; +import baubles.api.IBauble; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.ai.EntityAIAvoidEntity; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAITasks; @@ -33,7 +36,7 @@ import vazkii.tinkerer.common.item.ItemMod; import java.util.ArrayList; import java.util.List; -public class ItemCatAmulet extends ItemMod { +public class ItemCatAmulet extends ItemMod implements IBauble { public ItemCatAmulet() { super(); @@ -42,28 +45,7 @@ public class ItemCatAmulet extends ItemMod { @Override public void onUpdate(ItemStack par1ItemStack, World par2World, Entity e, int par4, boolean par5) { - int range = 10; - int rangeY = 4; - List entities = par2World.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(e.posX - range, e.posY - rangeY, e.posZ - range, e.posX + range, e.posY + rangeY, e.posZ + range)); - for(EntityLiving entity : entities) { - List entries = new ArrayList(entity.tasks.taskEntries); - entries.addAll(new ArrayList(entity.targetTasks.taskEntries)); - - boolean avoidsOcelots = false; - for(EntityAITasks.EntityAITaskEntry entry : entries) { - if(entry.action instanceof EntityAIAvoidEntity) - avoidsOcelots = messWithRunAwayAI((EntityAIAvoidEntity) entry.action) || avoidsOcelots; - - if(entry.action instanceof EntityAINearestAttackableTarget) - messWithGetTargetAI((EntityAINearestAttackableTarget) entry.action); - } - - if(entity instanceof EntityCreeper) { - ((EntityCreeper)entity).timeSinceIgnited=2; - entity.setAttackTarget(null); - } - } } @Override @@ -83,4 +65,55 @@ public class ItemCatAmulet extends ItemMod { if( aiEntry.targetClass== EntityPlayer.class) aiEntry.targetClass=EntityEnderCrystal.class; // Something random that won't be around } + + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.AMULET; + } + + @Override + public void onWornTick(ItemStack itemstack, EntityLivingBase player) { + int range = 10; + int rangeY = 4; + List entities = player.worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(player.posX - range, player.posY - rangeY, player.posZ - range, player.posX + range, player.posY + rangeY, player.posZ + range)); + + for(EntityLiving entity : entities) { + List entries = new ArrayList(entity.tasks.taskEntries); + entries.addAll(new ArrayList(entity.targetTasks.taskEntries)); + + boolean avoidsOcelots = false; + for(EntityAITasks.EntityAITaskEntry entry : entries) { + if(entry.action instanceof EntityAIAvoidEntity) + avoidsOcelots = messWithRunAwayAI((EntityAIAvoidEntity) entry.action) || avoidsOcelots; + + if(entry.action instanceof EntityAINearestAttackableTarget) + messWithGetTargetAI((EntityAINearestAttackableTarget) entry.action); + } + + if(entity instanceof EntityCreeper) { + ((EntityCreeper)entity).timeSinceIgnited=2; + entity.setAttackTarget(null); + } + } + } + + @Override + public void onEquipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public void onUnequipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } } diff --git a/src/main/java/vazkii/tinkerer/common/item/kami/ItemIchorPouch.java b/src/main/java/vazkii/tinkerer/common/item/kami/ItemIchorPouch.java index 9959eac2..71005697 100644 --- a/src/main/java/vazkii/tinkerer/common/item/kami/ItemIchorPouch.java +++ b/src/main/java/vazkii/tinkerer/common/item/kami/ItemIchorPouch.java @@ -14,9 +14,12 @@ */ package vazkii.tinkerer.common.item.kami; +import baubles.api.BaubleType; +import baubles.api.IBauble; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; @@ -32,7 +35,7 @@ import vazkii.tinkerer.common.ThaumicTinkerer; import vazkii.tinkerer.common.core.handler.ModCreativeTab; import vazkii.tinkerer.common.lib.LibGuiIDs; -public class ItemIchorPouch extends ItemFocusPouch { +public class ItemIchorPouch extends ItemFocusPouch implements IBauble { public ItemIchorPouch() { super(); @@ -77,4 +80,33 @@ public class ItemIchorPouch extends ItemFocusPouch { return stackList; } + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.BELT; + } + + @Override + public void onWornTick(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public void onEquipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public void onUnequipped(ItemStack itemstack, EntityLivingBase player) { + + } + + @Override + public boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + @Override + public boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } } diff --git a/src/main/java/vazkii/tinkerer/common/item/kami/armor/ItemGemHelm.java b/src/main/java/vazkii/tinkerer/common/item/kami/armor/ItemGemHelm.java index 6fa9786b..4f71f1b7 100644 --- a/src/main/java/vazkii/tinkerer/common/item/kami/armor/ItemGemHelm.java +++ b/src/main/java/vazkii/tinkerer/common/item/kami/armor/ItemGemHelm.java @@ -54,7 +54,7 @@ public class ItemGemHelm extends ItemIchorclothArmorAdv implements IGoggles, IRe if(effect != null && effect.duration <= 202) effect.duration=202; - else player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 202, 0)); + else player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 202, 0,true)); } if(player.isInsideOfMaterial(Material.lava) && ThaumicTinkerer.proxy.armorStatus(player) && armor.getItemDamage()==0) { player.setAir(300); @@ -62,7 +62,7 @@ public class ItemGemHelm extends ItemIchorclothArmorAdv implements IGoggles, IRe if(effect != null && effect.duration <= 202) effect.duration=202; - else player.addPotionEffect(new PotionEffect(Potion.blindness.id, 202, 0)); + else player.addPotionEffect(new PotionEffect(Potion.blindness.id, 202, 0,true)); } int food = player.getFoodStats().getFoodLevel(); if(food > 0 && food < 18 && player.shouldHeal() && player.ticksExisted % 80 == 0) diff --git a/src/main/resources/assets/ttinkerer/lang/en_US.lang b/src/main/resources/assets/ttinkerer/lang/en_US.lang index eed80430..993be37c 100644 --- a/src/main/resources/assets/ttinkerer/lang/en_US.lang +++ b/src/main/resources/assets/ttinkerer/lang/en_US.lang @@ -127,7 +127,7 @@ item.ttinkerer:ichorShovelGem.name=Awakened Ichorium Shovel item.ttinkerer:ichorAxeGem.name=Awakened Ichorium Axe item.ttinkerer:ichorSwordGem.name=Awakened Ichorium Sword item.ttinkerer:ichorPouch.name=Bottomless Pouch -item.ttinkerer:blockTalisman.name=Black Hole Talisman +item.ttinkerer:blockTalisman.name=Black Hole Ring item.ttinkerer:placementMirror.name=Worldshaper's Looking Glass item.ttinkerer:focusShadowbeam.name=Wand Focus: Shadowbeam item.ttinkerer:focusXPDrain.name=Wand Focus: Experience Drain @@ -528,15 +528,15 @@ ttresearch.name.ICHOR_POUCH=Bottomless Pouch ttresearch.lore.ICHOR_POUCH=Haha, he said bottom ttresearch.page.ICHOR_POUCH.0=By infusing a Focus Pouch with items such as the Portable Hole focus, you managed to allow it to not only store more than Foci, but also to have a very extensive storage space.

This pouch can not only carry more than four chests, but it also doubles as a standard Focus Pouch, allowing any foci within it to be inserted in a wand like normally. You can kiss your inventory problems goodbye. -# -- BLACK HOLE TALISMAN -ttresearch.name.BLOCK_TALISMAN=Black Hole Talisman +# -- BLACK HOLE RING +ttresearch.name.BLOCK_TALISMAN=Black Hole Ring ttresearch.lore.BLOCK_TALISMAN=More pascal than your mind can take -ttresearch.page.BLOCK_TALISMAN.0=This talisman can be set to condense any block, by right clicking with it in world in the type of block you want to have it be set to, when enabled via right click will absorb any excess (over 1 stack) of that block in your inventory, and make sure at least one stack stays there. The contents can be stored in any inventory by right clicking it, or placed in world as if they were normal blocks.

It can store over 2 billion of the same block. Guess cobblestone clogging the space isn't an issue. If the talisman is empty, it can be shift right clicked into another block to change its binding. +ttresearch.page.BLOCK_TALISMAN.0=This ring can be set to condense any block, by right clicking with it in world in the type of block you want to have it be set to, when enabled via right click will absorb any excess (over 1 stack) of that block in your inventory, and make sure at least one stack stays there. The contents can be stored in any inventory by right clicking it, or placed in world as if they were normal blocks.

It can store over 2 billion of the same block. Guess cobblestone clogging the space isn't an issue. If the ring is empty, it can be shift right clicked into another block to change its binding. # -- WORLDSHAPER'S LOOKING GLASS ttresearch.name.PLACEMENT_MIRROR=Worldshaper's Looking Glass ttresearch.lore.PLACEMENT_MIRROR=Eye of Mercury -ttresearch.page.PLACEMENT_MIRROR.0=Through studying the world, you constructed a glass that allows you place a large array of blocks in the world using the power of your mind.

To set a block to place, one would shift-right click this glass in that block. Shift-right clicking the item in the air changes the amount of blocks it'll place.

When placing blocks in the world, a phantom visualization of how the blocks will appear is shown. On right click, the blocks will be consumed and placed, either from the inventory, or any Black Hole Talismans that contain the required block. +ttresearch.page.PLACEMENT_MIRROR.0=Through studying the world, you constructed a glass that allows you place a large array of blocks in the world using the power of your mind.

To set a block to place, one would shift-right click this glass in that block. Shift-right clicking the item in the air changes the amount of blocks it'll place.

When placing blocks in the world, a phantom visualization of how the blocks will appear is shown. On right click, the blocks will be consumed and placed, either from the inventory, or any Black Hole Rings that contain the required block. # -- WAND FOCUS: SHADOWBEAM ttresearch.name.FOCUS_SHADOWBEAM=Wand Focus: Shadowbeam