mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
990d4990db | ||
|
|
ce232e808e | ||
|
|
31574a9c6e | ||
|
|
cd9a4110ee | ||
|
|
6b35ff2ba1 | ||
|
|
5133e721cc | ||
|
|
09ced92f5b | ||
|
|
12477a7711 | ||
|
|
b7dc4d9144 | ||
|
|
da48d317ff | ||
|
|
5bfb11e952 | ||
|
|
4dffb9f352 | ||
|
|
beadb47539 | ||
|
|
6301d3c193 | ||
|
|
883863e047 | ||
|
|
2c14f02151 | ||
|
|
00771b1a42 | ||
|
|
46ec2f2740 | ||
|
|
ac653d46c1 | ||
|
|
63d9935d01 | ||
|
|
ba695b977d | ||
|
|
6b1dfb1596 | ||
|
|
fff02be71d | ||
|
|
0e5b9e4957 | ||
|
|
3415030fbf |
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
mcversion=1.7.10
|
mcversion=1.7.10
|
||||||
forgeversion=10.13.0.1207
|
forgeversion=10.13.0.1207
|
||||||
version_major=3
|
version_major=3
|
||||||
version_minor=1
|
version_minor=3
|
||||||
version_patch=1
|
version_patch=0
|
||||||
|
|
||||||
+1
-1
Submodule lang updated: af11df9b5f...3c34adcc54.
@@ -105,13 +105,13 @@ public class BlockAlveary extends BlockStructure {
|
|||||||
public static final int BOTTOM = 2;
|
public static final int BOTTOM = 2;
|
||||||
public static final int LEFT = 3;
|
public static final int LEFT = 3;
|
||||||
public static final int RIGHT = 4;
|
public static final int RIGHT = 4;
|
||||||
public static final int TX_55_SWOF = 5;
|
public static final int ALVEARY_SWARMER_OFF = 5;
|
||||||
public static final int TX_56_SWON = 6;
|
public static final int ALVEARY_SWARMER_ON = 6;
|
||||||
public static final int TX_57_HTOF = 7;
|
public static final int ALVEARY_HEATER_OFF = 7;
|
||||||
public static final int TX_58_HTON = 8;
|
public static final int ALVEARY_HEATER_ON = 8;
|
||||||
public static final int TX_71_FNOF = 9;
|
public static final int ALVEARY_FAN_OFF = 9;
|
||||||
public static final int TX_72_FNON = 10;
|
public static final int ALVEARY_FAN_ON = 10;
|
||||||
public static final int TX_73_VLVE = 11;
|
public static final int ALVEARY_HYGRO = 11;
|
||||||
public static final int STABILISER = 12;
|
public static final int STABILISER = 12;
|
||||||
public static final int SIEVE = 13;
|
public static final int SIEVE = 13;
|
||||||
|
|
||||||
@@ -152,13 +152,13 @@ public class BlockAlveary extends BlockStructure {
|
|||||||
case 1:
|
case 1:
|
||||||
return icons[ENTRANCE];
|
return icons[ENTRANCE];
|
||||||
case TileAlvearySwarmer.BLOCK_META:
|
case TileAlvearySwarmer.BLOCK_META:
|
||||||
return icons[TX_55_SWOF];
|
return icons[ALVEARY_SWARMER_OFF];
|
||||||
case TileAlvearyFan.BLOCK_META:
|
case TileAlvearyFan.BLOCK_META:
|
||||||
return icons[TX_71_FNOF];
|
return icons[ALVEARY_FAN_OFF];
|
||||||
case TileAlvearyHeater.BLOCK_META:
|
case TileAlvearyHeater.BLOCK_META:
|
||||||
return icons[TX_57_HTOF];
|
return icons[ALVEARY_HEATER_OFF];
|
||||||
case TileAlvearyHygroregulator.BLOCK_META:
|
case TileAlvearyHygroregulator.BLOCK_META:
|
||||||
return icons[TX_73_VLVE];
|
return icons[ALVEARY_HYGRO];
|
||||||
case TileAlvearyStabiliser.BLOCK_META:
|
case TileAlvearyStabiliser.BLOCK_META:
|
||||||
return icons[STABILISER];
|
return icons[STABILISER];
|
||||||
case TileAlvearySieve.BLOCK_META:
|
case TileAlvearySieve.BLOCK_META:
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ package forestry.apiculture.gadgets;
|
|||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import forestry.api.apiculture.BeeManager;
|
|
||||||
import forestry.api.apiculture.IHiveDrop;
|
import forestry.api.apiculture.IHiveDrop;
|
||||||
import forestry.api.apiculture.hives.HiveManager;
|
import forestry.api.apiculture.hives.HiveManager;
|
||||||
import forestry.api.core.Tabs;
|
import forestry.api.core.Tabs;
|
||||||
@@ -123,9 +122,6 @@ public class BlockBeehives extends BlockContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<IHiveDrop> getDropsForHive(int meta) {
|
private List<IHiveDrop> getDropsForHive(int meta) {
|
||||||
if (meta == 8) //TODO: make a real hive for swarm
|
|
||||||
return BeeManager.hiveDrops[meta];
|
|
||||||
|
|
||||||
String hiveName = getHiveNameForMeta(meta);
|
String hiveName = getHiveNameForMeta(meta);
|
||||||
if (hiveName == null)
|
if (hiveName == null)
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -177,7 +173,7 @@ public class BlockBeehives extends BlockContainer {
|
|||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public IIcon getIcon(int i, int j) {
|
public IIcon getIcon(int i, int j) {
|
||||||
if (j == 0 || j >= 8)
|
if (j == 0 || j > 8)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (i == 0 || i == 1) {
|
if (i == 0 || i == 1) {
|
||||||
|
|||||||
@@ -34,15 +34,14 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
|||||||
}
|
}
|
||||||
protected final EnergyManager energyManager;
|
protected final EnergyManager energyManager;
|
||||||
private final ClimateControl climateControl;
|
private final ClimateControl climateControl;
|
||||||
private int transferTime = 0;
|
private int workingTime = 0;
|
||||||
private int animationDelay = 0;
|
|
||||||
private final int textureOff;
|
private final int textureOff;
|
||||||
private final int textureOn;
|
private final int textureOn;
|
||||||
|
|
||||||
public TileAlvearyClimatiser(ClimateControl control, int textureOff, int textureOn, int componentBlockMeta) {
|
public TileAlvearyClimatiser(ClimateControl control, int textureOff, int textureOn, int componentBlockMeta) {
|
||||||
super(componentBlockMeta);
|
super(componentBlockMeta);
|
||||||
this.climateControl = control;
|
this.climateControl = control;
|
||||||
energyManager = new EnergyManager(1000, 250, 2000);
|
energyManager = new EnergyManager(1000, 50, 2000);
|
||||||
energyManager.setReceiveOnly();
|
energyManager.setReceiveOnly();
|
||||||
this.textureOff = textureOff;
|
this.textureOff = textureOff;
|
||||||
this.textureOn = textureOn;
|
this.textureOn = textureOn;
|
||||||
@@ -60,28 +59,22 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
|||||||
if (!this.hasMaster())
|
if (!this.hasMaster())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (energyManager.consumeEnergyToDoWork()) {
|
boolean wasInactive = (workingTime == 0);
|
||||||
|
|
||||||
transferTime = energyManager.getEnergyPerWork();
|
if (workingTime < 20 && energyManager.consumeEnergyToDoWork()) {
|
||||||
|
// consume 10 RF per tick of work
|
||||||
if (animationDelay <= 0) {
|
workingTime += energyManager.getEnergyPerWork() / 10;
|
||||||
animationDelay = 100;
|
|
||||||
sendNetworkUpdate();
|
|
||||||
} else
|
|
||||||
animationDelay = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transferTime > 0) {
|
if (workingTime > 0) {
|
||||||
transferTime--;
|
workingTime--;
|
||||||
IAlvearyComponent component = (IAlvearyComponent) this.getCentralTE();
|
IAlvearyComponent component = (IAlvearyComponent) this.getCentralTE();
|
||||||
if (component != null)
|
if (component != null)
|
||||||
component.addTemperatureChange(climateControl.changePerTransfer, climateControl.boundaryDown, climateControl.boundaryUp);
|
component.addTemperatureChange(climateControl.changePerTransfer, climateControl.boundaryDown, climateControl.boundaryUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animationDelay > 0) {
|
if ((wasInactive && workingTime > 0) || (!wasInactive && workingTime == 0)) {
|
||||||
animationDelay--;
|
sendNetworkUpdate();
|
||||||
if (animationDelay <= 0)
|
|
||||||
sendNetworkUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +86,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
|||||||
/* TEXTURES */
|
/* TEXTURES */
|
||||||
@Override
|
@Override
|
||||||
public int getIcon(int side, int metadata) {
|
public int getIcon(int side, int metadata) {
|
||||||
if (animationDelay > 0)
|
if (workingTime > 0)
|
||||||
return textureOn;
|
return textureOn;
|
||||||
else
|
else
|
||||||
return textureOff;
|
return textureOff;
|
||||||
@@ -104,23 +97,23 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
|||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.readFromNBT(nbttagcompound);
|
super.readFromNBT(nbttagcompound);
|
||||||
energyManager.readFromNBT(nbttagcompound);
|
energyManager.readFromNBT(nbttagcompound);
|
||||||
transferTime = nbttagcompound.getInteger("Heating");
|
workingTime = nbttagcompound.getInteger("Heating");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.writeToNBT(nbttagcompound);
|
super.writeToNBT(nbttagcompound);
|
||||||
energyManager.writeToNBT(nbttagcompound);
|
energyManager.writeToNBT(nbttagcompound);
|
||||||
nbttagcompound.setInteger("Heating", transferTime);
|
nbttagcompound.setInteger("Heating", workingTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* NETWORK */
|
/* NETWORK */
|
||||||
@Override
|
@Override
|
||||||
public void fromPacketPayload(PacketPayload payload) {
|
public void fromPacketPayload(PacketPayload payload) {
|
||||||
short delay = payload.shortPayload[0];
|
short workingTime = payload.shortPayload[0];
|
||||||
if (animationDelay != delay) {
|
if (this.workingTime != workingTime) {
|
||||||
animationDelay = delay;
|
this.workingTime = workingTime;
|
||||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +121,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
|||||||
@Override
|
@Override
|
||||||
public PacketPayload getPacketPayload() {
|
public PacketPayload getPacketPayload() {
|
||||||
PacketPayload payload = new PacketPayload(0, 1);
|
PacketPayload payload = new PacketPayload(0, 1);
|
||||||
payload.shortPayload[0] = (short) animationDelay;
|
payload.shortPayload[0] = (short) workingTime;
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class TileAlvearyFan extends TileAlvearyClimatiser {
|
|||||||
public static final int BLOCK_META = 3;
|
public static final int BLOCK_META = 3;
|
||||||
|
|
||||||
public TileAlvearyFan() {
|
public TileAlvearyFan() {
|
||||||
super(new ClimateControl(-0.01f, 0.05f, 2.5f), BlockAlveary.TX_71_FNOF, BlockAlveary.TX_72_FNON, BLOCK_META);
|
super(new ClimateControl(-0.01f, 0.05f, 2.5f), BlockAlveary.ALVEARY_FAN_OFF, BlockAlveary.ALVEARY_FAN_ON, BLOCK_META);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,14 +12,11 @@ package forestry.apiculture.gadgets;
|
|||||||
|
|
||||||
public class TileAlvearyHeater extends TileAlvearyClimatiser {
|
public class TileAlvearyHeater extends TileAlvearyClimatiser {
|
||||||
|
|
||||||
public static final int TEXTURE_OFF = 57;
|
|
||||||
public static final int TEXTURE_ON = 58;
|
|
||||||
|
|
||||||
/* CONSTANTS */
|
/* CONSTANTS */
|
||||||
public static final int BLOCK_META = 4;
|
public static final int BLOCK_META = 4;
|
||||||
|
|
||||||
public TileAlvearyHeater() {
|
public TileAlvearyHeater() {
|
||||||
super(new ClimateControl(0.01f, 0.0f, 2.5f), BlockAlveary.TX_57_HTOF, BlockAlveary.TX_58_HTON, BLOCK_META);
|
super(new ClimateControl(0.01f, 0.0f, 2.5f), BlockAlveary.ALVEARY_HEATER_OFF, BlockAlveary.ALVEARY_HEATER_ON, BLOCK_META);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory
|
|||||||
/* TEXTURES */
|
/* TEXTURES */
|
||||||
@Override
|
@Override
|
||||||
public int getIcon(int side, int metadata) {
|
public int getIcon(int side, int metadata) {
|
||||||
return BlockAlveary.TX_73_VLVE;
|
return BlockAlveary.ALVEARY_HYGRO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
import net.minecraftforge.common.BiomeDictionary;
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -82,6 +81,17 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS
|
|||||||
player.openGui(ForestryAPI.instance, GuiId.AlvearyGUI.ordinal(), worldObj, masterX, masterY, masterZ);
|
player.openGui(ForestryAPI.instance, GuiId.AlvearyGUI.ordinal(), worldObj, masterX, masterY, masterZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
super.validate();
|
||||||
|
setBiomeInformation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBiomeInformation() {
|
||||||
|
this.biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||||
|
setErrorState(EnumErrorCode.OK);
|
||||||
|
}
|
||||||
|
|
||||||
/* LOADING & SAVING */
|
/* LOADING & SAVING */
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
@@ -115,8 +125,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS
|
|||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
this.biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
setBiomeInformation();
|
||||||
setErrorState(EnumErrorCode.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,17 +10,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package forestry.apiculture.gadgets;
|
package forestry.apiculture.gadgets;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
|
|
||||||
import forestry.api.apiculture.BeeManager;
|
import forestry.api.apiculture.BeeManager;
|
||||||
import forestry.api.apiculture.EnumBeeType;
|
import forestry.api.apiculture.EnumBeeType;
|
||||||
import forestry.api.apiculture.IAlvearyComponent;
|
import forestry.api.apiculture.IAlvearyComponent;
|
||||||
@@ -28,12 +17,23 @@ import forestry.api.apiculture.IBee;
|
|||||||
import forestry.api.apiculture.IBeeHousing;
|
import forestry.api.apiculture.IBeeHousing;
|
||||||
import forestry.api.core.ForestryAPI;
|
import forestry.api.core.ForestryAPI;
|
||||||
import forestry.api.core.ISpecialInventory;
|
import forestry.api.core.ISpecialInventory;
|
||||||
import forestry.apiculture.worldgen.WorldGenHive;
|
import forestry.apiculture.worldgen.HiveDecorator;
|
||||||
import forestry.apiculture.worldgen.WorldGenHiveSwamer;
|
import forestry.apiculture.worldgen.HiveSwarmer;
|
||||||
import forestry.core.network.GuiId;
|
import forestry.core.network.GuiId;
|
||||||
|
import forestry.core.network.PacketPayload;
|
||||||
import forestry.core.proxy.Proxies;
|
import forestry.core.proxy.Proxies;
|
||||||
|
import forestry.core.utils.StackUtils;
|
||||||
import forestry.core.utils.TileInventoryAdapter;
|
import forestry.core.utils.TileInventoryAdapter;
|
||||||
import forestry.plugins.PluginApiculture;
|
import forestry.plugins.PluginApiculture;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory {
|
public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory {
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
|||||||
|
|
||||||
TileInventoryAdapter swarmerInventory;
|
TileInventoryAdapter swarmerInventory;
|
||||||
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
|
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
|
||||||
|
private boolean isActive;
|
||||||
|
|
||||||
public TileAlvearySwarmer() {
|
public TileAlvearySwarmer() {
|
||||||
super(BLOCK_META);
|
super(BLOCK_META);
|
||||||
@@ -64,86 +65,103 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
|||||||
protected void updateServerSide() {
|
protected void updateServerSide() {
|
||||||
super.updateServerSide();
|
super.updateServerSide();
|
||||||
|
|
||||||
if (worldObj.getTotalWorldTime() % 100 != 0)
|
if (pendingSpawns.size() > 0) {
|
||||||
if (pendingSpawns.size() > 0)
|
setIsActive(true);
|
||||||
|
if (worldObj.getTotalWorldTime() % 1000 == 0)
|
||||||
trySpawnSwarm();
|
trySpawnSwarm();
|
||||||
|
} else {
|
||||||
|
setIsActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (worldObj.getTotalWorldTime() % 500 != 0)
|
if (worldObj.getTotalWorldTime() % 500 != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.hasMaster())
|
ItemStack princessStack = getPrincessStack();
|
||||||
|
if (princessStack == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IAlvearyComponent master = (IAlvearyComponent) this.getCentralTE();
|
int chance = consumeInducerAndGetChance();
|
||||||
if (!(master instanceof IBeeHousing))
|
if (chance == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IBeeHousing housing = (IBeeHousing) master;
|
|
||||||
ItemStack queenstack = housing.getQueen();
|
|
||||||
if (queenstack == null)
|
|
||||||
return;
|
|
||||||
if (!PluginApiculture.beeInterface.isMated(queenstack))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Calculate chance
|
|
||||||
int slot = getInducerSlot();
|
|
||||||
if (slot < 0)
|
|
||||||
return;
|
|
||||||
int chance = getChanceFor(swarmerInventory.getStackInSlot(slot));
|
|
||||||
|
|
||||||
// Remove resource
|
|
||||||
swarmerInventory.decrStackSize(slot, 1);
|
|
||||||
|
|
||||||
// Try to spawn princess
|
// Try to spawn princess
|
||||||
if (worldObj.rand.nextInt(1000) >= chance)
|
if (worldObj.rand.nextInt(1000) >= chance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Queue swarm spawn
|
// Queue swarm spawn
|
||||||
IBee spawn = PluginApiculture.beeInterface.getMember(queenstack);
|
IBee princess = PluginApiculture.beeInterface.getMember(princessStack);
|
||||||
spawn.setIsNatural(false);
|
princess.setIsNatural(false);
|
||||||
pendingSpawns.push(PluginApiculture.beeInterface.getMemberStack(spawn, EnumBeeType.PRINCESS.ordinal()));
|
pendingSpawns.push(PluginApiculture.beeInterface.getMemberStack(princess, EnumBeeType.PRINCESS.ordinal()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getChanceFor(ItemStack stack) {
|
private ItemStack getPrincessStack() {
|
||||||
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
|
if (!this.hasMaster())
|
||||||
if (entry.getKey().isItemEqual(stack))
|
return null;
|
||||||
return entry.getValue();
|
|
||||||
|
IAlvearyComponent master = (IAlvearyComponent) this.getCentralTE();
|
||||||
|
if (!(master instanceof IBeeHousing))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
IBeeHousing housing = (IBeeHousing) master;
|
||||||
|
ItemStack princessStack = housing.getQueen();
|
||||||
|
if (princessStack == null || !PluginApiculture.beeInterface.isMated(princessStack))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return princessStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int consumeInducerAndGetChance() {
|
||||||
|
if (swarmerInventory == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < swarmerInventory.getSizeInventory(); i++) {
|
||||||
|
ItemStack stack = swarmerInventory.getStackInSlot(i);
|
||||||
|
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
|
||||||
|
if (StackUtils.isIdenticalItem(entry.getKey(), stack)) {
|
||||||
|
swarmerInventory.decrStackSize(i, 1);
|
||||||
|
return entry.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getInducerSlot() {
|
|
||||||
for (int i = 0; i < swarmerInventory.getSizeInventory(); i++) {
|
|
||||||
if (swarmerInventory.getStackInSlot(i) == null)
|
|
||||||
continue;
|
|
||||||
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
|
|
||||||
if (entry.getKey().isItemEqual(swarmerInventory.getStackInSlot(i)))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void trySpawnSwarm() {
|
private void trySpawnSwarm() {
|
||||||
|
|
||||||
ItemStack toSpawn = pendingSpawns.peek();
|
ItemStack toSpawn = pendingSpawns.peek();
|
||||||
WorldGenHive generator = new WorldGenHiveSwamer(new ItemStack[] { toSpawn });
|
HiveSwarmer hive = new HiveSwarmer(128, toSpawn);
|
||||||
|
|
||||||
int i = 0;
|
int chunkX = (xCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16;
|
||||||
while (i < 10) {
|
int chunkZ = (zCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16;
|
||||||
i++;
|
|
||||||
int spawnX = xCoord + worldObj.rand.nextInt(40 * 2) - 40;
|
if (HiveDecorator.instance().genHive(worldObj, worldObj.rand, chunkX, chunkZ, hive)) {
|
||||||
int spawnY = yCoord + worldObj.rand.nextInt(40);
|
pendingSpawns.pop();
|
||||||
int spawnZ = zCoord + worldObj.rand.nextInt(40 * 2) - 40;
|
|
||||||
if (generator.generate(worldObj, worldObj.rand, spawnX, spawnY, spawnZ)) {
|
|
||||||
pendingSpawns.pop();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setIsActive(boolean isActive) {
|
||||||
|
if (this.isActive != isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
sendNetworkUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NETWORK */
|
||||||
|
@Override
|
||||||
|
public void fromPacketPayload(PacketPayload payload) {
|
||||||
|
boolean isActive = payload.shortPayload[0] > 0;
|
||||||
|
if (this.isActive != isActive) {
|
||||||
|
this.isActive = isActive;
|
||||||
|
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
|
@Override
|
||||||
@@ -157,10 +175,10 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
|||||||
if(side == 0 || side == 1)
|
if(side == 0 || side == 1)
|
||||||
return BlockAlveary.BOTTOM;
|
return BlockAlveary.BOTTOM;
|
||||||
|
|
||||||
if (pendingSpawns.size() > 0)
|
if (isActive)
|
||||||
return BlockAlveary.TX_56_SWON;
|
return BlockAlveary.ALVEARY_SWARMER_ON;
|
||||||
else
|
else
|
||||||
return BlockAlveary.TX_55_SWOF;
|
return BlockAlveary.ALVEARY_SWARMER_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SAVING & LOADING */
|
/* SAVING & LOADING */
|
||||||
|
|||||||
@@ -52,34 +52,39 @@ public class HiveDecorator {
|
|||||||
if (!TerrainGen.populate(event.chunkProvider, event.world, event.rand, event.chunkX, event.chunkZ, event.hasVillageGenerated, EVENT_TYPE)) {
|
if (!TerrainGen.populate(event.chunkProvider, event.world, event.rand, event.chunkX, event.chunkZ, event.hasVillageGenerated, EVENT_TYPE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
decorateHives(event.world, event.rand, event.chunkX * 16, event.chunkZ * 16);
|
decorateHives(event.world, event.rand, event.chunkX, event.chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decorateHives(World world, Random rand, int worldX, int worldZ) {
|
private void decorateHives(World world, Random rand, int chunkX, int chunkZ) {
|
||||||
for (IHive hive : HiveManager.getHives())
|
for (IHive hive : HiveManager.getHives())
|
||||||
if (Config.generateBeehivesDebug)
|
if (Config.generateBeehivesDebug)
|
||||||
genHiveDebug(world, worldX, worldZ, hive);
|
genHiveDebug(world, chunkX, chunkZ, hive);
|
||||||
else
|
else
|
||||||
genHive(world, rand, worldX, worldZ, hive);
|
genHive(world, rand, chunkX, chunkZ, hive);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genHive(World world, Random rand, int worldX, int worldZ, IHive hive) {
|
public boolean genHive(World world, Random rand, int chunkX, int chunkZ, IHive hive) {
|
||||||
if (hive.genChance() < rand.nextFloat() * 128.0f)
|
if (hive.genChance() < rand.nextFloat() * 128.0f)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
|
int worldX = chunkX * 16;
|
||||||
|
int worldZ = chunkZ * 16;
|
||||||
|
|
||||||
BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ);
|
BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ);
|
||||||
EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);
|
EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);
|
||||||
|
|
||||||
if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity))
|
if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
for (int tries = 0; tries < 4; tries ++) {
|
for (int tries = 0; tries < 4; tries ++) {
|
||||||
int x = worldX + rand.nextInt(16);
|
int x = worldX + rand.nextInt(16);
|
||||||
int z = worldZ + rand.nextInt(16);
|
int z = worldZ + rand.nextInt(16);
|
||||||
|
|
||||||
if (tryGenHive(world, x, z, hive))
|
if (tryGenHive(world, x, z, hive))
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genHiveDebug(World world, int worldX, int worldZ, IHive hive) {
|
private void genHiveDebug(World world, int worldX, int worldZ, IHive hive) {
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
package forestry.apiculture.worldgen;
|
package forestry.apiculture.worldgen;
|
||||||
|
|
||||||
import forestry.api.apiculture.hives.HiveGround;
|
import forestry.api.apiculture.hives.HiveGround;
|
||||||
import forestry.api.core.EnumHumidity;
|
|
||||||
import forestry.api.core.EnumTemperature;
|
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import forestry.api.apiculture.hives.HiveTree;
|
|||||||
import forestry.api.core.EnumHumidity;
|
import forestry.api.core.EnumHumidity;
|
||||||
import forestry.api.core.EnumTemperature;
|
import forestry.api.core.EnumTemperature;
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
public class HiveForest extends HiveTree {
|
public class HiveForest extends HiveTree {
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import forestry.api.apiculture.hives.HiveTree;
|
|||||||
import forestry.api.core.EnumHumidity;
|
import forestry.api.core.EnumHumidity;
|
||||||
import forestry.api.core.EnumTemperature;
|
import forestry.api.core.EnumTemperature;
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
public class HiveJungle extends HiveTree {
|
public class HiveJungle extends HiveTree {
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import forestry.api.core.EnumHumidity;
|
|||||||
import forestry.api.core.EnumTemperature;
|
import forestry.api.core.EnumTemperature;
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
public class HiveMeadows extends HiveGround {
|
public class HiveMeadows extends HiveGround {
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,10 @@
|
|||||||
package forestry.apiculture.worldgen;
|
package forestry.apiculture.worldgen;
|
||||||
|
|
||||||
import forestry.api.apiculture.hives.HiveGround;
|
import forestry.api.apiculture.hives.HiveGround;
|
||||||
import forestry.api.core.EnumHumidity;
|
|
||||||
import forestry.api.core.EnumTemperature;
|
import forestry.api.core.EnumTemperature;
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
public class HiveSnow extends HiveGround {
|
public class HiveSnow extends HiveGround {
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import forestry.api.core.EnumHumidity;
|
|||||||
import forestry.api.core.EnumTemperature;
|
import forestry.api.core.EnumTemperature;
|
||||||
import forestry.core.config.ForestryBlock;
|
import forestry.core.config.ForestryBlock;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
|
||||||
|
|
||||||
public class HiveSwamp extends HiveGround {
|
public class HiveSwamp extends HiveGround {
|
||||||
|
|
||||||
|
|||||||
Executable → Regular
+11
-23
@@ -4,46 +4,34 @@
|
|||||||
* are made available under the terms of the GNU Lesser Public License v3
|
* are made available under the terms of the GNU Lesser Public License v3
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||||
*
|
*
|
||||||
* Various Contributors including, but not limited to:
|
* Various Contributors including, but not limited to:
|
||||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package forestry.apiculture.worldgen;
|
package forestry.apiculture.worldgen;
|
||||||
|
|
||||||
import java.util.Random;
|
import forestry.api.apiculture.hives.HiveGround;
|
||||||
|
import forestry.apiculture.gadgets.TileSwarm;
|
||||||
|
import forestry.core.config.ForestryBlock;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import forestry.apiculture.gadgets.TileSwarm;
|
public class HiveSwarmer extends HiveGround {
|
||||||
|
|
||||||
/**
|
private final ItemStack[] bees;
|
||||||
*
|
|
||||||
* @author CovertJaguar <http://www.railcraft.info/>
|
|
||||||
*/
|
|
||||||
public class WorldGenHiveSwamer extends WorldGenHive {
|
|
||||||
|
|
||||||
private ItemStack[] bees;
|
public HiveSwarmer(float genChance, ItemStack... bees) {
|
||||||
|
super(ForestryBlock.beehives.block(), 8, genChance, Blocks.dirt, Blocks.grass);
|
||||||
public WorldGenHiveSwamer(ItemStack[] bees) {
|
|
||||||
this.bees = bees;
|
this.bees = bees;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean generate(World world, Random random, int x, int y, int z) {
|
public void postGen(World world, int x, int y, int z) {
|
||||||
if (world.blockExists(x, y, z) && world.isAirBlock(x, y, z) && (!world.isAirBlock(x, y - 1, z) || !world.isAirBlock(x, y + 1, z))) {
|
|
||||||
setHive(world, x, y, z, 8);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void postGen(World world, int x, int y, int z, int meta) {
|
|
||||||
TileEntity tile = world.getTileEntity(x, y, z);
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
if (tile instanceof TileSwarm)
|
if (tile instanceof TileSwarm)
|
||||||
((TileSwarm) tile).setContained(bees);
|
((TileSwarm) tile).setContained(bees);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,43 +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.apiculture.worldgen;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
|
||||||
|
|
||||||
import forestry.core.config.Defaults;
|
|
||||||
import forestry.core.config.ForestryBlock;
|
|
||||||
|
|
||||||
public abstract class WorldGenHive extends WorldGenerator {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract boolean generate(World world, Random random, int x, int y, int z);
|
|
||||||
|
|
||||||
protected void setHive(World world, int x, int y, int z, int meta) {
|
|
||||||
boolean placed = world.setBlock(x, y, z, ForestryBlock.beehives.block(), meta, Defaults.FLAG_BLOCK_SYNCH);
|
|
||||||
if (!placed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!ForestryBlock.beehives.isBlockEqual(world, x, y, z))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ForestryBlock.beehives.block().onBlockAdded(world, x, y, z);
|
|
||||||
world.markBlockForUpdate(x, y, z);
|
|
||||||
|
|
||||||
postGen(world, x, y, z, meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void postGen(World world, int x, int y, int z, int meta) {
|
|
||||||
ForestryBlock.beehives.block().onBlockPlaced(world, x, y, z, 0, 0.0f, 0.0f, 0.0f, meta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -101,4 +101,9 @@ public class BlockStainedGlass extends BlockBreakable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean canSilkHarvest() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -55,8 +55,6 @@ public class ContainerForestry extends Container {
|
|||||||
|
|
||||||
Slot slot = slotIndex < 0 ? null : (Slot) this.inventorySlots.get(slotIndex);
|
Slot slot = slotIndex < 0 ? null : (Slot) this.inventorySlots.get(slotIndex);
|
||||||
if (slot instanceof SlotForestry) {
|
if (slot instanceof SlotForestry) {
|
||||||
((SlotForestry) slot).onSlotClick(slotIndex, button, modifier, player);
|
|
||||||
|
|
||||||
if (((SlotForestry) slot).isPhantom()) {
|
if (((SlotForestry) slot).isPhantom()) {
|
||||||
return slotClickPhantom(slot, button, modifier, player);
|
return slotClickPhantom(slot, button, modifier, player);
|
||||||
}
|
}
|
||||||
@@ -67,29 +65,32 @@ public class ContainerForestry extends Container {
|
|||||||
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) {
|
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) {
|
||||||
ItemStack stack = null;
|
ItemStack stack = null;
|
||||||
|
|
||||||
|
ItemStack stackSlot = slot.getStack();
|
||||||
|
if (stackSlot != null)
|
||||||
|
stack = stackSlot.copy();
|
||||||
|
|
||||||
if (mouseButton == 2) {
|
if (mouseButton == 2) {
|
||||||
if (((SlotForestry) slot).canAdjustPhantom())
|
fillPhantomSlot(slot, null, mouseButton, modifier);
|
||||||
slot.putStack(null);
|
|
||||||
} else if (mouseButton == 0 || mouseButton == 1) {
|
} else if (mouseButton == 0 || mouseButton == 1) {
|
||||||
InventoryPlayer playerInv = player.inventory;
|
InventoryPlayer playerInv = player.inventory;
|
||||||
slot.onSlotChanged();
|
|
||||||
ItemStack stackSlot = slot.getStack();
|
|
||||||
ItemStack stackHeld = playerInv.getItemStack();
|
|
||||||
|
|
||||||
if (stackSlot != null)
|
ItemStack stackHeld = playerInv.getItemStack();
|
||||||
stack = stackSlot.copy();
|
|
||||||
|
|
||||||
if (stackSlot == null) {
|
if (stackSlot == null) {
|
||||||
if (stackHeld != null && slot.isItemValid(stackHeld))
|
if (stackHeld != null && slot.isItemValid(stackHeld))
|
||||||
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
||||||
} else if (stackHeld == null) {
|
} else if (stackHeld == null) {
|
||||||
adjustPhantomSlot(slot, mouseButton, modifier);
|
fillPhantomSlot(slot, null, mouseButton, modifier);
|
||||||
slot.onPickupFromSlot(player, playerInv.getItemStack());
|
|
||||||
} else if (slot.isItemValid(stackHeld))
|
} else if (slot.isItemValid(stackHeld))
|
||||||
if (StackUtils.isIdenticalItem(stackSlot, stackHeld))
|
if (StackUtils.isIdenticalItem(stackSlot, stackHeld))
|
||||||
adjustPhantomSlot(slot, mouseButton, modifier);
|
adjustPhantomSlot(slot, mouseButton, modifier);
|
||||||
else
|
else
|
||||||
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
||||||
|
} else if (mouseButton == 5) {
|
||||||
|
InventoryPlayer playerInv = player.inventory;
|
||||||
|
ItemStack stackHeld = playerInv.getItemStack();
|
||||||
|
if (!slot.getHasStack())
|
||||||
|
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,12 @@ public class ContainerForestry extends Container {
|
|||||||
protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier) {
|
protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier) {
|
||||||
if (!((SlotForestry) slot).canAdjustPhantom())
|
if (!((SlotForestry) slot).canAdjustPhantom())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (stackHeld == null) {
|
||||||
|
slot.putStack(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int stackSize = mouseButton == 0 ? stackHeld.stackSize : 1;
|
int stackSize = mouseButton == 0 ? stackHeld.stackSize : 1;
|
||||||
if (stackSize > slot.getSlotStackLimit())
|
if (stackSize > slot.getSlotStackLimit())
|
||||||
stackSize = slot.getSlotStackLimit();
|
stackSize = slot.getSlotStackLimit();
|
||||||
|
|||||||
@@ -214,9 +214,6 @@ public abstract class GuiForestry<T extends TileForestry> extends GuiContainer i
|
|||||||
|
|
||||||
widgetManager.handleMouseMove(mouseX, mouseY, mouseButton, time);
|
widgetManager.handleMouseMove(mouseX, mouseY, mouseButton, time);
|
||||||
|
|
||||||
Slot slot = getSlotAtPosition(mouseX, mouseY);
|
|
||||||
if (mouseButton == 1 && slot instanceof SlotForestry && ((SlotForestry) slot).isPhantom())
|
|
||||||
return;
|
|
||||||
super.mouseClickMove(mouseX, mouseY, mouseButton, time);
|
super.mouseClickMove(mouseX, mouseY, mouseButton, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,20 +10,22 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package forestry.core.gui.slots;
|
package forestry.core.gui.slots;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import forestry.core.interfaces.ICrafter;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.SlotCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import forestry.core.interfaces.ICrafter;
|
public class SlotCrafter extends SlotCrafting {
|
||||||
|
|
||||||
public class SlotCrafter extends Slot {
|
|
||||||
|
|
||||||
private final ICrafter crafter;
|
private final ICrafter crafter;
|
||||||
|
private final IInventory craftMatrix;
|
||||||
|
|
||||||
public SlotCrafter(IInventory inventory, ICrafter crafter, int slot, int xPos, int yPos) {
|
public SlotCrafter(EntityPlayer player, IInventory craftMatrix, ICrafter crafter, int slot, int xPos, int yPos) {
|
||||||
super(inventory, slot, xPos, yPos);
|
super(player, craftMatrix, craftMatrix, slot, xPos, yPos);
|
||||||
this.crafter = crafter;
|
this.crafter = crafter;
|
||||||
|
this.craftMatrix = craftMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,6 +58,8 @@ public class SlotCrafter extends Slot {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) {
|
public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) {
|
||||||
|
FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, craftMatrix);
|
||||||
|
this.onCrafting(itemStack, itemStack.stackSize); // handles crafting achievements, maps, and statistics
|
||||||
crafter.takenFromSlot(getSlotIndex(), true, player);
|
crafter.takenFromSlot(getSlotIndex(), true, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,12 @@ public class SlotForestry extends Slot implements IToolTipProvider{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putStack(ItemStack itemStack) {
|
||||||
|
if (!isPhantom() || canAdjustPhantom())
|
||||||
|
super.putStack(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
public SlotForestry setCanAdjustPhantom(boolean canAdjust) {
|
public SlotForestry setCanAdjustPhantom(boolean canAdjust) {
|
||||||
this.canAdjustPhantom = canAdjust;
|
this.canAdjustPhantom = canAdjust;
|
||||||
return this;
|
return this;
|
||||||
@@ -105,9 +111,6 @@ public class SlotForestry extends Slot implements IToolTipProvider{
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSlotClick(int slotIndex, int button, int modifier, EntityPlayer player) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param toolTips the tooltips to set
|
* @param toolTips the tooltips to set
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -47,6 +47,25 @@ public class ItemInventory implements IInventory, INBTTagable {
|
|||||||
readFromNBT(itemstack.getTagCompound());
|
readFromNBT(itemstack.getTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getOccupiedSlotCount(ItemStack itemStack) {
|
||||||
|
NBTTagCompound nbt = itemStack.getTagCompound();
|
||||||
|
if (nbt == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
if (nbt.hasKey("Items")) {
|
||||||
|
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
|
||||||
|
for (int i = 0; i < nbttaglist.tagCount(); i++) {
|
||||||
|
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||||
|
ItemStack itemStack1 = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||||
|
if (itemStack1 != null && itemStack1.stackSize > 0) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
protected void setUID(boolean override) {
|
protected void setUID(boolean override) {
|
||||||
if (parent.getTagCompound() == null)
|
if (parent.getTagCompound() == null)
|
||||||
parent.setTagCompound(new NBTTagCompound());
|
parent.setTagCompound(new NBTTagCompound());
|
||||||
|
|||||||
@@ -12,12 +12,19 @@ package forestry.core.utils;
|
|||||||
|
|
||||||
import forestry.api.recipes.RecipeManagers;
|
import forestry.api.recipes.RecipeManagers;
|
||||||
import forestry.core.config.Defaults;
|
import forestry.core.config.Defaults;
|
||||||
|
import forestry.core.gui.ContainerDummy;
|
||||||
import forestry.core.interfaces.IDescriptiveRecipe;
|
import forestry.core.interfaces.IDescriptiveRecipe;
|
||||||
import forestry.core.proxy.Proxies;
|
import forestry.core.proxy.Proxies;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class RecipeUtil {
|
public class RecipeUtil {
|
||||||
|
|
||||||
|
private static final Container DUMMY_CONTAINER = new ContainerDummy();
|
||||||
|
|
||||||
public static void injectLeveledRecipe(ItemStack resource, int fermentationValue, String output) {
|
public static void injectLeveledRecipe(ItemStack resource, int fermentationValue, String output) {
|
||||||
if (RecipeManagers.fermenterManager == null)
|
if (RecipeManagers.fermenterManager == null)
|
||||||
return;
|
return;
|
||||||
@@ -67,4 +74,53 @@ public class RecipeUtil {
|
|||||||
result[9] = output;
|
result[9] = output;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean canCraftRecipe(World world, ItemStack[] recipeItems, ItemStack recipeOutput, ItemStack[] availableItems) {
|
||||||
|
// Need at least one matched set
|
||||||
|
if (StackUtils.containsSets(recipeItems, availableItems, true, true) == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check that it doesn't make a different recipe.
|
||||||
|
// For example:
|
||||||
|
// Wood Logs are all ore dictionary equivalent with each other,
|
||||||
|
// but an Oak Log shouldn't be able to make Ebony Wood Planks
|
||||||
|
// because it makes Oak Wood Planks using the same recipe.
|
||||||
|
// Strategy:
|
||||||
|
// Create a fake crafting inventory using items we have in availableItems
|
||||||
|
// in place of the ones in the saved crafting inventory.
|
||||||
|
// Check that the recipe it makes is the same as the currentRecipe.
|
||||||
|
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
||||||
|
ItemStack[] stockCopy = StackUtils.condenseStacks(availableItems);
|
||||||
|
|
||||||
|
for (int slot = 0; slot < recipeItems.length; slot++) {
|
||||||
|
ItemStack recipeStack = recipeItems[slot];
|
||||||
|
if (recipeStack == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Use crafting equivalent (not oredict) items first
|
||||||
|
for (ItemStack stockStack : stockCopy) {
|
||||||
|
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
|
||||||
|
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
|
||||||
|
stockStack.stackSize--;
|
||||||
|
crafting.setInventorySlotContents(slot, stack);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use oredict items if crafting equivalent items aren't available
|
||||||
|
if (crafting.getStackInSlot(slot) == null) {
|
||||||
|
for (ItemStack stockStack : stockCopy) {
|
||||||
|
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
|
||||||
|
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
|
||||||
|
stockStack.stackSize--;
|
||||||
|
crafting.setInventorySlotContents(slot, stack);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemStack output = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||||
|
|
||||||
|
return ItemStack.areItemStacksEqual(output, recipeOutput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,23 +10,8 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package forestry.factory.gadgets;
|
package forestry.factory.gadgets;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.inventory.Container;
|
|
||||||
import net.minecraft.inventory.IInventory;
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import forestry.api.core.ForestryAPI;
|
import forestry.api.core.ForestryAPI;
|
||||||
import forestry.api.core.INBTTagable;
|
|
||||||
import forestry.core.gadgets.TileBase;
|
import forestry.core.gadgets.TileBase;
|
||||||
import forestry.core.gui.ContainerDummy;
|
|
||||||
import forestry.core.interfaces.ICrafter;
|
import forestry.core.interfaces.ICrafter;
|
||||||
import forestry.core.network.ForestryPacket;
|
import forestry.core.network.ForestryPacket;
|
||||||
import forestry.core.network.GuiId;
|
import forestry.core.network.GuiId;
|
||||||
@@ -35,309 +20,27 @@ import forestry.core.network.PacketTileNBT;
|
|||||||
import forestry.core.network.PacketTileUpdate;
|
import forestry.core.network.PacketTileUpdate;
|
||||||
import forestry.core.proxy.Proxies;
|
import forestry.core.proxy.Proxies;
|
||||||
import forestry.core.utils.InventoryAdapter;
|
import forestry.core.utils.InventoryAdapter;
|
||||||
import forestry.core.utils.PlainInventory;
|
import forestry.core.utils.RecipeUtil;
|
||||||
import forestry.core.utils.StackUtils;
|
|
||||||
import forestry.core.utils.TileInventoryAdapter;
|
import forestry.core.utils.TileInventoryAdapter;
|
||||||
|
import forestry.factory.recipes.RecipeMemory;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
public class TileWorktable extends TileBase implements ICrafter {
|
public class TileWorktable extends TileBase implements ICrafter {
|
||||||
|
|
||||||
/* CONSTANTS */
|
/* CONSTANTS */
|
||||||
public final static int SLOT_CRAFTING_1 = 0;
|
public final static int SLOT_CRAFTING_1 = 0;
|
||||||
|
public final static int SLOT_CRAFTING_COUNT = 9;
|
||||||
public final static int SLOT_CRAFTING_RESULT = 9;
|
public final static int SLOT_CRAFTING_RESULT = 9;
|
||||||
public final static short SLOT_INVENTORY_1 = 0;
|
public final static short SLOT_INVENTORY_1 = 0;
|
||||||
public final static short SLOT_INVENTORY_COUNT = 18;
|
public final static short SLOT_INVENTORY_COUNT = 18;
|
||||||
private final static Container DUMMY_CONTAINER = new ContainerDummy();
|
|
||||||
private final static RecipeBridge RECIPE_BRIDGE = new RecipeBridge();
|
|
||||||
|
|
||||||
private static class RecipeBridge {
|
|
||||||
public ItemStack findMatchingRecipe(InventoryCrafting crafting, World world) {
|
|
||||||
return CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* RECIPE MEMORY */
|
|
||||||
public static final class Recipe implements INBTTagable {
|
|
||||||
|
|
||||||
private InventoryAdapter matrix;
|
|
||||||
private long lastUsed;
|
|
||||||
private boolean locked;
|
|
||||||
private World cachedWorld;
|
|
||||||
private ItemStack cachedRecipeOutput;
|
|
||||||
|
|
||||||
public Recipe(InventoryCrafting crafting) {
|
|
||||||
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Recipe(NBTTagCompound nbttagcompound) {
|
|
||||||
readFromNBT(nbttagcompound);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCacheWorld(World world) {
|
|
||||||
this.cachedWorld = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean updateCachedRecipeOutput() {
|
|
||||||
|
|
||||||
if (cachedRecipeOutput != null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
|
||||||
for (int i = 0; i < crafting.getSizeInventory(); i++) {
|
|
||||||
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedRecipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, cachedWorld);
|
|
||||||
return cachedRecipeOutput != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateLastUse(World world) {
|
|
||||||
lastUsed = world.getTotalWorldTime();
|
|
||||||
setCacheWorld(world);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toogleLock() {
|
|
||||||
locked = !locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InventoryAdapter getMatrix() {
|
|
||||||
return matrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) {
|
|
||||||
if (updateCachedRecipeOutput())
|
|
||||||
return cachedRecipeOutput;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getRecipeOutput() {
|
|
||||||
if (updateCachedRecipeOutput())
|
|
||||||
return cachedRecipeOutput;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastUsed() {
|
|
||||||
return this.lastUsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLocked() {
|
|
||||||
return this.locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRecipeSize() {
|
|
||||||
return matrix.getSizeInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
|
|
||||||
|
|
||||||
if (!updateCachedRecipeOutput())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, world);
|
|
||||||
return recipeOutput != null && cachedRecipeOutput.isItemEqual(recipeOutput);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
|
||||||
matrix.readFromNBT(nbttagcompound);
|
|
||||||
sanitizeMatrix();
|
|
||||||
lastUsed = nbttagcompound.getLong("LastUsed");
|
|
||||||
locked = nbttagcompound.getBoolean("Locked");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
sanitizeMatrix();
|
|
||||||
matrix.writeToNBT(nbttagcompound);
|
|
||||||
nbttagcompound.setLong("LastUsed", lastUsed);
|
|
||||||
nbttagcompound.setBoolean("Locked", locked);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a nasty hack to hide a bug where the recipe stacks somehow
|
|
||||||
* get the stackSize set to -1. Which makes the recipe no longer work,
|
|
||||||
* ever. I've seen the bug, even inspected the NBT data of an afflicted
|
|
||||||
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
|
|
||||||
*/
|
|
||||||
private void sanitizeMatrix() {
|
|
||||||
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
|
|
||||||
ItemStack stack = matrix.getStackInSlot(slot);
|
|
||||||
if (stack != null)
|
|
||||||
stack.stackSize = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class RecipeMemory implements INBTTagable, IInventory {
|
|
||||||
|
|
||||||
private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
|
|
||||||
private long lastUpdate;
|
|
||||||
public final int capacity = 9;
|
|
||||||
|
|
||||||
public long getLastUpdate() {
|
|
||||||
return lastUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) {
|
|
||||||
|
|
||||||
lastUpdate = world.getTotalWorldTime();
|
|
||||||
recipe.updateLastUse(world);
|
|
||||||
|
|
||||||
Recipe memory = getMemorized(crafting, world);
|
|
||||||
if (memory != null) {
|
|
||||||
int index = recipes.indexOf(memory);
|
|
||||||
recipes.set(index, recipe);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recipes.size() < capacity) {
|
|
||||||
recipes.add(recipe);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Recipe oldest = null;
|
|
||||||
for (Recipe existing : recipes) {
|
|
||||||
if (oldest != null && oldest.getLastUsed() < existing.getLastUsed())
|
|
||||||
continue;
|
|
||||||
if (existing.isLocked())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
oldest = existing;
|
|
||||||
}
|
|
||||||
if (oldest != null) {
|
|
||||||
recipes.remove(oldest);
|
|
||||||
recipes.add(recipe);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Recipe getRecipe(int recipeIndex) {
|
|
||||||
if (recipes.size() > recipeIndex)
|
|
||||||
return recipes.get(recipeIndex);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getRecipeOutput(int recipeIndex) {
|
|
||||||
if (recipes.size() > recipeIndex)
|
|
||||||
return recipes.get(recipeIndex).getRecipeOutput();
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLocked(int recipeIndex) {
|
|
||||||
if (recipes.size() > recipeIndex)
|
|
||||||
return recipes.get(recipeIndex).isLocked();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleLock(World world, int recipeIndex) {
|
|
||||||
lastUpdate = world.getTotalWorldTime();
|
|
||||||
if (recipes.size() > recipeIndex)
|
|
||||||
recipes.get(recipeIndex).toogleLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Recipe getMemorized(InventoryCrafting crafting, World world) {
|
|
||||||
for (Recipe recipe : recipes) {
|
|
||||||
if (recipe.hasSameOutput(crafting, world))
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
recipes = new LinkedList<Recipe>();
|
|
||||||
if (!nbttagcompound.hasKey("RecipeMemory"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
NBTTagList nbttaglist = nbttagcompound.getTagList("RecipeMemory", 10);
|
|
||||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
|
||||||
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
|
|
||||||
recipes.add(new Recipe(nbttagcompound2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
NBTTagList nbttaglist = new NBTTagList();
|
|
||||||
for (Recipe recipe : recipes) {
|
|
||||||
if (recipe != null) {
|
|
||||||
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
|
||||||
recipe.writeToNBT(nbttagcompound2);
|
|
||||||
nbttaglist.appendTag(nbttagcompound2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nbttagcompound.setTag("RecipeMemory", nbttaglist);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeInventory() {
|
|
||||||
return recipes.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlot(int i) {
|
|
||||||
return getRecipeOutput(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack decrStackSize(int i, int j) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getStackInSlotOnClosing(int i) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getInventoryName() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCustomInventoryName() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInventoryStackLimit() {
|
|
||||||
return 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void markDirty() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void openInventory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeInventory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* MEMBERS */
|
/* MEMBERS */
|
||||||
private Recipe currentRecipe;
|
private RecipeMemory.Recipe currentRecipe;
|
||||||
private InventoryCrafting currentCrafting;
|
private InventoryCrafting currentCrafting;
|
||||||
private final RecipeMemory memorized;
|
private final RecipeMemory memorized;
|
||||||
private final TileInventoryAdapter craftingInventory;
|
private final TileInventoryAdapter craftingInventory;
|
||||||
@@ -392,6 +95,12 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
|
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
super.validate();
|
||||||
|
memorized.validate(worldObj);
|
||||||
|
}
|
||||||
|
|
||||||
/* RECIPE SELECTION */
|
/* RECIPE SELECTION */
|
||||||
public RecipeMemory getMemory() {
|
public RecipeMemory getMemory() {
|
||||||
return memorized;
|
return memorized;
|
||||||
@@ -405,9 +114,7 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipe recipe = memorized.getRecipe(recipeIndex);
|
IInventory matrix = memorized.getRecipeMatrix(recipeIndex);
|
||||||
recipe.sanitizeMatrix();
|
|
||||||
IInventory matrix = recipe.getMatrix();
|
|
||||||
if (matrix == null)
|
if (matrix == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -419,20 +126,20 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
/* CRAFTING */
|
/* CRAFTING */
|
||||||
public void setRecipe(InventoryCrafting crafting) {
|
public void setRecipe(InventoryCrafting crafting) {
|
||||||
|
|
||||||
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, worldObj);
|
ItemStack recipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, worldObj);
|
||||||
if (recipeOutput == null) {
|
if (recipeOutput == null) {
|
||||||
currentRecipe = null;
|
currentRecipe = null;
|
||||||
currentCrafting = null;
|
currentCrafting = null;
|
||||||
} else {
|
} else {
|
||||||
currentRecipe = new Recipe(crafting);
|
currentRecipe = new RecipeMemory.Recipe(crafting);
|
||||||
currentCrafting = crafting;
|
currentCrafting = crafting;
|
||||||
}
|
}
|
||||||
updateCraftResult(currentCrafting);
|
updateCraftResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCraftResult(InventoryCrafting inventorycrafting) {
|
private void updateCraftResult() {
|
||||||
if (currentRecipe != null) {
|
if (currentRecipe != null) {
|
||||||
ItemStack result = currentRecipe.getCraftingResult(inventorycrafting);
|
ItemStack result = currentRecipe.getRecipeOutput(worldObj);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy());
|
craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy());
|
||||||
return;
|
return;
|
||||||
@@ -446,56 +153,11 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
if (currentRecipe == null)
|
if (currentRecipe == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Need at least one matched set
|
ItemStack[] recipeItems = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||||
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
|
ItemStack[] inventory = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||||
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj);
|
||||||
if (StackUtils.containsSets(set, stock, true, true) == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Check that it doesn't make a different recipe.
|
return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory);
|
||||||
// For example:
|
|
||||||
// Wood Logs are all ore dictionary equivalent with each other,
|
|
||||||
// but an Oak Log shouldn't be able to make Ebony Wood Planks
|
|
||||||
// because it makes Oak Wood Planks using the same recipe.
|
|
||||||
// Strategy:
|
|
||||||
// Create a fake crafting inventory using items we have in stock
|
|
||||||
// in place of the ones in the saved crafting inventory.
|
|
||||||
// Check that the recipe it makes is the same as the currentRecipe.
|
|
||||||
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
|
||||||
ItemStack[] stockCopy = StackUtils.condenseStacks(stock);
|
|
||||||
|
|
||||||
for (int slot = 0; slot < currentCrafting.getSizeInventory(); slot++) {
|
|
||||||
ItemStack recipeStack = currentCrafting.getStackInSlot(slot);
|
|
||||||
if (recipeStack == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Use crafting equivalent (not oredict) items first
|
|
||||||
for (ItemStack stockStack : stockCopy) {
|
|
||||||
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
|
|
||||||
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
|
|
||||||
stockStack.stackSize--;
|
|
||||||
crafting.setInventorySlotContents(slot, stack);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use oredict items if crafting equivalent items aren't available
|
|
||||||
if (crafting.getStackInSlot(slot) == null) {
|
|
||||||
for (ItemStack stockStack : stockCopy) {
|
|
||||||
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
|
|
||||||
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
|
|
||||||
stockStack.stackSize--;
|
|
||||||
crafting.setInventorySlotContents(slot, stack);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, worldObj);
|
|
||||||
if (recipeOutput == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return recipeOutput.isItemEqual(currentRecipe.getRecipeOutput());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeResources(EntityPlayer player) {
|
private boolean removeResources(EntityPlayer player) {
|
||||||
@@ -518,8 +180,8 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
if (Proxies.common.isSimulating(worldObj))
|
if (Proxies.common.isSimulating(worldObj))
|
||||||
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
|
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
|
||||||
|
|
||||||
updateCraftResult(currentCrafting);
|
updateCraftResult();
|
||||||
return currentRecipe.getRecipeOutput().copy();
|
return currentRecipe.getRecipeOutput(worldObj).copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -527,8 +189,8 @@ public class TileWorktable extends TileBase implements ICrafter {
|
|||||||
if (currentRecipe == null)
|
if (currentRecipe == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (currentRecipe.getRecipeOutput() != null)
|
if (currentRecipe.getRecipeOutput(worldObj) != null)
|
||||||
return currentRecipe.getRecipeOutput().copy();
|
return currentRecipe.getRecipeOutput(worldObj).copy();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
|||||||
|
|
||||||
private final MachineFabricator tile;
|
private final MachineFabricator tile;
|
||||||
|
|
||||||
public ContainerFabricator(InventoryPlayer player, MachineFabricator tile) {
|
public ContainerFabricator(InventoryPlayer playerInventory, MachineFabricator tile) {
|
||||||
super(tile, tile);
|
super(tile, tile);
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
|||||||
this.addSlot(new Slot(tile, MachineFabricator.SLOT_PLAN, 139, 17));
|
this.addSlot(new Slot(tile, MachineFabricator.SLOT_PLAN, 139, 17));
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
this.addSlot(new SlotCrafter(tile, tile, MachineFabricator.SLOT_RESULT, 139, 53));
|
this.addSlot(new SlotCrafter(playerInventory.player, tile, tile, MachineFabricator.SLOT_RESULT, 139, 53));
|
||||||
|
|
||||||
// Crafting matrix
|
// Crafting matrix
|
||||||
for (int l = 0; l < 3; l++)
|
for (int l = 0; l < 3; l++)
|
||||||
@@ -46,10 +46,10 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
|||||||
// Player inventory
|
// Player inventory
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
for (int k = 0; k < 9; k++)
|
for (int k = 0; k < 9; k++)
|
||||||
addSlot(new Slot(player, k + i * 9 + 9, 8 + k * 18, 129 + i * 18));
|
addSlot(new Slot(playerInventory, k + i * 9 + 9, 8 + k * 18, 129 + i * 18));
|
||||||
// Player hotbar
|
// Player hotbar
|
||||||
for (int j = 0; j < 9; j++)
|
for (int j = 0; j < 9; j++)
|
||||||
addSlot(new Slot(player, j, 8 + j * 18, 187));
|
addSlot(new Slot(playerInventory, j, 8 + j * 18, 187));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CraftResult display
|
// CraftResult display
|
||||||
addSlot(new SlotCrafter(craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38));
|
addSlot(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38));
|
||||||
|
|
||||||
// Player inventory
|
// Player inventory
|
||||||
for (int i1 = 0; i1 < 3; i1++) {
|
for (int i1 = 0; i1 < 3; i1++) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import net.minecraft.client.renderer.OpenGlHelper;
|
|||||||
import net.minecraft.client.renderer.RenderHelper;
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
||||||
@@ -29,14 +30,16 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
|||||||
private class MemorizedSlot extends Widget {
|
private class MemorizedSlot extends Widget {
|
||||||
|
|
||||||
private final int slotNumber;
|
private final int slotNumber;
|
||||||
|
private final World world;
|
||||||
|
|
||||||
public MemorizedSlot(WidgetManager manager, int xPos, int yPos, int slot) {
|
public MemorizedSlot(World world, WidgetManager manager, int xPos, int yPos, int slot) {
|
||||||
super(manager, xPos, yPos);
|
super(manager, xPos, yPos);
|
||||||
this.slotNumber = slot;
|
this.slotNumber = slot;
|
||||||
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getOutputStack() {
|
private ItemStack getOutputStack() {
|
||||||
return worktable.getMemory().getRecipeOutput(slotNumber);
|
return worktable.getMemory().getRecipeOutput(world, slotNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,7 +114,7 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
|||||||
int yPos = 20 + (y * spacing);
|
int yPos = 20 + (y * spacing);
|
||||||
for (int x = 0; x < 3; x++) {
|
for (int x = 0; x < 3; x++) {
|
||||||
int xPos = 110 + (x * spacing);
|
int xPos = 110 + (x * spacing);
|
||||||
widgetManager.add(new MemorizedSlot(widgetManager, xPos, yPos, slot));
|
widgetManager.add(new MemorizedSlot(player.getEntityWorld(), widgetManager, xPos, yPos, slot));
|
||||||
slot += 1;
|
slot += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,259 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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.factory.recipes;
|
||||||
|
|
||||||
|
import forestry.api.core.INBTTagable;
|
||||||
|
import forestry.core.gui.ContainerDummy;
|
||||||
|
import forestry.core.utils.InventoryAdapter;
|
||||||
|
import forestry.core.utils.PlainInventory;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemMap;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class RecipeMemory implements INBTTagable {
|
||||||
|
|
||||||
|
public static final class Recipe implements INBTTagable {
|
||||||
|
|
||||||
|
private InventoryAdapter matrix;
|
||||||
|
private long lastUsed;
|
||||||
|
private boolean locked;
|
||||||
|
private ItemStack cachedRecipeOutput;
|
||||||
|
|
||||||
|
public Recipe(InventoryCrafting crafting) {
|
||||||
|
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipe(NBTTagCompound nbttagcompound) {
|
||||||
|
readFromNBT(nbttagcompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLastUse(long lastUsed) {
|
||||||
|
this.lastUsed = lastUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleLock() {
|
||||||
|
locked = !locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryAdapter getMatrix() {
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getRecipeOutput(World world) {
|
||||||
|
if (cachedRecipeOutput == null) {
|
||||||
|
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
|
||||||
|
for (int i = 0; i < crafting.getSizeInventory(); i++) {
|
||||||
|
crafting.setInventorySlotContents(i, matrix.getStackInSlot(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||||
|
}
|
||||||
|
return cachedRecipeOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastUsed() {
|
||||||
|
return this.lastUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLocked() {
|
||||||
|
return this.locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSameOutput(InventoryCrafting crafting, World world) {
|
||||||
|
ItemStack recipeOutput = getRecipeOutput(world);
|
||||||
|
if (recipeOutput == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ItemStack matchingRecipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, world);
|
||||||
|
return ItemStack.areItemStacksEqual(recipeOutput, matchingRecipeOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||||
|
matrix.readFromNBT(nbttagcompound);
|
||||||
|
sanitizeMatrix();
|
||||||
|
lastUsed = nbttagcompound.getLong("LastUsed");
|
||||||
|
locked = nbttagcompound.getBoolean("Locked");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
sanitizeMatrix();
|
||||||
|
matrix.writeToNBT(nbttagcompound);
|
||||||
|
nbttagcompound.setLong("LastUsed", lastUsed);
|
||||||
|
nbttagcompound.setBoolean("Locked", locked);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a nasty hack to hide a bug where the recipe stacks somehow
|
||||||
|
* get the stackSize set to -1. Which makes the recipe no longer work,
|
||||||
|
* ever. I've seen the bug, even inspected the NBT data of an afflicted
|
||||||
|
* worktable, but can't duplicate it, and can't trace it. -CovertJaguar
|
||||||
|
*/
|
||||||
|
private void sanitizeMatrix() {
|
||||||
|
for (int slot = 0; slot < matrix.getSizeInventory(); slot++) {
|
||||||
|
ItemStack stack = matrix.getStackInSlot(slot);
|
||||||
|
if (stack != null)
|
||||||
|
stack.stackSize = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Container DUMMY_CONTAINER = new ContainerDummy();
|
||||||
|
private static final List<Class<? extends Item>> memoryBlacklist = new ArrayList<Class<? extends Item>>();
|
||||||
|
static {
|
||||||
|
memoryBlacklist.add(ItemMap.class); // almost every ItemMap is unique
|
||||||
|
}
|
||||||
|
|
||||||
|
private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
|
||||||
|
private long lastUpdate;
|
||||||
|
public final int capacity = 9;
|
||||||
|
|
||||||
|
private static boolean isValid(World world, Recipe recipe) {
|
||||||
|
if (recipe == null)
|
||||||
|
return false;
|
||||||
|
ItemStack recipeOutput = recipe.getRecipeOutput(world);
|
||||||
|
if (recipeOutput == null)
|
||||||
|
return false;
|
||||||
|
Item item = recipeOutput.getItem();
|
||||||
|
return item != null && !memoryBlacklist.contains(item.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validate(World world) {
|
||||||
|
LinkedList<Recipe> validRecipes = new LinkedList<Recipe>();
|
||||||
|
for (Recipe recipe : recipes) {
|
||||||
|
if (isValid(world, recipe))
|
||||||
|
validRecipes.add(recipe);
|
||||||
|
}
|
||||||
|
this.recipes = validRecipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastUpdate() {
|
||||||
|
return lastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) {
|
||||||
|
|
||||||
|
if (!isValid(world, recipe))
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastUpdate = world.getTotalWorldTime();
|
||||||
|
recipe.updateLastUse(lastUpdate);
|
||||||
|
|
||||||
|
Recipe memory = getMemorized(crafting, world);
|
||||||
|
if (memory != null) {
|
||||||
|
int index = recipes.indexOf(memory);
|
||||||
|
recipes.set(index, recipe);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recipes.size() < capacity) {
|
||||||
|
recipes.add(recipe);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Recipe oldest = null;
|
||||||
|
for (Recipe existing : recipes) {
|
||||||
|
if (oldest != null && oldest.getLastUsed() < existing.getLastUsed())
|
||||||
|
continue;
|
||||||
|
if (existing.isLocked())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
oldest = existing;
|
||||||
|
}
|
||||||
|
if (oldest != null) {
|
||||||
|
recipes.remove(oldest);
|
||||||
|
recipes.add(recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipe getRecipe(int recipeIndex) {
|
||||||
|
if (recipes.size() > recipeIndex)
|
||||||
|
return recipes.get(recipeIndex);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IInventory getRecipeMatrix(int recipeIndex) {
|
||||||
|
RecipeMemory.Recipe recipe = getRecipe(recipeIndex);
|
||||||
|
recipe.sanitizeMatrix();
|
||||||
|
return recipe.getMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getRecipeOutput(World world, int recipeIndex) {
|
||||||
|
if (recipes.size() > recipeIndex)
|
||||||
|
return recipes.get(recipeIndex).getRecipeOutput(world);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLocked(int recipeIndex) {
|
||||||
|
if (recipes.size() > recipeIndex)
|
||||||
|
return recipes.get(recipeIndex).isLocked();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleLock(World world, int recipeIndex) {
|
||||||
|
lastUpdate = world.getTotalWorldTime();
|
||||||
|
if (recipes.size() > recipeIndex)
|
||||||
|
recipes.get(recipeIndex).toggleLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Recipe getMemorized(InventoryCrafting crafting, World world) {
|
||||||
|
for (Recipe recipe : recipes) {
|
||||||
|
if (recipe.hasSameOutput(crafting, world))
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
recipes = new LinkedList<Recipe>();
|
||||||
|
if (!nbttagcompound.hasKey("RecipeMemory"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
NBTTagList nbttaglist = nbttagcompound.getTagList("RecipeMemory", 10);
|
||||||
|
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||||
|
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j);
|
||||||
|
recipes.add(new Recipe(nbttagcompound2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
NBTTagList nbttaglist = new NBTTagList();
|
||||||
|
for (Recipe recipe : recipes) {
|
||||||
|
if (recipe != null) {
|
||||||
|
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
|
||||||
|
recipe.writeToNBT(nbttagcompound2);
|
||||||
|
nbttaglist.appendTag(nbttagcompound2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nbttagcompound.setTag("RecipeMemory", nbttaglist);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -314,11 +314,6 @@ public class PluginApiculture extends ForestryPlugin {
|
|||||||
|
|
||||||
registerTemplates();
|
registerTemplates();
|
||||||
|
|
||||||
definitionAnalyzer.register();
|
|
||||||
definitionApiary.register();
|
|
||||||
definitionBeehouse.register();
|
|
||||||
definitionChest.register();
|
|
||||||
|
|
||||||
GameRegistry.registerTileEntity(TileAlvearyPlain.class, "forestry.Alveary");
|
GameRegistry.registerTileEntity(TileAlvearyPlain.class, "forestry.Alveary");
|
||||||
GameRegistry.registerTileEntity(TileSwarm.class, "forestry.Swarm");
|
GameRegistry.registerTileEntity(TileSwarm.class, "forestry.Swarm");
|
||||||
GameRegistry.registerTileEntity(TileAlvearySwarmer.class, "forestry.AlvearySwarmer");
|
GameRegistry.registerTileEntity(TileAlvearySwarmer.class, "forestry.AlvearySwarmer");
|
||||||
@@ -715,6 +710,11 @@ public class PluginApiculture extends ForestryPlugin {
|
|||||||
|
|
||||||
// ANALYZER
|
// ANALYZER
|
||||||
definitionAnalyzer.recipes = createAlyzerRecipes(ForestryBlock.core.block(), Defaults.DEFINITION_ANALYZER_META);
|
definitionAnalyzer.recipes = createAlyzerRecipes(ForestryBlock.core.block(), Defaults.DEFINITION_ANALYZER_META);
|
||||||
|
|
||||||
|
definitionAnalyzer.register();
|
||||||
|
definitionApiary.register();
|
||||||
|
definitionBeehouse.register();
|
||||||
|
definitionChest.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRecipe[] createAlyzerRecipes(Block block, int meta) {
|
public IRecipe[] createAlyzerRecipes(Block block, int meta) {
|
||||||
|
|||||||
@@ -173,12 +173,6 @@ public class PluginIC2 extends ForestryPlugin {
|
|||||||
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_EFFICIENCY_I, "forestry.energyEfficiency1");
|
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_EFFICIENCY_I, "forestry.energyEfficiency1");
|
||||||
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_BOOST_I, "forestry.energyBoost1");
|
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_BOOST_I, "forestry.energyBoost1");
|
||||||
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_BOOST_II, "forestry.energyBoost2");
|
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_BOOST_II, "forestry.energyBoost2");
|
||||||
|
|
||||||
// Remove some items from the recycler
|
|
||||||
if (PluginManager.Module.APICULTURE.isEnabled()) {
|
|
||||||
Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beeQueenGE.getItemStack()));
|
|
||||||
Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beePrincessGE.getItemStack()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -188,6 +182,16 @@ public class PluginIC2 extends ForestryPlugin {
|
|||||||
|
|
||||||
config = Config.config;
|
config = Config.config;
|
||||||
|
|
||||||
|
// Remove some items from the recycler
|
||||||
|
if (Recipes.recyclerBlacklist != null) {
|
||||||
|
if (PluginManager.Module.APICULTURE.isEnabled()) {
|
||||||
|
Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beeQueenGE.getItemStack()));
|
||||||
|
Recipes.recyclerBlacklist.add(new RecipeInputItemStack(ForestryItem.beePrincessGE.getItemStack()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Proxies.log.severe("IC2 Recipes.recyclerBlacklist not found.");
|
||||||
|
}
|
||||||
|
|
||||||
definitionEngineTin.register();
|
definitionEngineTin.register();
|
||||||
definitionGenerator.register();
|
definitionGenerator.register();
|
||||||
|
|
||||||
|
|||||||
@@ -222,21 +222,7 @@ public class ItemBackpack extends ItemInventoried {
|
|||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
|
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
|
||||||
ItemInventory inventory = new ItemInventory(ItemBackpack.class, getBackpackSize(), itemstack);
|
int occupied = ItemInventory.getOccupiedSlotCount(itemstack);
|
||||||
|
|
||||||
// HashMap<ItemStack, Integer> contents = new HashMap<ItemStack,
|
|
||||||
// Integer>();
|
|
||||||
int occupied = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
||||||
if (inventory.getStackInSlot(i) == null)
|
|
||||||
continue;
|
|
||||||
if (inventory.getStackInSlot(i).stackSize <= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Count the slot as occupied
|
|
||||||
occupied++;
|
|
||||||
}
|
|
||||||
|
|
||||||
BackpackMode mode = getMode(itemstack);
|
BackpackMode mode = getMode(itemstack);
|
||||||
if (mode == BackpackMode.LOCKED)
|
if (mode == BackpackMode.LOCKED)
|
||||||
|
|||||||
Reference in new issue
Block a user