mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-16 01:54:40 +00:00
103 lines
3.5 KiB
Java
103 lines
3.5 KiB
Java
/*******************************************************************************
|
|
* Copyright (c) 2011-2014 SirSengir. All rights reserved. This program and the accompanying materials are made
|
|
* available under the terms of the GNU Lesser Public License v3 which accompanies this distribution, and is available
|
|
* at http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
*
|
|
* Various Contributors including, but not limited to: SirSengir (original work), CovertJaguar, Player, Binnie,
|
|
* MysteriousAges
|
|
******************************************************************************/
|
|
package forestry.apiculture;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ChunkCoordinates;
|
|
import net.minecraft.world.World;
|
|
|
|
import forestry.api.apiculture.BeeManager;
|
|
import forestry.api.apiculture.EnumBeeType;
|
|
import forestry.api.apiculture.IBeeHousingInventory;
|
|
import forestry.core.access.IAccessHandler;
|
|
import forestry.core.inventory.InventoryAdapterRestricted;
|
|
import forestry.core.utils.InventoryUtil;
|
|
import forestry.core.utils.SlotUtil;
|
|
|
|
public class InventoryBeeHousing extends InventoryAdapterRestricted implements IBeeHousingInventory {
|
|
|
|
public static final int SLOT_QUEEN = 0;
|
|
public static final int SLOT_DRONE = 1;
|
|
public static final int SLOT_PRODUCT_1 = 2;
|
|
public static final int SLOT_PRODUCT_COUNT = 7;
|
|
|
|
public InventoryBeeHousing(int size, IAccessHandler accessHandler) {
|
|
super(size, "Items", accessHandler);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
|
EnumBeeType beeType = BeeManager.beeRoot.getType(itemStack);
|
|
|
|
if (slotIndex == SLOT_QUEEN) {
|
|
return beeType == EnumBeeType.QUEEN || beeType == EnumBeeType.PRINCESS;
|
|
} else if (slotIndex == SLOT_DRONE) {
|
|
return beeType == EnumBeeType.DRONE;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
|
|
if (!super.canExtractItem(slotIndex, itemstack, side)) {
|
|
return false;
|
|
}
|
|
return SlotUtil.isSlotInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT);
|
|
}
|
|
|
|
@Override
|
|
public final ItemStack getQueen() {
|
|
return getStackInSlot(SLOT_QUEEN);
|
|
}
|
|
|
|
@Override
|
|
public final ItemStack getDrone() {
|
|
return getStackInSlot(SLOT_DRONE);
|
|
}
|
|
|
|
@Override
|
|
public final void setQueen(ItemStack itemstack) {
|
|
setInventorySlotContents(SLOT_QUEEN, itemstack);
|
|
}
|
|
|
|
@Override
|
|
public final void setDrone(ItemStack itemstack) {
|
|
setInventorySlotContents(SLOT_DRONE, itemstack);
|
|
}
|
|
|
|
@Override
|
|
public final boolean addProduct(ItemStack product, boolean all) {
|
|
return InventoryUtil.tryAddStack(this, product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all, true);
|
|
}
|
|
|
|
public void dumpInventoryIntoWorld(World world, ChunkCoordinates coordinates) {
|
|
if (world.isRemote) {
|
|
return;
|
|
}
|
|
for (int i = 0; i < SLOT_PRODUCT_COUNT; i++) {
|
|
ItemStack stack = getStackInSlot(i);
|
|
if (stack == null) {
|
|
continue;
|
|
}
|
|
setInventorySlotContents(i, null);
|
|
|
|
EntityItem entityitem = new EntityItem(
|
|
world,
|
|
coordinates.posX + 0.5,
|
|
coordinates.posY + 0.5,
|
|
coordinates.posZ + 0.5,
|
|
stack);
|
|
entityitem.delayBeforeCanPickup = 10;
|
|
world.spawnEntityInWorld(entityitem);
|
|
}
|
|
|
|
}
|
|
}
|