Compare commits

..
14 Commits
30 changed files with 297 additions and 180 deletions

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@ mcversion=1.7.10
forgeversion=10.13.3.1370-1.7.10
version_major=3
version_minor=6
version_patch=0
version_patch=5
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture;
import java.util.Collections;
import java.util.Set;
import java.util.Stack;
@@ -36,7 +37,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 static final int ticksPerCheckQueenCanWork = 10;
private final IBeeHousing housing;
private final boolean housingSupportsMultipleErrorStates;
@@ -45,6 +46,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
private int breedingTime;
private int queenWorkCycleThrottle;
private IEffectData effectData[] = new IEffectData[2];
private ItemStack queenStack;
private IBee queen;
private IIndividual pollen;
private int attemptedPollinations = 0;
@@ -53,8 +55,8 @@ public class BeekeepingLogic implements IBeekeepingLogic {
// Cached flowers check
private boolean hasFlowersCached = false;
private int hasFlowersCooldown = 0;
private boolean canWorkCached = false;
private int canWorkCooldown = 0;
private Set<IErrorState> queenCanWorkCached = Collections.emptySet();
private int queenCanWorkCooldown = 0;
public BeekeepingLogic(IBeeHousing housing) {
this.housing = housing;
@@ -128,16 +130,6 @@ public class BeekeepingLogic implements IBeekeepingLogic {
@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) {
@@ -183,7 +175,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
if (hasFlowersCooldown <= 0) {
hasFlowersCached = queen.hasFlower(housing);
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle / ticksPerCheckCanWork;
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle;
// check more often if we haven't found flowers
if (!hasFlowersCached) {
@@ -318,7 +310,12 @@ public class BeekeepingLogic implements IBeekeepingLogic {
ItemStack queenStack = housing.getQueen();
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
if (!ItemStack.areItemStacksEqual(this.queenStack, queenStack)) {
this.queen = BeeManager.beeRoot.getMember(queenStack);
this.queenStack = queenStack;
}
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(queenStack)) {
housingErrorState = EnumErrorCode.NOQUEEN;
hasQueen = false;
queen = null;
@@ -367,30 +364,46 @@ public class BeekeepingLogic implements IBeekeepingLogic {
}
private boolean queenCanWork() {
if (queen == null) {
return false;
if (queenCanWorkCooldown > 0) {
queenCanWorkCooldown--;
} else {
if (queen == null) {
return false;
}
queenCanWorkCached = checkQueenCanWork();
queenCanWorkCooldown = ticksPerCheckQueenCanWork;
}
if (housingSupportsMultipleErrorStates) {
try {
Set<IErrorState> errorStates = queen.getCanWork(housing);
Set<IErrorState> errorStates = queenCanWorkCached;
if (errorStates.size() > 0) {
if (housingSupportsMultipleErrorStates) {
for (IErrorState errorState : errorStates) {
housing.setErrorCondition(true, errorState);
}
return (errorStates.size() == 0);
} catch (Throwable ignored) {
// queen might not support getCanWork(housing)
} else {
IErrorState state = errorStates.iterator().next();
housing.setErrorState(state);
}
return false;
} else {
return true;
}
}
private Set<IErrorState> checkQueenCanWork() {
try {
return queen.getCanWork(housing);
} catch (Throwable ignored) {
// queen might not support getCanWork
}
IErrorState state = queen.canWork(housing);
if (state != EnumErrorCode.OK) {
housing.setErrorState(state);
return false;
return Collections.singleton(state);
}
return true;
return Collections.emptySet();
}
// / BREEDING
@@ -141,10 +141,12 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
this.active = active;
if (worldObj.isRemote) {
worldObj.func_147479_m(xCoord, yCoord, zCoord);
} else {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
if (worldObj != null) {
if (worldObj.isRemote) {
worldObj.func_147479_m(xCoord, yCoord, zCoord);
} else {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
}
@@ -155,7 +155,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
}
this.active = active;
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
@@ -229,7 +229,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory,
this.active = active;
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
@@ -456,7 +456,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised,
}
this.active = active;
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
@@ -77,6 +77,10 @@ public class BeeGenome extends Genome implements IBeeGenome {
// NBT RETRIEVAL
public static IAlleleBeeSpecies getSpecies(ItemStack itemStack) {
if (!BeeManager.beeRoot.isMember(itemStack)) {
return null;
}
IAlleleSpecies species = getSpeciesDirectly(itemStack);
if (species instanceof IAlleleBeeSpecies) {
return (IAlleleBeeSpecies) species;
@@ -1,48 +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 net.minecraft.tileentity.TileEntity;
import net.minecraftforge.event.entity.player.BonemealEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import forestry.api.genetics.IFruitBearer;
import forestry.arboriculture.gadgets.TileFruitPod;
import forestry.core.proxy.Proxies;
public class EventHandlerArboriculture {
@SubscribeEvent
public void handleBonemeal(BonemealEvent event) {
if (!Proxies.common.isSimulating(event.world)) {
return;
}
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
if (tile instanceof TileFruitPod) {
if (((TileFruitPod) tile).canMature()) {
((TileFruitPod) tile).mature();
event.setResult(Result.ALLOW);
}
} else if (tile instanceof IFruitBearer) {
IFruitBearer bearer = (IFruitBearer) tile;
if (bearer.getRipeness() < 1.0f) {
bearer.addRipeness(1.0f);
event.setResult(Result.ALLOW);
}
}
}
}
@@ -139,4 +139,30 @@ public class BlockFruitPod extends BlockCocoa {
return PluginArboriculture.modelIdPods;
}
/* IGrowable */
@Override
// canFertilize
public boolean func_149851_a(World world, int x, int y, int z, boolean isClient) {
TileFruitPod podTile = getPodTile(world, x, y, z);
if (podTile != null) {
return podTile.canMature();
}
return false;
}
@Override
// shouldFertilize
public boolean func_149852_a(World world, Random random, int x, int y, int z) {
return true;
}
@Override
// fertilize
public void func_149853_b(World world, Random random, int x, int y, int z) {
TileFruitPod podTile = getPodTile(world, x, y, z);
if (podTile != null) {
podTile.mature();
}
}
}
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockNewLeaf;
import net.minecraft.block.IGrowable;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@@ -49,7 +50,7 @@ import forestry.core.utils.StackUtils;
import forestry.plugins.PluginArboriculture;
import forestry.plugins.PluginLepidopterology;
public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProvider {
public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProvider, IGrowable {
public ForestryBlockLeaves() {
this.setCreativeTab(Tabs.tabArboriculture);
@@ -328,4 +329,30 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv
return super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
}
/* IGrowable */
@Override
// canFertilize
public boolean func_149851_a(World world, int x, int y, int z, boolean isClient) {
TileLeaves leafTile = getLeafTile(world, x, y, z);
if (leafTile != null) {
return leafTile.hasFruit() && leafTile.getRipeness() < 1.0f;
}
return false;
}
@Override
// shouldFertilize
public boolean func_149852_a(World world, Random random, int x, int y, int z) {
return true;
}
@Override
// fertilize
public void func_149853_b(World world, Random random, int x, int y, int z) {
TileLeaves leafTile = getLeafTile(world, x, y, z);
if (leafTile != null) {
leafTile.addRipeness(1.0f);
}
}
}
@@ -138,6 +138,14 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
Proxies.net.sendNetworkPacket(new PacketRipeningUpdate(this));
}
public void fromRipeningPacket(int newMaturity) {
if (newMaturity == maturity) {
return;
}
maturity = (short) newMaturity;
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
/* IFRUITBEARER */
@Override
public boolean hasFruit() {
@@ -421,8 +421,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
}
}
public void fromRipeningPacket(PacketRipeningUpdate packet) {
int newColourFruits = packet.getValue();
public void fromRipeningPacket(int newColourFruits) {
if (newColourFruits == colourFruits) {
return;
}
@@ -46,6 +46,10 @@ public class TreeGenome extends Genome implements ITreeGenome {
// NBT RETRIEVAL
public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) {
if (!PluginArboriculture.treeInterface.isMember(itemStack)) {
return null;
}
IAlleleSpecies species = getSpeciesDirectly(itemStack);
if (species instanceof IAlleleTreeSpecies) {
return (IAlleleTreeSpecies) species;
@@ -13,13 +13,10 @@ 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 {
@@ -28,8 +25,7 @@ public class PacketHandlerArboriculture implements IPacketHandler {
switch (packetID) {
case RIPENING_UPDATE: {
PacketRipeningUpdate packet = new PacketRipeningUpdate(data);
onRipeningUpdate(packet);
PacketRipeningUpdate.onPacketData(data);
return true;
}
}
@@ -37,10 +33,4 @@ public class PacketHandlerArboriculture implements IPacketHandler {
return false;
}
private static void onRipeningUpdate(PacketRipeningUpdate packet) {
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileLeaves) {
((TileLeaves) tile).fromRipeningPacket(packet);
}
}
}
@@ -12,17 +12,24 @@ package forestry.arboriculture.network;
import java.io.IOException;
import net.minecraft.tileentity.TileEntity;
import forestry.arboriculture.gadgets.TileFruitPod;
import forestry.arboriculture.gadgets.TileLeaves;
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 PacketRipeningUpdate extends PacketCoordinates {
private int value;
public static void onPacketData(DataInputStreamForestry data) throws IOException {
new PacketRipeningUpdate(data);
}
public PacketRipeningUpdate(DataInputStreamForestry data) throws IOException {
super(data);
}
@@ -40,13 +47,20 @@ public class PacketRipeningUpdate extends PacketCoordinates {
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeInt(value);
data.writeVarInt(value);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
value = data.readInt();
value = data.readVarInt();
TileEntity tile = getTarget(Proxies.common.getRenderWorld());
if (tile instanceof TileLeaves) {
((TileLeaves) tile).fromRipeningPacket(value);
} else if (tile instanceof TileFruitPod) {
((TileFruitPod) tile).fromRipeningPacket(value);
}
}
public int getValue() {
@@ -172,7 +172,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection, IAct
}
this.active = active;
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this));
}
}
@@ -24,6 +24,10 @@ public class ContainerTile<T extends TileForestry> extends ContainerForestry {
protected final T tile;
public ContainerTile(T tileForestry) {
this.tile = tileForestry;
}
public ContainerTile(T tileForestry, InventoryPlayer playerInventory, int xInv, int yInv) {
this.tile = tileForestry;
@@ -61,11 +61,11 @@ public class PacketHandler {
@SubscribeEvent
public void onPacket(ClientCustomPacketEvent event) {
onPacketData(event.packet, null);
onPacketData(event.packet, Proxies.common.getPlayer());
}
/** Returns true if the packet has been handled */
private static boolean onPacketData(FMLProxyPacket fmlPacket, EntityPlayerMP player) {
private static boolean onPacketData(FMLProxyPacket fmlPacket, EntityPlayer player) {
InputStream is = new ByteBufInputStream(fmlPacket.payload());
DataInputStreamForestry data = new DataInputStreamForestry(is);
@@ -107,7 +107,7 @@ public class PacketHandler {
case PIPETTE_CLICK: {
PacketSlotClick packet = new PacketSlotClick(data);
onPipetteClick(packet, player);
onPipetteClick(packet, (EntityPlayerMP) player);
return true;
}
case SOLDERING_IRON_CLICK: {
@@ -98,7 +98,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
craftPreviewInventory = new InventoryCraftResult();
setInternalInventory(new CarpenterInventoryAdapter(this));
InvTools.configureSided(getInternalInventory(), Defaults.FACINGS, SLOT_BOX, 20);
InvTools.configureSided(getInternalInventory(), Defaults.FACINGS, SLOT_BOX, 21);
tankManager = new TankManager(resourceTank);
}
@@ -76,8 +76,8 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
this.chance = chance;
}
public boolean matches(ItemStack[] res) {
return StackUtils.containsSets(resources, res, true, true) > 0;
public boolean matches(ItemStack[] res, boolean oreDict) {
return StackUtils.containsSets(resources, res, oreDict, true) > 0;
}
}
@@ -104,8 +104,16 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
}
public static Recipe findMatchingRecipe(ItemStack[] items) {
// First try to match a specific recipe (without OD)
for (Recipe recipe : recipes) {
if (recipe.matches(items)) {
if (recipe.matches(items, false)) {
return recipe;
}
}
// If that fails - try again with oredict support enabled
for (Recipe recipe : recipes) {
if (recipe.matches(items, true)) {
return recipe;
}
}
@@ -118,7 +126,7 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
return true;
}
for (ItemStack recipeInput : recipeInputs) {
if (StackUtils.isCraftingEquivalent(recipeInput, itemStack)) {
if (StackUtils.isCraftingEquivalent(recipeInput, itemStack, true, true)) {
return true;
}
}
@@ -43,6 +43,10 @@ public class ButterflyGenome extends Genome implements IButterflyGenome {
// NBT RETRIEVAL
public static IAlleleButterflySpecies getSpecies(ItemStack itemStack) {
if (!PluginLepidopterology.butterflyInterface.isMember(itemStack)) {
return null;
}
IAlleleSpecies species = getSpeciesDirectly(itemStack);
if (species instanceof IAlleleButterflySpecies) {
return (IAlleleButterflySpecies) species;
@@ -76,7 +76,7 @@ public class GuiHandlerMail extends GuiHandlerBase {
case TraderGUI:
return new GuiTrader(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class));
case TraderNameGUI:
return new GuiTradeName(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class));
return new GuiTradeName(getTileForestry(world, x, y, z, player, MachineTrader.class));
default:
return null;
@@ -122,7 +122,7 @@ public class GuiHandlerMail extends GuiHandlerBase {
case TraderGUI:
return new ContainerTrader(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class));
case TraderNameGUI:
return new ContainerTradeName(player.inventory, getTileForestry(world, x, y, z, player, MachineTrader.class));
return new ContainerTradeName(getTileForestry(world, x, y, z, player, MachineTrader.class));
default:
return null;
@@ -14,19 +14,21 @@ import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.IPacketHandler;
import forestry.core.network.PacketId;
import forestry.core.network.PacketString;
import forestry.core.proxy.Proxies;
import forestry.mail.gadgets.MachineTrader;
import forestry.mail.gui.ContainerCatalogue;
import forestry.mail.gui.ContainerLetter;
import forestry.mail.gui.ContainerTradeName;
import forestry.mail.gui.GuiMailboxInfo;
import forestry.mail.network.PacketLetterInfo;
import forestry.mail.network.PacketPOBoxInfo;
import forestry.mail.network.PacketRequestLetterInfo;
import forestry.mail.network.PacketTraderAddress;
public class PacketHandlerMail implements IPacketHandler {
@@ -55,8 +57,8 @@ public class PacketHandlerMail implements IPacketHandler {
return true;
}
case TRADING_ADDRESS_SET: {
PacketString packet = new PacketString(data);
onAddressSet(player, packet);
PacketTraderAddress packet = new PacketTraderAddress(data);
handleTradeAddressSet(player, packet);
return true;
}
case POBOX_INFO_REQUEST: {
@@ -83,12 +85,15 @@ public class PacketHandlerMail implements IPacketHandler {
GuiMailboxInfo.instance.setPOBoxInfo(packet.poboxInfo);
}
private static void onAddressSet(EntityPlayer player, PacketString packet) {
if (!(player.openContainer instanceof ContainerTradeName)) {
private static void handleTradeAddressSet(EntityPlayer player, PacketTraderAddress packet) {
TileEntity tile = packet.getTarget(player.worldObj);
if (!(tile instanceof MachineTrader)) {
return;
}
((ContainerTradeName) player.openContainer).handleSetAddress(packet);
String addressName = packet.getAddressName();
((MachineTrader) tile).handleSetAddress(addressName);
}
private static void onLetterText(EntityPlayer player, PacketString packet) {
@@ -36,9 +36,11 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.EnumAccess;
import forestry.core.utils.StackUtils;
import forestry.mail.MailAddress;
import forestry.mail.TradeStation;
import forestry.mail.network.PacketTraderAddress;
import forestry.mail.triggers.MailTriggers;
import buildcraft.api.statements.ITriggerExternal;
@@ -94,14 +96,23 @@ public class MachineTrader extends TileBase {
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeUTF(address.getName());
String name = null;
if (address != null) {
name = address.getName();
}
if (name == null) {
name = "";
}
data.writeUTF(name);
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
String address = data.readUTF();
this.address = PostManager.postRegistry.getMailAddress(address);
if (address.length() > 0) {
this.address = PostManager.postRegistry.getMailAddress(address);
}
}
/* UPDATING */
@@ -240,6 +251,22 @@ public class MachineTrader extends TileBase {
return address;
}
public void handleSetAddress(String addressName) {
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
setAddress(address);
if (!worldObj.isRemote) {
IMailAddress newAddress = getAddress();
if (newAddress != null) {
String newAddressName = newAddress.getName();
if (newAddressName != null && newAddressName.equals(addressName)) {
PacketTraderAddress packetResponse = new PacketTraderAddress(this, addressName);
Proxies.net.sendNetworkPacket(packetResponse);
}
}
}
}
public void setAddress(IMailAddress address) {
if (address == null) {
throw new NullPointerException("address must not be null");
@@ -260,6 +287,8 @@ public class MachineTrader extends TileBase {
this.address = address;
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwner(), address);
}
} else {
this.address = address;
}
}
@@ -273,6 +302,15 @@ public class MachineTrader extends TileBase {
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwner(), address);
}
@Override
public EnumAccess getAccess() {
if (isLinked()) {
return super.getAccess();
} else {
return EnumAccess.PRIVATE;
}
}
/* ITRIGGERPROVIDER */
@Optional.Method(modid = "BuildCraftAPI|statements")
@Override
@@ -10,52 +10,33 @@
******************************************************************************/
package forestry.mail.gui;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import forestry.api.mail.IMailAddress;
import forestry.api.mail.PostManager;
import forestry.core.network.PacketId;
import forestry.core.network.PacketString;
import forestry.core.proxy.Proxies;
import forestry.core.gui.ContainerTile;
import forestry.mail.gadgets.MachineTrader;
public class ContainerTradeName extends Container {
public class ContainerTradeName extends ContainerTile<MachineTrader> {
protected final MachineTrader machine;
public ContainerTradeName(InventoryPlayer player, MachineTrader tile) {
machine = tile;
public ContainerTradeName(MachineTrader tile) {
super(tile);
}
public IMailAddress getAddress() {
return machine.getAddress();
}
public void setAddress(String addressName) {
if (StringUtils.isBlank(addressName)) {
return;
}
PacketString packet = new PacketString(PacketId.TRADING_ADDRESS_SET, addressName);
Proxies.net.sendToServer(packet);
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
machine.setAddress(address);
}
public void handleSetAddress(PacketString packet) {
String addressName = packet.getString();
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
machine.setAddress(address);
return tile.getAddress();
}
@Override
public boolean canInteractWith(EntityPlayer entityPlayer) {
return machine.isOwner(entityPlayer);
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (tile.isLinked()) {
for (Object crafter : crafters) {
if (crafter instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) crafter;
tile.openGui(player, tile);
}
}
}
}
}
@@ -13,23 +13,22 @@ package forestry.mail.gui;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.input.Keyboard;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StringUtil;
import forestry.mail.gadgets.MachineTrader;
import forestry.mail.network.PacketTraderAddress;
public class GuiTradeName extends GuiForestry<ContainerTradeName, MachineTrader> {
private GuiTextField addressNameField;
private boolean addressNameFocus;
public GuiTradeName(InventoryPlayer inventoryplayer, MachineTrader tile) {
super(Defaults.TEXTURE_PATH_GUI + "/tradername.png", new ContainerTradeName(inventoryplayer, tile), tile);
public GuiTradeName(MachineTrader tile) {
super(Defaults.TEXTURE_PATH_GUI + "/tradername.png", new ContainerTradeName(tile), tile);
this.xSize = 176;
this.ySize = 90;
}
@@ -51,8 +50,7 @@ public class GuiTradeName extends GuiForestry<ContainerTradeName, MachineTrader>
// Set focus or enter text into address
if (addressNameField.isFocused()) {
if (eventKey == Keyboard.KEY_RETURN) {
addressNameFocus = true;
addressNameField.setFocused(false);
setAddress();
} else {
addressNameField.textboxKeyTyped(eventCharacter, eventKey);
}
@@ -70,36 +68,24 @@ public class GuiTradeName extends GuiForestry<ContainerTradeName, MachineTrader>
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
// Close gui screen if we linked up.
if (container.machine.isLinked()) {
this.mc.thePlayer.closeScreen();
this.mc.setIngameFocus();
}
// Check for focus changes
if (addressNameFocus && !addressNameField.isFocused()) {
this.setAddress();
}
addressNameFocus = addressNameField.isFocused();
super.drawGuiContainerBackgroundLayer(var1, var2, var3);
String prompt = StringUtil.localize("gui.mail.nametrader");
fontRendererObj.drawString(prompt, guiLeft + this.getCenteredOffset(prompt), guiTop + 16, fontColor.get("gui.mail.text"));
addressNameField.drawTextBox();
}
@Override
public void onGuiClosed() {
setAddress();
super.onGuiClosed();
setAddress();
}
private void setAddress() {
String address = addressNameField.getText();
if (StringUtils.isNotBlank(address)) {
container.setAddress(address);
PacketTraderAddress packet = new PacketTraderAddress(inventory, address);
Proxies.net.sendToServer(packet);
}
}
@@ -0,0 +1,51 @@
/*******************************************************************************
* 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.mail.network;
import java.io.IOException;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketId;
import forestry.mail.gadgets.MachineTrader;
public class PacketTraderAddress extends PacketCoordinates {
private String addressName;
public PacketTraderAddress(DataInputStreamForestry data) throws IOException {
super(data);
}
public PacketTraderAddress(MachineTrader tile, String addressName) {
super(PacketId.TRADING_ADDRESS_SET, tile);
this.addressName = addressName;
}
@Override
protected void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
data.writeUTF(addressName);
}
@Override
protected void readData(DataInputStreamForestry data) throws IOException {
super.readData(data);
addressName = data.readUTF();
}
public String getAddressName() {
return addressName;
}
}
@@ -297,6 +297,8 @@ public class PluginApiculture extends ForestryPlugin {
createAlleles();
BeeDefinition.initBees();
AlleleManager.alleleRegistry.registerDeprecatedAlleleReplacement("forestry.speciesArgrarian", BeeDefinition.AGRARIAN.getGenome().getPrimary());
// Hives
createHives();
registerBeehiveDrops();
@@ -23,7 +23,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.IFuelHandler;
@@ -48,7 +47,6 @@ import forestry.api.genetics.IFruitFamily;
import forestry.api.recipes.RecipeManagers;
import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.arboriculture.EventHandlerArboriculture;
import forestry.arboriculture.FruitProviderNone;
import forestry.arboriculture.FruitProviderPod;
import forestry.arboriculture.FruitProviderPod.EnumPodType;
@@ -338,8 +336,6 @@ public class PluginArboriculture extends ForestryPlugin {
GameRegistry.registerTileEntity(TileFruitPod.class, "forestry.Pods");
definitionChest.register();
MinecraftForge.EVENT_BUS.register(new EventHandlerArboriculture());
if (Config.enableVillager) {
VillagerRegistry.instance().registerVillagerId(Defaults.ID_VILLAGER_LUMBERJACK);
Proxies.render.registerVillagerSkin(Defaults.ID_VILLAGER_LUMBERJACK, Defaults.TEXTURE_SKIN_LUMBERJACK);
@@ -97,6 +97,10 @@ public class PluginManager {
PLANTMEGAPACK(new PluginPlantMegaPack()),
WITCHERY(new PluginWitchery());
static {
ForestryAPI.enabledPlugins = new HashSet<String>();
}
private final ForestryPlugin instance;
private final boolean canBeDisabled;
@@ -220,7 +224,6 @@ public class PluginManager {
unloadedModules.removeAll(toLoad);
loadedModules.addAll(toLoad);
ForestryAPI.enabledPlugins = new HashSet<String>();
for (Module m : loadedModules) {
ForestryAPI.enabledPlugins.add(m.toString());
}