Added a right-click helper function

This commit is contained in:
jss2a98aj committed 2023-02-27 15:41:51 -05:00
1 parent eadf3f76fc
commit 346feedbcb
2 files changed
+45 -6

No files matched your search

@@ -1,9 +1,14 @@
package baubles.api.expanded;
import baubles.api.BaublesApi;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import java.util.List;
@@ -17,7 +22,7 @@ public class BaubleItemHelper {
* @return If shift was held.
*/
@SideOnly(Side.CLIENT)
public static boolean addSlotInformation(List tooltip, String[] types) {
public static boolean addSlotInformation(List<String> tooltip, String[] types) {
boolean shiftHeld = GuiScreen.isShiftKeyDown();
if(shiftHeld) {
tooltip.add(StatCollector.translateToLocal("tooltip.compatibleslots"));
@@ -32,4 +37,35 @@ public class BaubleItemHelper {
return shiftHeld;
}
/**
* Equips a bauble in an appropriate slot when right-clicked.
*
* @param itemStackIn The item stack being right-clicked with.
* @param worldIn The world instance.
* @param player The player that right-clicked.
* @return The item stack.
*/
public static ItemStack onBaubleRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player) {
IInventory baubles = BaublesApi.getBaubles(player);
if(baubles == null) {
return itemStackIn;
}
for(int slotIndex = 0; slotIndex < baubles.getSizeInventory(); slotIndex++) {
if(baubles.getStackInSlot(slotIndex) == null && baubles.isItemValidForSlot(slotIndex, itemStackIn)) {
if(!worldIn.isRemote) {
baubles.setInventorySlotContents(slotIndex, itemStackIn.copy());
if(!player.capabilities.isCreativeMode) {
itemStackIn.stackSize--;
//Work around the event being fired twice in single player before the return stack is set.
player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStackIn);
}
((IBaubleExpanded)itemStackIn.getItem()).onEquipped(itemStackIn, player);
return itemStackIn;
}
}
}
return itemStackIn;
}
}
@@ -15,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class ItemDebugger extends Item implements IBaubleExpanded {
@@ -43,6 +44,7 @@ public class ItemDebugger extends Item implements IBaubleExpanded {
return icons[meta >= icons.length ? 0 : meta];
}
@SuppressWarnings({"unchecked", "rawtypes"})
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
@@ -51,6 +53,11 @@ public class ItemDebugger extends Item implements IBaubleExpanded {
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer player) {
return BaubleItemHelper.onBaubleRightClick(itemStackIn, worldIn, player);
}
@Override
public String[] getBaubleTypes(ItemStack itemStack) {
String type;
@@ -68,6 +75,7 @@ public class ItemDebugger extends Item implements IBaubleExpanded {
return null;
}
@SuppressWarnings({"unchecked", "rawtypes"})
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean debug) {
@@ -83,11 +91,6 @@ public class ItemDebugger extends Item implements IBaubleExpanded {
return true;
}
/*@Override
public String getUnlocalizedName(ItemStack itemStack) {
return super.getUnlocalizedName() + "." + itemStack.getItemDamage();
}*/
@Override
public void onEquipped(ItemStack itemStack, EntityLivingBase player) {
}