Fixing InventoryBeeRing and adding some minor functionality to ItemBeeRing

This commit is contained in:
rjnasers committed 2023-04-23 20:39:53 -05:00
1 parent c17c2f3746
commit e5cea4e3dd
5 files changed
+171 -81

No files matched your search

@@ -1,18 +1,17 @@
package magicbees.client.gui;
import cpw.mods.fml.common.registry.GameRegistry;
import magicbees.main.utils.LogHelper;
import magicbees.itemInventories.InventoryBeeRing;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerEffectRing extends Container {
IInventory IBR;
InventoryBeeRing IBR;
public ContainerEffectRing(IInventory IBR, EntityPlayer player) {
public ContainerEffectRing(InventoryBeeRing IBR, EntityPlayer player) {
this.IBR = IBR;
this.addSlotToContainer(
new SlotCustomItems(this.IBR, 0, 80, 22, GameRegistry.findItemStack("Forestry", "beeDroneGE", 1)));
@@ -1,6 +1,7 @@
package magicbees.client.gui;
import magicbees.item.ItemBeeRing;
import magicbees.itemInventories.InventoryBeeRing;
import magicbees.main.CommonProxy;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
@@ -21,7 +22,7 @@ public class GUIEffectRing extends GuiContainer {
private static final int HEIGHT = 156;
public GUIEffectRing(ItemStack itemStack, EntityPlayer player) {
super(new ContainerEffectRing(ItemBeeRing.getInventory(player, itemStack), player));
super(new ContainerEffectRing((InventoryBeeRing) ItemBeeRing.getInventory(player, itemStack), player));
this.xSize = WIDTH;
this.ySize = HEIGHT;
}
@@ -1,6 +1,7 @@
package magicbees.client.gui;
import magicbees.item.ItemBeeRing;
import magicbees.itemInventories.InventoryBeeRing;
import magicbees.tileentity.TileEntityEffectJar;
import magicbees.tileentity.TileEntityMagicApiary;
@@ -23,7 +24,7 @@ public class GUIHandler implements IGuiHandler {
TileEntityMagicApiary tileEntityThaumicApiary = (TileEntityMagicApiary) world.getTileEntity(x, y, z);
value = new ContainerMagicApiary(player.inventory, tileEntityThaumicApiary);
} else if (ID == UIScreens.EFFECT_RING.ordinal()) {
value = new ContainerEffectRing(ItemBeeRing.getInventory(player, player.getHeldItem()),player);
value = new ContainerEffectRing((InventoryBeeRing) ItemBeeRing.getInventory(player, player.getHeldItem()),player);
}
return value;
+70 -3
View File
@@ -2,14 +2,16 @@ package magicbees.item;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.IBee;
import magicbees.client.gui.UIScreens;
import magicbees.main.CommonProxy;
import magicbees.main.MagicBees;
import magicbees.itemInventories.InventoryBeeRing;
import magicbees.main.utils.MoonPhase;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -25,6 +27,8 @@ public class ItemBeeRing extends Item implements IBauble {
@SideOnly(Side.CLIENT)
private IIcon icon;
private final int DRONE_SLOT = 0;
private final int QUEEN_SLOT = 1;
public ItemBeeRing()
{
super();
@@ -43,8 +47,24 @@ public class ItemBeeRing extends Item implements IBauble {
onCreated(itemStack, world, player);
}
if (world.isRemote) {
player.openGui(MagicBees.object, UIScreens.EFFECT_RING.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
if (!world.isRemote) {
if(!player.isSneaking())
{
player.openGui(MagicBees.object, UIScreens.EFFECT_RING.ordinal(), world, (int) player.posX, (int) player.posY, (int) player.posZ);
}
else
{
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
for(int i = 0; i < baubles.getSizeInventory(); ++i) {
if (baubles.getStackInSlot(i) == null && baubles.isItemValidForSlot(i, itemStack)) {
baubles.setInventorySlotContents(i, itemStack.copy());
player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
this.onEquipped(itemStack, player);
break;
}
}
}
}
return itemStack;
}
@@ -62,7 +82,48 @@ public class ItemBeeRing extends Item implements IBauble {
@Override
public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
if (entityLivingBase instanceof EntityPlayer)
{
if (hasQueen(itemStack, (EntityPlayer) entityLivingBase)) {
tickQueen(itemStack);
} else if (hasDrone(itemStack, (EntityPlayer) entityLivingBase)) {
createQueenFromDrone(itemStack, (EntityPlayer) entityLivingBase);
}
}
}
private void createQueenFromDrone(ItemStack itemStack, EntityPlayer player) {
IInventory IBR = getInventory(player, itemStack);
ItemStack droneStack = IBR.getStackInSlot(0);
if (magicbees.bees.BeeManager.beeRoot.isDrone(droneStack)) {
IBee bee = magicbees.bees.BeeManager.beeRoot.getMember(droneStack);
if (droneStack.stackSize == 1) {
IBR.setInventorySlotContents(0, null);
} else {
droneStack.stackSize = droneStack.stackSize - 1;
IBR.setInventorySlotContents(0, droneStack);
}
ItemStack temp = droneStack.copy();
temp.stackSize = 1;
IBR.setInventorySlotContents(1, temp);
int current = bee.getHealth();
int max = bee.getMaxHealth();
// currentBeeHealth = (current * 100) / max;
// currentBeeColour = bee.getGenome().getPrimary().getIconColour(0);
}
}
private boolean hasDrone(ItemStack itemStack, EntityPlayer player) {
return getInventory(player, itemStack).getStackInSlot(DRONE_SLOT) != null;
}
private void tickQueen(ItemStack itemStack) {
}
private boolean hasQueen(ItemStack itemStack, EntityPlayer player) {
return getInventory(player, itemStack).getStackInSlot(QUEEN_SLOT) != null;
}
@Override
@@ -85,6 +146,12 @@ public class ItemBeeRing extends Item implements IBauble {
return true;
}
public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
{
// if (itemStack.getTagCompound() == null) {
// itemStack.setTagCompound(new NBTTagCompound());
// }
}
public static IInventory getInventory(EntityPlayer player, ItemStack itemStack)
{
return new InventoryBeeRing(itemStack, player);
@@ -1,66 +1,72 @@
package magicbees.itemInventories;
import baubles.common.lib.PlayerHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.Random;
public class InventoryBeeRing implements IInventory {
public EntityPlayer player;
public ItemStack parent;
public ItemStack[] contents;
public int currentBeeHealth;
public int throttle;
private final static String KEY_SLOTS = "Slots";
private static final String KEY_UID = "UID";
private static final Random rand = new Random();
public InventoryBeeRing(ItemStack stack, EntityPlayer player)
{
parent = stack;
this.player = player;
this.contents = new ItemStack[2];
readFromNBT(stack.getTagCompound());
}
public void readFromNBT(NBTTagCompound compound)
{
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.contents = new ItemStack[this.getSizeInventory()];
public void readFromNBT(NBTTagCompound compound) {
if (compound == null) {
return;
}
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.contents.length)
{
this.contents[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
if (compound.hasKey(KEY_SLOTS)) {
NBTTagCompound nbtSlots = compound.getCompoundTag(KEY_SLOTS);
for (int i = 0; i < contents.length; i++) {
String slotKey = getSlotNBTKey(i);
if (nbtSlots.hasKey(slotKey)) {
NBTTagCompound itemNbt = nbtSlots.getCompoundTag(slotKey);
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemNbt);
contents[i] = itemStack;
} else {
contents[i] = null;
}
}
}
if (compound.getInteger("throttle") != 0) {
throttle = compound.getInteger("throttle");
}
if (compound.getInteger("currentBeeHealth") != 0)
{
currentBeeHealth = compound.getInteger("throttle");
}
}
public void writeToNBT(NBTTagCompound compound)
{
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.contents.length; ++i)
{
if (this.contents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.contents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
compound.setTag("Items", nbttaglist);
private static String getSlotNBTKey(int i) {
return Integer.toString(i, Character.MAX_RADIX);
}
@Override
public int getSizeInventory() {
return 1;
return contents.length;
}
@Override
@@ -70,46 +76,67 @@ public class InventoryBeeRing implements IInventory {
@Override
public ItemStack decrStackSize(int slot, int count) {
if (this.contents != null)
{
ItemStack itemstack;
if (this.contents[slot].stackSize <= count)
{
itemstack = this.contents[slot];
this.contents = null;
return itemstack;
}
else
{
itemstack = this.contents[slot].splitStack(count);
if (this.contents[slot].stackSize == 0)
{
this.contents = null;
}
return itemstack;
}
}
else
{
ItemStack stack = getStackInSlot(slot);
if (stack == null) {
return null;
}
if (stack.stackSize <= count) {
setInventorySlotContents(slot, null);
return stack;
} else {
ItemStack product = stack.splitStack(count);
setInventorySlotContents(slot, stack);
return product;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int index) {
return null;
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack toReturn = getStackInSlot(slot);
if (toReturn != null) {
setInventorySlotContents(slot, null);
}
return toReturn;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
this.contents[slot] = stack;
if (stack != null && stack.stackSize == 0) {
stack = null;
}
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
contents[slot] = stack;
// I have literally no idea, but for some reason when this is 'this.parent' it doesn't work...
ItemStack parent = player.getCurrentEquippedItem();
NBTTagCompound nbt = parent.getTagCompound();
if (nbt == null) {
nbt = new NBTTagCompound();
parent.setTagCompound(nbt);
}
NBTTagCompound slotNbt;
if (!nbt.hasKey("KEY_SLOTS")) {
slotNbt = new NBTTagCompound();
nbt.setTag(KEY_SLOTS, slotNbt);
} else {
slotNbt = nbt.getCompoundTag(KEY_SLOTS);
}
String slotKey = getSlotNBTKey(slot);
if (stack == null) {
slotNbt.removeTag(slotKey);
} else {
NBTTagCompound itemNbt = new NBTTagCompound();
stack.writeToNBT(itemNbt);
slotNbt.setTag(slotKey, itemNbt);
}
}
@@ -130,26 +157,21 @@ public class InventoryBeeRing implements IInventory {
@Override
public void markDirty() {
writeToNBT(parent.getTagCompound());
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return false;
return true;
}
@Override
public void openInventory() {
}
public void openInventory() {}
@Override
public void closeInventory() {
}
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return false;
return true;
}
}