mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-12 00:08:01 +00:00
extract MagicApiaryInventory into file
This commit is contained in:
1 parent
c8aaeba7cb
commit
ae246d87eb
2 files changed
+187
-177
No files matched your search
@@ -0,0 +1,186 @@
|
||||
package magicbees.bees;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeekeepingMode;
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import forestry.apiculture.inventory.IApiaryInventory;
|
||||
import magicbees.main.utils.ItemStackUtils;
|
||||
import magicbees.tileentity.TileEntityMagicApiary;
|
||||
|
||||
public class MagicApiaryInventory implements IApiaryInventory {
|
||||
|
||||
public static final int SLOT_QUEEN = 0;
|
||||
public static final int SLOT_DRONE = 1;
|
||||
public static final int SLOT_FRAME_START = 9;
|
||||
public static final int SLOT_FRAME_COUNT = 3;
|
||||
public static final int SLOT_PRODUCTS_START = 2;
|
||||
public static final int SLOT_PRODUCTS_COUNT = 7;
|
||||
|
||||
private final TileEntityMagicApiary magicApiary;
|
||||
private final ItemStack[] items;
|
||||
|
||||
public MagicApiaryInventory(TileEntityMagicApiary magicApiary) {
|
||||
this.magicApiary = magicApiary;
|
||||
this.items = new ItemStack[12];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getQueen() {
|
||||
return magicApiary.getStackInSlot(SLOT_QUEEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDrone() {
|
||||
return magicApiary.getStackInSlot(SLOT_DRONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueen(ItemStack itemstack) {
|
||||
magicApiary.setInventorySlotContents(SLOT_QUEEN, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrone(ItemStack itemstack) {
|
||||
magicApiary.setInventorySlotContents(SLOT_DRONE, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addProduct(ItemStack product, boolean all) {
|
||||
int countAdded = ItemStackUtils
|
||||
.addItemToInventory(magicApiary, product, SLOT_PRODUCTS_START, SLOT_PRODUCTS_COUNT);
|
||||
|
||||
if (all) {
|
||||
return countAdded == product.stackSize;
|
||||
} else {
|
||||
return countAdded > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeInventory() {
|
||||
return items.length;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return items[i];
|
||||
}
|
||||
|
||||
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
||||
items[i] = itemStack;
|
||||
|
||||
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
||||
itemStack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
if (side == 0 || side == 1) {
|
||||
return new int[] { SLOT_QUEEN, SLOT_DRONE };
|
||||
} else {
|
||||
int[] slots = new int[SLOT_PRODUCTS_COUNT];
|
||||
for (int i = 0, slot = SLOT_PRODUCTS_START; i < SLOT_PRODUCTS_COUNT; ++i, ++slot) {
|
||||
slots[i] = slot;
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
||||
if (slot == SLOT_QUEEN && BeeManager.beeRoot.isMember(itemStack) && !BeeManager.beeRoot.isDrone(itemStack)) {
|
||||
return true;
|
||||
} else if (slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
return slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack);
|
||||
}
|
||||
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
||||
return slot >= SLOT_FRAME_START && slot <= SLOT_FRAME_START + 2;
|
||||
}
|
||||
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
public Collection<IHiveFrame> getFrames() {
|
||||
Collection<IHiveFrame> hiveFrames = new ArrayList<IHiveFrame>(SLOT_FRAME_COUNT);
|
||||
|
||||
for (int i = SLOT_FRAME_START; i < SLOT_FRAME_START + SLOT_FRAME_COUNT; i++) {
|
||||
ItemStack stackInSlot = magicApiary.getStackInSlot(i);
|
||||
if (stackInSlot == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Item itemInSlot = stackInSlot.getItem();
|
||||
if (itemInSlot instanceof IHiveFrame) {
|
||||
hiveFrames.add((IHiveFrame) itemInSlot);
|
||||
}
|
||||
}
|
||||
|
||||
return hiveFrames;
|
||||
}
|
||||
|
||||
public void wearOutFrames(IBeeHousing beeHousing, int amount) {
|
||||
IBeekeepingMode beekeepingMode = BeeManager.beeRoot.getBeekeepingMode(magicApiary.getWorldObj());
|
||||
int wear = Math.round(amount * beekeepingMode.getWearModifier());
|
||||
|
||||
for (int i = MagicApiaryInventory.SLOT_FRAME_START; i
|
||||
< MagicApiaryInventory.SLOT_FRAME_START + MagicApiaryInventory.SLOT_FRAME_COUNT; i++) {
|
||||
ItemStack hiveFrameStack = magicApiary.getStackInSlot(i);
|
||||
if (hiveFrameStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Item hiveFrameItem = hiveFrameStack.getItem();
|
||||
if (!(hiveFrameItem instanceof IHiveFrame)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IHiveFrame hiveFrame = (IHiveFrame) hiveFrameItem;
|
||||
|
||||
ItemStack queenStack = magicApiary.getBeeInventory().getQueen();
|
||||
IBee queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
ItemStack usedFrame = hiveFrame.frameUsed(magicApiary, hiveFrameStack, queen, wear);
|
||||
|
||||
magicApiary.setInventorySlotContents(i, usedFrame);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagList itemsNBT = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
ItemStack itemStack = items[i];
|
||||
|
||||
if (itemStack != null) {
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
item.setByte("Slot", (byte) i);
|
||||
itemStack.writeToNBT(item);
|
||||
itemsNBT.appendTag(item);
|
||||
}
|
||||
}
|
||||
compound.setTag("Items", itemsNBT);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
NBTTagList items = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < items.tagCount(); i++) {
|
||||
NBTTagCompound item = items.getCompoundTagAt(i);
|
||||
int slot = item.getByte("Slot");
|
||||
|
||||
if (slot >= 0 && slot < getSizeInventory()) {
|
||||
setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package magicbees.tileentity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,10 +9,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
@@ -22,19 +19,15 @@ import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.apiculture.DefaultBeeModifier;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeeHousingInventory;
|
||||
import forestry.api.apiculture.IBeeListener;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
import forestry.api.apiculture.IBeekeepingMode;
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
@@ -46,9 +39,9 @@ import forestry.apiculture.inventory.IApiaryInventory;
|
||||
import magicbees.api.bees.IMagicApiaryAuraProvider;
|
||||
import magicbees.bees.AuraCharge;
|
||||
import magicbees.bees.BeeManager;
|
||||
import magicbees.bees.MagicApiaryInventory;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import magicbees.main.utils.ItemStackUtils;
|
||||
import magicbees.main.utils.net.EventAuraChargeUpdate;
|
||||
import magicbees.main.utils.net.NetworkEventHandler;
|
||||
|
||||
@@ -470,175 +463,6 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
|
||||
return inventory.canExtractItem(i, itemStack, i1);
|
||||
}
|
||||
|
||||
private static class MagicApiaryInventory implements IApiaryInventory {
|
||||
|
||||
public static final int SLOT_QUEEN = 0;
|
||||
public static final int SLOT_DRONE = 1;
|
||||
public static final int SLOT_FRAME_START = 9;
|
||||
public static final int SLOT_FRAME_COUNT = 3;
|
||||
public static final int SLOT_PRODUCTS_START = 2;
|
||||
public static final int SLOT_PRODUCTS_COUNT = 7;
|
||||
|
||||
private final TileEntityMagicApiary magicApiary;
|
||||
private final ItemStack[] items;
|
||||
|
||||
public MagicApiaryInventory(TileEntityMagicApiary magicApiary) {
|
||||
this.magicApiary = magicApiary;
|
||||
this.items = new ItemStack[12];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getQueen() {
|
||||
return magicApiary.getStackInSlot(SLOT_QUEEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDrone() {
|
||||
return magicApiary.getStackInSlot(SLOT_DRONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQueen(ItemStack itemstack) {
|
||||
magicApiary.setInventorySlotContents(SLOT_QUEEN, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrone(ItemStack itemstack) {
|
||||
magicApiary.setInventorySlotContents(SLOT_DRONE, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addProduct(ItemStack product, boolean all) {
|
||||
int countAdded = ItemStackUtils
|
||||
.addItemToInventory(magicApiary, product, SLOT_PRODUCTS_START, SLOT_PRODUCTS_COUNT);
|
||||
|
||||
if (all) {
|
||||
return countAdded == product.stackSize;
|
||||
} else {
|
||||
return countAdded > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSizeInventory() {
|
||||
return items.length;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return items[i];
|
||||
}
|
||||
|
||||
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
||||
items[i] = itemStack;
|
||||
|
||||
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
||||
itemStack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
if (side == 0 || side == 1) {
|
||||
return new int[] { SLOT_QUEEN, SLOT_DRONE };
|
||||
} else {
|
||||
int[] slots = new int[SLOT_PRODUCTS_COUNT];
|
||||
for (int i = 0, slot = SLOT_PRODUCTS_START; i < SLOT_PRODUCTS_COUNT; ++i, ++slot) {
|
||||
slots[i] = slot;
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
|
||||
if (slot == SLOT_QUEEN && BeeManager.beeRoot.isMember(itemStack)
|
||||
&& !BeeManager.beeRoot.isDrone(itemStack)) {
|
||||
return true;
|
||||
} else if (slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
return slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack);
|
||||
}
|
||||
|
||||
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
||||
return slot >= SLOT_FRAME_START && slot <= SLOT_FRAME_START + 2;
|
||||
}
|
||||
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
public Collection<IHiveFrame> getFrames() {
|
||||
Collection<IHiveFrame> hiveFrames = new ArrayList<IHiveFrame>(SLOT_FRAME_COUNT);
|
||||
|
||||
for (int i = SLOT_FRAME_START; i < SLOT_FRAME_START + SLOT_FRAME_COUNT; i++) {
|
||||
ItemStack stackInSlot = magicApiary.getStackInSlot(i);
|
||||
if (stackInSlot == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Item itemInSlot = stackInSlot.getItem();
|
||||
if (itemInSlot instanceof IHiveFrame) {
|
||||
hiveFrames.add((IHiveFrame) itemInSlot);
|
||||
}
|
||||
}
|
||||
|
||||
return hiveFrames;
|
||||
}
|
||||
|
||||
public void wearOutFrames(IBeeHousing beeHousing, int amount) {
|
||||
IBeekeepingMode beekeepingMode = BeeManager.beeRoot.getBeekeepingMode(magicApiary.getWorldObj());
|
||||
int wear = Math.round(amount * beekeepingMode.getWearModifier());
|
||||
|
||||
for (int i = MagicApiaryInventory.SLOT_FRAME_START; i
|
||||
< MagicApiaryInventory.SLOT_FRAME_START + MagicApiaryInventory.SLOT_FRAME_COUNT; i++) {
|
||||
ItemStack hiveFrameStack = magicApiary.getStackInSlot(i);
|
||||
if (hiveFrameStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Item hiveFrameItem = hiveFrameStack.getItem();
|
||||
if (!(hiveFrameItem instanceof IHiveFrame)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IHiveFrame hiveFrame = (IHiveFrame) hiveFrameItem;
|
||||
|
||||
ItemStack queenStack = magicApiary.getBeeInventory().getQueen();
|
||||
IBee queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
ItemStack usedFrame = hiveFrame.frameUsed(magicApiary, hiveFrameStack, queen, wear);
|
||||
|
||||
magicApiary.setInventorySlotContents(i, usedFrame);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagList itemsNBT = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
ItemStack itemStack = items[i];
|
||||
|
||||
if (itemStack != null) {
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
item.setByte("Slot", (byte) i);
|
||||
itemStack.writeToNBT(item);
|
||||
itemsNBT.appendTag(item);
|
||||
}
|
||||
}
|
||||
compound.setTag("Items", itemsNBT);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
NBTTagList items = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < items.tagCount(); i++) {
|
||||
NBTTagCompound item = items.getCompoundTagAt(i);
|
||||
int slot = item.getByte("Slot");
|
||||
|
||||
if (slot >= 0 && slot < getSizeInventory()) {
|
||||
setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MagicApiaryBeeModifier extends DefaultBeeModifier {
|
||||
|
||||
private final TileEntityMagicApiary magicApiary;
|
||||
|
||||
Reference in new issue
Block a user