mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-23 21:39:51 +00:00
Merge branch 'dev' into 3.6.0
This commit is contained in:
commit
be16bf4491
221 files changed
+4876
-4644
No files matched your search
@@ -36,6 +36,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
private static final int MAX_POLLINATION_ATTEMPTS = 20;
|
||||
private static final int totalBreedingTime = Defaults.APIARY_BREEDING_TIME;
|
||||
private static final int ticksPerCheckCanWork = 10;
|
||||
|
||||
private final IBeeHousing housing;
|
||||
private final boolean housingSupportsMultipleErrorStates;
|
||||
@@ -49,6 +50,12 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
private int attemptedPollinations = 0;
|
||||
private final Stack<ItemStack> spawn = new Stack<ItemStack>();
|
||||
|
||||
// Cached flowers check
|
||||
private boolean hasFlowersCached = false;
|
||||
private int hasFlowersCooldown = 0;
|
||||
private boolean canWorkCached = false;
|
||||
private int canWorkCooldown = 0;
|
||||
|
||||
public BeekeepingLogic(IBeeHousing housing) {
|
||||
this.housing = housing;
|
||||
|
||||
@@ -118,9 +125,19 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
if (canWorkCooldown > 0) {
|
||||
canWorkCooldown--;
|
||||
} else {
|
||||
canWorkCached = checkCanWork();
|
||||
canWorkCooldown = ticksPerCheckCanWork;
|
||||
}
|
||||
return canWorkCached;
|
||||
}
|
||||
|
||||
private boolean checkCanWork() {
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
Set<IErrorState> errorStates = housing.getErrorStates();
|
||||
for (IErrorState errorState : errorStates) {
|
||||
@@ -128,24 +145,72 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
}
|
||||
|
||||
this.queen = null;
|
||||
boolean hasSpace = addPendingProducts();
|
||||
|
||||
if (!addPendingProducts()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tryBreedingPrincess() || !hasHealthyQueen()) {
|
||||
return;
|
||||
if (hasBreedablePrincess()) {
|
||||
return hasSpace;
|
||||
}
|
||||
|
||||
if (!queenCanWork()) {
|
||||
return;
|
||||
if (hasHealthyQueen()) {
|
||||
boolean canWork = queenCanWork();
|
||||
boolean hasFlowers = hasFlowers();
|
||||
return hasSpace && canWork && hasFlowers;
|
||||
}
|
||||
|
||||
queenWorkTick();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork() {
|
||||
if (hasBreedablePrincess()) {
|
||||
tickBreed();
|
||||
} else if (queen != null) {
|
||||
queenWorkTick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (canWork()) {
|
||||
doWork();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasFlowers() {
|
||||
if (queen == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasFlowersCooldown <= 0) {
|
||||
hasFlowersCached = queen.hasFlower(housing);
|
||||
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle / ticksPerCheckCanWork;
|
||||
|
||||
// check more often if we haven't found flowers
|
||||
if (!hasFlowersCached) {
|
||||
hasFlowersCooldown /= 2;
|
||||
}
|
||||
} else {
|
||||
hasFlowersCooldown--;
|
||||
}
|
||||
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
housing.setErrorCondition(!hasFlowersCached, EnumErrorCode.NOFLOWER);
|
||||
} else {
|
||||
if (hasFlowersCached) {
|
||||
housing.setErrorState(EnumErrorCode.OK);
|
||||
} else {
|
||||
housing.setErrorState(EnumErrorCode.NOFLOWER);
|
||||
}
|
||||
}
|
||||
|
||||
return hasFlowersCached;
|
||||
}
|
||||
|
||||
private void queenWorkTick() {
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Effects only fire when queen can work.
|
||||
effectData = queen.doEffect(effectData, housing);
|
||||
|
||||
@@ -154,22 +219,6 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
if (queenWorkCycleThrottle >= PluginApiculture.ticksPerBeeWorkCycle) {
|
||||
queenWorkCycleThrottle = 0;
|
||||
|
||||
boolean hasFlower = queen.hasFlower(housing);
|
||||
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
housing.setErrorCondition(!hasFlower, EnumErrorCode.NOFLOWER);
|
||||
} else {
|
||||
if (hasFlower) {
|
||||
housing.setErrorState(EnumErrorCode.OK);
|
||||
} else {
|
||||
housing.setErrorState(EnumErrorCode.NOFLOWER);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasFlower) {
|
||||
return;
|
||||
}
|
||||
|
||||
doProduction();
|
||||
queen.plantFlowerRandom(housing);
|
||||
doPollination();
|
||||
@@ -181,8 +230,15 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
|
||||
private void doProduction() {
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Produce and add stacks
|
||||
ItemStack[] products = queen.produceStacks(housing);
|
||||
if (products == null) {
|
||||
return;
|
||||
}
|
||||
housing.wearOutEquipment(1);
|
||||
for (ItemStack stack : products) {
|
||||
housing.addProduct(stack, false);
|
||||
@@ -190,6 +246,10 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
|
||||
private void doPollination() {
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get pollen if none available yet
|
||||
if (pollen == null) {
|
||||
pollen = queen.retrievePollen(housing);
|
||||
@@ -209,6 +269,10 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
|
||||
private void updateQueenItemNBT() {
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Write the changed queen back into the item stack.
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
queen.writeToNBT(nbttagcompound);
|
||||
@@ -240,24 +304,32 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
return housingErrorState != EnumErrorCode.NOSPACE;
|
||||
}
|
||||
|
||||
|
||||
/** Checks if a queen is alive. Much faster than reading the whole bee nbt */
|
||||
private static boolean isQueenAlive(ItemStack queenStack) {
|
||||
NBTTagCompound nbtTagCompound = queenStack.getTagCompound();
|
||||
int health = nbtTagCompound.getInteger("Health");
|
||||
return health > 0;
|
||||
}
|
||||
|
||||
private boolean hasHealthyQueen() {
|
||||
boolean hasQueen = true;
|
||||
EnumErrorCode housingErrorState = null;
|
||||
|
||||
if (housing.getQueen() == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
|
||||
ItemStack queenStack = housing.getQueen();
|
||||
|
||||
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
|
||||
housingErrorState = EnumErrorCode.NOQUEEN;
|
||||
hasQueen = false;
|
||||
} else {
|
||||
IBee queen = BeeManager.beeRoot.getMember(housing.getQueen());
|
||||
// Kill dying queens
|
||||
if (!queen.isAlive()) {
|
||||
killQueen(queen);
|
||||
housingErrorState = EnumErrorCode.OK;
|
||||
hasQueen = false;
|
||||
} else {
|
||||
this.queen = queen;
|
||||
queen = null;
|
||||
} else if (!isQueenAlive(queenStack)) {
|
||||
if (queen == null) {
|
||||
queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
}
|
||||
killQueen();
|
||||
housingErrorState = EnumErrorCode.OK;
|
||||
hasQueen = false;
|
||||
queen = null;
|
||||
}
|
||||
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
@@ -268,13 +340,15 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasQueen && queen == null) {
|
||||
queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
}
|
||||
|
||||
return hasQueen;
|
||||
}
|
||||
|
||||
private boolean tryBreedingPrincess() {
|
||||
boolean isBreedingPrincess = false;
|
||||
|
||||
// Princess available? Try to breed!
|
||||
private boolean hasBreedablePrincess() {
|
||||
boolean isBreedingPrincess = false;
|
||||
if (ForestryItem.beePrincessGE.isItemEqual(housing.getQueen())) {
|
||||
boolean hasDrone = ForestryItem.beeDroneGE.isItemEqual(housing.getDrone());
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
@@ -286,7 +360,6 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
housing.setErrorState(EnumErrorCode.NODRONE);
|
||||
}
|
||||
}
|
||||
tickBreed();
|
||||
isBreedingPrincess = true;
|
||||
}
|
||||
|
||||
@@ -294,6 +367,9 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
|
||||
private boolean queenCanWork() {
|
||||
if (queen == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
try {
|
||||
@@ -371,14 +447,15 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!housing.canBreed()) {
|
||||
return false;
|
||||
}
|
||||
return housing.canBreed();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void killQueen(IBee queen) {
|
||||
private void killQueen() {
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (queen.canSpawn()) {
|
||||
spawnOffspring(queen);
|
||||
housing.getQueen().stackSize = 0;
|
||||
|
||||
@@ -59,19 +59,19 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
switch (GuiId.values()[cleanId]) {
|
||||
|
||||
case AlvearyGUI:
|
||||
return new GuiAlveary(player.inventory, (TileAlvearyPlain) getTileForestry(world, x, y, z));
|
||||
return new GuiAlveary(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyPlain.class));
|
||||
|
||||
case AlvearySieveGUI:
|
||||
return new GuiAlvearySieve(player.inventory, (TileAlvearySieve) getTileForestry(world, x, y, z));
|
||||
return new GuiAlvearySieve(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySieve.class));
|
||||
|
||||
case AlvearySwarmerGUI:
|
||||
return new GuiAlvearySwarmer(player.inventory, (TileAlvearySwarmer) getTileForestry(world, x, y, z));
|
||||
return new GuiAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySwarmer.class));
|
||||
|
||||
case ApiaristChestGUI:
|
||||
return getNaturalistChestGui(BeeHelper.UID, player, world, x, y, z, guiData);
|
||||
|
||||
case ApiaryGUI:
|
||||
return new GuiApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z));
|
||||
return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, player, TileApiary.class));
|
||||
|
||||
case BeealyzerGUI:
|
||||
equipped = player.getCurrentEquippedItem();
|
||||
@@ -82,7 +82,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
return new GuiBeealyzer(player, new BeealyzerInventory(player, equipped));
|
||||
|
||||
case BeehouseGUI:
|
||||
return new GuiApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z));
|
||||
return new GuiApiary(player.inventory, getTileForestry(world, x, y, z, player, TileBeehouse.class));
|
||||
|
||||
case HabitatLocatorGUI:
|
||||
equipped = player.getCurrentEquippedItem();
|
||||
@@ -93,7 +93,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
return new GuiHabitatLocator(player, new HabitatLocatorInventory(player, equipped));
|
||||
|
||||
case HygroregulatorGUI:
|
||||
return new GuiAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z));
|
||||
return new GuiAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyHygroregulator.class));
|
||||
|
||||
case ImprinterGUI:
|
||||
equipped = player.getCurrentEquippedItem();
|
||||
@@ -122,20 +122,20 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
|
||||
case AlvearyGUI:
|
||||
synchApiaristTracker(world, player);
|
||||
return new ContainerAlveary(player.inventory, (TileAlvearyPlain) getTileForestry(world, x, y, z));
|
||||
return new ContainerAlveary(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyPlain.class));
|
||||
|
||||
case AlvearySieveGUI:
|
||||
return new ContainerAlvearySieve(player.inventory, (TileAlvearySieve) getTileForestry(world, x, y, z));
|
||||
return new ContainerAlvearySieve(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySieve.class));
|
||||
|
||||
case AlvearySwarmerGUI:
|
||||
return new ContainerAlvearySwarmer(player.inventory, (TileAlvearySwarmer) getTileForestry(world, x, y, z));
|
||||
return new ContainerAlvearySwarmer(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearySwarmer.class));
|
||||
|
||||
case ApiaristChestGUI:
|
||||
return getNaturalistChestContainer(BeeHelper.UID, player, world, x, y, z, guiData);
|
||||
|
||||
case ApiaryGUI:
|
||||
synchApiaristTracker(world, player);
|
||||
return new ContainerApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z), true);
|
||||
return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, player, TileApiary.class), true);
|
||||
|
||||
case BeealyzerGUI:
|
||||
equipped = player.getCurrentEquippedItem();
|
||||
@@ -148,7 +148,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
|
||||
case BeehouseGUI:
|
||||
synchApiaristTracker(world, player);
|
||||
return new ContainerApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z), false);
|
||||
return new ContainerApiary(player.inventory, getTileForestry(world, x, y, z, player, TileBeehouse.class), false);
|
||||
|
||||
case HabitatLocatorGUI:
|
||||
equipped = player.getCurrentEquippedItem();
|
||||
@@ -159,7 +159,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase {
|
||||
return new ContainerHabitatLocator(player, new HabitatLocatorInventory(player, equipped));
|
||||
|
||||
case HygroregulatorGUI:
|
||||
return new ContainerAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z));
|
||||
return new ContainerAlvearyHygroregulator(player.inventory, getTileForestry(world, x, y, z, player, TileAlvearyHygroregulator.class));
|
||||
|
||||
case ImprinterGUI:
|
||||
synchApiaristTracker(world, player);
|
||||
|
||||
Executable → Regular
+29
-10
@@ -11,14 +11,17 @@
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.apiculture.IAlvearyComponent;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.gadgets.BlockStructure.EnumStructureState;
|
||||
import forestry.core.gadgets.StructureLogic;
|
||||
import forestry.core.utils.Schemata;
|
||||
@@ -29,18 +32,19 @@ public class StructureLogicAlveary extends StructureLogic {
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final String UID_ALVEARY = "alveary";
|
||||
public static final Schemata SCHEMATA_ALVEARY = new Schemata("alveary3x3", 5, 6, 5, "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FAAAF",
|
||||
"FAAAF", "FABAF", "FCCCF", "FFFFF", "FFFFF", "FAAAF", "FAAAF", "FBMBF", "FCCCF", "FFFFF", "FFFFF", "FAAAF", "FAAAF", "FABAF", "FCCCF", "FFFFF",
|
||||
public static final Schemata SCHEMATA_ALVEARY = new Schemata("alveary3x3", 5, 6, 5,
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FABAF", "FCCCF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBMBF", "FCCCF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FABAF", "FCCCF", "FFFFF",
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF").setOffsets(-2, -3, -2);
|
||||
|
||||
public static final HashSet<Block> slabBlocks = new HashSet<Block>();
|
||||
private static final Set<Block> slabBlocks = new HashSet<Block>();
|
||||
private static final Set<Integer> slabOreDictIds = new HashSet<Integer>();
|
||||
|
||||
static {
|
||||
slabBlocks.add(Blocks.wooden_slab);
|
||||
slabBlocks.add(ForestryBlock.slabs1.block());
|
||||
slabBlocks.add(ForestryBlock.slabs2.block());
|
||||
slabBlocks.add(ForestryBlock.slabs3.block());
|
||||
slabBlocks.add(ForestryBlock.slabs4.block());
|
||||
int slabWoodId = OreDictionary.getOreID("slabWood");
|
||||
slabOreDictIds.add(slabWoodId);
|
||||
}
|
||||
|
||||
public StructureLogicAlveary(ITileStructure structure) {
|
||||
@@ -100,7 +104,7 @@ public class StructureLogicAlveary extends StructureLogic {
|
||||
}
|
||||
break;
|
||||
case BLOCK_C:
|
||||
if (!slabBlocks.contains(block)) {
|
||||
if (!isWoodSlabBlock(block)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
if ((structureTile.getWorldObj().getBlockMetadata(x, y, z) & 8) != 0) {
|
||||
@@ -127,4 +131,19 @@ public class StructureLogicAlveary extends StructureLogic {
|
||||
return EnumStructureState.VALID;
|
||||
}
|
||||
|
||||
private static boolean isWoodSlabBlock(Block block) {
|
||||
int[] oreIds = OreDictionary.getOreIDs(new ItemStack(block));
|
||||
for (int oreId : oreIds) {
|
||||
if (slabOreDictIds.contains(oreId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return slabBlocks.contains(block);
|
||||
}
|
||||
|
||||
public static void addSlabBlock(Block block) {
|
||||
slabBlocks.add(block);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -31,7 +32,8 @@ import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
@@ -106,24 +108,23 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 2);
|
||||
payload.shortPayload[0] = (short) (isMaster() ? 1 : 0);
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(isMaster);
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
payload.shortPayload[1] = (short) this.masterY;
|
||||
|
||||
return payload;
|
||||
data.writeVarInt(masterY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
if (payload.shortPayload[0] > 0) {
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
if (data.readBoolean()) {
|
||||
makeMaster();
|
||||
}
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
this.masterY = payload.shortPayload[1];
|
||||
masterY = data.readVarInt();
|
||||
}
|
||||
|
||||
/* ITILESTRUCTURE */
|
||||
@@ -145,6 +146,10 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon
|
||||
if (getInternalInventory() instanceof FakeInventoryAdapter) {
|
||||
createInventory();
|
||||
}
|
||||
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,17 +10,23 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.apiculture.IAlvearyComponent;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.core.interfaces.IActivatable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyHandler {
|
||||
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyHandler, IActivatable {
|
||||
|
||||
public static class ClimateControl {
|
||||
|
||||
@@ -41,6 +47,9 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
private final int textureOff;
|
||||
private final int textureOn;
|
||||
|
||||
// CLIENT
|
||||
private boolean active;
|
||||
|
||||
public TileAlvearyClimatiser(ClimateControl control, int textureOff, int textureOn, int componentBlockMeta) {
|
||||
super(componentBlockMeta);
|
||||
this.climateControl = control;
|
||||
@@ -59,8 +68,6 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
return;
|
||||
}
|
||||
|
||||
boolean wasInactive = (workingTime == 0);
|
||||
|
||||
if (workingTime < 20 && energyManager.consumeEnergyToDoWork()) {
|
||||
// consume 10 RF per tick of work
|
||||
workingTime += energyManager.getEnergyPerWork() / 10;
|
||||
@@ -74,9 +81,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
}
|
||||
}
|
||||
|
||||
if ((wasInactive && workingTime > 0) || (!wasInactive && workingTime == 0)) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
setActive(workingTime > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +92,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
/* TEXTURES */
|
||||
@Override
|
||||
public int getIcon(int side, int metadata) {
|
||||
if (workingTime > 0) {
|
||||
if (active) {
|
||||
return textureOn;
|
||||
} else {
|
||||
return textureOff;
|
||||
@@ -100,6 +105,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
super.readFromNBT(nbttagcompound);
|
||||
energyManager.readFromNBT(nbttagcompound);
|
||||
workingTime = nbttagcompound.getInteger("Heating");
|
||||
setActive(workingTime > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,22 +115,37 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
nbttagcompound.setInteger("Heating", workingTime);
|
||||
}
|
||||
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
short workingTime = payload.shortPayload[0];
|
||||
if (this.workingTime != workingTime) {
|
||||
this.workingTime = workingTime;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
payload.shortPayload[0] = (short) workingTime;
|
||||
return payload;
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
setActive(data.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
if (this.active == active) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.active = active;
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
} else {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyHandler */
|
||||
|
||||
@@ -127,17 +127,14 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
||||
}
|
||||
}
|
||||
|
||||
if (!updateOnInterval(20)) {
|
||||
return;
|
||||
if (updateOnInterval(20)) {
|
||||
IInventoryAdapter canInventory = getInternalInventory();
|
||||
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (canInventory.getStackInSlot(0) != null) {
|
||||
FluidHelper.drainContainers(tankManager, canInventory, 0);
|
||||
}
|
||||
}
|
||||
|
||||
IInventoryAdapter canInventory = getInternalInventory();
|
||||
|
||||
// Check if we have suitable items waiting in the item slot
|
||||
if (canInventory.getStackInSlot(0) != null) {
|
||||
FluidHelper.drainContainers(tankManager, canInventory, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -39,27 +39,28 @@ import forestry.api.core.IErrorState;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.apiculture.gui.ContainerAlveary;
|
||||
import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.interfaces.IActivatable;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.interfaces.IErrorSource;
|
||||
import forestry.core.interfaces.IHintSource;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketInventoryStack;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IBeeHousing, IClimatised, IHintSource {
|
||||
public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IBeeHousing, IClimatised, IHintSource, IActivatable {
|
||||
|
||||
// / CONSTANTS
|
||||
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_PRODUCTION_COUNT = 7;
|
||||
public static final int SLOT_PRODUCT_COUNT = 7;
|
||||
public static final int BLOCK_META = 0;
|
||||
|
||||
// / MEMBERS
|
||||
@@ -67,8 +68,12 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
protected BiomeGenBase biome;
|
||||
protected float tempChange = 0.0f;
|
||||
protected float humidChange = 0.0f;
|
||||
|
||||
// CLIENT
|
||||
private boolean active;
|
||||
private int displayHealthMax = 0;
|
||||
private int displayHealth = 0;
|
||||
private IBee displayQueen;
|
||||
|
||||
public TileAlvearyPlain() {
|
||||
super(0);
|
||||
@@ -90,7 +95,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
}
|
||||
|
||||
private void setBiomeInformation() {
|
||||
this.biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||
this.biome = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord);
|
||||
}
|
||||
|
||||
/* LOADING & SAVING */
|
||||
@@ -118,6 +123,43 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
if (active) {
|
||||
ItemStack queen = getStackInSlot(SLOT_QUEEN);
|
||||
data.writeItemStack(queen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
active = data.readBoolean();
|
||||
if (active) {
|
||||
ItemStack queen = data.readItemStack();
|
||||
setInventorySlotContents(SLOT_QUEEN, queen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
if (this.active == active) {
|
||||
return;
|
||||
}
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void initialize() {
|
||||
@@ -136,65 +178,33 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return;
|
||||
}
|
||||
|
||||
beekeepingLogic.update();
|
||||
boolean canWork = beekeepingLogic.canWork();
|
||||
setActive(canWork);
|
||||
if (canWork) {
|
||||
beekeepingLogic.doWork();
|
||||
}
|
||||
|
||||
// Equalize humidity and temperature
|
||||
equalizeTemperature();
|
||||
equalizeHumidity();
|
||||
|
||||
IBee queen = beekeepingLogic.getQueen();
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add swarm effects
|
||||
if (updateOnInterval(200)) {
|
||||
ISidedInventory inventory = getStructureInventory();
|
||||
if (inventory != null) {
|
||||
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasErrorState()) {
|
||||
queen.doFX(beekeepingLogic.getEffectData(), this);
|
||||
|
||||
if (updateOnInterval(50)) {
|
||||
float f = xCoord + 0.5F;
|
||||
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
|
||||
float f2 = zCoord + 0.5F;
|
||||
float f3 = 0.52F;
|
||||
float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
|
||||
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateClientSide() {
|
||||
if (isMaster() && active && (displayQueen != null) && updateOnInterval(2)) {
|
||||
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
|
||||
|
||||
if (!isMaster()) {
|
||||
return;
|
||||
}
|
||||
if (updateOnInterval(50)) {
|
||||
float fxX = xCoord + 0.5F;
|
||||
float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F;
|
||||
float fxZ = zCoord + 0.5F;
|
||||
float f3 = 1.6F;
|
||||
float f4 = worldObj.rand.nextFloat() * f3 - 0.5F;
|
||||
|
||||
if (hasErrorState()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateOnInterval(2)) {
|
||||
ISidedInventory inventory = getStructureInventory();
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// / Multiplayer FX
|
||||
ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN);
|
||||
if (BeeManager.beeRoot.isMated(queenStack)) {
|
||||
IBee displayQueen = BeeManager.beeRoot.getMember(queenStack);
|
||||
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,32 +233,26 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
|
||||
/* STATE INFORMATION */
|
||||
private int getHealthDisplay() {
|
||||
IInventory inventory = getStructureInventory();
|
||||
if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) {
|
||||
if (displayQueen == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BeeManager.beeRoot.isMated(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth();
|
||||
} else if (!BeeManager.beeRoot.isDrone(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return displayHealth;
|
||||
if (displayQueen.getMate() != null) {
|
||||
return displayQueen.getHealth();
|
||||
} else {
|
||||
return 0;
|
||||
return displayHealth;
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxHealthDisplay() {
|
||||
IInventory inventory = getStructureInventory();
|
||||
if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) {
|
||||
if (displayQueen == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BeeManager.beeRoot.isMated(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth();
|
||||
} else if (!BeeManager.beeRoot.isDrone(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return displayHealthMax;
|
||||
if (displayQueen.getMate() != null) {
|
||||
return displayQueen.getMaxHealth();
|
||||
} else {
|
||||
return 0;
|
||||
return displayHealthMax;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,6 +283,8 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
super.onStructureReset();
|
||||
modifiers.clear();
|
||||
eventHandlers.clear();
|
||||
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
/* IALVEARYCOMPONENT */
|
||||
@@ -307,7 +313,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
|
||||
@Override
|
||||
public void addTemperatureChange(float change, float boundaryDown, float boundaryUp) {
|
||||
float temperature = biome.temperature;
|
||||
float temperature = biome.getFloatTemperature(xCoord, yCoord, zCoord);
|
||||
tempChange = Math.min(boundaryUp - temperature, Math.max(boundaryDown - temperature, tempChange + change));
|
||||
}
|
||||
|
||||
@@ -348,6 +354,33 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
setInventorySlotContents(SLOT_QUEEN, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotIndex, int amount) {
|
||||
ItemStack itemStack = super.decrStackSize(slotIndex, amount);
|
||||
if (slotIndex == SLOT_QUEEN) {
|
||||
handleQueenChange();
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) {
|
||||
super.setInventorySlotContents(slotIndex, itemStack);
|
||||
if (slotIndex == SLOT_QUEEN) {
|
||||
handleQueenChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleQueenChange() {
|
||||
if (!Proxies.common.isSimulating(worldObj)) {
|
||||
TileAlvearyPlain master = (TileAlvearyPlain) getCentralTE();
|
||||
if (master != null) {
|
||||
ItemStack itemStack = getStackInSlot(SLOT_QUEEN);
|
||||
master.displayQueen = BeeManager.beeRoot.getMember(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrone(ItemStack itemstack) {
|
||||
setInventorySlotContents(SLOT_DRONE, itemstack);
|
||||
@@ -360,7 +393,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
if (BiomeHelper.isBiomeHellish(biome) && tempChange >= 0) {
|
||||
if (isHellish() && tempChange >= 0) {
|
||||
return EnumTemperature.HELLISH;
|
||||
}
|
||||
|
||||
@@ -443,7 +476,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return false;
|
||||
}
|
||||
|
||||
return InvTools.tryAddStack(inventory, product, SLOT_PRODUCT_1, inventory.getSizeInventory() - SLOT_PRODUCT_1, all);
|
||||
return InvTools.tryAddStack(inventory, product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -468,9 +501,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
|
||||
zCoord);
|
||||
|
||||
for (IBeeListener eventHandler : eventHandlers) {
|
||||
eventHandler.onQueenChange(queenStack);
|
||||
}
|
||||
@@ -545,6 +575,10 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
|
||||
@Override
|
||||
public boolean isHellish() {
|
||||
if (BiomeHelper.isBiomeHellish(biome)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IBeeModifier modifier : modifiers) {
|
||||
if (modifier.isHellish()) {
|
||||
return true;
|
||||
@@ -634,7 +668,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
return biome.temperature + this.tempChange;
|
||||
return biome.getFloatTemperature(xCoord, yCoord, zCoord) + this.tempChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -653,16 +687,10 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return Config.hints.get("alveary");
|
||||
}
|
||||
|
||||
/* IOWNABLE */
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IHousing */
|
||||
@Override
|
||||
public GameProfile getOwnerName() {
|
||||
return this.getOwnerProfile();
|
||||
return this.getOwner();
|
||||
}
|
||||
|
||||
private static class AlvearyInventoryAdapter extends TileInventoryAdapter<TileAlvearyPlain> {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -25,23 +26,27 @@ import forestry.api.apiculture.IAlvearyComponent;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.apiculture.worldgen.Hive;
|
||||
import forestry.apiculture.worldgen.HiveDecorator;
|
||||
import forestry.apiculture.worldgen.HiveDescriptionSwarmer;
|
||||
import forestry.core.interfaces.IActivatable;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory, IActivatable {
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final int BLOCK_META = 2;
|
||||
|
||||
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
|
||||
private boolean isActive;
|
||||
private boolean active;
|
||||
|
||||
public TileAlvearySwarmer() {
|
||||
super(BLOCK_META);
|
||||
@@ -59,12 +64,12 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
super.updateServerSide();
|
||||
|
||||
if (pendingSpawns.size() > 0) {
|
||||
setIsActive(true);
|
||||
setActive(true);
|
||||
if (updateOnInterval(1000)) {
|
||||
trySpawnSwarm();
|
||||
}
|
||||
} else {
|
||||
setIsActive(false);
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
if (!updateOnInterval(500)) {
|
||||
@@ -143,30 +148,24 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
}
|
||||
}
|
||||
|
||||
private void setIsActive(boolean isActive) {
|
||||
if (this.isActive != isActive) {
|
||||
this.isActive = isActive;
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
/* NETWORK */
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
boolean act = payload.shortPayload[0] > 0;
|
||||
if (this.isActive != act) {
|
||||
this.isActive = act;
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
boolean active = data.readBoolean();
|
||||
if (this.active != active) {
|
||||
this.active = active;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
payload.shortPayload[0] = (short) (isActive ? 1 : 0);
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
@@ -179,7 +178,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
return BlockAlveary.BOTTOM;
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
if (active) {
|
||||
return BlockAlveary.ALVEARY_SWARMER_ON;
|
||||
} else {
|
||||
return BlockAlveary.ALVEARY_SWARMER_OFF;
|
||||
@@ -217,6 +216,24 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
if (this.active == active) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
private static class SwarmerInventoryAdapter extends TileInventoryAdapter<TileAlvearySwarmer> {
|
||||
public SwarmerInventoryAdapter(TileAlvearySwarmer alvearySwarmer) {
|
||||
super(alvearySwarmer, 4, "SwarmInv");
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -33,24 +34,21 @@ import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.apiculture.network.PacketActiveUpdate;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.IActivatable;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketInventoryStack;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised, IActivatable {
|
||||
// CONSTANTS
|
||||
public static final int SLOT_QUEEN = 0;
|
||||
public static final int SLOT_DRONE = 1;
|
||||
@@ -58,10 +56,15 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
public static final int SLOT_PRODUCT_COUNT = 7;
|
||||
public static final int SLOT_FRAMES_1 = 9;
|
||||
public static final int SLOT_FRAMES_COUNT = 3;
|
||||
|
||||
private final IBeekeepingLogic logic;
|
||||
private BiomeGenBase biome;
|
||||
|
||||
// CLIENT
|
||||
private boolean active;
|
||||
private int displayHealthMax = 0;
|
||||
private int displayHealth = 0;
|
||||
private IBee displayQueen;
|
||||
|
||||
public TileBeehouse() {
|
||||
setHints(Config.hints.get("apiary"));
|
||||
@@ -92,7 +95,26 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
int biomeId = nbttagcompound.getInteger("BiomeId");
|
||||
biome = BiomeGenBase.getBiome(biomeId);
|
||||
logic.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
if (active) {
|
||||
ItemStack queen = getStackInSlot(SLOT_QUEEN);
|
||||
data.writeItemStack(queen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
active = data.readBoolean();
|
||||
if (active) {
|
||||
ItemStack queen = data.readItemStack();
|
||||
setInventorySlotContents(SLOT_QUEEN, queen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,7 +136,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromBiome(biome);
|
||||
return EnumTemperature.getFromBiome(biome, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +166,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
return biome.temperature;
|
||||
return biome.getFloatTemperature(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,30 +177,30 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateClientSide() {
|
||||
if (isActive() && (displayQueen != null) && updateOnInterval(4)) {
|
||||
displayQueen.doFX(logic.getEffectData(), this);
|
||||
|
||||
// / Multiplayer FX
|
||||
if (BeeManager.beeRoot.isMated(getInternalInventory().getStackInSlot(SLOT_QUEEN))) {
|
||||
if (!hasErrorState() && updateOnInterval(2)) {
|
||||
IBee displayQueen = BeeManager.beeRoot.getMember(getInternalInventory().getStackInSlot(SLOT_QUEEN));
|
||||
displayQueen.doFX(logic.getEffectData(), this);
|
||||
if (updateOnInterval(50)) {
|
||||
float fxX = xCoord + 0.5F;
|
||||
float fxY = yCoord + 0.25F + (worldObj.rand.nextFloat() * 6F) / 16F;
|
||||
float fxZ = zCoord + 0.5F;
|
||||
float f3 = 0.6F;
|
||||
float f4 = worldObj.rand.nextFloat() * f3 - 0.5F;
|
||||
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX - f3), fxY, (fxZ + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f3), fxY, (fxZ + f4), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ - f3), 0F, 0F, 0F);
|
||||
Proxies.common.addEntitySwarmFX(worldObj, (fxX + f4), fxY, (fxZ + f3), 0F, 0F, 0F);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
logic.update();
|
||||
|
||||
IBee queen = logic.getQueen();
|
||||
if (queen == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add swarm effects
|
||||
if (updateOnInterval(200)) {
|
||||
onQueenChange(getInternalInventory().getStackInSlot(SLOT_QUEEN));
|
||||
boolean canWork = logic.canWork();
|
||||
setActive(canWork);
|
||||
if (canWork) {
|
||||
logic.doWork();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,43 +217,30 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
/* NETWORK SYNCH */
|
||||
@Override
|
||||
public void onQueenChange(ItemStack queenStack) {
|
||||
if (!Proxies.common.isSimulating(worldObj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
|
||||
zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketTileUpdate(this), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
private int getHealthDisplay() {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.getStackInSlot(SLOT_QUEEN) == null) {
|
||||
if (displayQueen == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth();
|
||||
} else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return displayHealth;
|
||||
if (displayQueen.getMate() != null) {
|
||||
return displayQueen.getHealth();
|
||||
} else {
|
||||
return 0;
|
||||
return displayHealth;
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxHealthDisplay() {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
if (inventory.getStackInSlot(SLOT_QUEEN) == null) {
|
||||
if (displayQueen == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return BeeManager.beeRoot.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth();
|
||||
} else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN))) {
|
||||
return displayHealthMax;
|
||||
if (displayQueen.getMate() != null) {
|
||||
return displayQueen.getMaxHealth();
|
||||
} else {
|
||||
return 0;
|
||||
return displayHealthMax;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +257,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
|
||||
public void updateBiome() {
|
||||
if (worldObj != null) {
|
||||
BiomeGenBase biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||
BiomeGenBase biome = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord);
|
||||
if (biome != null) {
|
||||
this.biome = biome;
|
||||
}
|
||||
@@ -318,6 +327,30 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
setInventorySlotContents(SLOT_QUEEN, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotIndex, int amount) {
|
||||
ItemStack itemStack = super.decrStackSize(slotIndex, amount);
|
||||
if (slotIndex == SLOT_QUEEN) {
|
||||
handleQueenChange();
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) {
|
||||
super.setInventorySlotContents(slotIndex, itemStack);
|
||||
if (slotIndex == SLOT_QUEEN) {
|
||||
handleQueenChange();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleQueenChange() {
|
||||
if (!Proxies.common.isSimulating(worldObj)) {
|
||||
ItemStack itemStack = getStackInSlot(SLOT_QUEEN);
|
||||
displayQueen = BeeManager.beeRoot.getMember(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrone(ItemStack itemstack) {
|
||||
setInventorySlotContents(SLOT_DRONE, itemstack);
|
||||
@@ -408,7 +441,24 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
/* IHousing */
|
||||
@Override
|
||||
public GameProfile getOwnerName() {
|
||||
return this.getOwnerProfile();
|
||||
return this.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active) {
|
||||
if (this.active == active) {
|
||||
return;
|
||||
}
|
||||
this.active = active;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
|
||||
}
|
||||
}
|
||||
|
||||
protected static class BeehouseInventoryAdapter extends TileInventoryAdapter<TileBeehouse> {
|
||||
|
||||
@@ -37,8 +37,7 @@ public class AlleleEffectGlacial extends AlleleEffectThrottled {
|
||||
return storedData;
|
||||
}
|
||||
|
||||
BiomeGenBase biome = housing.getBiome();
|
||||
EnumTemperature temp = EnumTemperature.getFromBiome(biome);
|
||||
EnumTemperature temp = housing.getTemperature();
|
||||
|
||||
switch (temp) {
|
||||
case HELLISH:
|
||||
|
||||
@@ -38,8 +38,7 @@ public class AlleleEffectSnowing extends AlleleEffectThrottled {
|
||||
return storedData;
|
||||
}
|
||||
|
||||
BiomeGenBase biome = housing.getBiome();
|
||||
EnumTemperature temp = EnumTemperature.getFromBiome(biome);
|
||||
EnumTemperature temp = housing.getTemperature();
|
||||
|
||||
switch (temp) {
|
||||
case HELLISH:
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -246,7 +245,7 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
World world = housing.getWorld();
|
||||
BiomeGenBase biome = housing.getBiome();
|
||||
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
Set<IErrorState> errorStates = new HashSet<IErrorState>();
|
||||
|
||||
// / Rain needs tolerant flyers
|
||||
if (world.isRaining() && !genome.getTolerantFlyer() && BiomeHelper.canRainOrSnow(biome) && !housing.isSealed()) {
|
||||
@@ -281,7 +280,7 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
errorStates.add(EnumErrorCode.INVALIDBIOME);
|
||||
}
|
||||
|
||||
return errorStates.build();
|
||||
return errorStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -467,10 +466,6 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
|
||||
@Override
|
||||
public ItemStack[] produceStacks(IBeeHousing housing) {
|
||||
if (!hasFlower(housing)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (housing == null) {
|
||||
Proxies.log.warning("Failed to produce in an apiary because the beehousing was null.");
|
||||
return null;
|
||||
@@ -481,7 +476,7 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> products = new ArrayList<ItemStack>();
|
||||
List<ItemStack> products = new ArrayList<ItemStack>();
|
||||
|
||||
IAlleleBeeSpecies primary = genome.getPrimary();
|
||||
IAlleleBeeSpecies secondary = genome.getSecondary();
|
||||
@@ -507,20 +502,17 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
}
|
||||
}
|
||||
|
||||
// We are done if the we are not jubilant.
|
||||
if (!primary.isJubilant(genome, housing) || !secondary.isJubilant(genome, housing)) {
|
||||
return products.toArray(new ItemStack[products.size()]);
|
||||
}
|
||||
|
||||
// / Specialty products
|
||||
for (Map.Entry<ItemStack, Integer> entry : primary.getSpecialty().entrySet()) {
|
||||
if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed) {
|
||||
products.add(entry.getKey().copy());
|
||||
if (primary.isJubilant(genome, housing) && secondary.isJubilant(genome, housing)) {
|
||||
for (Map.Entry<ItemStack, Integer> entry : primary.getSpecialty().entrySet()) {
|
||||
if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed) {
|
||||
products.add(entry.getKey().copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return genome.getFlowerProvider().affectProducts(housing.getWorld(), this, housing.getXCoord(), housing.getYCoord(), housing.getZCoord(),
|
||||
products.toArray(new ItemStack[products.size()]));
|
||||
ItemStack[] productsArray = products.toArray(new ItemStack[products.size()]);
|
||||
return genome.getFlowerProvider().affectProducts(housing.getWorld(), this, housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), productsArray);
|
||||
}
|
||||
|
||||
/* REPRODUCTION */
|
||||
|
||||
@@ -12,19 +12,24 @@ package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.IAlleleBeeEffect;
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleFloat;
|
||||
import forestry.api.genetics.IAlleleFlowers;
|
||||
import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IFlowerProvider;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.genetics.Chromosome;
|
||||
import forestry.core.genetics.Genome;
|
||||
import forestry.core.genetics.alleles.AlleleArea;
|
||||
import forestry.core.genetics.alleles.AlleleBoolean;
|
||||
@@ -72,6 +77,11 @@ public class BeeGenome extends Genome implements IBeeGenome {
|
||||
|
||||
// NBT RETRIEVAL
|
||||
public static IAlleleBeeSpecies getSpecies(ItemStack itemStack) {
|
||||
IAlleleSpecies species = getSpeciesDirectly(itemStack);
|
||||
if (species instanceof IAlleleBeeSpecies) {
|
||||
return (IAlleleBeeSpecies) species;
|
||||
}
|
||||
|
||||
return (IAlleleBeeSpecies) getActiveAllele(itemStack, EnumBeeChromosome.SPECIES, BeeManager.beeRoot);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,8 +157,8 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBee bee = getMember(stack);
|
||||
return bee.getMate() != null;
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
return nbt != null && nbt.hasKey("Mate");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,16 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IJubilanceProvider;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.vect.Vect;
|
||||
|
||||
public class JubilanceDefault implements IJubilanceProvider {
|
||||
|
||||
@@ -38,24 +34,10 @@ public class JubilanceDefault implements IJubilanceProvider {
|
||||
|
||||
@Override
|
||||
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
|
||||
BiomeGenBase biome = housing.getBiome();
|
||||
|
||||
EnumTemperature temperature = EnumTemperature.getFromBiome(biome);
|
||||
EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);
|
||||
EnumTemperature temperature = housing.getTemperature();
|
||||
EnumHumidity humidity = housing.getHumidity();
|
||||
|
||||
return temperature == species.getTemperature() && humidity == species.getHumidity();
|
||||
|
||||
}
|
||||
|
||||
protected static AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
|
||||
int[] areaAr = genome.getTerritory();
|
||||
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
|
||||
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
|
||||
|
||||
Vect min = new Vect(housing.getXCoord() + offset.x, housing.getYCoord() + offset.y, housing.getZCoord() + offset.z);
|
||||
Vect max = new Vect(housing.getXCoord() + offset.x + area.x, housing.getYCoord() + offset.y + area.y, housing.getZCoord() + offset.z + area.z);
|
||||
|
||||
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.core.vect.Vect;
|
||||
|
||||
/**
|
||||
* Hermits will not produce if there are any other living creatures nearby.
|
||||
@@ -33,4 +34,15 @@ public class JubilanceProviderHermit extends JubilanceDefault {
|
||||
return list.size() <= 0;
|
||||
}
|
||||
|
||||
private static AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
|
||||
int[] areaAr = genome.getTerritory();
|
||||
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
|
||||
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
|
||||
|
||||
Vect min = new Vect(housing.getXCoord() + offset.x, housing.getYCoord() + offset.y, housing.getZCoord() + offset.z);
|
||||
Vect max = new Vect(housing.getXCoord() + offset.x + area.x, housing.getYCoord() + offset.y + area.y, housing.getZCoord() + offset.z + area.z);
|
||||
|
||||
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,8 +23,6 @@ public class ContainerAlveary extends ContainerTile<TileAlvearyPlain> {
|
||||
public ContainerAlveary(InventoryPlayer player, TileAlvearyPlain tile) {
|
||||
super(tile, player, 8, 108);
|
||||
|
||||
tile.sendNetworkUpdate();
|
||||
|
||||
// Queen/Princess
|
||||
this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyPlain.SLOT_QUEEN, 29, 39));
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ public class ContainerApiary extends ContainerTile<TileBeehouse> {
|
||||
public ContainerApiary(InventoryPlayer player, TileBeehouse tile, boolean hasFrames) {
|
||||
super(tile, player, 8, 108);
|
||||
|
||||
tile.sendNetworkUpdate();
|
||||
|
||||
// Queen/Princess
|
||||
this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_QUEEN, 29, 39));
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerImprinter extends ContainerItemInventory<ImprinterInventory> implements IGuiSelectable {
|
||||
@@ -57,50 +57,36 @@ public class ContainerImprinter extends ContainerItemInventory<ImprinterInventor
|
||||
}
|
||||
}
|
||||
|
||||
public void advanceSelection(int index, World world) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 0;
|
||||
sendSelectionChange(payload);
|
||||
public void advanceSelection(int index) {
|
||||
sendSelectionChange(index, 0);
|
||||
}
|
||||
|
||||
public void regressSelection(int index, World world) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 1;
|
||||
sendSelectionChange(payload);
|
||||
}
|
||||
|
||||
private void sendSelectionChange(PacketPayload payload) {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
isNetSynced = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
inventory.setPrimaryIndex(packet.payload.intPayload[0]);
|
||||
inventory.setSecondaryIndex(packet.payload.intPayload[1]);
|
||||
public void regressSelection(int index) {
|
||||
sendSelectionChange(index, 1);
|
||||
}
|
||||
|
||||
public void updateContainer(World world) {
|
||||
if (!isNetSynced && !Proxies.common.isSimulating(world)) {
|
||||
isNetSynced = true;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.IMPRINT_SELECTION_GET));
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketId.IMPRINT_SELECTION_GET));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
private void sendSelectionChange(int index, int advance) {
|
||||
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, advance);
|
||||
Proxies.net.sendToServer(packet);
|
||||
isNetSynced = false;
|
||||
}
|
||||
|
||||
if (packet.payload.intPayload[1] == 0) {
|
||||
if (packet.payload.intPayload[0] == 0) {
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
if (packet.getSecondaryIndex() == 0) {
|
||||
if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.advancePrimary();
|
||||
} else {
|
||||
inventory.advanceSecondary();
|
||||
}
|
||||
|
||||
} else if (packet.payload.intPayload[0] == 0) {
|
||||
} else if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.regressPrimary();
|
||||
} else {
|
||||
inventory.regressSecondary();
|
||||
@@ -108,9 +94,13 @@ public class ContainerImprinter extends ContainerItemInventory<ImprinterInventor
|
||||
}
|
||||
|
||||
public void sendSelection(EntityPlayer player) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = inventory.getPrimaryIndex();
|
||||
payload.intPayload[1] = inventory.getSecondaryIndex();
|
||||
Proxies.net.sendToPlayer(new PacketUpdate(PacketIds.GUI_SELECTION, payload), player);
|
||||
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_SET, inventory.getPrimaryIndex(), inventory.getSecondaryIndex());
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketGuiSelect packetPayload) {
|
||||
inventory.setPrimaryIndex(packetPayload.getPrimaryIndex());
|
||||
inventory.setSecondaryIndex(packetPayload.getSecondaryIndex());
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -36,6 +36,102 @@ import forestry.core.render.TextureManager;
|
||||
|
||||
public class GuiHabitatLocator extends GuiForestry<ContainerHabitatLocator, HabitatLocatorInventory> {
|
||||
|
||||
private final HabitatSlot[] habitatSlots = new HabitatSlot[]{
|
||||
new HabitatSlot(0, "Ocean"), // ocean, beach
|
||||
new HabitatSlot(1, "Plains"),
|
||||
new HabitatSlot(2, "Desert"), // desert, desert hills
|
||||
new HabitatSlot(3, "Forest"), // forest, forestHills, river
|
||||
new HabitatSlot(4, "Jungle"), // jungle, jungleHills
|
||||
new HabitatSlot(5, "Taiga"), // taiga, taigaHills
|
||||
new HabitatSlot(6, "Hills"), // extremeHills, extremeHillsEdge
|
||||
new HabitatSlot(7, "Swamp"),
|
||||
new HabitatSlot(8, "Snow"), // Ice plains, mountains, frozen rivers, frozen oceans
|
||||
new HabitatSlot(9, "Mushroom"),
|
||||
new HabitatSlot(10, "Nether"),
|
||||
new HabitatSlot(11, "End")};
|
||||
private final Map<BiomeDictionary.Type, HabitatSlot> biomeToHabitat = new EnumMap<BiomeDictionary.Type, HabitatSlot>(BiomeDictionary.Type.class);
|
||||
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
||||
public GuiHabitatLocator(EntityPlayer player, HabitatLocatorInventory item) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, item), item);
|
||||
|
||||
xSize = 176;
|
||||
ySize = 184;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
|
||||
if (slot.slot > 5) {
|
||||
x = 18 + (slot.slot - 6) * 20;
|
||||
y = 50;
|
||||
} else {
|
||||
x = 18 + slot.slot * 20;
|
||||
y = 32;
|
||||
}
|
||||
|
||||
slot.setPosition(x, y);
|
||||
this.widgetManager.add(slot);
|
||||
}
|
||||
|
||||
biomeToHabitat.put(BiomeDictionary.Type.OCEAN, habitatSlots[0]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.BEACH, habitatSlots[0]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.PLAINS, habitatSlots[1]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SANDY, habitatSlots[2]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.FOREST, habitatSlots[3]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.RIVER, habitatSlots[3]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.JUNGLE, habitatSlots[4]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.CONIFEROUS, habitatSlots[5]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.MOUNTAIN, habitatSlots[6]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SWAMP, habitatSlots[7]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SNOWY, habitatSlots[8]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.MUSHROOM, habitatSlots[9]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.NETHER, habitatSlots[10]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.END, habitatSlots[11]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
String str = StatCollector.translateToLocal("item.for.habitatLocator.name").toUpperCase();
|
||||
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen"));
|
||||
|
||||
// Set active according to valid biomes.
|
||||
Set<BiomeDictionary.Type> activeBiomeTypes = EnumSet.noneOf(BiomeDictionary.Type.class);
|
||||
|
||||
for (HabitatSlot habitatSlot : habitatSlots) {
|
||||
habitatSlot.isActive = false;
|
||||
}
|
||||
|
||||
for (BiomeGenBase biome : inventory.getBiomesToSearch()) {
|
||||
Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome));
|
||||
}
|
||||
|
||||
for (BiomeDictionary.Type biomeType : activeBiomeTypes) {
|
||||
HabitatSlot habitatSlot = biomeToHabitat.get(biomeType);
|
||||
if (habitatSlot != null) {
|
||||
habitatSlot.isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
slot.draw(startX, startY);
|
||||
}
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
startX = (this.width - this.xSize) / 2;
|
||||
startY = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
public class HabitatSlot extends Widget {
|
||||
|
||||
private final int slot;
|
||||
@@ -84,101 +180,4 @@ public class GuiHabitatLocator extends GuiForestry<ContainerHabitatLocator, Habi
|
||||
|
||||
}
|
||||
|
||||
private final HabitatSlot[] habitatSlots = new HabitatSlot[]{
|
||||
new HabitatSlot(0, "Ocean"), // ocean, beach
|
||||
new HabitatSlot(1, "Plains"),
|
||||
new HabitatSlot(2, "Desert"), // desert, desert hills
|
||||
new HabitatSlot(3, "Forest"), // forest, forestHills, river
|
||||
new HabitatSlot(4, "Jungle"), // jungle, jungleHills
|
||||
new HabitatSlot(5, "Taiga"), // taiga, taigaHills
|
||||
new HabitatSlot(6, "Hills"), // extremeHills, extremeHillsEdge
|
||||
new HabitatSlot(7, "Swamp"),
|
||||
new HabitatSlot(8, "Snow"), // Ice plains, mountains, frozen rivers, frozen oceans
|
||||
new HabitatSlot(9, "Mushroom"),
|
||||
new HabitatSlot(10, "Nether"),
|
||||
new HabitatSlot(11, "End")};
|
||||
private final Map<BiomeDictionary.Type, HabitatSlot> biomeToHabitat = new HashMap<BiomeDictionary.Type, HabitatSlot>();
|
||||
|
||||
private int startX;
|
||||
private int startY;
|
||||
|
||||
public GuiHabitatLocator(EntityPlayer player, HabitatLocatorInventory item) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(player, item), item);
|
||||
|
||||
this.inventory.tryAnalyze();
|
||||
xSize = 176;
|
||||
ySize = 184;
|
||||
|
||||
int x;
|
||||
int y;
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
|
||||
if (slot.slot > 5) {
|
||||
x = 18 + (slot.slot - 6) * 20;
|
||||
y = 50;
|
||||
} else {
|
||||
x = 18 + slot.slot * 20;
|
||||
y = 32;
|
||||
}
|
||||
|
||||
slot.setPosition(x, y);
|
||||
this.widgetManager.add(slot);
|
||||
}
|
||||
|
||||
biomeToHabitat.put(BiomeDictionary.Type.OCEAN, habitatSlots[0]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.BEACH, habitatSlots[0]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.PLAINS, habitatSlots[1]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SANDY, habitatSlots[2]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.FOREST, habitatSlots[3]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.RIVER, habitatSlots[3]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.JUNGLE, habitatSlots[4]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.CONIFEROUS, habitatSlots[5]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.MOUNTAIN, habitatSlots[6]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SWAMP, habitatSlots[7]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.SNOWY, habitatSlots[8]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.MUSHROOM, habitatSlots[9]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.NETHER, habitatSlots[10]);
|
||||
biomeToHabitat.put(BiomeDictionary.Type.END, habitatSlots[11]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
String str = StatCollector.translateToLocal("item.for.habitatLocator.name").toUpperCase();
|
||||
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen"));
|
||||
|
||||
// Set active according to valid biomes.
|
||||
Set<BiomeDictionary.Type> activeBiomeTypes = new HashSet<BiomeDictionary.Type>();
|
||||
|
||||
for (HabitatSlot habitatSlot : habitatSlots) {
|
||||
habitatSlot.isActive = false;
|
||||
}
|
||||
|
||||
for (BiomeGenBase biome : inventory.biomesToSearch) {
|
||||
Collections.addAll(activeBiomeTypes, BiomeDictionary.getTypesForBiome(biome));
|
||||
}
|
||||
|
||||
for (BiomeDictionary.Type biomeType : activeBiomeTypes) {
|
||||
HabitatSlot habitatSlot = biomeToHabitat.get(biomeType);
|
||||
if (habitatSlot != null) {
|
||||
habitatSlot.isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (HabitatSlot slot : habitatSlots) {
|
||||
slot.draw(startX, startY);
|
||||
}
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
startX = (this.width - this.xSize) / 2;
|
||||
startY = (this.height - this.ySize) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -106,9 +106,9 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter, ImprinterInven
|
||||
}
|
||||
|
||||
if (k == 0) {
|
||||
container.advanceSelection(slot, Proxies.common.getRenderWorld());
|
||||
container.advanceSelection(slot);
|
||||
} else {
|
||||
container.regressSelection(slot, Proxies.common.getRenderWorld());
|
||||
container.regressSelection(slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ItemBeeGE extends ItemGE {
|
||||
@Override
|
||||
public int getColourFromSpecies(IAlleleSpecies species, int renderPass) {
|
||||
|
||||
if (species != null && species instanceof IAlleleBeeSpecies) {
|
||||
if (species instanceof IAlleleBeeSpecies) {
|
||||
return species.getIconColour(renderPass);
|
||||
} else {
|
||||
return 0xffffff;
|
||||
|
||||
@@ -39,7 +39,8 @@ public class ItemBeealyzer extends ItemInventoried {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
|
||||
private void tryAnalyze() {
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
// Source slot to analyze empty
|
||||
if (getStackInSlot(SLOT_SPECIMEN) == null) {
|
||||
return;
|
||||
@@ -77,11 +78,6 @@ public class ItemBeealyzer extends ItemInventoried {
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryAnalyze();
|
||||
}
|
||||
|
||||
// / IHINTSOURCE
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
|
||||
@@ -57,107 +57,9 @@ import forestry.core.vect.Vect;
|
||||
|
||||
public class ItemHabitatLocator extends ItemInventoried {
|
||||
|
||||
public static class HabitatLocatorInventory extends ItemInventory implements IErrorSource, IHintSource {
|
||||
|
||||
private static final short SLOT_ENERGY = 2;
|
||||
private static final short SLOT_SPECIMEN = 0;
|
||||
private static final short SLOT_ANALYZED = 1;
|
||||
|
||||
public Set<BiomeGenBase> biomesToSearch = new HashSet<BiomeGenBase>();
|
||||
private final ItemHabitatLocator habitatLocator;
|
||||
|
||||
public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) {
|
||||
super(player, 3, itemstack);
|
||||
this.habitatLocator = (ItemHabitatLocator) itemstack.getItem();
|
||||
}
|
||||
|
||||
private static boolean isEnergy(ItemStack itemstack) {
|
||||
if (itemstack == null || itemstack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
|
||||
}
|
||||
|
||||
public void tryAnalyze() {
|
||||
|
||||
if (getStackInSlot(SLOT_SPECIMEN) != null) {
|
||||
// Requires energy
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrease energy
|
||||
decrStackSize(SLOT_ENERGY, 1);
|
||||
|
||||
setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN));
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
IBee bee = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED));
|
||||
|
||||
// No bee, abort
|
||||
if (bee == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
biomesToSearch = new HashSet<BiomeGenBase>(bee.getSuitableBiomes());
|
||||
habitatLocator.startBiomeSearch(biomesToSearch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryAnalyze();
|
||||
}
|
||||
|
||||
// / IHINTSOURCE
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHints() {
|
||||
return Config.hints.get("habitatlocator");
|
||||
}
|
||||
|
||||
// / IERRORSOURCE
|
||||
@Override
|
||||
public ImmutableSet<IErrorState> getErrorStates() {
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
|
||||
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
|
||||
if (!BeeManager.beeRoot.isMember(specimen)) {
|
||||
errorStates.add(EnumErrorCode.NOTHINGANALYZE);
|
||||
}
|
||||
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
errorStates.add(EnumErrorCode.NOHONEY);
|
||||
}
|
||||
|
||||
return errorStates.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (slotIndex == SLOT_ENERGY) {
|
||||
Item item = itemStack.getItem();
|
||||
return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item();
|
||||
} else if (slotIndex == SLOT_SPECIMEN) {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final String iconName = "forestry:biomefinder";
|
||||
|
||||
private Set<BiomeGenBase> biomesToSearch = new HashSet<BiomeGenBase>();
|
||||
private Set<BiomeGenBase> targetBiomes = new HashSet<BiomeGenBase>();
|
||||
private boolean biomeFound = false;
|
||||
private int searchRadiusIteration = 0;
|
||||
private int searchAngleIteration = 0;
|
||||
@@ -204,13 +106,16 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
list.add(StringUtil.localize("gui.humidity") + ": " + AlleleManager.climateHelper.toDisplay(humidity));
|
||||
}
|
||||
|
||||
public void startBiomeSearch(Set<BiomeGenBase> biomesToSearch) {
|
||||
public void startBiomeSearch(IBee bee, EntityPlayer player) {
|
||||
|
||||
this.biomesToSearch = biomesToSearch;
|
||||
this.targetBiomes = new HashSet<BiomeGenBase>(bee.getSuitableBiomes());
|
||||
this.searchAngleIteration = 0;
|
||||
this.searchRadiusIteration = 0;
|
||||
this.biomeFound = false;
|
||||
this.searchCenter = null;
|
||||
this.searchCenter = new Vect(player);
|
||||
|
||||
BiomeGenBase currentBiome = player.worldObj.getBiomeGenForCoords(searchCenter.x, searchCenter.z);
|
||||
removeInvalidBiomes(currentBiome, targetBiomes);
|
||||
|
||||
// reset the locator coordinates
|
||||
Proxies.common.setHabitatLocatorCoordinates(null, null);
|
||||
@@ -223,14 +128,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.searchCenter == null) {
|
||||
this.searchCenter = new Vect((int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
|
||||
BiomeGenBase currentBiome = world.getBiomeGenForCoords(searchCenter.x, searchCenter.z);
|
||||
removeInvalidBiomes(currentBiome, biomesToSearch);
|
||||
}
|
||||
|
||||
if (biomesToSearch.isEmpty()) {
|
||||
if (targetBiomes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,7 +137,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
return;
|
||||
}
|
||||
|
||||
ChunkCoordinates target = findNearestBiome(player, biomesToSearch);
|
||||
ChunkCoordinates target = findNearestBiome(player, targetBiomes);
|
||||
|
||||
// send an update if we find the biome
|
||||
if (target != null) {
|
||||
@@ -254,7 +152,7 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
final int maxSearchRadiusIterations = 500;
|
||||
final int spacing = 20;
|
||||
|
||||
Vect playerPos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
Vect playerPos = new Vect(player);
|
||||
|
||||
// If we are in a valid spot, we point to ourselves.
|
||||
ChunkCoordinates coordinates = getChunkCoordinates(playerPos, player.worldObj, biomesToSearch);
|
||||
@@ -369,4 +267,105 @@ public class ItemHabitatLocator extends ItemInventoried {
|
||||
biomesToSearch.removeAll(endBiomes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class HabitatLocatorInventory extends ItemInventory implements IErrorSource, IHintSource {
|
||||
|
||||
private static final short SLOT_ENERGY = 2;
|
||||
private static final short SLOT_SPECIMEN = 0;
|
||||
private static final short SLOT_ANALYZED = 1;
|
||||
|
||||
private final ItemHabitatLocator habitatLocator;
|
||||
|
||||
public HabitatLocatorInventory(EntityPlayer player, ItemStack itemstack) {
|
||||
super(player, 3, itemstack);
|
||||
this.habitatLocator = (ItemHabitatLocator) itemstack.getItem();
|
||||
}
|
||||
|
||||
private static boolean isEnergy(ItemStack itemstack) {
|
||||
if (itemstack == null || itemstack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
if (habitatLocator.biomeFound) {
|
||||
return;
|
||||
}
|
||||
} else if (getStackInSlot(SLOT_SPECIMEN) != null) {
|
||||
// Requires energy
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decrease energy
|
||||
decrStackSize(SLOT_ENERGY, 1);
|
||||
|
||||
setInventorySlotContents(SLOT_ANALYZED, getStackInSlot(SLOT_SPECIMEN));
|
||||
setInventorySlotContents(SLOT_SPECIMEN, null);
|
||||
}
|
||||
|
||||
IBee bee = BeeManager.beeRoot.getMember(getStackInSlot(SLOT_ANALYZED));
|
||||
|
||||
// No bee, abort
|
||||
if (bee == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
habitatLocator.startBiomeSearch(bee, player);
|
||||
}
|
||||
|
||||
public Set<BiomeGenBase> getBiomesToSearch() {
|
||||
return habitatLocator.targetBiomes;
|
||||
}
|
||||
|
||||
// / IHINTSOURCE
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHints() {
|
||||
return Config.hints.get("habitatlocator");
|
||||
}
|
||||
|
||||
// / IERRORSOURCE
|
||||
@Override
|
||||
public ImmutableSet<IErrorState> getErrorStates() {
|
||||
if (getStackInSlot(SLOT_ANALYZED) != null) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
|
||||
|
||||
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
|
||||
if (!BeeManager.beeRoot.isMember(specimen)) {
|
||||
errorStates.add(EnumErrorCode.NOTHINGANALYZE);
|
||||
}
|
||||
|
||||
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
|
||||
errorStates.add(EnumErrorCode.NOHONEY);
|
||||
}
|
||||
|
||||
return errorStates.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (slotIndex == SLOT_ENERGY) {
|
||||
Item item = itemStack.getItem();
|
||||
return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item();
|
||||
} else if (slotIndex == SLOT_SPECIMEN) {
|
||||
return BeeManager.beeRoot.isMember(itemStack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,8 +102,8 @@ public class ItemImprinter extends ItemForestry {
|
||||
secondaryIndex = index;
|
||||
}
|
||||
|
||||
private void tryImprint() {
|
||||
|
||||
@Override
|
||||
public void onSlotClick(EntityPlayer player) {
|
||||
ItemStack specimen = getStackInSlot(specimenSlot);
|
||||
if (specimen == null) {
|
||||
return;
|
||||
@@ -132,11 +132,6 @@ public class ItemImprinter extends ItemForestry {
|
||||
setInventorySlotContents(specimenSlot, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tryImprint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "Imprinter";
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* 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.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.IActivatable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketActiveUpdate extends PacketCoordinates {
|
||||
|
||||
private IActivatable activatable;
|
||||
|
||||
public static void onPacketData(DataInputStreamForestry data) throws IOException {
|
||||
new PacketActiveUpdate(data);
|
||||
}
|
||||
|
||||
private PacketActiveUpdate(DataInputStreamForestry data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public <T extends TileForestry & IActivatable> PacketActiveUpdate(T tile) {
|
||||
super(PacketId.TILE_FORESTRY_ACTIVE, tile);
|
||||
this.activatable = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(activatable.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
boolean active = data.readBoolean();
|
||||
|
||||
TileEntity tile = getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof IActivatable) {
|
||||
((IActivatable) tile).setActive(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -18,30 +17,29 @@ import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.apiculture.gui.ContainerImprinter;
|
||||
import forestry.core.interfaces.IPacketHandler;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.IPacketHandler;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketHandlerApiculture implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
public boolean onPacketData(PacketId packetID, DataInputStreamForestry data, EntityPlayer player) throws IOException {
|
||||
|
||||
switch (packetID) {
|
||||
case PacketIds.HABITAT_BIOME_POINTER: {
|
||||
PacketCoordinates packetC = new PacketCoordinates();
|
||||
packetC.readData(data);
|
||||
Proxies.common.setHabitatLocatorCoordinates(player, packetC.getCoordinates());
|
||||
case HABITAT_BIOME_POINTER: {
|
||||
PacketCoordinates packet = new PacketCoordinates(data);
|
||||
Proxies.common.setHabitatLocatorCoordinates(player, packet.getCoordinates());
|
||||
return true;
|
||||
}
|
||||
case PacketIds.IMPRINT_SELECTION_GET: {
|
||||
case IMPRINT_SELECTION_GET: {
|
||||
onImprintSelectionGet(player);
|
||||
return true;
|
||||
}
|
||||
case PacketIds.CANDLE: {
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle();
|
||||
updateCandle.readData(data);
|
||||
case CANDLE: {
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle(data);
|
||||
onCandleUpdate(updateCandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package forestry.apiculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
|
||||
public class PacketUpdateCandle extends PacketCoordinates {
|
||||
|
||||
private int colour;
|
||||
private boolean lit;
|
||||
|
||||
public PacketUpdateCandle() {
|
||||
|
||||
public PacketUpdateCandle(DataInputStreamForestry data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketUpdateCandle(TileCandle tileCandle) {
|
||||
super(PacketIds.CANDLE, tileCandle);
|
||||
super(PacketId.CANDLE, tileCandle);
|
||||
|
||||
colour = tileCandle.getColour();
|
||||
lit = tileCandle.isLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(colour);
|
||||
data.writeBoolean(lit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
colour = data.readInt();
|
||||
lit = data.readBoolean();
|
||||
|
||||
@@ -22,9 +22,9 @@ import forestry.apiculture.render.BeeItemRenderer;
|
||||
import forestry.apiculture.render.EntityBeeFX;
|
||||
import forestry.apiculture.render.ParticleRenderer;
|
||||
import forestry.apiculture.render.RenderBee;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.interfaces.IBlockRenderer;
|
||||
import forestry.core.proxy.ClientProxyRender;
|
||||
import forestry.core.render.RenderAnalyzer;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.plugins.PluginApiculture;
|
||||
@@ -44,7 +44,7 @@ public class ClientProxyApiculture extends ProxyApiculture {
|
||||
|
||||
@Override
|
||||
public void addBeeHiveFX(String icon, World world, double xCoord, double yCoord, double zCoord, int color, int areaX, int areaY, int areaZ) {
|
||||
if (!Config.enableParticleFX) {
|
||||
if (!ClientProxyRender.shouldSpawnParticle(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ClientProxyApiculture extends ProxyApiculture {
|
||||
|
||||
@Override
|
||||
public void addBeeSwarmFX(String icon, World world, double xCoord, double yCoord, double zCoord, int color) {
|
||||
if (!Config.enableParticleFX) {
|
||||
if (!ClientProxyRender.shouldSpawnParticle(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraftforge.common.ChestGenHooks;
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.apiculture.FlowerManager;
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
@@ -328,7 +329,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 {
|
||||
}
|
||||
}
|
||||
|
||||
private IBee getVillageBee(World world, int xCoord, int yCoord, int zCoord) {
|
||||
private static IBee getVillageBee(World world, int xCoord, int yCoord, int zCoord) {
|
||||
|
||||
// Get current biome
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(xCoord, zCoord);
|
||||
@@ -340,10 +341,13 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 {
|
||||
candidates = BeeManager.villageBees[0];
|
||||
}
|
||||
|
||||
EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, xCoord, yCoord, zCoord);
|
||||
EnumHumidity biomeHumidity = EnumHumidity.getFromValue(biome.rainfall);
|
||||
|
||||
// Add bees that can live in this environment
|
||||
ArrayList<IBeeGenome> valid = new ArrayList<IBeeGenome>();
|
||||
List<IBeeGenome> valid = new ArrayList<IBeeGenome>();
|
||||
for (IBeeGenome genome : candidates) {
|
||||
if (checkBiomeHazard(genome, biome.temperature, biome.rainfall)) {
|
||||
if (checkBiomeHazard(genome, biomeTemperature, biomeHumidity)) {
|
||||
valid.add(genome);
|
||||
}
|
||||
}
|
||||
@@ -356,23 +360,11 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 {
|
||||
return BeeManager.beeRoot.getBee(world, valid.get(world.rand.nextInt(valid.size())));
|
||||
}
|
||||
|
||||
private boolean checkBiomeHazard(IBeeGenome genome, float temperature, float humidity) {
|
||||
|
||||
EnumTemperature beeTemperature = genome.getPrimary().getTemperature();
|
||||
EnumTolerance temperatureTolerance = genome.getToleranceTemp();
|
||||
|
||||
Collection<EnumTemperature> toleratedTemperatures = AlleleManager.climateHelper.getToleratedTemperature(beeTemperature, temperatureTolerance);
|
||||
|
||||
if (!toleratedTemperatures.contains(EnumTemperature.getFromValue(temperature))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EnumHumidity beeHumidity = genome.getPrimary().getHumidity();
|
||||
EnumTolerance humidityTolerance = genome.getToleranceHumid();
|
||||
|
||||
Collection<EnumHumidity> toleratedHumidity = AlleleManager.climateHelper.getToleratedHumidity(beeHumidity, humidityTolerance);
|
||||
|
||||
return toleratedHumidity.contains(EnumHumidity.getFromValue(humidity));
|
||||
private static boolean checkBiomeHazard(IBeeGenome genome, EnumTemperature biomeTemperature, EnumHumidity biomeHumidity) {
|
||||
IAlleleBeeSpecies species = genome.getPrimary();
|
||||
return AlleleManager.climateHelper.isWithinLimits(biomeTemperature, biomeHumidity,
|
||||
species.getTemperature(), genome.getToleranceTemp(),
|
||||
species.getHumidity(), genome.getToleranceHumid());
|
||||
}
|
||||
|
||||
protected void fillBoxWith(World world, StructureBoundingBox box, int par3, int par4, int par5, int par6, int par7, int par8, ItemStack buildingBlock,
|
||||
|
||||
Reference in new issue
Block a user