Merge branch 'dev' into 3.6.0

This commit is contained in:
mezz committed 2015-06-19 00:34:41 -07:00
commit be16bf4491
221 files changed
+4876 -4644

No files matched your search

+2 -1
View File
@@ -1,4 +1,5 @@
Account;Email;Date;
samtrion;[email protected];2015-01-18
GenuineSounds;[email protected];2015-02-26
airbreather;[email protected];2015-04-10
airbreather;[email protected];2015-04-10
ganymedes01;[email protected];2015-05-27
+1 -1
Submodule lang updated: a626ae3d04...e111b835ad.
@@ -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);
+29 -10
View File
@@ -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,
@@ -1,82 +0,0 @@
/*******************************************************************************
* 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.arboriculture;
import java.io.DataInputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import forestry.arboriculture.gadgets.TileLeaves;
import forestry.arboriculture.gadgets.TileSapling;
import forestry.arboriculture.network.PacketLeaf;
import forestry.arboriculture.network.PacketRipeningUpdate;
import forestry.arboriculture.network.PacketSapling;
import forestry.core.interfaces.IPacketHandler;
import forestry.core.network.PacketIds;
import forestry.core.proxy.Proxies;
public class PacketHandlerArboriculture implements IPacketHandler {
@Override
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
switch (packetID) {
case PacketIds.SAPLING: {
PacketSapling packet = new PacketSapling();
packet.readData(data);
onSaplingPacket(packet);
return true;
}
case PacketIds.LEAF: {
PacketLeaf packet = new PacketLeaf();
packet.readData(data);
onLeafPacket(packet);
return true;
}
case PacketIds.RIPENING_UPDATE: {
PacketRipeningUpdate packet = new PacketRipeningUpdate();
packet.readData(data);
onRipeningUpdate(packet);
return true;
}
}
return false;
}
private void onSaplingPacket(PacketSapling packet) {
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileSapling) {
((TileSapling) tile).fromPacket(packet);
}
}
private void onLeafPacket(PacketLeaf packet) {
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileLeaves) {
((TileLeaves) tile).fromPacket(packet);
}
}
private void onRipeningUpdate(PacketRipeningUpdate packet) {
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileLeaves) {
((TileLeaves) tile).fromRipeningPacket(packet);
}
}
}
@@ -79,7 +79,7 @@ public class BlockArbStairs extends BlockStairs {
ItemStack stack = new ItemStack(this, 1, 0);
NBTTagCompound compound = new NBTTagCompound();
stairs.getType().saveToCompound(compound);
stairs.getWoodType().saveToCompound(compound);
stack.setTagCompound(compound);
StackUtils.dropItemStackAsEntity(stack, world, x, y, z);
}
@@ -122,11 +122,11 @@ public class BlockArbStairs extends BlockStairs {
TileStairs stairs = getStairTile(world, x, y, z);
NBTTagCompound nbttagcompound = new NBTTagCompound();
if (stairs == null || stairs.getType() == null) {
if (stairs == null || stairs.getWoodType() == null) {
return nbttagcompound;
}
stairs.getType().saveToCompound(nbttagcompound);
stairs.getWoodType().saveToCompound(nbttagcompound);
return nbttagcompound;
}
@@ -141,8 +141,8 @@ public class BlockArbStairs extends BlockStairs {
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileStairs stairs = getStairTile(world, x, y, z);
if (stairs != null && stairs.getType() != null) {
return stairs.getType().getPlankIcon();
if (stairs != null && stairs.getWoodType() != null) {
return stairs.getWoodType().getPlankIcon();
} else {
return WoodType.LARCH.getPlankIcon();
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.arboriculture.gadgets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -28,15 +29,15 @@ import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IFruitBearer;
import forestry.api.genetics.IFruitFamily;
import forestry.core.network.ForestryPacket;
import forestry.core.network.INetworkedEntity;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketPayload;
import forestry.core.network.PacketUpdate;
import forestry.arboriculture.network.PacketRipeningUpdate;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruitBearer {
public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamable {
private static final short MAX_MATURITY = 2;
@@ -130,37 +131,11 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
/* NETWORK */
@Override
public Packet getDescriptionPacket() {
return toPacket().getPacket();
}
@Override
public void sendNetworkUpdate() {
Proxies.net.sendNetworkPacket(toPacket(), xCoord, yCoord, zCoord);
return new PacketTileStream(this).getPacket();
}
private void sendNetworkUpdateRipening() {
Proxies.net.sendNetworkPacket(new PacketUpdate(PacketIds.TILE_UPDATE, xCoord, yCoord, zCoord, maturity), xCoord, yCoord, zCoord);
}
private ForestryPacket toPacket() {
PacketPayload payload = new PacketPayload(indices.length, 1);
payload.shortPayload[0] = maturity;
payload.intPayload = indices;
return new PacketUpdate(PacketIds.TILE_UPDATE, xCoord, yCoord, zCoord, payload);
}
@Override
public void fromPacket(ForestryPacket packetRaw) {
PacketUpdate packet = (PacketUpdate) packetRaw;
maturity = packet.payload.shortPayload[0];
if (packet.payload.intPayload != null && packet.payload.intPayload.length > 0) {
indices = packet.payload.intPayload;
}
worldObj.func_147479_m(xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(new PacketRipeningUpdate(this));
}
/* IFRUITBEARER */
@@ -183,7 +158,6 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
return new ArrayList<ItemStack>();
}
Collection<ItemStack> fruits = Arrays.asList(getDrop());
maturity = 0;
sendNetworkUpdateRipening();
@@ -201,4 +175,24 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
sendNetworkUpdateRipening();
}
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeShort(maturity);
data.writeShort(indices.length);
for (int i : indices) {
data.writeInt(i);
}
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
maturity = data.readShort();
int indicesLength = data.readShort();
indices = new int[indicesLength];
for (int i = 0; i < indicesLength; i++) {
indices[i] = data.readInt();
}
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
@@ -12,6 +12,7 @@ package forestry.arboriculture.gadgets;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -33,6 +34,7 @@ import net.minecraftforge.common.EnumPlantType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ILeafTickHandler;
@@ -43,6 +45,7 @@ import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.IErrorState;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IEffectData;
import forestry.api.genetics.IFruitBearer;
import forestry.api.genetics.IFruitFamily;
@@ -52,11 +55,12 @@ import forestry.api.lepidopterology.IButterfly;
import forestry.api.lepidopterology.IButterflyGenome;
import forestry.api.lepidopterology.IButterflyNursery;
import forestry.api.lepidopterology.IButterflyRoot;
import forestry.arboriculture.network.PacketLeaf;
import forestry.arboriculture.network.PacketRipeningUpdate;
import forestry.core.EnumErrorCode;
import forestry.core.genetics.alleles.Allele;
import forestry.core.network.ForestryPacket;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
import forestry.core.utils.GeneticsUtil;
@@ -91,7 +95,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
if (worldObj == null) {
return;
}
biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
biome = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord);
}
/* SAVING & LOADING */
@@ -330,13 +334,11 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
/* NETWORK */
@Override
public Packet getDescriptionPacket() {
return new PacketLeaf(this).getPacket();
return new PacketTileStream(this).getPacket();
}
@Override
public void sendNetworkUpdate() {
PacketLeaf packet = new PacketLeaf(this);
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(new PacketTileStream(this));
}
private void sendNetworkUpdateRipening() {
@@ -347,31 +349,76 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
colourFruits = newColourFruits;
PacketRipeningUpdate ripeningUpdate = new PacketRipeningUpdate(this);
Proxies.net.sendNetworkPacket(ripeningUpdate, xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(ripeningUpdate);
}
private static final short hasFruitFlag = 1;
private static final short isPollinatedFlag = 1 << 1;
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
byte leafState = 0;
boolean hasFruit = hasFruit();
if (isPollinated()) {
leafState |= isPollinatedFlag;
}
if (hasFruit) {
leafState |= hasFruitFlag;
}
data.writeByte(leafState);
if (hasFruit) {
String fruitAlleleUID = getTree().getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).getUID();
int colourFruits = getFruitColour();
data.writeUTF(fruitAlleleUID);
data.writeInt(colourFruits);
}
}
@Override
public void fromPacket(ForestryPacket packetRaw) {
PacketLeaf packet = (PacketLeaf) packetRaw;
public void readData(DataInputStreamForestry data) throws IOException {
isFruitLeaf = packet.isFruitLeaf();
isPollinatedState = packet.isPollinated();
String speciesUID = data.readUTF(); // this is called instead of super.readData, be careful!
colourFruits = packet.getColourFruits();
byte leafState = data.readByte();
isFruitLeaf = (leafState & hasFruitFlag) > 0;
isPollinatedState = (leafState & isPollinatedFlag) > 0;
String fruitAlleleUID = null;
ITree tree = getTree();
if (!packet.matchesTree(tree)) {
ITree newTree = packet.getTree();
if (newTree != null) {
setTree(newTree);
if (isFruitLeaf) {
fruitAlleleUID = data.readUTF();
colourFruits = data.readInt();
}
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
if (fruitAlleleUID != null) {
IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
if (fruitAllele != null) {
treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
}
}
worldObj.func_147479_m(xCoord, yCoord, zCoord);
if (treeTemplate != null) {
ITree tree = PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
if (isPollinatedState) {
tree.mate(tree);
}
setTree(tree);
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
public void fromRipeningPacket(PacketRipeningUpdate packet) {
int newColourFruits = packet.getColourFruits();
int newColourFruits = packet.getValue();
if (newColourFruits == colourFruits) {
return;
}
@@ -465,7 +512,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
}
}
private void attemptButterflySpawn(World world, IButterfly butterfly, double x, double y, double z) {
private static void attemptButterflySpawn(World world, IButterfly butterfly, double x, double y, double z) {
IButterflyRoot butterflyRoot = (IButterflyRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies");
if (butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), x, y + 0.1f, z) != null) {
Proxies.log.finest("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), x, y, z);
@@ -560,6 +607,6 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
return this.getOwner();
}
}
@@ -14,10 +14,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.world.gen.feature.WorldGenerator;
import forestry.api.arboriculture.ITree;
import forestry.arboriculture.network.PacketSapling;
import forestry.core.network.ForestryPacket;
import forestry.core.proxy.Proxies;
import forestry.core.network.PacketTileStream;
import forestry.plugins.PluginArboriculture;
public class TileSapling extends TileTreeContainer {
@@ -67,7 +64,7 @@ public class TileSapling extends TileTreeContainer {
WorldGenerator generator = this.getTree().getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed);
if (generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord)) {
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwnerProfile()).registerBirth(getTree());
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwner()).registerBirth(getTree());
return 2;
}
@@ -76,31 +73,6 @@ public class TileSapling extends TileTreeContainer {
@Override
public Packet getDescriptionPacket() {
return new PacketSapling(this).getPacket();
return new PacketTileStream(this).getPacket();
}
@Override
public void sendNetworkUpdate() {
PacketSapling saplingPacket = new PacketSapling(this);
Proxies.net.sendNetworkPacket(saplingPacket, xCoord, yCoord, zCoord);
}
@Override
public void fromPacket(ForestryPacket packetRaw) {
PacketSapling packet = (PacketSapling) packetRaw;
ITree tree = getTree();
if (packet.matchesTree(tree)) {
return;
}
ITree newTree = packet.getTree();
if (newTree == null) {
return;
}
setTree(newTree);
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
@@ -10,27 +10,29 @@
******************************************************************************/
package forestry.arboriculture.gadgets;
import java.io.IOException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import forestry.arboriculture.WoodType;
import forestry.core.network.ForestryPacket;
import forestry.core.network.INetworkedEntity;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketTileNBT;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
public class TileStairs extends TileEntity implements INetworkedEntity {
public class TileStairs extends TileEntity implements IStreamable {
private WoodType type;
private WoodType woodType;
public WoodType getType() {
return this.type;
public WoodType getWoodType() {
return this.woodType;
}
public void setType(WoodType type) {
this.type = type;
public void setWoodType(WoodType woodType) {
this.woodType = woodType;
sendNetworkUpdate();
}
@@ -40,7 +42,7 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
super.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("WT")) {
type = WoodType.VALUES[nbttagcompound.getShort("WT")];
woodType = WoodType.VALUES[nbttagcompound.getShort("WT")];
}
}
@@ -48,8 +50,8 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (type != null) {
nbttagcompound.setShort("WT", (short) type.ordinal());
if (woodType != null) {
nbttagcompound.setShort("WT", (short) woodType.ordinal());
}
}
@@ -66,19 +68,22 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
/* INETWORKEDENTITY */
@Override
public Packet getDescriptionPacket() {
return new PacketTileNBT(PacketIds.TILE_NBT, this).getPacket();
return new PacketTileStream(this).getPacket();
}
@Override
public void sendNetworkUpdate() {
Proxies.net.sendNetworkPacket(new PacketTileNBT(PacketIds.TILE_NBT, this), xCoord, yCoord, zCoord);
Proxies.net.sendNetworkPacket(new PacketTileStream(this));
}
@Override
public void fromPacket(ForestryPacket packetRaw) {
PacketTileNBT packet = (PacketTileNBT) packetRaw;
this.readFromNBT(packet.getTagCompound());
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeVarInt(woodType.ordinal());
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
int woodTypeOrdinal = data.readVarInt();
woodType = WoodType.values()[woodTypeOrdinal];
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.arboriculture.gadgets;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
@@ -19,17 +21,21 @@ import net.minecraft.tileentity.TileEntity;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.ITree;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.genetics.Tree;
import forestry.core.interfaces.IOwnable;
import forestry.core.network.INetworkedEntity;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.utils.PlayerUtil;
import forestry.plugins.PluginArboriculture;
/**
* This is the base TE class for any block that needs to contain tree genome information.
*
* @author SirSengir
*/
public abstract class TileTreeContainer extends TileEntity implements INetworkedEntity, IOwnable {
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnable {
private ITree containedTree;
@@ -44,7 +50,6 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
if (nbttagcompound.hasKey("owner")) {
owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner"));
}
}
@Override
@@ -61,7 +66,31 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
NBTUtil.func_152460_a(nbt, owner);
nbttagcompound.setTag("owner", nbt);
}
}
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
String speciesUID = "";
ITree tree = getTree();
if (tree != null) {
speciesUID = tree.getIdent();
}
data.writeUTF(speciesUID);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
String speciesUID = data.readUTF();
ITree tree = getTree(speciesUID);
setTree(tree);
}
public static ITree getTree(String speciesUID) {
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
if (treeTemplate == null) {
return null;
}
return PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
}
/* CLIENT INFORMATION */
@@ -102,18 +131,13 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
return true;
}
@Override
public boolean isOwnable() {
return false;
}
@Override
public boolean isOwned() {
return owner != null;
}
@Override
public GameProfile getOwnerProfile() {
public GameProfile getOwner() {
return owner;
}
@@ -47,7 +47,7 @@ public class GrowthProvider implements IGrowthProvider {
return new String[0];
}
protected EnumGrowthConditions getConditionsFromRainfall(World world, int xPos, int yPos, int zPos, float min, float max) {
protected static EnumGrowthConditions getConditionsFromRainfall(World world, int xPos, int yPos, int zPos, float min, float max) {
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(xPos, zPos);
if (biome.rainfall < min || biome.rainfall > max) {
@@ -57,17 +57,18 @@ public class GrowthProvider implements IGrowthProvider {
return EnumGrowthConditions.EXCELLENT;
}
protected EnumGrowthConditions getConditionsFromTemperature(World world, int xPos, int yPos, int zPos, float min, float max) {
protected static EnumGrowthConditions getConditionsFromTemperature(World world, int xPos, int yPos, int zPos, float min, float max) {
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(xPos, zPos);
if (biome.temperature < min || biome.temperature > max) {
float biomeTemperature = biome.getFloatTemperature(xPos, yPos, zPos);
if (biomeTemperature < min || biomeTemperature > max) {
return EnumGrowthConditions.HOSTILE;
}
return EnumGrowthConditions.EXCELLENT;
}
protected EnumGrowthConditions getConditionFromLight(World world, int xPos, int yPos, int zPos) {
protected static EnumGrowthConditions getConditionFromLight(World world, int xPos, int yPos, int zPos) {
int lightvalue = world.getBlockLightValue(xPos, yPos + 1, zPos);
if (lightvalue > 13) {
@@ -93,7 +94,7 @@ public class GrowthProvider implements IGrowthProvider {
* return EnumGrowthConditions.HOSTILE; }
*/
protected boolean hasRoom(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth, int expectedHeight) {
protected static boolean hasRoom(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth, int expectedHeight) {
int offset = (expectedGirth - 1) / 2;
// if(offset <= 0)
@@ -103,7 +104,7 @@ public class GrowthProvider implements IGrowthProvider {
new Vect(-offset + expectedGirth, expectedHeight + 1, -offset + expectedGirth));
}
protected final boolean checkArea(World world, Vect start, Vect area) {
protected static boolean checkArea(World world, Vect start, Vect area) {
for (int x = start.x; x < start.x + area.x; x++) {
for (int y = start.y; y < start.y + area.y; y++) {
for (int z = start.z; z < start.z + area.z; z++) {
@@ -116,7 +117,7 @@ public class GrowthProvider implements IGrowthProvider {
return true;
}
protected boolean hasSufficientSaplings(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth) {
protected static boolean hasSufficientSaplings(ITreeGenome genome, World world, int xPos, int yPos, int zPos, int expectedGirth) {
if (expectedGirth == 1) {
return true;
@@ -25,7 +25,10 @@ public class GrowthProviderTropical extends GrowthProvider {
public EnumGrowthConditions getGrowthConditions(ITreeGenome genome, World world, int xPos, int yPos, int zPos) {
EnumGrowthConditions light = getConditionFromLight(world, xPos, yPos, zPos);
EnumGrowthConditions moisture = getConditionsFromRainfall(world, xPos, yPos, zPos, BiomeGenBase.jungle.rainfall, 2.0f);
EnumGrowthConditions temperature = getConditionsFromTemperature(world, xPos, yPos, zPos, BiomeGenBase.jungle.temperature, BiomeGenBase.desert.temperature - 0.1f);
float jungleTemperature = BiomeGenBase.jungle.getFloatTemperature(xPos, yPos, zPos);
float desertTemperature = BiomeGenBase.desert.getFloatTemperature(xPos, yPos, zPos);
EnumGrowthConditions temperature = getConditionsFromTemperature(world, xPos, yPos, zPos, jungleTemperature, desertTemperature - 0.1f);
EnumSet<EnumGrowthConditions> conditions = EnumSet.of(light, moisture, temperature);
@@ -27,6 +27,7 @@ import forestry.api.arboriculture.IGrowthProvider;
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.genetics.IAlleleFloat;
import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.genetics.Genome;
@@ -45,6 +46,11 @@ public class TreeGenome extends Genome implements ITreeGenome {
// NBT RETRIEVAL
public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) {
IAlleleSpecies species = getSpeciesDirectly(itemStack);
if (species instanceof IAlleleTreeSpecies) {
return (IAlleleTreeSpecies) species;
}
return (IAlleleTreeSpecies) getActiveAllele(itemStack, EnumTreeChromosome.SPECIES, PluginArboriculture.treeInterface);
}
@@ -60,7 +60,7 @@ public class ItemStairs extends ItemForestryBlock {
return false;
}
((TileStairs) tile).setType(type);
((TileStairs) tile).setWoodType(type);
return true;
}
@@ -40,7 +40,8 @@ public class ItemTreealyzer extends ItemInventoried {
return GeneticsUtil.getGeneticEquivalent(itemStack) instanceof ITree;
}
private void tryAnalyze() {
@Override
public void onSlotClick(EntityPlayer player) {
// Source slot to analyze empty
if (getStackInSlot(SLOT_SPECIMEN) == null) {
return;
@@ -83,11 +84,6 @@ public class ItemTreealyzer extends ItemInventoried {
setInventorySlotContents(SLOT_SPECIMEN, null);
}
@Override
public void markDirty() {
tryAnalyze();
}
// / IHINTSOURCE
@Override
public boolean hasHints() {
@@ -0,0 +1,46 @@
/*******************************************************************************
* 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.arboriculture.network;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import forestry.arboriculture.gadgets.TileLeaves;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.IPacketHandler;
import forestry.core.network.PacketId;
import forestry.core.proxy.Proxies;
public class PacketHandlerArboriculture implements IPacketHandler {
@Override
public boolean onPacketData(PacketId packetID, DataInputStreamForestry data, EntityPlayer player) throws IOException {
switch (packetID) {
case RIPENING_UPDATE: {
PacketRipeningUpdate packet = new PacketRipeningUpdate(data);
onRipeningUpdate(packet);
return true;
}
}
return false;
}
private static void onRipeningUpdate(PacketRipeningUpdate packet) {
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileLeaves) {
((TileLeaves) tile).fromRipeningPacket(packet);
}
}
}
@@ -1,105 +0,0 @@
/*******************************************************************************
* 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.arboriculture.network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.ITree;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.gadgets.TileLeaves;
import forestry.core.network.PacketIds;
import forestry.plugins.PluginArboriculture;
public class PacketLeaf extends PacketTreeContainer {
private static final short hasFruitFlag = 1;
private static final short isPollinatedFlag = 1 << 1;
private byte leafState = 0;
private int colourFruits = -1;
private String fruitAlleleUID;
public PacketLeaf() {
}
public PacketLeaf(TileLeaves leaves) {
super(PacketIds.LEAF, leaves);
if (leaves.hasFruit()) {
leafState |= hasFruitFlag;
fruitAlleleUID = leaves.getTree().getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).getUID();
colourFruits = leaves.getFruitColour();
}
if (leaves.isPollinated()) {
leafState |= isPollinatedFlag;
}
}
@Override
public void writeData(DataOutputStream data) throws IOException {
super.writeData(data);
data.writeByte(leafState);
if (isFruitLeaf()) {
data.writeUTF(fruitAlleleUID);
data.writeInt(colourFruits);
}
}
@Override
public void readData(DataInputStream data) throws IOException {
super.readData(data);
leafState = data.readByte();
if (isFruitLeaf()) {
fruitAlleleUID = data.readUTF();
colourFruits = data.readInt();
}
}
public boolean isFruitLeaf() {
return (leafState & hasFruitFlag) > 0;
}
public boolean isPollinated() {
return (leafState & isPollinatedFlag) > 0;
}
public int getColourFruits() {
return colourFruits;
}
@Override
public ITree getTree() {
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
if (treeTemplate == null) {
return null;
}
if (fruitAlleleUID != null) {
IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
if (fruitAllele != null) {
treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
}
}
ITree tree = PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
if (isPollinated()) {
tree.mate(tree);
}
return tree;
}
}
@@ -10,58 +10,46 @@
******************************************************************************/
package forestry.arboriculture.network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import forestry.arboriculture.gadgets.TileFruitPod;
import forestry.arboriculture.gadgets.TileLeaves;
import forestry.core.network.ForestryPacket;
import forestry.core.network.PacketIds;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketId;
public class PacketRipeningUpdate extends ForestryPacket {
public class PacketRipeningUpdate extends PacketCoordinates {
private int colourFruits;
private int posX, posY, posZ;
private int value;
public PacketRipeningUpdate() {
public PacketRipeningUpdate(DataInputStreamForestry data) throws IOException {
super(data);
}
public PacketRipeningUpdate(TileFruitPod fruitPod) {
super(PacketId.RIPENING_UPDATE, fruitPod);
value = fruitPod.getMaturity();
}
public PacketRipeningUpdate(TileLeaves leaves) {
super(PacketIds.RIPENING_UPDATE);
posX = leaves.xCoord;
posY = leaves.yCoord;
posZ = leaves.zCoord;
colourFruits = leaves.getFruitColour();
super(PacketId.RIPENING_UPDATE, leaves);
value = leaves.getFruitColour();
}
@Override
public void writeData(DataOutputStream data) throws IOException {
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeInt(posX);
data.writeInt(posY);
data.writeInt(posZ);
data.writeInt(colourFruits);
data.writeInt(value);
}
@Override
public void readData(DataInputStream data) throws IOException {
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
posX = data.readInt();
posY = data.readInt();
posZ = data.readInt();
colourFruits = data.readInt();
value = data.readInt();
}
public int getColourFruits() {
return colourFruits;
}
public TileEntity getTarget(World world) {
return world.getTileEntity(posX, posY, posZ);
public int getValue() {
return value;
}
}
@@ -1,16 +0,0 @@
package forestry.arboriculture.network;
import forestry.arboriculture.gadgets.TileSapling;
import forestry.core.network.PacketIds;
public class PacketSapling extends PacketTreeContainer {
public PacketSapling() {
}
public PacketSapling(TileSapling sapling) {
super(PacketIds.SAPLING, sapling);
}
}
@@ -1,57 +0,0 @@
package forestry.arboriculture.network;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import forestry.api.arboriculture.ITree;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.gadgets.TileTreeContainer;
import forestry.core.network.PacketCoordinates;
import forestry.plugins.PluginArboriculture;
public class PacketTreeContainer extends PacketCoordinates {
protected String speciesUID = "";
public PacketTreeContainer() {
}
public PacketTreeContainer(int id, TileTreeContainer treeContainer) {
super(id, treeContainer);
ITree tree = treeContainer.getTree();
if (tree != null) {
speciesUID = tree.getIdent();
}
}
@Override
public void writeData(DataOutputStream data) throws IOException {
super.writeData(data);
data.writeUTF(speciesUID);
}
@Override
public void readData(DataInputStream data) throws IOException {
super.readData(data);
speciesUID = data.readUTF();
}
public boolean matchesTree(ITree tree) {
if (tree == null) {
return speciesUID.isEmpty();
} else {
return tree.getIdent().equals(speciesUID);
}
}
public ITree getTree() {
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
if (treeTemplate != null) {
return PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
}
return null;
}
}
@@ -65,7 +65,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
private GameProfile getOwner() {
TileEntity tile = world.getTileEntity(startX, startY, startZ);
if (tile instanceof TileSapling) {
return ((TileSapling) tile).getOwnerProfile();
return ((TileSapling) tile).getOwner();
} else {
return null;
}
@@ -10,12 +10,9 @@
******************************************************************************/
package forestry.core;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@@ -23,7 +20,6 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.core.ErrorStateRegistry;
import forestry.core.interfaces.IOreDictionaryHandler;
import forestry.core.interfaces.IPickupHandler;
import forestry.core.interfaces.ISaveEventHandler;
import forestry.core.render.TextureManager;
@@ -32,11 +28,6 @@ import forestry.plugins.PluginManager;
public class EventHandlerCore {
public EventHandlerCore() {
for (String name : OreDictionary.getOreNames()) {
for (ItemStack ore : OreDictionary.getOres(name)) {
handleOreRegistration(name, ore);
}
}
}
@SubscribeEvent
@@ -54,22 +45,6 @@ public class EventHandlerCore {
}
}
@SubscribeEvent
public void handleOreRegistration(OreDictionary.OreRegisterEvent event) {
if (event.isCanceled()) {
return;
}
handleOreRegistration(event.Name, event.Ore);
}
private void handleOreRegistration(String name, ItemStack ore) {
for (IOreDictionaryHandler handler : PluginManager.dictionaryHandlers) {
handler.onOreRegistration(name, ore);
}
}
@SubscribeEvent
public void handleWorldLoad(WorldEvent.Load event) {
for (ISaveEventHandler handler : PluginManager.saveEventHandlers) {
@@ -100,9 +75,4 @@ public class EventHandlerCore {
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void handleTexturePostmap(TextureStitchEvent.Post event) {
}
}
@@ -37,9 +37,6 @@ import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.config.Version;
import forestry.core.fluids.Fluids;
import forestry.core.gadgets.TileEngine;
import forestry.core.gadgets.TileMachine;
import forestry.core.gadgets.TileMill;
import forestry.core.proxy.Proxies;
import forestry.plugins.PluginManager;
@@ -106,11 +103,6 @@ public class ForestryCore {
// Register gui handler
NetworkRegistry.INSTANCE.registerGuiHandler(basemod, new GuiHandler());
// Register machines
GameRegistry.registerTileEntity(TileMill.class, "forestry.Grower");
GameRegistry.registerTileEntity(TileEngine.class, "forestry.Engine");
GameRegistry.registerTileEntity(TileMachine.class, "forestry.Machine");
PluginManager.runInit();
}
+4 -4
View File
@@ -38,10 +38,10 @@ public class GuiHandler extends GuiHandlerBase {
switch (GuiId.values()[cleanId]) {
case AnalyzerGUI:
return new GuiAnalyzer(player.inventory, (TileAnalyzer) getTileForestry(world, x, y, z));
return new GuiAnalyzer(player.inventory, getTileForestry(world, x, y, z, player, TileAnalyzer.class));
case NaturalistBenchGUI:
return new GuiEscritoire(player, (TileEscritoire) getTileForestry(world, x, y, z));
return new GuiEscritoire(player, getTileForestry(world, x, y, z, player, TileEscritoire.class));
case SolderingIronGUI:
ItemStack equipped = player.getCurrentEquippedItem();
@@ -73,10 +73,10 @@ public class GuiHandler extends GuiHandlerBase {
switch (GuiId.values()[cleanId]) {
case AnalyzerGUI:
return new ContainerAnalyzer(player.inventory, (TileAnalyzer) getTileForestry(world, x, y, z));
return new ContainerAnalyzer(player.inventory, getTileForestry(world, x, y, z, player, TileAnalyzer.class));
case NaturalistBenchGUI:
return new ContainerEscritoire(player, (TileEscritoire) getTileForestry(world, x, y, z));
return new ContainerEscritoire(player, getTileForestry(world, x, y, z, player, TileEscritoire.class));
case SolderingIronGUI:
ItemStack equipped = player.getCurrentEquippedItem();
@@ -25,18 +25,23 @@ import forestry.core.proxy.Proxies;
public abstract class GuiHandlerBase implements IGuiHandler {
public TileForestry getTileForestry(World world, int x, int y, int z) {
public <T extends TileForestry> T getTileForestry(World world, int x, int y, int z, EntityPlayer player, Class<T> tileClass) {
T tileForestry = null;
try {
return (TileForestry) world.getTileEntity(x, y, z);
} catch (Exception ex) {
Proxies.log.warning("Failed to cast a tile entity to a TileForestry at " + x + "/" + y + "/" + z);
tileForestry = tileClass.cast(world.getTileEntity(x, y, z));
} catch (ClassCastException ex) {
Proxies.log.warning("Failed to cast a tile entity to a TileForestry at " + x + '/' + y + '/' + z);
}
return null;
if (tileForestry != null && !world.isRemote) {
tileForestry.sendGuiOpened(player);
}
return tileForestry;
}
public GuiNaturalistInventory getNaturalistChestGui(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) {
TileNaturalistChest tile = (TileNaturalistChest) getTileForestry(world, x, y, z);
TileNaturalistChest tile = getTileForestry(world, x, y, z, player, TileNaturalistChest.class);
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID);
return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistInventory(player.inventory, tile, page, 25), tile, page, 5);
}
@@ -44,7 +49,7 @@ public abstract class GuiHandlerBase implements IGuiHandler {
public ContainerNaturalistInventory getNaturalistChestContainer(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) {
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID);
speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player);
return new ContainerNaturalistInventory(player.inventory, (TileNaturalistChest) getTileForestry(world, x, y, z), page, 25);
return new ContainerNaturalistInventory(player.inventory, getTileForestry(world, x, y, z, player, TileNaturalistChest.class), page, 25);
}
public static int encodeGuiData(int guiId, int data) {
@@ -18,9 +18,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.PacketGuiSelect;
import forestry.core.network.PacketId;
import forestry.core.network.PacketString;
import forestry.core.proxy.Proxies;
public class ContainerSolderingIron extends ContainerItemInventory<SolderingInventory> implements IGuiSelectable {
@@ -46,38 +46,26 @@ public class ContainerSolderingIron extends ContainerItemInventory<SolderingInve
}
public static void advanceSelection(int index) {
PacketPayload payload = new PacketPayload(2, 0, 0);
payload.intPayload[0] = index;
payload.intPayload[1] = 0;
sendSelectionChange(payload);
sendSelectionChange(index, 0);
}
public static void regressSelection(int index) {
PacketPayload payload = new PacketPayload(2, 0, 0);
payload.intPayload[0] = index;
payload.intPayload[1] = 1;
sendSelectionChange(payload);
sendSelectionChange(index, 1);
}
private static void sendSelectionChange(PacketPayload payload) {
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
private static void sendSelectionChange(int index, int advance) {
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, advance);
Proxies.net.sendToServer(packet);
}
@Override
public void setSelection(PacketUpdate packet) {
inventory.setLayout(packet.payload.stringPayload[0]);
}
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
@Override
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
if (packet.payload.intPayload[1] == 0) {
if (packet.payload.intPayload[0] == 0) {
if (packet.getSecondaryIndex() == 0) {
if (packet.getPrimaryIndex() == 0) {
inventory.advanceLayout();
}
} else if (packet.payload.intPayload[0] == 0) {
} else if (packet.getPrimaryIndex() == 0) {
inventory.regressLayout();
}
@@ -85,9 +73,15 @@ public class ContainerSolderingIron extends ContainerItemInventory<SolderingInve
}
public void sendSelection(EntityPlayer player) {
PacketPayload payload = new PacketPayload(0, 0, 1);
payload.stringPayload[0] = inventory.getLayout().getUID();
Proxies.net.sendToPlayer(new PacketUpdate(PacketIds.GUI_SELECTION, payload), player);
PacketString packet = new PacketString(PacketId.GUI_LAYOUT_SELECT, inventory.getLayout().getUID());
Proxies.net.sendToPlayer(packet, player);
}
@Override
public void setSelection(PacketGuiSelect packet) {
}
public void setLayout(String layoutUID) {
inventory.setLayout(layoutUID);
}
}
@@ -164,7 +164,8 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron {
return circuits;
}
public void trySolder() {
@Override
public void onSlotClick(EntityPlayer player) {
if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) {
return;
}
@@ -217,11 +218,6 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron {
return count;
}
@Override
public void markDirty() {
trySolder();
}
@Override
public ImmutableSet<IErrorState> getErrorStates() {
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
@@ -115,7 +115,7 @@ public final class CommandSaveStats extends SubCommand {
}
}
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + "-" + saveHelper.getFileSuffix() + ".log");
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + '-' + saveHelper.getFileSuffix() + ".log");
try {
File folder = file.getParentFile();
if (folder != null && !folder.exists()) {
@@ -100,27 +100,6 @@ public class Defaults {
public static final int DEFINITION_ARBCHEST_META = 0;
// Package Ids
public static final int ID_PACKAGE_MACHINE_FERMENTER = 0;
public static final int ID_PACKAGE_MACHINE_STILL = 1;
public static final int ID_PACKAGE_MACHINE_BOTTLER = 2;
public static final int ID_PACKAGE_MACHINE_RAINTANK = 3;
public static final int ID_PACKAGE_MACHINE_GENERATOR = 4;
public static final int ID_PACKAGE_MACHINE_CARPENTER = 5;
public static final int ID_PACKAGE_MACHINE_MOISTENER = 6;
public static final int ID_PACKAGE_MACHINE_APIARY = 7;
public static final int ID_PACKAGE_MACHINE_CENTRIFUGE = 8;
public static final int ID_PACKAGE_MACHINE_SQUEEZER = 9;
public static final int ID_PACKAGE_MACHINE_ALVEARY = 10;
public static final int ID_PACKAGE_MACHINE_FABRICATOR = 11;
public static final int ID_PACKAGE_MILL_RAINMAKER = 1;
public static final int ID_PACKAGE_MILL_APIARIST_CHEST = 3;
public static final int ID_PACKAGE_MILL_ANALYZER = 4;
public static final int ID_PACKAGE_MILL_MAILBOX = 5;
public static final int ID_PACKAGE_MILL_TRADER = 6;
public static final int ID_PACKAGE_MILL_PHILATELIST = 7;
// Item Ids
public static final int SLOTS_BACKPACK_DEFAULT = 15;
@@ -216,7 +216,7 @@ public class BlockBase extends BlockForestry {
return world.setBlockToAir(x, y, z);
}
if (tile.isOwnable() && !tile.allowsRemoval(player)) {
if (tile.isOwned() && !tile.allowsRemoval(player)) {
return false;
}
@@ -37,7 +37,7 @@ public abstract class BlockForestry extends BlockContainer {
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
IOwnable tile = (IOwnable) world.getTileEntity(x, y, z);
if (!tile.isOwnable() || tile.allowsRemoval(player)) {
if (!tile.isOwned() || tile.allowsRemoval(player)) {
return super.removedByPlayer(world, player, x, y, z);
} else {
return false;
@@ -73,6 +73,11 @@ public class BlockResource extends Block {
return world.getBlockMetadata(x, y, z);
}
@Override
public int damageDropped(int meta) {
return meta;
}
// / CREATIVE INVENTORY
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
+41 -34
View File
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.core.gadgets;
import java.io.IOException;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@@ -20,44 +22,22 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.apiculture.network.PacketActiveUpdate;
import forestry.core.EnumErrorCode;
import forestry.core.TemperatureState;
import forestry.core.config.Defaults;
import forestry.core.network.PacketPayload;
import forestry.core.interfaces.IActivatable;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.proxy.Proxies;
import forestry.core.utils.BlockUtil;
import forestry.energy.EnergyManager;
import cofh.api.energy.IEnergyConnection;
public abstract class Engine extends TileBase implements IEnergyConnection {
public abstract class Engine extends TileBase implements IEnergyConnection, IActivatable {
@Override
public PacketPayload getPacketPayload() {
PacketPayload payload = new PacketPayload(3, 1, 0);
if (this.isActive) {
payload.intPayload[0] = 1;
} else {
payload.intPayload[0] = 0;
}
payload.intPayload[1] = energyManager.toPacketInt();
payload.intPayload[2] = heat;
payload.floatPayload[0] = pistonSpeedServer;
return payload;
}
@Override
public void fromPacketPayload(PacketPayload payload) {
isActive = payload.intPayload[0] > 0;
energyManager.fromPacketInt(payload.intPayload[1]);
heat = payload.intPayload[2];
pistonSpeedServer = payload.floatPayload[0];
}
public boolean isActive = false; // Used for smp.
public boolean active = false; // Used for smp.
/**
* Indicates whether the piston is receding from or approaching the
* combustion chamber
@@ -118,7 +98,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
stagePiston = 0;
progress = 0;
}
} else if (this.isActive) {
} else if (this.active) {
stagePiston = 1;
}
}
@@ -180,13 +160,21 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
}
}
private void setActive(boolean isActive) {
if (this.isActive == isActive) {
@Override
public boolean isActive() {
return active;
}
@Override
public void setActive(boolean active) {
if (this.active == active) {
return;
}
this.active = active;
this.isActive = isActive;
setNeedsNetworkUpdate();
if (!worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
/* INTERACTION */
@@ -296,6 +284,25 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
nbt.setBoolean("ForceCooldown", forceCooldown);
}
/* NETWORK */
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeBoolean(active);
data.writeInt(heat);
data.writeFloat(pistonSpeedServer);
energyManager.writeData(data);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
active = data.readBoolean();
heat = data.readInt();
pistonSpeedServer = data.readFloat();
energyManager.readData(data);
}
/* SMP GUI */
public abstract void getGUINetworkData(int i, int j);
+14 -13
View File
@@ -10,7 +10,10 @@
******************************************************************************/
package forestry.core.gadgets;
import forestry.core.network.PacketPayload;
import java.io.IOException;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
public abstract class Mill extends TileBase {
@@ -34,21 +37,19 @@ public abstract class Mill extends TileBase {
}
@Override
public PacketPayload getPacketPayload() {
PacketPayload payload = new PacketPayload(2, 1, 0);
payload.intPayload[0] = charge;
payload.intPayload[1] = stage;
payload.floatPayload[0] = speed;
return payload;
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeInt(charge);
data.writeFloat(speed);
data.writeInt(stage);
}
@Override
public void fromPacketPayload(PacketPayload payload) {
charge = payload.intPayload[0];
stage = payload.intPayload[1];
speed = payload.floatPayload[0];
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
charge = data.readInt();
speed = data.readFloat();
stage = data.readInt();
}
private void update(boolean isSimulating) {
@@ -10,8 +10,11 @@
******************************************************************************/
package forestry.core.gadgets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import net.minecraft.inventory.IInventory;
@@ -23,14 +26,17 @@ import forestry.api.core.INBTTagable;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Utils;
public class NaturalistGame implements INBTTagable {
public class NaturalistGame implements INBTTagable, IStreamable {
public static final int BOUNTY_MAX = 16;
public static class GameToken implements INBTTagable {
public static class GameToken implements INBTTagable, IStreamable {
private static final String[] OVERLAY_NONE = new String[0];
private static final String[] OVERLAY_FAILED = new String[]{"errors/errored"};
@@ -41,6 +47,10 @@ public class NaturalistGame implements INBTTagable {
protected boolean isProbed = false;
protected boolean isRevealed = false;
public GameToken() {
}
public GameToken(ItemStack tokenStack) {
this.tokenStack = tokenStack;
}
@@ -73,6 +83,23 @@ public class NaturalistGame implements INBTTagable {
}
}
/* NETWORK */
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeBoolean(isFailed);
data.writeBoolean(isProbed);
data.writeBoolean(isRevealed);
data.writeItemStack(tokenStack);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
isFailed = data.readBoolean();
isProbed = data.readBoolean();
isRevealed = data.readBoolean();
tokenStack = data.readItemStack();
}
public boolean isVisible() {
return isRevealed;
}
@@ -163,6 +190,29 @@ public class NaturalistGame implements INBTTagable {
lastUpdate = System.currentTimeMillis();
}
/* NETWORK */
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeBoolean(isEnded);
data.writeInt(bountyLevel);
data.writeLong(lastUpdate);
List<GameToken> gameTokensList = gameTokens == null ? null : Arrays.asList(gameTokens);
data.writeStreamables(gameTokensList);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
isEnded = data.readBoolean();
bountyLevel = data.readInt();
lastUpdate = data.readLong();
List<GameToken> gameTokensList = data.readStreamables(GameToken.class);
if (gameTokensList != null) {
this.gameTokens = gameTokensList.toArray(new GameToken[gameTokensList.size()]);
}
}
/* INTERACTION */
public void initialize(ItemStack specimen) {
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
@@ -174,7 +224,11 @@ public class NaturalistGame implements INBTTagable {
if (boardSize % 2 != 0) {
boardSize = Math.round((float) boardSize / 2) * 2;
}
boardSize = boardSize <= 22 ? boardSize >= 6 ? boardSize : 6 : 22;
if (boardSize > 22) {
boardSize = 22;
} else if (boardSize < 6) {
boardSize = 6;
}
isEnded = false;
bountyLevel = BOUNTY_MAX;
@@ -284,8 +338,9 @@ public class NaturalistGame implements INBTTagable {
continue;
}
gameTokens[tokenIndices[processedTokens]].isProbed = true;
gameTokens[tokenIndices[processedTokens]].isRevealed = true;
GameToken token = gameTokens[tokenIndices[processedTokens]];
token.isProbed = true;
token.isRevealed = true;
processedTokens++;
if (processedTokens >= tokenIndices.length) {
@@ -296,32 +351,34 @@ public class NaturalistGame implements INBTTagable {
lastUpdate = System.currentTimeMillis();
}
public void choose(int tokenIndex) {
public void choose(final int tokenIndex) {
if (isEnded) {
return;
}
if (gameTokens == null || tokenIndex >= gameTokens.length) {
return;
}
if (gameTokens[tokenIndex].isRevealed && !gameTokens[tokenIndex].isProbed) {
GameToken token = gameTokens[tokenIndex];
if (token.isRevealed && !token.isProbed) {
return;
}
hideProbedTokens();
Collection<GameToken> singles = getRevealedSingles(gameTokens[tokenIndex]);
Collection<GameToken> singles = getRevealedSingles(token);
if (singles.size() > 0) {
boolean matched = false;
for (GameToken single : singles) {
if (single.matches(gameTokens[tokenIndex])) {
if (single.matches(token)) {
matched = true;
break;
}
}
if (!matched) {
gameTokens[tokenIndex].isFailed = true;
token.isFailed = true;
}
}
gameTokens[tokenIndex].isRevealed = true;
token.isRevealed = true;
checkGameEnd();
lastUpdate = System.currentTimeMillis();
}
@@ -393,10 +450,7 @@ public class NaturalistGame implements INBTTagable {
ArrayList<GameToken> singles = new ArrayList<GameToken>();
for (GameToken token : gameTokens) {
if (!token.isRevealed) {
continue;
}
if (token == exclude) {
if (!token.isRevealed || token == exclude) {
continue;
}
@@ -420,27 +474,20 @@ public class NaturalistGame implements INBTTagable {
}
/* RETRIEVAL */
public int getBoardSize() {
return gameTokens != null ? gameTokens.length : 0;
}
public int getSampleSize() {
if (gameTokens == null) {
return 0;
}
int samples = gameTokens.length / 4;
return samples >= 2 ? samples : 2;
return Math.max(samples, 2);
}
public GameToken getToken(int index) {
return gameTokens != null ? index < gameTokens.length ? gameTokens[index] : null : null;
}
public void setToken(int index, NBTTagCompound nbttagcompound) {
if (gameTokens == null) {
gameTokens = new GameToken[24];
if (gameTokens != null && index < gameTokens.length) {
return gameTokens[index];
}
gameTokens[index] = new GameToken(nbttagcompound);
return null;
}
}
@@ -10,7 +10,7 @@
******************************************************************************/
package forestry.core.gadgets;
import java.util.HashMap;
import java.util.EnumMap;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -32,7 +32,7 @@ public abstract class StructureLogic implements IStructureLogic {
protected Schemata[] schematas;
protected short activeSchemata = -1;
protected boolean isRotated = false;
protected HashMap<EnumStructureBlock, Integer> metaOnValid = new HashMap<EnumStructureBlock, Integer>();
protected EnumMap<EnumStructureBlock, Integer> metaOnValid = new EnumMap<EnumStructureBlock, Integer>(EnumStructureBlock.class);
public StructureLogic(String uid, ITileStructure structure) {
this.uid = uid;
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core.gadgets;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -38,15 +39,15 @@ import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.Fluids;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.interfaces.IErrorSource;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.inventory.wrappers.IInvSlot;
import forestry.core.inventory.wrappers.InventoryIterator;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.network.PacketPayload;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.GuiUtil;
@@ -197,30 +198,33 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
}
/* Network */
public PacketPayload getPacketPayload() {
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
ItemStack displayStack = getIndividualOnDisplay();
if (displayStack == null) {
return null;
data.writeBoolean(false);
} else {
data.writeBoolean(true);
IIndividual displayIndividual = AlleleManager.alleleRegistry.getIndividual(displayStack);
int type = BeeManager.beeRoot.getType(displayStack).ordinal();
data.writeUTF(displayIndividual.getIdent());
data.writeShort(type);
data.writeShort(displayStack.stackSize);
}
IIndividual displayIndividual = AlleleManager.alleleRegistry.getIndividual(displayStack);
int type = BeeManager.beeRoot.getType(displayStack).ordinal();
PacketPayload payload = new PacketPayload();
payload.stringPayload = new String[1];
payload.shortPayload = new short[2];
payload.stringPayload[0] = displayIndividual.getIdent();
payload.shortPayload[0] = (short) type;
payload.shortPayload[1] = (short) displayStack.stackSize;
return payload;
}
public void fromPacketPayload(PacketPayload payload) {
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
ItemStack newIndividualOnDisplay = null;
if (!payload.isEmpty()) {
String individualUID = payload.stringPayload[0];
int type = payload.shortPayload[0];
int stackSize = payload.shortPayload[1];
if (data.readBoolean()) {
String individualUID = data.readUTF();
int type = data.readShort();
int stackSize = data.readShort();
IAllele[] template = BeeManager.beeRoot.getTemplate(individualUID);
IIndividual individual = BeeManager.beeRoot.templateAsIndividual(template);
@@ -13,31 +13,14 @@ package forestry.core.gadgets;
import net.minecraft.entity.player.EntityPlayer;
import forestry.core.interfaces.IHintSource;
import forestry.core.network.PacketPayload;
import forestry.core.proxy.Proxies;
public abstract class TileBase extends TileForestry implements IHintSource {
@Override
public boolean isOwnable() {
return true;
}
/* UPDATING */
@Override
public void initialize() {
}
/* NETWORK */
@Override
public PacketPayload getPacketPayload() {
return null;
}
@Override
public void fromPacketPayload(PacketPayload payload) {
}
/* INTERACTION */
public abstract void openGui(EntityPlayer player, TileBase tile);
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.core.gadgets;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -24,11 +26,10 @@ import forestry.core.interfaces.ICrafter;
import forestry.core.interfaces.IRenderableMachine;
import forestry.core.inventory.InvTools;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.ForestryPacket;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketTileNBT;
import forestry.core.network.PacketTileUpdate;
import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.GeneticsUtil;
@@ -56,13 +57,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
}
/* SAVING & LOADING */
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
game.writeToNBT(nbttagcompound);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
@@ -70,6 +64,13 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
game.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
game.writeToNBT(nbttagcompound);
}
/* GAME */
public NaturalistGame getGame() {
return game;
@@ -109,19 +110,21 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
}
/* NETWORK */
@Override
public void fromPacket(ForestryPacket packetRaw) {
if (packetRaw instanceof PacketTileUpdate) {
super.fromPacket(packetRaw);
return;
}
PacketTileNBT packet = (PacketTileNBT) packetRaw;
readFromNBT(packet.getTagCompound());
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
game.writeData(data);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
game.readData(data);
}
public void sendBoard(EntityPlayer player) {
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
Proxies.net.sendToPlayer(new PacketTileStream(this), player);
}
@Override
@@ -12,10 +12,12 @@ package forestry.core.gadgets;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
@@ -35,18 +37,22 @@ import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional;
import forestry.api.core.ErrorStateRegistry;
import forestry.api.core.IErrorState;
import forestry.core.config.Config;
import forestry.core.config.Defaults;
import forestry.core.fluids.TankManager;
import forestry.core.interfaces.IErrorSource;
import forestry.core.interfaces.IFilterSlotDelegate;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.interfaces.IRestrictedAccess;
import forestry.core.inventory.FakeInventoryAdapter;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.network.ForestryPacket;
import forestry.core.network.INetworkedEntity;
import forestry.core.network.PacketPayload;
import forestry.core.network.PacketTileUpdate;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketTileGuiOpened;
import forestry.core.network.PacketTileStream;
import forestry.core.proxy.Proxies;
import forestry.core.utils.AdjacentTileCache;
import forestry.core.utils.EnumAccess;
@@ -59,15 +65,17 @@ import buildcraft.api.statements.ITriggerInternal;
import buildcraft.api.statements.ITriggerProvider;
@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
public abstract class TileForestry extends TileEntity implements INetworkedEntity, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate {
public abstract class TileForestry extends TileEntity implements IStreamable, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate {
private static final Random rand = new Random();
protected final AdjacentTileCache tileCache = new AdjacentTileCache(this);
protected boolean isInited = false;
private IInventoryAdapter inventory = FakeInventoryAdapter.instance();
private int tickCount = rand.nextInt(256);
private boolean needsNetworkUpdate = false;
private ForgeDirection orientation = ForgeDirection.WEST;
protected final AdjacentTileCache tileCache = new AdjacentTileCache(this);
protected boolean isInited = false;
public AdjacentTileCache getTileCache() {
return tileCache;
@@ -184,37 +192,84 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
}
@Override
public Packet getDescriptionPacket() {
PacketTileUpdate packet = new PacketTileUpdate(this);
public final Packet getDescriptionPacket() {
PacketTileStream packet = new PacketTileStream(this);
return packet.getPacket();
}
/* INetworkedEntity */
@Override
public void sendNetworkUpdate() {
PacketTileUpdate packet = new PacketTileUpdate(this);
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
public final void sendNetworkUpdate() {
PacketTileStream packet = new PacketTileStream(this);
Proxies.net.sendNetworkPacket(packet);
}
@Override
public void fromPacket(ForestryPacket packetRaw) {
PacketTileUpdate packet = (PacketTileUpdate) packetRaw;
if (orientation != packet.getOrientation()) {
orientation = packet.getOrientation();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeByte(orientation.ordinal());
if (this instanceof ILiquidTankContainer) {
TankManager tankManager = ((ILiquidTankContainer) this).getTankManager();
if (tankManager != null) {
tankManager.writePacketData(data);
}
}
errorStates.clear();
errorStates.addAll(packet.getErrorStates());
owner = packet.getOwner();
access = packet.getAccess();
fromPacketPayload(packet.payload);
}
public abstract PacketPayload getPacketPayload();
public void readData(DataInputStreamForestry data) throws IOException {
orientation = ForgeDirection.getOrientation(data.readByte());
public abstract void fromPacketPayload(PacketPayload payload);
if (this instanceof ILiquidTankContainer) {
TankManager tankManager = ((ILiquidTankContainer) this).getTankManager();
if (tankManager != null) {
tankManager.readPacketData(data);
}
}
}
public final void writeErrorData(DataOutputStreamForestry data) throws IOException {
data.writeShort(errorStates.size());
for (IErrorState errorState : errorStates) {
data.writeShort(errorState.getID());
}
}
public final void readErrorData(DataInputStreamForestry data) throws IOException {
errorStates.clear();
short errorStateCount = data.readShort();
for (int i = 0; i < errorStateCount; i++) {
short errorStateId = data.readShort();
IErrorState errorState = ErrorStateRegistry.getErrorState(errorStateId);
errorStates.add(errorState);
}
}
public final void sendGuiOpened(EntityPlayer player) {
PacketTileGuiOpened packet = new PacketTileGuiOpened(this);
Proxies.net.sendToPlayer(packet, player);
}
public final void writeGuiData(DataOutputStreamForestry data) throws IOException {
writeErrorData(data);
if (owner == null) {
data.writeByte(-1);
} else {
data.writeByte(access.ordinal());
data.writeLong(owner.getId().getMostSignificantBits());
data.writeLong(owner.getId().getLeastSignificantBits());
data.writeUTF(owner.getName());
}
}
public final void readGuiData(DataInputStreamForestry data) throws IOException {
readErrorData(data);
byte accessOrdinal = data.readByte();
if (accessOrdinal >= 0) {
access = EnumAccess.values()[accessOrdinal];
owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
}
}
public void onRemoval() {
}
@@ -233,17 +288,11 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
}
// / REDSTONE INFO
/**
* @return true if tile is activated by redstone current.
*/
public boolean isRedstoneActivated() {
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
// / ORIENTATION
private ForgeDirection orientation = ForgeDirection.WEST;
public ForgeDirection getOrientation() {
return this.orientation;
}
@@ -253,7 +302,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
return;
}
this.orientation = orientation;
this.sendNetworkUpdate();
this.setNeedsNetworkUpdate();
}
protected final void setNeedsNetworkUpdate() {
@@ -265,29 +314,20 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
public final boolean setErrorCondition(boolean condition, IErrorState errorState) {
if (condition) {
if (errorStates.add(errorState)) {
setNeedsNetworkUpdate();
}
errorStates.add(errorState);
} else {
if (errorStates.remove(errorState)) {
setNeedsNetworkUpdate();
}
errorStates.remove(errorState);
}
return condition;
}
@Deprecated
protected final void addErrorState(IErrorState state) {
if (errorStates.add(state)) {
setNeedsNetworkUpdate();
}
errorStates.add(state);
}
@Deprecated
protected final void removeErrorStates() {
if (errorStates.size() > 0) {
setNeedsNetworkUpdate();
}
errorStates.clear();
}
@@ -310,7 +350,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
@Override
public final boolean allowsRemoval(EntityPlayer player) {
return Config.disablePermissions || getAccess() == EnumAccess.SHARED || !isOwnable() || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
return Config.disablePermissions || getAccess() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
}
@Override
@@ -332,18 +372,13 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
return access;
}
@Override
public boolean isOwnable() {
return false;
}
@Override
public boolean isOwned() {
return owner != null;
}
@Override
public GameProfile getOwnerProfile() {
public GameProfile getOwner() {
return owner;
}
@@ -371,14 +406,14 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
int ordinal = (access.ordinal() + 1) % EnumAccess.values().length;
access = EnumAccess.values()[ordinal];
if (!this.worldObj.isRemote) {
sendNetworkUpdate();
}
sendGuiOpened(player);
boolean canPipesConnect = allowsPipeConnections();
if (couldPipesConnect != canPipesConnect) {
// pipes connected to this need to update
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
markDirty();
boolean canPipesConnect = allowsPipeConnections();
if (couldPipesConnect != canPipesConnect) {
// pipes connected to this need to update
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
markDirty();
}
}
return true;
@@ -391,7 +426,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
*/
public String getUnlocalizedName() {
String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.", "");
return blockUnlocalizedName + "." + getBlockMetadata() + ".name";
return blockUnlocalizedName + '.' + getBlockMetadata() + ".name";
}
/* INVENTORY BASICS */
@@ -418,7 +453,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
}
@Override
public final ItemStack decrStackSize(int slotIndex, int amount) {
public ItemStack decrStackSize(int slotIndex, int amount) {
return getInternalInventory().decrStackSize(slotIndex, amount);
}
@@ -428,7 +463,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
}
@Override
public final void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
getInternalInventory().setInventorySlotContents(slotIndex, itemstack);
}
@@ -1,259 +0,0 @@
/*******************************************************************************
* 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.core.gadgets;
import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryBlock;
import forestry.core.interfaces.IClimatised;
import forestry.core.interfaces.IHintSource;
import forestry.core.network.PacketPayload;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumTankLevel;
import forestry.plugins.PluginApiculture;
import forestry.plugins.PluginEnergy;
import forestry.plugins.PluginFactory;
import forestry.plugins.PluginIC2;
import forestry.plugins.PluginMail;
public abstract class TileMachine extends TileForestry implements IClimatised, IHintSource {
public TileMachine() {
}
// / IHINTSOURCE
@Override
public boolean hasHints() {
return false;
}
@Override
public String[] getHints() {
return null;
}
// / ICLIMATISED
@Override
public boolean isClimatized() {
return false;
}
@Override
public EnumTemperature getTemperature() {
return EnumTemperature.NORMAL;
}
@Override
public EnumHumidity getHumidity() {
return EnumHumidity.NORMAL;
}
@Override
public float getExactTemperature() {
return 0;
}
@Override
public float getExactHumidity() {
return 0;
}
// / IOWNABLE
@Override
public boolean isOwnable() {
return true;
}
int oldkind;
NBTTagCompound olddata;
@Override
public void initialize() {
if (!Proxies.common.isSimulating(worldObj)) {
return;
}
if (olddata != null) {
legacyConversion(oldkind, olddata);
}
}
/**
* Read saved data
*/
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
oldkind = nbttagcompound.getInteger("Kind");
olddata = nbttagcompound;
}
private HashMap<Block, HashMap<Integer, MachineDefinition>> definitionMap;
private void createDefinitionMap() {
definitionMap = new HashMap<Block, HashMap<Integer, MachineDefinition>>();
HashMap<Integer, MachineDefinition> machineMap = new HashMap<Integer, MachineDefinition>();
machineMap.put(Defaults.ID_PACKAGE_MACHINE_BOTTLER, PluginFactory.definitionBottler);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_CARPENTER, PluginFactory.definitionCarpenter);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_CENTRIFUGE, PluginFactory.definitionCentrifuge);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_FABRICATOR, PluginFactory.definitionFabricator);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_FERMENTER, PluginFactory.definitionFermenter);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_MOISTENER, PluginFactory.definitionMoistener);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_RAINTANK, PluginFactory.definitionRaintank);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_SQUEEZER, PluginFactory.definitionSqueezer);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_STILL, PluginFactory.definitionStill);
machineMap.put(Defaults.ID_PACKAGE_MACHINE_APIARY, PluginApiculture.definitionApiary);
if (PluginIC2.instance.isAvailable()) {
machineMap.put(Defaults.ID_PACKAGE_MACHINE_GENERATOR, PluginIC2.definitionGenerator);
}
definitionMap.put(ForestryBlock.factoryTESR.block(), machineMap);
HashMap<Integer, MachineDefinition> millMap = new HashMap<Integer, MachineDefinition>();
millMap.put(Defaults.ID_PACKAGE_MILL_MAILBOX, PluginMail.definitionMailbox);
millMap.put(Defaults.ID_PACKAGE_MILL_TRADER, PluginMail.definitionTradestation);
millMap.put(Defaults.ID_PACKAGE_MILL_PHILATELIST, PluginMail.definitionPhilatelist);
millMap.put(Defaults.ID_PACKAGE_MILL_APIARIST_CHEST, PluginApiculture.definitionChest);
millMap.put(Defaults.ID_PACKAGE_MILL_ANALYZER, PluginApiculture.definitionAnalyzer);
millMap.put(Defaults.ID_PACKAGE_MILL_RAINMAKER, PluginFactory.definitionRainmaker);
definitionMap.put(ForestryBlock.factoryPlain.block(), millMap);
HashMap<Integer, MachineDefinition> engineMap = new HashMap<Integer, MachineDefinition>();
engineMap.put(0, PluginEnergy.definitionEngineBronze);
engineMap.put(1, PluginEnergy.definitionEngineCopper);
if (PluginIC2.instance.isAvailable()) {
engineMap.put(2, PluginIC2.definitionEngineTin);
}
definitionMap.put(ForestryBlock.engine.block(), engineMap);
}
private void legacyConversion(int kind, NBTTagCompound nbttagcompound) {
if (definitionMap == null) {
createDefinitionMap();
}
Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
if (!definitionMap.containsKey(block) || !definitionMap.get(block).containsKey(kind)) {
commitSeppuku(block, kind);
return;
}
MachineDefinition definition = definitionMap.get(block).get(kind);
Proxies.log.info("Converting obsolete gadget %s-%s to new '%s' %s-%s", block.getUnlocalizedName(), kind, definition.teIdent, definition.block.getUnlocalizedName(), definition.meta);
Proxies.log.info("Removing old tile entity...");
worldObj.removeTileEntity(xCoord, yCoord, zCoord);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
Proxies.log.info("Setting to new block id...");
worldObj.setBlock(xCoord, yCoord, zCoord, definition.block, definition.meta, Defaults.FLAG_BLOCK_SYNCH);
TileEntity tile = worldObj.getTileEntity(xCoord, yCoord, zCoord);
if (tile == null) {
throw new RuntimeException("Failed to set new block tile entity!");
} else if (tile.getClass() != definition.teClass) {
throw new RuntimeException(String.format("Converted tile entity was '%s' instead of expected '%s'", tile.getClass(), definition.teClass));
}
Proxies.log.info("Refreshing converted tile entity %s with nbt data...", tile.getClass());
if (nbttagcompound.hasKey("Machine")) {
tile.readFromNBT(complementNBT(nbttagcompound, nbttagcompound.getCompoundTag("Machine"), definition));
} else {
tile.readFromNBT(nbttagcompound);
}
}
private NBTTagCompound complementNBT(NBTTagCompound parent, NBTTagCompound inner, MachineDefinition definition) {
inner.setString("id", definition.teIdent);
inner.setInteger("x", this.xCoord);
inner.setInteger("y", this.yCoord);
inner.setInteger("z", this.zCoord);
inner.setInteger("Access", parent.getInteger("Access"));
if (parent.hasKey("Owner")) {
inner.setString("Owner", parent.getString("Owner"));
}
if (parent.hasKey("Orientation")) {
inner.setInteger("Orientation", parent.getInteger("Orientation"));
}
return inner;
}
private void commitSeppuku(Block block, int meta) {
Proxies.log.info("Obsolete gadget %s-%s has no replacement defined. Committing sepukku.", block.getUnlocalizedName(), meta);
worldObj.removeTileEntity(xCoord, yCoord, zCoord);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
/**
* Write save data
*/
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
// Legacy for old fermenter with strange meta data
int kind = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
nbttagcompound.setInteger("Kind", kind);
/*
* if (machine != null) { NBTTagCompound NBTmachine = new NBTTagCompound(); machine.writeToNBT(NBTmachine); nbttagcompound.setTag("Machine",
* NBTmachine); } else { Proxies.log.warning("Saved a " + getClass() + " without machine."); }
*/
}
@Override
public void validate() {
super.validate();
}
public boolean isWorking() {
return false;
}
public static EnumTankLevel rateTankLevel(int scaled) {
if (scaled < 5) {
return EnumTankLevel.EMPTY;
} else if (scaled < 30) {
return EnumTankLevel.LOW;
} else if (scaled < 60) {
return EnumTankLevel.MEDIUM;
} else if (scaled < 90) {
return EnumTankLevel.HIGH;
} else {
return EnumTankLevel.MAXIMUM;
}
}
// INETWORKEDTILE IMPLEMENTATION
@Override
public PacketPayload getPacketPayload() {
return null;
}
@Override
public void fromPacketPayload(PacketPayload payload) {
}
}
@@ -1,14 +0,0 @@
/*******************************************************************************
* 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.core.gadgets;
public class TileMill extends TileMachine {
}
@@ -28,7 +28,7 @@ import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketId;
import forestry.core.network.PacketNBT;
import forestry.core.proxy.Proxies;
@@ -77,7 +77,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
NBTTagCompound nbttagcompound = new NBTTagCompound();
encodeToNBT(nbttagcompound);
Proxies.net.sendToPlayer(new PacketNBT(PacketIds.GENOME_TRACKER_UPDATE, nbttagcompound), player);
Proxies.net.sendToPlayer(new PacketNBT(PacketId.GENOME_TRACKER_UPDATE, nbttagcompound), player);
}
/* HELPER FUNCTIONS TO PREVENT OBFUSCATION OF INTERFACE METHODS */
@@ -19,7 +19,6 @@ import net.minecraft.nbt.NBTTagCompound;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.ILegacyHandler;
import forestry.core.proxy.Proxies;
public class Chromosome implements IChromosome {
@@ -69,7 +68,7 @@ public class Chromosome implements IChromosome {
@Override
public IAllele getActiveAllele() {
if (primary == null || secondary == null) {
Proxies.log.severe("Chromosome is missing alleles");
return null;
}
if (primary.isDominant()) {
return primary;
@@ -51,6 +51,37 @@ public abstract class Genome implements IGenome {
}
// NBT RETRIEVAL
/**
* Quickly gets the species without loading the whole genome.
* We need this because the client uses the species for rendering.
*/
protected static IAlleleSpecies getSpeciesDirectly(ItemStack itemStack) {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null) {
return null;
}
NBTTagCompound genomeNBT = nbtTagCompound.getCompoundTag("Genome");
if (genomeNBT == null) {
return null;
}
NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10);
if (chromosomesNBT == null) {
return null;
}
NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(0);
Chromosome chromosome = Chromosome.loadChromosomeFromNBT(chromosomeNBT);
IAllele activeAllele = chromosome.getActiveAllele();
if (!(activeAllele instanceof IAlleleSpecies)) {
return null;
}
return (IAlleleSpecies) activeAllele;
}
public static IChromosome getChromosome(ItemStack itemStack, IChromosomeType chromosomeType, ISpeciesRoot speciesRoot) {
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound == null) {
@@ -46,7 +46,8 @@ public abstract class Mutation implements IMutationCustom {
this.template = template;
this.chance = chance;
}
@Override
public Collection<String> getSpecialConditions() {
return specialConditions;
}
@@ -31,7 +31,7 @@ public class MutationConditionTemperature implements IMutationCondition {
@Override
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(x, z);
EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome);
EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, x, y, z);
if (biomeTemperature.ordinal() < minTemperature.ordinal() || biomeTemperature.ordinal() > maxTemperature.ordinal()) {
return 0;
@@ -21,7 +21,6 @@ import forestry.api.arboriculture.IAlleleGrowth;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.ILegacyHandler;
import forestry.api.lepidopterology.IAlleleButterflySpecies;
public abstract class Allele implements IAllele {
@@ -199,138 +198,6 @@ public abstract class Allele implements IAllele {
public static final Allele plantTypeNether = new AllelePlantType(EnumPlantType.Nether);
public static final Allele plantTypeCrop = new AllelePlantType(EnumPlantType.Crop);
public static void setupAPI() {
// LEGACY MAPPINGS
ILegacyHandler legacy = (ILegacyHandler) AlleleManager.alleleRegistry;
legacy.registerLegacyMapping(0, "forestry.speciesForest");
legacy.registerLegacyMapping(1, "forestry.speciesMeadows");
legacy.registerLegacyMapping(2, "forestry.speciesCommon");
legacy.registerLegacyMapping(3, "forestry.speciesCultivated");
legacy.registerLegacyMapping(4, "forestry.speciesNoble");
legacy.registerLegacyMapping(5, "forestry.speciesMajestic");
legacy.registerLegacyMapping(6, "forestry.speciesImperial");
legacy.registerLegacyMapping(7, "forestry.speciesDiligent");
legacy.registerLegacyMapping(8, "forestry.speciesUnweary");
legacy.registerLegacyMapping(9, "forestry.speciesIndustrious");
legacy.registerLegacyMapping(10, "forestry.speciesSteadfast");
legacy.registerLegacyMapping(11, "forestry.speciesValiant");
legacy.registerLegacyMapping(12, "forestry.speciesHeroic");
legacy.registerLegacyMapping(13, "forestry.speciesSinister");
legacy.registerLegacyMapping(14, "forestry.speciesFiendish");
legacy.registerLegacyMapping(15, "forestry.speciesDemonic");
legacy.registerLegacyMapping(16, "forestry.speciesModest");
legacy.registerLegacyMapping(17, "forestry.speciesFrugal");
legacy.registerLegacyMapping(18, "forestry.speciesAustere");
legacy.registerLegacyMapping(19, "forestry.speciesTropical");
legacy.registerLegacyMapping(20, "forestry.speciesExotic");
legacy.registerLegacyMapping(21, "forestry.speciesEdenic");
legacy.registerLegacyMapping(22, "forestry.speciesEnded");
legacy.registerLegacyMapping(25, "forestry.speciesWintry");
legacy.registerLegacyMapping(28, "forestry.speciesVindictive");
legacy.registerLegacyMapping(29, "forestry.speciesVengeful");
legacy.registerLegacyMapping(30, "forestry.speciesAvenging");
legacy.registerLegacyMapping(34, "forestry.speciesLeporine");
legacy.registerLegacyMapping(40, "forestry.speciesRural");
legacy.registerLegacyMapping(43, "forestry.speciesMarshy");
// Flowers
legacy.registerLegacyMapping(1500, "forestry.flowersVanilla");
legacy.registerLegacyMapping(1501, "forestry.flowersNether");
legacy.registerLegacyMapping(1502, "forestry.flowersCacti");
legacy.registerLegacyMapping(1503, "forestry.flowersMushrooms");
legacy.registerLegacyMapping(1504, "forestry.flowersEnd");
legacy.registerLegacyMapping(1505, "forestry.flowersJungle");
legacy.registerLegacyMapping(1506, "forestry.flowersSnow");
legacy.registerLegacyMapping(1507, "forestry.flowersWheat");
// Effects
legacy.registerLegacyMapping(1800, "forestry.effectNone");
legacy.registerLegacyMapping(1801, "forestry.effectAggressive");
legacy.registerLegacyMapping(1802, "forestry.effectHeroic");
legacy.registerLegacyMapping(1803, "forestry.effectBeatific");
legacy.registerLegacyMapping(1804, "forestry.effectMiasmic");
legacy.registerLegacyMapping(1805, "forestry.effectMisanthrope");
legacy.registerLegacyMapping(1806, "forestry.effectGlacial");
legacy.registerLegacyMapping(1807, "forestry.effectRadioactive");
legacy.registerLegacyMapping(1808, "forestry.effectCreeper");
legacy.registerLegacyMapping(1809, "forestry.effectIgnition");
legacy.registerLegacyMapping(1810, "forestry.effectExploration");
legacy.registerLegacyMapping(1811, "forestry.effectFestiveEaster");
// Generic
legacy.registerLegacyMapping(1024, "forestry.boolFalse");
legacy.registerLegacyMapping(1025, "forestry.boolTrue");
// Speed
legacy.registerLegacyMapping(1100, "forestry.speedSlowest");
legacy.registerLegacyMapping(1101, "forestry.speedSlower");
legacy.registerLegacyMapping(1102, "forestry.speedSlow");
legacy.registerLegacyMapping(1103, "forestry.speedNorm");
legacy.registerLegacyMapping(1104, "forestry.speedFast");
legacy.registerLegacyMapping(1105, "forestry.speedFaster");
legacy.registerLegacyMapping(1106, "forestry.speedFastest");
// Lifespan
legacy.registerLegacyMapping(1200, "forestry.lifespanShortest");
legacy.registerLegacyMapping(1201, "forestry.lifespanShorter");
legacy.registerLegacyMapping(1202, "forestry.lifespanShort");
legacy.registerLegacyMapping(1203, "forestry.lifespanShortened");
legacy.registerLegacyMapping(1204, "forestry.lifespanNormal");
legacy.registerLegacyMapping(1205, "forestry.lifespanElongated");
legacy.registerLegacyMapping(1206, "forestry.lifespanLong");
legacy.registerLegacyMapping(1207, "forestry.lifespanLonger");
legacy.registerLegacyMapping(1208, "forestry.lifespanLongest");
// Fertility
legacy.registerLegacyMapping(1300, "forestry.fertilityLow");
legacy.registerLegacyMapping(1301, "forestry.fertilityNormal");
legacy.registerLegacyMapping(1302, "forestry.fertilityHigh");
legacy.registerLegacyMapping(1303, "forestry.fertilityMaximum");
// Tolerance
legacy.registerLegacyMapping(1450, "forestry.toleranceNone");
legacy.registerLegacyMapping(1451, "forestry.toleranceBoth1");
legacy.registerLegacyMapping(1452, "forestry.toleranceBoth2");
legacy.registerLegacyMapping(1453, "forestry.toleranceBoth3");
legacy.registerLegacyMapping(1454, "forestry.toleranceBoth4");
legacy.registerLegacyMapping(1455, "forestry.toleranceBoth5");
legacy.registerLegacyMapping(1456, "forestry.toleranceUp1");
legacy.registerLegacyMapping(1457, "forestry.toleranceUp2");
legacy.registerLegacyMapping(1458, "forestry.toleranceUp3");
legacy.registerLegacyMapping(1459, "forestry.toleranceUp4");
legacy.registerLegacyMapping(1460, "forestry.toleranceUp5");
legacy.registerLegacyMapping(1461, "forestry.toleranceDown1");
legacy.registerLegacyMapping(1462, "forestry.toleranceDown2");
legacy.registerLegacyMapping(1463, "forestry.toleranceDown3");
legacy.registerLegacyMapping(1464, "forestry.toleranceDown4");
legacy.registerLegacyMapping(1465, "forestry.toleranceDown5");
// Flower growth
legacy.registerLegacyMapping(1700, "forestry.floweringSlowest");
legacy.registerLegacyMapping(1701, "forestry.floweringSlower");
legacy.registerLegacyMapping(1702, "forestry.floweringSlow");
legacy.registerLegacyMapping(1710, "forestry.floweringMaximum");
// Territory
legacy.registerLegacyMapping(1750, "forestry.territoryDefault");
legacy.registerLegacyMapping(1751, "forestry.territoryLarge");
legacy.registerLegacyMapping(1752, "forestry.territoryLarger");
legacy.registerLegacyMapping(1753, "forestry.territoryLargest");
}
@Override
public String getName() {
return StatCollector.translateToLocal(getUnlocalizedName());
@@ -13,7 +13,6 @@ package forestry.core.genetics.alleles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -30,14 +29,13 @@ import forestry.api.genetics.IClassification;
import forestry.api.genetics.IClassification.EnumClassLevel;
import forestry.api.genetics.IFruitFamily;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ILegacyHandler;
import forestry.api.genetics.IMutation;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.ForestryItem;
import forestry.core.genetics.Classification;
import forestry.core.genetics.ItemResearchNote.EnumNoteType;
public class AlleleRegistry implements IAlleleRegistry, ILegacyHandler {
public class AlleleRegistry implements IAlleleRegistry {
private static final int ALLELE_ARRAY_SIZE = 2048;
@@ -104,11 +102,6 @@ public class AlleleRegistry implements IAlleleRegistry, ILegacyHandler {
private final LinkedHashMap<String, IClassification> classificationMap = new LinkedHashMap<String, IClassification>(128);
private final LinkedHashMap<String, IFruitFamily> fruitMap = new LinkedHashMap<String, IFruitFamily>(64);
private final HashMap<Integer, String> metaMapToUID = new HashMap<Integer, String>();
private final HashMap<String, Integer> uidMapToMeta = new HashMap<String, Integer>();
private final HashMap<Integer, String> legacyMap = new HashMap<Integer, String>();
/*
* Internal HashSet of all alleleHandlers, which trigger when an allele or branch is registered
*/
@@ -225,21 +218,6 @@ public class AlleleRegistry implements IAlleleRegistry, ILegacyHandler {
return fruitMap.get(uid);
}
/* LEGACY MAPPINGS */
@Override
public void registerLegacyMapping(int id, String uid) {
this.legacyMap.put(id, uid);
}
@Override
public IAllele getFromLegacyMap(int id) {
if (!legacyMap.containsKey(id)) {
return null;
}
return getAllele(legacyMap.get(id));
}
/* ALLELE HANDLERS */
@Override
public void registerAlleleHandler(IAlleleHandler handler) {
@@ -72,7 +72,8 @@ public class EnumAllele {
AVERAGE(20),
FAST(25),
FASTER(30),
FASTEST(35);
FASTEST(35),
MAXIMUM(99, true);
private final Integer value;
private final boolean dominant;
@@ -23,10 +23,9 @@ public class ClimateLedger extends Ledger {
private final IClimatised tile;
public ClimateLedger(LedgerManager manager, IClimatised tile) {
super(manager);
super(manager, "climate");
this.tile = tile;
maxHeight = 72;
overlayColor = manager.gui.fontColor.get("ledger.climate.background");
}
@Override
@@ -44,16 +43,13 @@ public class ClimateLedger extends Ledger {
return;
}
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.climate"), x + 22, y + 8,
manager.gui.fontColor.get("ledger.climate.header"));
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.temperature") + ":", x + 22, y + 20,
manager.gui.fontColor.get("ledger.climate.subheader"));
manager.minecraft.fontRenderer.drawString(AlleleManager.climateHelper.toDisplay(temperature) + " " + StringUtil.floatAsPercent(tile.getExactTemperature()), x + 22,
y + 32, manager.gui.fontColor.get("ledger.climate.text"));
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.humidity") + ":", x + 22, y + 44,
manager.gui.fontColor.get("ledger.climate.subheader"));
manager.minecraft.fontRenderer.drawString(AlleleManager.climateHelper.toDisplay(tile.getHumidity()) + " " + StringUtil.floatAsPercent(tile.getExactHumidity()),
x + 22, y + 56, manager.gui.fontColor.get("ledger.climate.text"));
drawHeader(StringUtil.localize("gui.climate"), x + 22, y + 8);
drawSubheader(StringUtil.localize("gui.temperature") + ':', x + 22, y + 20);
drawText(AlleleManager.climateHelper.toDisplay(temperature) + ' ' + StringUtil.floatAsPercent(tile.getExactTemperature()), x + 22, y + 32);
drawSubheader(StringUtil.localize("gui.humidity") + ':', x + 22, y + 44);
drawText(AlleleManager.climateHelper.toDisplay(tile.getHumidity()) + ' ' + StringUtil.floatAsPercent(tile.getExactHumidity()), x + 22, y + 56);
}
@Override
@@ -15,10 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
import forestry.core.gadgets.TileEscritoire;
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.proxy.Proxies;
import forestry.core.network.PacketGuiSelect;
public class ContainerEscritoire extends ContainerTile<TileEscritoire> implements IGuiSelectable {
@@ -32,7 +29,7 @@ public class ContainerEscritoire extends ContainerTile<TileEscritoire> implement
this.player = player;
// Analyze slot
addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(this.tile));
addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(this.tile).setStackLimit(1));
for (int i = 0; i < TileEscritoire.SLOTS_INPUT_COUNT; i++) {
addSlotToContainer(new SlotFiltered(this.tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2"));
@@ -56,35 +53,20 @@ public class ContainerEscritoire extends ContainerTile<TileEscritoire> implement
tile.sendBoard(player);
}
public void sendTokenClick(int index) {
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = index;
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
Proxies.net.sendToServer(packet);
}
public void sendProbeClick() {
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = -1;
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
Proxies.net.sendToServer(packet);
}
@Override
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
if (!tile.getGame().isEnded()) {
int index = packet.payload.intPayload[0];
int index = packet.getPrimaryIndex();
if (index == -1) {
tile.probe();
} else {
tile.getGame().choose(packet.payload.intPayload[0]);
tile.getGame().choose(index);
tile.processTurnResult(player.getGameProfile());
}
}
}
@Override
public void setSelection(PacketUpdate packet) {
public void setSelection(PacketGuiSelect packet) {
}
}
@@ -48,4 +48,12 @@ public abstract class ContainerItemInventory<I extends ItemInventory> extends Co
public final boolean canInteractWith(EntityPlayer entityplayer) {
return inventory.isUseableByPlayer(entityplayer);
}
@Override
public final ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) {
ItemStack result = super.slotClick(slotIndex, button, modifier, player);
inventory.onSlotClick(player);
return result;
}
}
@@ -26,9 +26,8 @@ import forestry.api.core.IToolPipette;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.gadgets.TileForestry;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketPayload;
import forestry.core.network.PacketUpdate;
import forestry.core.network.PacketId;
import forestry.core.network.PacketSlotClick;
import forestry.core.proxy.Proxies;
public class ContainerLiquidTanks<T extends TileForestry & ILiquidTankContainer> extends ContainerTile<T> {
@@ -44,9 +43,7 @@ public class ContainerLiquidTanks<T extends TileForestry & ILiquidTankContainer>
return;
}
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = slot;
Proxies.net.sendToServer(new PacketUpdate(PacketIds.PIPETTE_CLICK, payload));
Proxies.net.sendToServer(new PacketSlotClick(PacketId.PIPETTE_CLICK, tile, slot));
}
public void handlePipetteClick(int slot, EntityPlayerMP player) {
@@ -15,7 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.gadgets.TileNaturalistChest;
import forestry.core.gui.slots.SlotFiltered;
import forestry.core.network.PacketUpdate;
import forestry.core.network.PacketGuiSelect;
public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistChest> implements IGuiSelectable {
@@ -31,11 +31,11 @@ public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistCh
}
@Override
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
tile.flipPage(player, packet.payload.intPayload[0]);
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
tile.flipPage(player, packet.getPrimaryIndex());
}
@Override
public void setSelection(PacketUpdate packet) {
public void setSelection(PacketGuiSelect packet) {
}
}
@@ -13,14 +13,12 @@ package forestry.core.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import forestry.core.gadgets.TileForestry;
import forestry.core.interfaces.ISocketable;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketPayload;
import forestry.core.network.PacketId;
import forestry.core.network.PacketSlotClick;
import forestry.core.network.PacketSocketUpdate;
import forestry.core.network.PacketUpdate;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StackUtils;
@@ -32,9 +30,8 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
public void handleChipsetClick(int slot, EntityPlayer player, ItemStack itemstack) {
if (!Proxies.common.isSimulating(player.worldObj)) {
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = slot;
Proxies.net.sendToServer(new PacketUpdate(PacketIds.CHIPSET_CLICK, payload));
PacketSlotClick packet = new PacketSlotClick(PacketId.CHIPSET_CLICK, tile, slot);
Proxies.net.sendToServer(packet);
player.inventory.setItemStack(null);
return;
}
@@ -50,18 +47,16 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
player.inventory.setItemStack(null);
}
Proxies.net.inventoryChangeNotify(player);
TileEntity te = (TileEntity) tile;
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, te.xCoord, te.yCoord, te.zCoord, tile), player);
}
PacketSocketUpdate packet = new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile);
Proxies.net.sendToPlayer(packet, player);
}
}
public void handleSolderingIronClick(int slot, EntityPlayer player, ItemStack itemstack) {
if (!Proxies.common.isSimulating(player.worldObj)) {
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = slot;
Proxies.net.sendToServer(new PacketUpdate(PacketIds.SOLDERING_IRON_CLICK, payload));
PacketSlotClick packet = new PacketSlotClick(PacketId.SOLDERING_IRON_CLICK, tile, slot);
Proxies.net.sendToServer(packet);
return;
}
@@ -82,9 +77,7 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
player.inventory.setItemStack(null);
}
TileEntity te = (TileEntity) tile;
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, te.xCoord, te.yCoord, te.zCoord, tile), player);
PacketSocketUpdate packet = new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile);
Proxies.net.sendToPlayer(packet, player);
}
}
@@ -10,10 +10,15 @@
******************************************************************************/
package forestry.core.gui;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.api.core.IErrorState;
import forestry.core.gadgets.TileForestry;
import forestry.core.network.PacketErrorUpdate;
import forestry.core.proxy.Proxies;
public class ContainerTile<T extends TileForestry> extends ContainerForestry {
@@ -34,4 +39,24 @@ public class ContainerTile<T extends TileForestry> extends ContainerForestry {
public final boolean canInteractWith(EntityPlayer entityplayer) {
return tile.isUseableByPlayer(entityplayer);
}
private ImmutableSet<IErrorState> previousErrorStates;
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
ImmutableSet<IErrorState> errorStates = tile.getErrorStates();
if ((previousErrorStates != null) && !errorStates.equals(previousErrorStates)) {
PacketErrorUpdate packet = new PacketErrorUpdate(tile);
for (Object crafter : crafters) {
if (crafter instanceof EntityPlayer) {
Proxies.net.sendToPlayer(packet, (EntityPlayer) crafter);
}
}
}
previousErrorStates = errorStates;
}
}
@@ -26,9 +26,8 @@ public class ErrorLedger extends Ledger {
private IErrorState state;
public ErrorLedger(LedgerManager manager) {
super(manager, false);
super(manager, "error", false);
maxHeight = 72;
overlayColor = manager.gui.fontColor.get("ledger.error.background");
}
public void setState(@Nullable IErrorState state) {
@@ -37,7 +36,7 @@ public class ErrorLedger extends Ledger {
String helpString = StringUtil.localize(state.getHelp());
FontRenderer fontRenderer = manager.minecraft.fontRenderer;
int lineCount = fontRenderer.listFormattedStringToWidth(helpString, maxWidth - 28).size();
maxHeight = lineCount * (fontRenderer.FONT_HEIGHT + 2) + 20;
maxHeight = (lineCount + 1) * fontRenderer.FONT_HEIGHT + 20;
}
}
@@ -47,8 +46,6 @@ public class ErrorLedger extends Ledger {
return;
}
// Draw background
drawBackground(x, y);
@@ -57,12 +54,10 @@ public class ErrorLedger extends Ledger {
// Write description if fully opened
if (isFullyOpened()) {
FontRenderer fontRenderer = manager.minecraft.fontRenderer;
fontRenderer.drawStringWithShadow(getTooltip(), x + 24, y + 8, manager.gui.fontColor.get("ledger.error.header"));
drawHeader(getTooltip(), x + 24, y + 8);
String helpString = StringUtil.localize(state.getHelp());
fontRenderer.drawSplitString(helpString, x + 24, y + 20, maxWidth - 28, manager.gui.fontColor.get("ledger.error.text"));
drawSplitText(helpString, x + 24, y + 20, maxWidth - 28);
}
}
@@ -28,6 +28,8 @@ import forestry.core.gadgets.NaturalistGame;
import forestry.core.gadgets.NaturalistGame.GameToken;
import forestry.core.gadgets.TileEscritoire;
import forestry.core.gui.widgets.Widget;
import forestry.core.network.PacketGuiSelect;
import forestry.core.network.PacketId;
import forestry.core.proxy.Proxies;
import forestry.core.render.SpriteSheet;
import forestry.core.render.TextureManager;
@@ -35,7 +37,7 @@ import forestry.core.utils.StringUtil;
public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoire> {
private static enum Notes {
private enum Notes {
level1, level2, level3, level4, success, failure
}
@@ -46,7 +48,7 @@ public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoi
for (Notes notesLevel : Notes.values()) {
int levelCount = Integer.valueOf(StringUtil.localize("gui.escritoire.notes." + notesLevel + ".count"));
for (int i = 1; i <= levelCount; i++) {
String note = StringUtil.localize("gui.escritoire.notes." + notesLevel + "." + i);
String note = StringUtil.localize("gui.escritoire.notes." + notesLevel + '.' + i);
researchNotes.put(notesLevel, note);
}
}
@@ -120,7 +122,8 @@ public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoi
@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
container.sendTokenClick(index);
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, 0);
Proxies.net.sendToServer(packet);
}
}
@@ -149,7 +152,8 @@ public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoi
@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
pressed = true;
container.sendProbeClick();
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, -1, 0);
Proxies.net.sendToServer(packet);
}
@Override
@@ -10,7 +10,6 @@
******************************************************************************/
package forestry.core.gui;
import javax.annotation.Nonnull;
import java.awt.Color;
import java.util.Collection;
import java.util.List;
@@ -98,7 +97,7 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
ledgerManager.add(new HintLedger(ledgerManager, (IHintSource) inventory));
}
if (inventory instanceof IOwnable && ((IOwnable) inventory).isOwnable()) {
if (inventory instanceof IOwnable) {
ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnable) inventory));
}
@@ -30,9 +30,9 @@ import forestry.core.config.Defaults;
import forestry.core.genetics.EnumMutateChance;
import forestry.core.gui.buttons.GuiBetterButton;
import forestry.core.gui.buttons.StandardButtonTextureSets;
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;
import forestry.core.utils.StringUtil;
@@ -93,10 +93,8 @@ public class GuiNaturalistInventory extends GuiForestry<Container, IPagedInvento
buttonList.add(new GuiBetterButton(2, guiLeft + 180, guiTop + 7, StandardButtonTextureSets.RIGHT_BUTTON_SMALL));
}
private void flipPage(int page) {
PacketPayload payload = new PacketPayload(1, 0, 0);
payload.intPayload[0] = page;
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
private static void flipPage(int page) {
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, page, 0);
Proxies.net.sendToServer(packet);
}
+13 -16
View File
@@ -20,19 +20,20 @@ import forestry.core.utils.StringUtil;
public class HintLedger extends Ledger {
private final int position;
private final String[] hints;
private final String hintString;
private final String hintTooltip;
public HintLedger(LedgerManager manager, IHintSource tile) {
super(manager);
this.hints = tile.getHints();
position = new Random().nextInt(hints.length);
overlayColor = manager.gui.fontColor.get("ledger.hint.background");
super(manager, "hint");
String[] hints = tile.getHints();
int position = new Random().nextInt(hints.length);
hintString = StringUtil.localize("hints." + hints[position] + ".desc");
hintTooltip = StringUtil.localize("hints." + hints[position] + ".tag");
String helpString = StringUtil.localize("hints." + hints[position] + ".desc");
FontRenderer fontRenderer = manager.minecraft.fontRenderer;
int lineCount = fontRenderer.listFormattedStringToWidth(helpString, maxWidth - 28).size();
maxHeight = lineCount * (fontRenderer.FONT_HEIGHT + 2) + 20;
int lineCount = fontRenderer.listFormattedStringToWidth(hintString, maxWidth - 28).size();
maxHeight = (lineCount + 1) * fontRenderer.FONT_HEIGHT + 20;
}
@Override
@@ -48,16 +49,12 @@ public class HintLedger extends Ledger {
return;
}
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.didyouknow") + '?', x + 22, y + 8,
manager.gui.fontColor.get("ledger.hint.header"));
manager.minecraft.fontRenderer.drawSplitString(StringUtil.localize("hints." + hints[position] + ".desc"), x + 22, y + 20, maxWidth - 28,
manager.gui.fontColor.get("ledger.hint.text"));
drawHeader(StringUtil.localize("gui.didyouknow") + '?', x + 22, y + 8);
drawSplitText(hintString, x + 22, y + 20, maxWidth - 28);
}
@Override
public String getTooltip() {
return StringUtil.localize("hints." + hints[position] + ".tag");
return hintTooltip;
}
}
@@ -12,10 +12,10 @@ package forestry.core.gui;
import net.minecraft.entity.player.EntityPlayer;
import forestry.core.network.PacketUpdate;
import forestry.core.network.PacketGuiSelect;
public interface IGuiSelectable {
void handleSelectionChange(EntityPlayer player, PacketUpdate packet);
void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet);
void setSelection(PacketUpdate packet);
void setSelection(PacketGuiSelect packetPayload);
}
+63 -16
View File
@@ -30,47 +30,72 @@ public abstract class Ledger {
protected static final int maxWidth = 124;
protected static final int minWidth = 24;
public static final int minHeight = 24;
protected int maxHeight = 24;
private static final ResourceLocation ledgerTextureRight = new ForestryResource(Defaults.TEXTURE_PATH_GUI + "/ledger.png");
private static final ResourceLocation ledgerTextureLeft = new ForestryResource(Defaults.TEXTURE_PATH_GUI + "/ledgerLeft.png");
protected final LedgerManager manager;
private boolean open;
protected final int fontColorHeader;
protected final int fontColorText;
protected final int fontColorSubheader;
protected final int overlayColor;
protected int overlayColor = 0xffffff;
private boolean open;
public int currentShiftX = 0;
public int currentShiftY = 0;
protected int currentWidth = minWidth;
protected int maxHeight = 24;
protected int currentHeight = minHeight;
protected float currentWidth = minWidth;
protected float currentHeight = minHeight;
protected final ResourceLocation texture;
public Ledger(LedgerManager manager) {
this(manager, true);
public Ledger(LedgerManager manager, String name) {
this(manager, name, true);
}
public Ledger(LedgerManager manager, boolean rightSide) {
public Ledger(LedgerManager manager, String name, boolean rightSide) {
this.manager = manager;
if (rightSide) {
texture = ledgerTextureRight;
} else {
texture = ledgerTextureLeft;
}
fontColorHeader = manager.gui.fontColor.get("ledger." + name + ".header");
fontColorSubheader = manager.gui.fontColor.get("ledger." + name + ".subheader");
fontColorText = manager.gui.fontColor.get("ledger." + name + ".text");
overlayColor = manager.gui.fontColor.get("ledger." + name + ".background");
}
// adjust the update's move amount to match the look of 60 fps (16.67 ms per update)
private static final float msPerUpdate = 16.667f;
private long lastUpdateTime = 0;
public void update() {
long updateTime;
if (lastUpdateTime == 0) {
lastUpdateTime = System.currentTimeMillis();
updateTime = lastUpdateTime + Math.round(msPerUpdate);
} else {
updateTime = System.currentTimeMillis();
}
float moveAmount = Config.guiTabSpeed * (updateTime - lastUpdateTime) / msPerUpdate;
lastUpdateTime = updateTime;
// Width
if (open && currentWidth < maxWidth) {
currentWidth += Config.guiTabSpeed;
currentWidth += moveAmount;
if (currentWidth > maxWidth) {
currentWidth = maxWidth;
}
} else if (!open && currentWidth > minWidth) {
currentWidth -= Config.guiTabSpeed;
currentWidth -= moveAmount;
if (currentWidth < minWidth) {
currentWidth = minWidth;
}
@@ -78,12 +103,12 @@ public abstract class Ledger {
// Height
if (open && currentHeight < maxHeight) {
currentHeight += Config.guiTabSpeed;
currentHeight += moveAmount;
if (currentHeight > maxHeight) {
currentHeight = maxHeight;
}
} else if (!open && currentHeight > minHeight) {
currentHeight -= Config.guiTabSpeed;
currentHeight -= moveAmount;
if (currentHeight < minHeight) {
currentHeight = minHeight;
}
@@ -91,7 +116,11 @@ public abstract class Ledger {
}
public int getHeight() {
return currentHeight;
return Math.round(currentHeight);
}
public int getWidth() {
return Math.round(currentWidth);
}
public abstract void draw(int x, int y);
@@ -144,11 +173,14 @@ public abstract class Ledger {
Proxies.common.bindTexture(texture);
manager.gui.drawTexturedModalRect(x, y + 4, 0, 256 - currentHeight + 4, 4, currentHeight - 4); // left edge
manager.gui.drawTexturedModalRect(x + 4, y, 256 - currentWidth + 4, 0, currentWidth - 4, 4); // top edge
int height = getHeight();
int width = getWidth();
manager.gui.drawTexturedModalRect(x, y + 4, 0, 256 - height + 4, 4, height - 4); // left edge
manager.gui.drawTexturedModalRect(x + 4, y, 256 - width + 4, 0, width - 4, 4); // top edge
manager.gui.drawTexturedModalRect(x, y, 0, 0, 4, 4); // top left corner
manager.gui.drawTexturedModalRect(x + 4, y + 4, 256 - currentWidth + 4, 256 - currentHeight + 4, currentWidth - 4, currentHeight - 4); // body + bottom + right
manager.gui.drawTexturedModalRect(x + 4, y + 4, 256 - width + 4, 256 - height + 4, width - 4, height - 4); // body + bottom + right
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
}
@@ -162,6 +194,21 @@ public abstract class Ledger {
manager.gui.drawTexturedModelRectFromIcon(x, y, icon, 16, 16);
GL11.glEnable(GL11.GL_LIGHTING);
}
}
protected void drawHeader(String string, int x, int y) {
manager.minecraft.fontRenderer.drawStringWithShadow(string, x, y, fontColorHeader);
}
protected void drawSubheader(String string, int x, int y) {
manager.minecraft.fontRenderer.drawStringWithShadow(string, x, y, fontColorSubheader);
}
protected void drawText(String string, int x, int y) {
manager.minecraft.fontRenderer.drawString(string, x, y, fontColorText);
}
protected void drawSplitText(String string, int x, int y, int width) {
manager.minecraft.fontRenderer.drawSplitString(string, x, y, width, fontColorText);
}
}
@@ -90,7 +90,7 @@ public class LedgerManager {
continue;
}
errorLedger.currentShiftX = xShiftError - errorLedger.currentWidth;
errorLedger.currentShiftX = xShiftError - errorLedger.getWidth();
errorLedger.currentShiftY = yShiftError;
if (errorLedger.intersectsWith(mX, mY)) {
return errorLedger;
@@ -135,7 +135,7 @@ public class LedgerManager {
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
errorLedger.draw(-errorLedger.currentWidth, yPos);
errorLedger.draw(-errorLedger.getWidth(), yPos);
yPos += errorLedger.getHeight();
}
}
@@ -18,7 +18,7 @@ import net.minecraft.util.IIcon;
import forestry.core.interfaces.IOwnable;
import forestry.core.interfaces.IRestrictedAccess;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketId;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
import forestry.core.utils.EnumAccess;
@@ -33,8 +33,16 @@ public class OwnerLedger extends Ledger {
private final IOwnable tile;
public OwnerLedger(LedgerManager manager, IOwnable tile) {
super(manager);
super(manager, "owner");
this.tile = tile;
boolean playerIsOwner = tile.isOwner(manager.minecraft.thePlayer);
if (playerIsOwner) {
maxHeight = 60;
} else {
maxHeight = 36;
}
}
public boolean isAccessButton(int mouseX, int mouseY) {
@@ -45,18 +53,13 @@ public class OwnerLedger extends Ledger {
return mouseX >= shiftX && mouseX <= currentShiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + 12;
}
@Override
public boolean isVisible() {
return tile.isOwned();
}
@Override
public void draw(int x, int y) {
// Update state
boolean playerIsOwner = tile.isOwner(manager.minecraft.thePlayer);
if (playerIsOwner) {
maxHeight = 60;
} else {
maxHeight = 36;
}
// Draw background
drawBackground(x, y);
@@ -75,16 +78,16 @@ public class OwnerLedger extends Ledger {
return;
}
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.owner"), x + 22, y + 8, manager.gui.fontColor.get("ledger.owner.header"));
drawHeader(StringUtil.localize("gui.owner"), x + 22, y + 8);
manager.minecraft.fontRenderer.drawString(PlayerUtil.getOwnerName(tile), x + 22, y + 20, manager.gui.fontColor.get("ledger.owner.text"));
drawText(PlayerUtil.getOwnerName(tile), x + 22, y + 20);
boolean playerIsOwner = tile.isOwner(manager.minecraft.thePlayer);
if (playerIsOwner && tile instanceof IRestrictedAccess) {
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.access") + ":", x + 22, y + 32,
manager.gui.fontColor.get("ledger.owner.subheader"));
drawSubheader(StringUtil.localize("gui.access") + ':', x + 22, y + 32);
// Access rules
drawIcon(accessIcon, x + 20, y + 40);
manager.minecraft.fontRenderer.drawString(StringUtil.localize(access.getName()), x + 38, y + 44, manager.gui.fontColor.get("ledger.owner.text"));
drawText(StringUtil.localize(access.getName()), x + 38, y + 44);
}
}
@@ -99,7 +102,7 @@ public class OwnerLedger extends Ledger {
if (isAccessButton(x, y) && tile instanceof IRestrictedAccess) {
if (!Proxies.common.isSimulating(((TileEntity) tile).getWorldObj())) {
TileEntity te = (TileEntity) tile;
Proxies.net.sendToServer(new PacketCoordinates(PacketIds.ACCESS_SWITCH, te.xCoord, te.yCoord, te.zCoord));
Proxies.net.sendToServer(new PacketCoordinates(PacketId.ACCESS_SWITCH, te));
}
((IRestrictedAccess) tile).switchAccessRule(manager.minecraft.thePlayer);
@@ -108,5 +111,4 @@ public class OwnerLedger extends Ledger {
return false;
}
}
@@ -20,10 +20,9 @@ public class PowerLedger extends Ledger {
private final IPowerHandler tile;
public PowerLedger(LedgerManager manager, IPowerHandler tile) {
super(manager);
super(manager, "power");
this.tile = tile;
maxHeight = 94;
overlayColor = manager.gui.fontColor.get("ledger.power.background");
}
@Override
@@ -39,17 +38,17 @@ public class PowerLedger extends Ledger {
}
EnergyManager energyManager = tile.getEnergyManager();
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.energy"), x + 22, y + 8, manager.gui.fontColor.get("ledger.power.header"));
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.stored") + ":", x + 22, y + 20,
manager.gui.fontColor.get("ledger.power.subheader"));
manager.minecraft.fontRenderer.drawString(energyManager.getTotalEnergyStored() + " RF", x + 22, y + 32, manager.gui.fontColor.get("ledger.power.text"));
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.maxenergy") + ":", x + 22, y + 44,
manager.gui.fontColor.get("ledger.power.subheader"));
manager.minecraft.fontRenderer.drawString(energyManager.getMaxEnergyStored() + " RF", x + 22, y + 56, manager.gui.fontColor.get("ledger.power.text"));
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.maxenergyreceive") + ":", x + 22, y + 68,
manager.gui.fontColor.get("ledger.power.subheader"));
manager.minecraft.fontRenderer.drawString(energyManager.getMaxEnergyReceived() + " RF", x + 22, y + 80, manager.gui.fontColor.get("ledger.power.text"));
drawHeader(StringUtil.localize("gui.energy"), x + 22, y + 8);
drawSubheader(StringUtil.localize("gui.stored") + ':', x + 22, y + 20);
drawText(energyManager.getTotalEnergyStored() + " RF", x + 22, y + 32);
drawSubheader(StringUtil.localize("gui.maxenergy") + ':', x + 22, y + 44);
drawText(energyManager.getMaxEnergyStored() + " RF", x + 22, y + 56);
drawSubheader(StringUtil.localize("gui.maxenergyreceive") + ':', x + 22, y + 68);
drawText(energyManager.getMaxEnergyReceived() + " RF", x + 22, y + 80);
}
@Override
@@ -16,7 +16,7 @@ import net.minecraft.item.ItemStack;
import forestry.core.interfaces.IFilterSlotDelegate;
/**
* Slot which only takes specific items, specified by the ICustomSlotInventory.
* Slot which only takes specific items, specified by the IFilterSlotDelegate.
*/
public class SlotFiltered extends SlotWatched {
@@ -21,7 +21,6 @@ import forestry.core.gui.tooltips.ToolTip;
public class SlotForestry extends Slot implements IToolTipProvider {
private boolean isPhantom;
private boolean isInfinite;
private boolean canAdjustPhantom = true;
private boolean canShift = true;
private int stackLimit;
@@ -35,11 +34,6 @@ public class SlotForestry extends Slot implements IToolTipProvider {
this.stackLimit = -1;
}
public SlotForestry setInfinite() {
this.isInfinite = true;
return this;
}
public SlotForestry setPhantom() {
isPhantom = true;
return this;
@@ -93,22 +87,6 @@ public class SlotForestry extends Slot implements IToolTipProvider {
}
}
@Override
public ItemStack decrStackSize(int i) {
if (!isInfinite) {
return super.decrStackSize(i);
}
ItemStack stack = inventory.getStackInSlot(getSlotIndex());
if (stack == null) {
return null;
}
ItemStack result = stack.copy();
result.stackSize = i;
return result;
}
/**
* @param toolTips the tooltips to set
*/
@@ -16,8 +16,8 @@ import net.minecraft.item.ItemStack;
public class SlotLocked extends SlotForestry {
public SlotLocked(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
public SlotLocked(IInventory inventory, int slotIndex, int xPos, int yPos) {
super(inventory, slotIndex, xPos, yPos);
setCanAdjustPhantom(false);
blockShift();
setPhantom();
Loaded 100 of 221 files, more files were not shown because too many files have changed in this diff. Show more