2014-09-16 20:30:20 +02:00
|
|
|
package magicbees.tileentity;
|
|
|
|
|
|
2015-03-27 16:31:15 -07:00
|
|
|
import java.util.ArrayList;
|
2015-10-01 21:47:53 -07:00
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
2015-03-27 16:31:15 -07:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2023-01-29 10:24:49 -08:00
|
|
|
|
2023-12-07 18:00:36 +01:00
|
|
|
|
2015-01-08 21:48:13 -08:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-01-16 22:59:06 +01:00
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.ICrafting;
|
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2015-10-01 21:47:53 -07:00
|
|
|
import net.minecraft.item.Item;
|
2015-01-08 21:48:13 -08:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-01-16 22:59:06 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2015-03-28 02:51:41 -07:00
|
|
|
import net.minecraft.network.Packet;
|
2015-01-08 21:48:13 -08:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-10-01 21:47:53 -07:00
|
|
|
import net.minecraft.util.ChunkCoordinates;
|
2015-03-27 16:31:15 -07:00
|
|
|
import net.minecraft.util.Vec3;
|
2015-03-26 13:57:29 -07:00
|
|
|
import net.minecraft.world.ChunkPosition;
|
2015-01-08 21:48:13 -08:00
|
|
|
import net.minecraft.world.World;
|
2015-01-08 23:42:46 -08:00
|
|
|
import net.minecraft.world.biome.BiomeGenBase;
|
2015-03-26 13:57:29 -07:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2015-01-16 22:59:06 +01:00
|
|
|
import net.minecraftforge.common.util.Constants;
|
2015-01-08 23:42:46 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2023-01-29 10:24:49 -08:00
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
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;
|
|
|
|
|
import forestry.api.core.ForestryAPI;
|
|
|
|
|
import forestry.api.core.IErrorLogic;
|
2023-12-07 18:00:36 +01:00
|
|
|
import forestry.apiculture.ApiaryBeeListener;
|
|
|
|
|
import forestry.apiculture.IApiary;
|
|
|
|
|
import forestry.apiculture.inventory.IApiaryInventory;
|
2023-04-28 17:50:21 +02:00
|
|
|
import magicbees.api.bees.IMagicApiaryAuraProvider;
|
|
|
|
|
import magicbees.bees.AuraCharge;
|
|
|
|
|
import magicbees.bees.BeeManager;
|
|
|
|
|
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;
|
2023-01-29 10:24:49 -08:00
|
|
|
|
2023-12-07 16:49:09 +01:00
|
|
|
public class TileEntityMagicApiary extends TileEntity implements ISidedInventory, IApiary, ITileEntityAuraCharged {
|
2015-01-16 22:59:06 +01:00
|
|
|
|
|
|
|
|
// Constants
|
2015-03-21 18:20:45 -07:00
|
|
|
private static final int AURAPROVIDER_SEARCH_RADIUS = 6;
|
2015-10-01 21:47:53 -07:00
|
|
|
public static final String tileEntityName = CommonProxy.DOMAIN + ".magicApiary";
|
|
|
|
|
|
|
|
|
|
private GameProfile ownerProfile;
|
2015-03-21 18:20:45 -07:00
|
|
|
private IMagicApiaryAuraProvider auraProvider;
|
|
|
|
|
private ChunkCoords auraProviderPosition;
|
2015-01-16 22:59:06 +01:00
|
|
|
private BiomeGenBase biome;
|
2015-10-01 21:47:53 -07:00
|
|
|
private int breedingProgressPercent = 0;
|
2015-03-28 02:51:41 -07:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
private final IBeekeepingLogic beeLogic;
|
|
|
|
|
private final IErrorLogic errorLogic;
|
2023-12-07 16:49:09 +01:00
|
|
|
private final IBeeListener beeListener = new ApiaryBeeListener(this);
|
2015-10-01 21:47:53 -07:00
|
|
|
private final IBeeModifier beeModifier;
|
|
|
|
|
private final MagicApiaryInventory inventory;
|
2015-03-28 02:51:41 -07:00
|
|
|
private final AuraCharges auraCharges = new AuraCharges();
|
|
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
public TileEntityMagicApiary() {
|
2015-10-01 21:47:53 -07:00
|
|
|
beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
|
|
|
|
|
beeModifier = new MagicApiaryBeeModifier(this);
|
|
|
|
|
inventory = new MagicApiaryInventory(this);
|
|
|
|
|
errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public Iterable<IBeeModifier> getBeeModifiers() {
|
|
|
|
|
List<IBeeModifier> beeModifiers = new ArrayList<IBeeModifier>();
|
2015-01-16 22:59:06 +01:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
beeModifiers.add(beeModifier);
|
2015-01-16 22:59:06 +01:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
for (IHiveFrame frame : inventory.getFrames()) {
|
|
|
|
|
beeModifiers.add(frame.getBeeModifier());
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2015-01-16 22:59:06 +01:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
return beeModifiers;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public Iterable<IBeeListener> getBeeListeners() {
|
|
|
|
|
return Collections.singleton(beeListener);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public IBeeHousingInventory getBeeInventory() {
|
|
|
|
|
return inventory;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 16:49:09 +01:00
|
|
|
@Override
|
|
|
|
|
public IApiaryInventory getApiaryInventory() {
|
|
|
|
|
return inventory;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 22:59:06 +01:00
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public IBeekeepingLogic getBeekeepingLogic() {
|
|
|
|
|
return beeLogic;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public IErrorLogic getErrorLogic() {
|
|
|
|
|
return errorLogic;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public GameProfile getOwner() {
|
2015-03-19 13:51:41 -07:00
|
|
|
return this.ownerProfile;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public World getWorld() {
|
|
|
|
|
return worldObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public ChunkCoordinates getCoordinates() {
|
|
|
|
|
return new ChunkCoordinates(xCoord, yCoord, zCoord);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-21 19:28:09 -08:00
|
|
|
@Override
|
|
|
|
|
public Vec3 getBeeFXCoordinates() {
|
|
|
|
|
return Vec3.createVectorHelper(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 22:59:06 +01:00
|
|
|
@Override
|
|
|
|
|
public BiomeGenBase getBiome() {
|
2015-10-01 21:47:53 -07:00
|
|
|
if (biome == null) {
|
|
|
|
|
biome = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord);
|
|
|
|
|
}
|
2015-01-16 22:59:06 +01:00
|
|
|
return biome;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public EnumTemperature getTemperature() {
|
2015-10-01 21:47:53 -07:00
|
|
|
return EnumTemperature.getFromBiome(getBiome(), xCoord, yCoord, zCoord);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public EnumHumidity getHumidity() {
|
|
|
|
|
return EnumHumidity.getFromValue(getExactHumidity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public int getBlockLightValue() {
|
|
|
|
|
return worldObj.getBlockLightValue(xCoord, yCoord + 1, zCoord);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-01 21:47:53 -07:00
|
|
|
public boolean canBlockSeeTheSky() {
|
|
|
|
|
return worldObj.canBlockSeeTheSky(xCoord, yCoord + 1, zCoord);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSizeInventory() {
|
2015-10-01 21:47:53 -07:00
|
|
|
return inventory.getSizeInventory();
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlot(int i) {
|
2015-10-01 21:47:53 -07:00
|
|
|
return inventory.getStackInSlot(i);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack decrStackSize(int i, int j) {
|
|
|
|
|
ItemStack itemStack = getStackInSlot(i);
|
|
|
|
|
|
|
|
|
|
if (itemStack != null) {
|
|
|
|
|
if (itemStack.stackSize <= j) {
|
|
|
|
|
setInventorySlotContents(i, null);
|
2022-10-12 21:09:45 +02:00
|
|
|
} else {
|
2015-01-16 22:59:06 +01:00
|
|
|
itemStack = itemStack.splitStack(j);
|
|
|
|
|
markDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return itemStack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ItemStack getStackInSlotOnClosing(int i) {
|
|
|
|
|
ItemStack item = getStackInSlot(i);
|
|
|
|
|
setInventorySlotContents(i, null);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
2015-10-01 21:47:53 -07:00
|
|
|
inventory.setInventorySlotContents(i, itemStack);
|
2015-01-16 22:59:06 +01:00
|
|
|
markDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getInventoryName() {
|
2015-03-19 13:51:41 -07:00
|
|
|
return tileEntityName;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasCustomInventoryName() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getInventoryStackLimit() {
|
2015-10-01 21:47:53 -07:00
|
|
|
return inventory.getInventoryStackLimit();
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer entityPlayer) {
|
|
|
|
|
return entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-10-12 21:09:45 +02:00
|
|
|
public void openInventory() {}
|
2015-01-16 22:59:06 +01:00
|
|
|
|
|
|
|
|
@Override
|
2022-10-12 21:09:45 +02:00
|
|
|
public void closeInventory() {}
|
2015-01-16 22:59:06 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public int getHealthScaled(int i) {
|
2015-10-01 21:47:53 -07:00
|
|
|
return (breedingProgressPercent * i) / 100;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Saving and loading */
|
|
|
|
|
@Override
|
2015-03-17 23:03:48 -07:00
|
|
|
public void writeToNBT(NBTTagCompound compound) {
|
2015-01-16 22:59:06 +01:00
|
|
|
super.writeToNBT(compound);
|
|
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
inventory.writeToNBT(compound);
|
|
|
|
|
beeLogic.writeToNBT(compound);
|
|
|
|
|
ChunkCoords.writeToNBT(auraProviderPosition, compound);
|
2015-03-28 02:51:41 -07:00
|
|
|
auraCharges.writeToNBT(compound);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-03-17 23:03:48 -07:00
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
2015-01-16 22:59:06 +01:00
|
|
|
super.readFromNBT(compound);
|
|
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
inventory.readFromNBT(compound);
|
|
|
|
|
beeLogic.readFromNBT(compound);
|
|
|
|
|
auraProviderPosition = ChunkCoords.readFromNBT(compound);
|
2015-03-28 02:51:41 -07:00
|
|
|
auraCharges.readFromNBT(compound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Packet getDescriptionPacket() {
|
2015-10-01 21:47:53 -07:00
|
|
|
beeLogic.syncToClient();
|
2015-03-28 02:51:41 -07:00
|
|
|
EventAuraChargeUpdate event = new EventAuraChargeUpdate(new ChunkCoords(this), auraCharges);
|
|
|
|
|
return event.getPacket();
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public float getExactTemperature() {
|
2015-10-01 21:47:53 -07:00
|
|
|
return getBiome().getFloatTemperature(xCoord, yCoord, zCoord);
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public float getExactHumidity() {
|
2015-10-01 21:47:53 -07:00
|
|
|
return getBiome().rainfall;
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-03-17 23:03:48 -07:00
|
|
|
public void updateEntity() {
|
2015-03-18 23:53:22 -07:00
|
|
|
if (worldObj.isRemote) {
|
2015-03-19 13:51:41 -07:00
|
|
|
updateClientSide();
|
2022-10-12 21:09:45 +02:00
|
|
|
} else {
|
|
|
|
|
updateServerSide();
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public void updateClientSide() {
|
2015-10-01 21:47:53 -07:00
|
|
|
if (beeLogic.canDoBeeFX() && worldObj.getTotalWorldTime() % 10 == 0) {
|
|
|
|
|
beeLogic.doBeeFX();
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public void updateServerSide() {
|
2022-10-12 21:09:45 +02:00
|
|
|
if (this.auraProvider == null) {
|
|
|
|
|
findAuraProvider();
|
|
|
|
|
} else {
|
|
|
|
|
updateAuraProvider();
|
|
|
|
|
}
|
|
|
|
|
tickCharges();
|
2015-01-16 22:59:06 +01:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
if (beeLogic.canWork()) {
|
|
|
|
|
beeLogic.doWork();
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public void getGUINetworkData(int i, int j) {
|
2015-10-01 21:47:53 -07:00
|
|
|
switch (i) {
|
2015-01-16 22:59:06 +01:00
|
|
|
case 0:
|
2015-10-01 21:47:53 -07:00
|
|
|
breedingProgressPercent = j;
|
2015-01-16 22:59:06 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
2015-10-01 21:47:53 -07:00
|
|
|
iCrafting.sendProgressBarUpdate(container, 0, beeLogic.getBeeProgressPercent());
|
2015-01-16 22:59:06 +01:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
2015-03-21 20:45:36 -07:00
|
|
|
public boolean isProductionBoosted() {
|
2015-04-24 14:45:21 -07:00
|
|
|
return auraCharges.isActive(AuraCharge.PRODUCTION);
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public boolean isDeathRateBoosted() {
|
2015-04-24 14:45:21 -07:00
|
|
|
return auraCharges.isActive(AuraCharge.DEATH);
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
2015-03-17 23:03:48 -07:00
|
|
|
public boolean isMutationBoosted() {
|
2015-04-24 14:45:21 -07:00
|
|
|
return auraCharges.isActive(AuraCharge.MUTATION);
|
2015-03-17 23:03:48 -07:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
2015-03-21 18:20:45 -07:00
|
|
|
private void updateAuraProvider() {
|
2022-10-12 21:09:45 +02:00
|
|
|
if (worldObj.getTotalWorldTime() % 10 != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (getAuraProvider(auraProviderPosition) == null) {
|
|
|
|
|
this.auraProvider = null;
|
|
|
|
|
this.auraProviderPosition = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean auraChargesChanged = false;
|
2015-04-24 14:45:21 -07:00
|
|
|
for (AuraCharge charge : AuraCharge.values()) {
|
|
|
|
|
if (!auraCharges.isActive(charge) && auraProvider.getCharge(charge.type)) {
|
|
|
|
|
auraCharges.start(charge, worldObj);
|
2015-03-28 02:51:41 -07:00
|
|
|
auraChargesChanged = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
|
|
|
|
if (auraChargesChanged) {
|
2015-03-28 02:51:41 -07:00
|
|
|
NetworkEventHandler.getInstance().sendAuraChargeUpdate(this, auraCharges);
|
2022-10-12 21:09:45 +02:00
|
|
|
}
|
2015-03-27 22:35:33 -07:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
2015-03-27 22:35:33 -07:00
|
|
|
private void tickCharges() {
|
2015-03-28 02:51:41 -07:00
|
|
|
boolean auraChargesChanged = false;
|
|
|
|
|
|
2015-04-24 14:45:21 -07:00
|
|
|
for (AuraCharge charge : AuraCharge.values()) {
|
2022-10-12 21:09:45 +02:00
|
|
|
if (auraCharges.isActive(charge) && auraCharges.isExpired(charge, worldObj)
|
|
|
|
|
&& (auraProvider == null || !auraProvider.getCharge(charge.type))) {
|
2015-04-24 14:45:21 -07:00
|
|
|
auraCharges.stop(charge);
|
2015-03-28 02:51:41 -07:00
|
|
|
auraChargesChanged = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
if (auraChargesChanged) {
|
|
|
|
|
NetworkEventHandler.getInstance().sendAuraChargeUpdate(this, auraCharges);
|
|
|
|
|
}
|
2015-03-21 18:20:45 -07:00
|
|
|
}
|
2015-03-21 21:26:51 -07:00
|
|
|
|
2015-03-21 18:20:45 -07:00
|
|
|
private void findAuraProvider() {
|
2022-10-12 21:09:45 +02:00
|
|
|
if (worldObj.getTotalWorldTime() % 5 != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-03-28 02:51:41 -07:00
|
|
|
|
|
|
|
|
if (this.auraProviderPosition == null) {
|
|
|
|
|
List<Chunk> chunks = getChunksInSearchRange();
|
|
|
|
|
for (Chunk chunk : chunks) {
|
|
|
|
|
if (searchChunkForBooster(chunk)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.auraProvider = getAuraProvider(auraProviderPosition);
|
|
|
|
|
if (auraProvider == null) {
|
|
|
|
|
this.auraProviderPosition = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-21 18:20:45 -07:00
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
|
|
|
|
|
private List<Chunk> getChunksInSearchRange() {
|
|
|
|
|
List<Chunk> chunks = new ArrayList<Chunk>(4);
|
|
|
|
|
chunks.add(
|
|
|
|
|
worldObj.getChunkFromBlockCoords(
|
|
|
|
|
xCoord - AURAPROVIDER_SEARCH_RADIUS,
|
|
|
|
|
zCoord - AURAPROVIDER_SEARCH_RADIUS));
|
|
|
|
|
Chunk chunk = worldObj
|
|
|
|
|
.getChunkFromBlockCoords(xCoord + AURAPROVIDER_SEARCH_RADIUS, zCoord - AURAPROVIDER_SEARCH_RADIUS);
|
|
|
|
|
if (!chunks.contains(chunk)) {
|
|
|
|
|
chunks.add(chunk);
|
|
|
|
|
}
|
|
|
|
|
chunk = worldObj
|
|
|
|
|
.getChunkFromBlockCoords(xCoord - AURAPROVIDER_SEARCH_RADIUS, zCoord + AURAPROVIDER_SEARCH_RADIUS);
|
|
|
|
|
if (!chunks.contains(chunk)) {
|
|
|
|
|
chunks.add(chunk);
|
|
|
|
|
}
|
|
|
|
|
chunk = worldObj
|
|
|
|
|
.getChunkFromBlockCoords(xCoord + AURAPROVIDER_SEARCH_RADIUS, zCoord + AURAPROVIDER_SEARCH_RADIUS);
|
|
|
|
|
if (!chunks.contains(chunk)) {
|
|
|
|
|
chunks.add(chunk);
|
|
|
|
|
}
|
|
|
|
|
return chunks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private boolean searchChunkForBooster(Chunk chunk) {
|
|
|
|
|
Vec3 apiaryPos = Vec3.createVectorHelper(xCoord, yCoord, zCoord);
|
|
|
|
|
for (Map.Entry<ChunkPosition, TileEntity> entry : ((Map<ChunkPosition, TileEntity>) chunk.chunkTileEntityMap)
|
|
|
|
|
.entrySet()) {
|
|
|
|
|
TileEntity entity = entry.getValue();
|
|
|
|
|
if (entity instanceof IMagicApiaryAuraProvider) {
|
|
|
|
|
Vec3 tePos = Vec3.createVectorHelper(entity.xCoord, entity.yCoord, entity.zCoord);
|
|
|
|
|
Vec3 result = apiaryPos.subtract(tePos);
|
|
|
|
|
if (result.lengthVector() <= AURAPROVIDER_SEARCH_RADIUS) {
|
|
|
|
|
saveAuraProviderPosition(entity.xCoord, entity.yCoord, entity.zCoord);
|
|
|
|
|
this.auraProvider = (IMagicApiaryAuraProvider) entity;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveAuraProviderPosition(int x, int y, int z) {
|
|
|
|
|
auraProviderPosition = new ChunkCoords(worldObj.provider.dimensionId, x, y, z);
|
|
|
|
|
}
|
2015-03-21 18:20:45 -07:00
|
|
|
|
2015-03-28 02:51:41 -07:00
|
|
|
private IMagicApiaryAuraProvider getAuraProvider(ChunkCoords coords) {
|
2022-10-12 21:09:45 +02:00
|
|
|
return getAuraProvider(coords.x, coords.y, coords.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IMagicApiaryAuraProvider getAuraProvider(int x, int y, int z) {
|
|
|
|
|
Chunk chunk = worldObj.getChunkFromBlockCoords(x, z);
|
|
|
|
|
x %= 16;
|
|
|
|
|
z %= 16;
|
|
|
|
|
if (x < 0) {
|
|
|
|
|
x += 16;
|
|
|
|
|
}
|
|
|
|
|
if (z < 0) {
|
|
|
|
|
z += 16;
|
|
|
|
|
}
|
|
|
|
|
ChunkPosition cPos = new ChunkPosition(x, y, z);
|
|
|
|
|
TileEntity entity = (TileEntity) chunk.chunkTileEntityMap.get(cPos);
|
2015-03-28 02:51:41 -07:00
|
|
|
if (!(entity instanceof IMagicApiaryAuraProvider)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-10-12 21:09:45 +02:00
|
|
|
return (IMagicApiaryAuraProvider) entity;
|
2015-03-28 02:51:41 -07:00
|
|
|
}
|
2015-03-21 20:45:36 -07:00
|
|
|
|
2015-03-28 02:51:41 -07:00
|
|
|
@Override
|
|
|
|
|
public AuraCharges getAuraCharges() {
|
|
|
|
|
return auraCharges;
|
|
|
|
|
}
|
2015-10-01 21:47:53 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int[] getAccessibleSlotsFromSide(int i) {
|
|
|
|
|
return inventory.getAccessibleSlotsFromSide(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem(int i, ItemStack itemStack, int i1) {
|
|
|
|
|
return inventory.canInsertItem(i, itemStack, i1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int i, ItemStack itemStack, int i1) {
|
|
|
|
|
return inventory.canExtractItem(i, itemStack, i1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-07 16:49:09 +01:00
|
|
|
private static class MagicApiaryInventory implements IApiaryInventory {
|
2023-01-29 10:24:49 -08:00
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
public static final int SLOT_QUEEN = 0;
|
|
|
|
|
public static final int SLOT_DRONE = 1;
|
|
|
|
|
public static final int SLOT_FRAME_START = 2;
|
|
|
|
|
public static final int SLOT_FRAME_COUNT = 3;
|
|
|
|
|
public static final int SLOT_PRODUCTS_START = 5;
|
|
|
|
|
public static final int SLOT_PRODUCTS_COUNT = 7;
|
|
|
|
|
|
|
|
|
|
private final TileEntityMagicApiary magicApiary;
|
2023-12-07 16:49:09 +01:00
|
|
|
private final ItemStack[] items;
|
2015-10-01 21:47:53 -07:00
|
|
|
|
|
|
|
|
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) {
|
2022-10-12 21:09:45 +02:00
|
|
|
int countAdded = ItemStackUtils
|
|
|
|
|
.addItemToInventory(magicApiary, product, SLOT_PRODUCTS_START, SLOT_PRODUCTS_COUNT);
|
2015-10-01 21:47:53 -07:00
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
|
return countAdded == product.stackSize;
|
2022-10-12 21:09:45 +02:00
|
|
|
} else {
|
2015-10-01 21:47:53 -07:00
|
|
|
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;
|
|
|
|
|
|
2022-10-12 21:09:45 +02:00
|
|
|
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
2015-10-01 21:47:53 -07:00
|
|
|
itemStack.stackSize = getInventoryStackLimit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side) {
|
|
|
|
|
if (side == 0 || side == 1) {
|
2022-10-12 21:09:45 +02:00
|
|
|
return new int[] { SLOT_QUEEN, SLOT_DRONE };
|
|
|
|
|
} else {
|
2015-10-01 21:47:53 -07:00
|
|
|
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) {
|
2022-10-12 21:09:45 +02:00
|
|
|
if (slot == SLOT_QUEEN && BeeManager.beeRoot.isMember(itemStack)
|
2015-10-01 21:47:53 -07:00
|
|
|
&& !BeeManager.beeRoot.isDrone(itemStack)) {
|
|
|
|
|
return true;
|
2022-10-12 21:09:45 +02:00
|
|
|
} else if (slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack)) {
|
2015-10-01 21:47:53 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return slot == SLOT_DRONE && BeeManager.beeRoot.isDrone(itemStack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
|
2022-10-12 21:09:45 +02:00
|
|
|
switch (slot) {
|
2015-10-01 21:47:53 -07:00
|
|
|
case SLOT_FRAME_START:
|
|
|
|
|
case SLOT_FRAME_START + 1:
|
|
|
|
|
case SLOT_FRAME_START + 2:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-07 18:00:36 +01:00
|
|
|
public void wearOutFrames(IBeeHousing beeHousing, int amount) {
|
2023-12-07 16:49:09 +01:00
|
|
|
IBeekeepingMode beekeepingMode = BeeManager.beeRoot.getBeekeepingMode(magicApiary.getWorldObj());
|
|
|
|
|
int wear = Math.round(amount * beekeepingMode.getWearModifier());
|
|
|
|
|
|
|
|
|
|
for (int i = MagicApiaryInventory.SLOT_FRAME_START; i
|
2023-12-07 18:00:36 +01:00
|
|
|
< MagicApiaryInventory.SLOT_FRAME_START + MagicApiaryInventory.SLOT_FRAME_COUNT; i++) {
|
2023-12-07 16:49:09 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 21:47:53 -07:00
|
|
|
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();
|
2022-10-12 21:09:45 +02:00
|
|
|
item.setByte("Slot", (byte) i);
|
2015-10-01 21:47:53 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
public MagicApiaryBeeModifier(TileEntityMagicApiary magicApiary) {
|
|
|
|
|
this.magicApiary = magicApiary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
|
|
|
|
|
float mod = 1.0f;
|
|
|
|
|
if (magicApiary.isMutationBoosted()) {
|
|
|
|
|
mod = mod * 2f;
|
|
|
|
|
}
|
|
|
|
|
return mod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
|
|
|
|
|
float mod = 1.0f;
|
|
|
|
|
if (magicApiary.isDeathRateBoosted()) {
|
|
|
|
|
mod = mod / 2f;
|
|
|
|
|
}
|
|
|
|
|
return mod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
|
2023-07-14 16:05:06 -04:00
|
|
|
float mod = -0.1f;// was 0.9x, now -0.1
|
2015-10-01 21:47:53 -07:00
|
|
|
if (magicApiary.isProductionBoosted()) {
|
2023-07-18 15:45:18 +00:00
|
|
|
mod = 0.8f;// was 1.8x, now +0.8
|
2015-10-01 21:47:53 -07:00
|
|
|
}
|
|
|
|
|
return mod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
|
|
|
|
|
return 0.8f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-16 20:30:20 +02:00
|
|
|
}
|