Files
MagicBees/src/main/java/magicbees/client/gui/ContainerEffectJar.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.3 KiB
Java
Raw Normal View History

2013-05-23 21:07:28 -07:00
package magicbees.client.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2023-04-28 17:50:21 +02:00
import magicbees.tileentity.TileEntityEffectJar;
2022-10-12 21:09:45 +02:00
public class ContainerEffectJar extends Container {
2022-10-12 21:09:45 +02:00
public TileEntityEffectJar jar;
2022-10-12 21:09:45 +02:00
public int lastBeeHealth = 0;
public int speciesColour = 0xffffff;
public ContainerEffectJar(TileEntityEffectJar tileEntityEffectJar, EntityPlayer player) {
this.jar = tileEntityEffectJar;
this.addSlotToContainer(
new SlotCustomItems(this.jar, 0, 80, 22, GameRegistry.findItemStack("Forestry", "beeDroneGE", 1)));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 74 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 132));
}
}
@Override
public void addCraftingToCrafters(ICrafting crafting) {
super.addCraftingToCrafters(crafting);
crafting.sendProgressBarUpdate(this, 0, this.jar.currentBeeHealth);
crafting.sendProgressBarUpdate(this, 1, this.jar.currentBeeColour);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i) {
ICrafting crafting = (ICrafting) this.crafters.get(i);
if (this.lastBeeHealth != this.jar.currentBeeHealth) {
crafting.sendProgressBarUpdate(this, 0, this.jar.currentBeeHealth);
this.lastBeeHealth = this.jar.currentBeeHealth;
}
if (this.speciesColour != this.jar.currentBeeColour) {
crafting.sendProgressBarUpdate(this, 1, this.jar.currentBeeColour);
this.speciesColour = this.jar.currentBeeColour;
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int craftingId, int value) {
if (craftingId == 0) {
this.jar.currentBeeHealth = value;
} else if (craftingId == 1) {
this.jar.currentBeeColour = value;
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return this.jar.isUseableByPlayer(entityplayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
Slot itemSlot = this.getSlot(slot);
boolean clearSlot = false;
if (itemSlot != null && itemSlot.getHasStack()) {
ItemStack srcStack = itemSlot.getStack();
if (slot == 0 && srcStack != null) {
clearSlot = this.mergeItemStack(srcStack, 1, 36 + 1, false);
} else {
if (this.getSlot(0).isItemValid(srcStack)) {
clearSlot = this.mergeItemStack(srcStack, 0, 1, false);
}
}
}
if (clearSlot) {
itemSlot.putStack(null);
}
itemSlot.onSlotChanged();
player.inventory.markDirty();
return null;
}
}