mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 09:04:42 +00:00
Compare 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
|
||||
forgeversion=10.13.0.1207
|
||||
version_major=3
|
||||
version_minor=1
|
||||
version_patch=1
|
||||
version_minor=3
|
||||
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 LEFT = 3;
|
||||
public static final int RIGHT = 4;
|
||||
public static final int TX_55_SWOF = 5;
|
||||
public static final int TX_56_SWON = 6;
|
||||
public static final int TX_57_HTOF = 7;
|
||||
public static final int TX_58_HTON = 8;
|
||||
public static final int TX_71_FNOF = 9;
|
||||
public static final int TX_72_FNON = 10;
|
||||
public static final int TX_73_VLVE = 11;
|
||||
public static final int ALVEARY_SWARMER_OFF = 5;
|
||||
public static final int ALVEARY_SWARMER_ON = 6;
|
||||
public static final int ALVEARY_HEATER_OFF = 7;
|
||||
public static final int ALVEARY_HEATER_ON = 8;
|
||||
public static final int ALVEARY_FAN_OFF = 9;
|
||||
public static final int ALVEARY_FAN_ON = 10;
|
||||
public static final int ALVEARY_HYGRO = 11;
|
||||
public static final int STABILISER = 12;
|
||||
public static final int SIEVE = 13;
|
||||
|
||||
@@ -152,13 +152,13 @@ public class BlockAlveary extends BlockStructure {
|
||||
case 1:
|
||||
return icons[ENTRANCE];
|
||||
case TileAlvearySwarmer.BLOCK_META:
|
||||
return icons[TX_55_SWOF];
|
||||
return icons[ALVEARY_SWARMER_OFF];
|
||||
case TileAlvearyFan.BLOCK_META:
|
||||
return icons[TX_71_FNOF];
|
||||
return icons[ALVEARY_FAN_OFF];
|
||||
case TileAlvearyHeater.BLOCK_META:
|
||||
return icons[TX_57_HTOF];
|
||||
return icons[ALVEARY_HEATER_OFF];
|
||||
case TileAlvearyHygroregulator.BLOCK_META:
|
||||
return icons[TX_73_VLVE];
|
||||
return icons[ALVEARY_HYGRO];
|
||||
case TileAlvearyStabiliser.BLOCK_META:
|
||||
return icons[STABILISER];
|
||||
case TileAlvearySieve.BLOCK_META:
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.apiculture.gadgets;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.IHiveDrop;
|
||||
import forestry.api.apiculture.hives.HiveManager;
|
||||
import forestry.api.core.Tabs;
|
||||
@@ -123,9 +122,6 @@ public class BlockBeehives extends BlockContainer {
|
||||
}
|
||||
|
||||
private List<IHiveDrop> getDropsForHive(int meta) {
|
||||
if (meta == 8) //TODO: make a real hive for swarm
|
||||
return BeeManager.hiveDrops[meta];
|
||||
|
||||
String hiveName = getHiveNameForMeta(meta);
|
||||
if (hiveName == null)
|
||||
return Collections.emptyList();
|
||||
@@ -177,7 +173,7 @@ public class BlockBeehives extends BlockContainer {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int i, int j) {
|
||||
if (j == 0 || j >= 8)
|
||||
if (j == 0 || j > 8)
|
||||
return null;
|
||||
|
||||
if (i == 0 || i == 1) {
|
||||
|
||||
@@ -34,15 +34,14 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
}
|
||||
protected final EnergyManager energyManager;
|
||||
private final ClimateControl climateControl;
|
||||
private int transferTime = 0;
|
||||
private int animationDelay = 0;
|
||||
private int workingTime = 0;
|
||||
private final int textureOff;
|
||||
private final int textureOn;
|
||||
|
||||
public TileAlvearyClimatiser(ClimateControl control, int textureOff, int textureOn, int componentBlockMeta) {
|
||||
super(componentBlockMeta);
|
||||
this.climateControl = control;
|
||||
energyManager = new EnergyManager(1000, 250, 2000);
|
||||
energyManager = new EnergyManager(1000, 50, 2000);
|
||||
energyManager.setReceiveOnly();
|
||||
this.textureOff = textureOff;
|
||||
this.textureOn = textureOn;
|
||||
@@ -60,28 +59,22 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
if (!this.hasMaster())
|
||||
return;
|
||||
|
||||
if (energyManager.consumeEnergyToDoWork()) {
|
||||
boolean wasInactive = (workingTime == 0);
|
||||
|
||||
transferTime = energyManager.getEnergyPerWork();
|
||||
|
||||
if (animationDelay <= 0) {
|
||||
animationDelay = 100;
|
||||
sendNetworkUpdate();
|
||||
} else
|
||||
animationDelay = 100;
|
||||
if (workingTime < 20 && energyManager.consumeEnergyToDoWork()) {
|
||||
// consume 10 RF per tick of work
|
||||
workingTime += energyManager.getEnergyPerWork() / 10;
|
||||
}
|
||||
|
||||
if (transferTime > 0) {
|
||||
transferTime--;
|
||||
if (workingTime > 0) {
|
||||
workingTime--;
|
||||
IAlvearyComponent component = (IAlvearyComponent) this.getCentralTE();
|
||||
if (component != null)
|
||||
component.addTemperatureChange(climateControl.changePerTransfer, climateControl.boundaryDown, climateControl.boundaryUp);
|
||||
}
|
||||
|
||||
if (animationDelay > 0) {
|
||||
animationDelay--;
|
||||
if (animationDelay <= 0)
|
||||
sendNetworkUpdate();
|
||||
if ((wasInactive && workingTime > 0) || (!wasInactive && workingTime == 0)) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +86,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
/* TEXTURES */
|
||||
@Override
|
||||
public int getIcon(int side, int metadata) {
|
||||
if (animationDelay > 0)
|
||||
if (workingTime > 0)
|
||||
return textureOn;
|
||||
else
|
||||
return textureOff;
|
||||
@@ -104,23 +97,23 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
energyManager.readFromNBT(nbttagcompound);
|
||||
transferTime = nbttagcompound.getInteger("Heating");
|
||||
workingTime = nbttagcompound.getInteger("Heating");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
energyManager.writeToNBT(nbttagcompound);
|
||||
nbttagcompound.setInteger("Heating", transferTime);
|
||||
nbttagcompound.setInteger("Heating", workingTime);
|
||||
}
|
||||
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
short delay = payload.shortPayload[0];
|
||||
if (animationDelay != delay) {
|
||||
animationDelay = delay;
|
||||
short workingTime = payload.shortPayload[0];
|
||||
if (this.workingTime != workingTime) {
|
||||
this.workingTime = workingTime;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +121,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
payload.shortPayload[0] = (short) animationDelay;
|
||||
payload.shortPayload[0] = (short) workingTime;
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TileAlvearyFan extends TileAlvearyClimatiser {
|
||||
public static final int BLOCK_META = 3;
|
||||
|
||||
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 static final int TEXTURE_OFF = 57;
|
||||
public static final int TEXTURE_ON = 58;
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final int BLOCK_META = 4;
|
||||
|
||||
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 */
|
||||
@Override
|
||||
public int getIcon(int side, int metadata) {
|
||||
return BlockAlveary.TX_73_VLVE;
|
||||
return BlockAlveary.ALVEARY_HYGRO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
setBiomeInformation();
|
||||
}
|
||||
|
||||
private void setBiomeInformation() {
|
||||
this.biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
/* LOADING & SAVING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
@@ -115,8 +125,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
this.biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
setBiomeInformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,17 +10,6 @@
|
||||
******************************************************************************/
|
||||
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.EnumBeeType;
|
||||
import forestry.api.apiculture.IAlvearyComponent;
|
||||
@@ -28,12 +17,23 @@ import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.apiculture.worldgen.WorldGenHive;
|
||||
import forestry.apiculture.worldgen.WorldGenHiveSwamer;
|
||||
import forestry.apiculture.worldgen.HiveDecorator;
|
||||
import forestry.apiculture.worldgen.HiveSwarmer;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.TileInventoryAdapter;
|
||||
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 {
|
||||
|
||||
@@ -42,6 +42,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
||||
|
||||
TileInventoryAdapter swarmerInventory;
|
||||
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
|
||||
private boolean isActive;
|
||||
|
||||
public TileAlvearySwarmer() {
|
||||
super(BLOCK_META);
|
||||
@@ -64,86 +65,103 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 100 != 0)
|
||||
if (pendingSpawns.size() > 0)
|
||||
if (pendingSpawns.size() > 0) {
|
||||
setIsActive(true);
|
||||
if (worldObj.getTotalWorldTime() % 1000 == 0)
|
||||
trySpawnSwarm();
|
||||
} else {
|
||||
setIsActive(false);
|
||||
}
|
||||
|
||||
if (worldObj.getTotalWorldTime() % 500 != 0)
|
||||
return;
|
||||
|
||||
if (!this.hasMaster())
|
||||
ItemStack princessStack = getPrincessStack();
|
||||
if (princessStack == null)
|
||||
return;
|
||||
|
||||
IAlvearyComponent master = (IAlvearyComponent) this.getCentralTE();
|
||||
if (!(master instanceof IBeeHousing))
|
||||
int chance = consumeInducerAndGetChance();
|
||||
if (chance == 0)
|
||||
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
|
||||
if (worldObj.rand.nextInt(1000) >= chance)
|
||||
return;
|
||||
|
||||
// Queue swarm spawn
|
||||
IBee spawn = PluginApiculture.beeInterface.getMember(queenstack);
|
||||
spawn.setIsNatural(false);
|
||||
pendingSpawns.push(PluginApiculture.beeInterface.getMemberStack(spawn, EnumBeeType.PRINCESS.ordinal()));
|
||||
|
||||
IBee princess = PluginApiculture.beeInterface.getMember(princessStack);
|
||||
princess.setIsNatural(false);
|
||||
pendingSpawns.push(PluginApiculture.beeInterface.getMemberStack(princess, EnumBeeType.PRINCESS.ordinal()));
|
||||
}
|
||||
|
||||
private int getChanceFor(ItemStack stack) {
|
||||
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
|
||||
if (entry.getKey().isItemEqual(stack))
|
||||
return entry.getValue();
|
||||
private ItemStack getPrincessStack() {
|
||||
if (!this.hasMaster())
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
ItemStack toSpawn = pendingSpawns.peek();
|
||||
WorldGenHive generator = new WorldGenHiveSwamer(new ItemStack[] { toSpawn });
|
||||
HiveSwarmer hive = new HiveSwarmer(128, toSpawn);
|
||||
|
||||
int i = 0;
|
||||
while (i < 10) {
|
||||
i++;
|
||||
int spawnX = xCoord + worldObj.rand.nextInt(40 * 2) - 40;
|
||||
int spawnY = yCoord + worldObj.rand.nextInt(40);
|
||||
int spawnZ = zCoord + worldObj.rand.nextInt(40 * 2) - 40;
|
||||
if (generator.generate(worldObj, worldObj.rand, spawnX, spawnY, spawnZ)) {
|
||||
pendingSpawns.pop();
|
||||
break;
|
||||
}
|
||||
int chunkX = (xCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16;
|
||||
int chunkZ = (zCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16;
|
||||
|
||||
if (HiveDecorator.instance().genHive(worldObj, worldObj.rand, chunkX, chunkZ, hive)) {
|
||||
pendingSpawns.pop();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -157,10 +175,10 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory
|
||||
if(side == 0 || side == 1)
|
||||
return BlockAlveary.BOTTOM;
|
||||
|
||||
if (pendingSpawns.size() > 0)
|
||||
return BlockAlveary.TX_56_SWON;
|
||||
if (isActive)
|
||||
return BlockAlveary.ALVEARY_SWARMER_ON;
|
||||
else
|
||||
return BlockAlveary.TX_55_SWOF;
|
||||
return BlockAlveary.ALVEARY_SWARMER_OFF;
|
||||
}
|
||||
|
||||
/* 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)) {
|
||||
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())
|
||||
if (Config.generateBeehivesDebug)
|
||||
genHiveDebug(world, worldX, worldZ, hive);
|
||||
genHiveDebug(world, chunkX, chunkZ, hive);
|
||||
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)
|
||||
return;
|
||||
return false;
|
||||
|
||||
int worldX = chunkX * 16;
|
||||
int worldZ = chunkZ * 16;
|
||||
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(worldX, worldZ);
|
||||
EnumHumidity humidity = EnumHumidity.getFromValue(biome.rainfall);
|
||||
|
||||
if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity))
|
||||
return;
|
||||
return false;
|
||||
|
||||
for (int tries = 0; tries < 4; tries ++) {
|
||||
int x = worldX + rand.nextInt(16);
|
||||
int z = worldZ + rand.nextInt(16);
|
||||
|
||||
if (tryGenHive(world, x, z, hive))
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void genHiveDebug(World world, int worldX, int worldZ, IHive hive) {
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
package forestry.apiculture.worldgen;
|
||||
|
||||
import forestry.api.apiculture.hives.HiveGround;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.init.Blocks;
|
||||
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.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class HiveForest extends HiveTree {
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import forestry.api.apiculture.hives.HiveTree;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class HiveJungle extends HiveTree {
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class HiveMeadows extends HiveGround {
|
||||
|
||||
|
||||
@@ -11,12 +11,10 @@
|
||||
package forestry.apiculture.worldgen;
|
||||
|
||||
import forestry.api.apiculture.hives.HiveGround;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
public class HiveSnow extends HiveGround {
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
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
|
||||
* 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 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.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.apiculture.gadgets.TileSwarm;
|
||||
public class HiveSwarmer extends HiveGround {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class WorldGenHiveSwamer extends WorldGenHive {
|
||||
private final ItemStack[] bees;
|
||||
|
||||
private ItemStack[] bees;
|
||||
|
||||
public WorldGenHiveSwamer(ItemStack[] bees) {
|
||||
public HiveSwarmer(float genChance, ItemStack... bees) {
|
||||
super(ForestryBlock.beehives.block(), 8, genChance, Blocks.dirt, Blocks.grass);
|
||||
this.bees = bees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(World world, Random random, 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) {
|
||||
public void postGen(World world, int x, int y, int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileSwarm)
|
||||
((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;
|
||||
}
|
||||
|
||||
@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);
|
||||
if (slot instanceof SlotForestry) {
|
||||
((SlotForestry) slot).onSlotClick(slotIndex, button, modifier, player);
|
||||
|
||||
if (((SlotForestry) slot).isPhantom()) {
|
||||
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) {
|
||||
ItemStack stack = null;
|
||||
|
||||
ItemStack stackSlot = slot.getStack();
|
||||
if (stackSlot != null)
|
||||
stack = stackSlot.copy();
|
||||
|
||||
if (mouseButton == 2) {
|
||||
if (((SlotForestry) slot).canAdjustPhantom())
|
||||
slot.putStack(null);
|
||||
fillPhantomSlot(slot, null, mouseButton, modifier);
|
||||
} else if (mouseButton == 0 || mouseButton == 1) {
|
||||
InventoryPlayer playerInv = player.inventory;
|
||||
slot.onSlotChanged();
|
||||
ItemStack stackSlot = slot.getStack();
|
||||
ItemStack stackHeld = playerInv.getItemStack();
|
||||
|
||||
if (stackSlot != null)
|
||||
stack = stackSlot.copy();
|
||||
ItemStack stackHeld = playerInv.getItemStack();
|
||||
|
||||
if (stackSlot == null) {
|
||||
if (stackHeld != null && slot.isItemValid(stackHeld))
|
||||
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
|
||||
} else if (stackHeld == null) {
|
||||
adjustPhantomSlot(slot, mouseButton, modifier);
|
||||
slot.onPickupFromSlot(player, playerInv.getItemStack());
|
||||
fillPhantomSlot(slot, null, mouseButton, modifier);
|
||||
} else if (slot.isItemValid(stackHeld))
|
||||
if (StackUtils.isIdenticalItem(stackSlot, stackHeld))
|
||||
adjustPhantomSlot(slot, mouseButton, modifier);
|
||||
else
|
||||
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;
|
||||
}
|
||||
@@ -116,6 +117,12 @@ public class ContainerForestry extends Container {
|
||||
protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier) {
|
||||
if (!((SlotForestry) slot).canAdjustPhantom())
|
||||
return;
|
||||
|
||||
if (stackHeld == null) {
|
||||
slot.putStack(null);
|
||||
return;
|
||||
}
|
||||
|
||||
int stackSize = mouseButton == 0 ? stackHeld.stackSize : 1;
|
||||
if (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);
|
||||
|
||||
Slot slot = getSlotAtPosition(mouseX, mouseY);
|
||||
if (mouseButton == 1 && slot instanceof SlotForestry && ((SlotForestry) slot).isPhantom())
|
||||
return;
|
||||
super.mouseClickMove(mouseX, mouseY, mouseButton, time);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,20 +10,22 @@
|
||||
******************************************************************************/
|
||||
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.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
|
||||
public class SlotCrafter extends Slot {
|
||||
public class SlotCrafter extends SlotCrafting {
|
||||
|
||||
private final ICrafter crafter;
|
||||
private final IInventory craftMatrix;
|
||||
|
||||
public SlotCrafter(IInventory inventory, ICrafter crafter, int slot, int xPos, int yPos) {
|
||||
super(inventory, slot, xPos, yPos);
|
||||
public SlotCrafter(EntityPlayer player, IInventory craftMatrix, ICrafter crafter, int slot, int xPos, int yPos) {
|
||||
super(player, craftMatrix, craftMatrix, slot, xPos, yPos);
|
||||
this.crafter = crafter;
|
||||
this.craftMatrix = craftMatrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,6 +58,8 @@ public class SlotCrafter extends Slot {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ public class SlotForestry extends Slot implements IToolTipProvider{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack itemStack) {
|
||||
if (!isPhantom() || canAdjustPhantom())
|
||||
super.putStack(itemStack);
|
||||
}
|
||||
|
||||
public SlotForestry setCanAdjustPhantom(boolean canAdjust) {
|
||||
this.canAdjustPhantom = canAdjust;
|
||||
return this;
|
||||
@@ -105,9 +111,6 @@ public class SlotForestry extends Slot implements IToolTipProvider{
|
||||
return result;
|
||||
}
|
||||
|
||||
public void onSlotClick(int slotIndex, int button, int modifier, EntityPlayer player) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toolTips the tooltips to set
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,25 @@ public class ItemInventory implements IInventory, INBTTagable {
|
||||
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) {
|
||||
if (parent.getTagCompound() == null)
|
||||
parent.setTagCompound(new NBTTagCompound());
|
||||
|
||||
@@ -12,12 +12,19 @@ package forestry.core.utils;
|
||||
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.gui.ContainerDummy;
|
||||
import forestry.core.interfaces.IDescriptiveRecipe;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RecipeUtil {
|
||||
|
||||
private static final Container DUMMY_CONTAINER = new ContainerDummy();
|
||||
|
||||
public static void injectLeveledRecipe(ItemStack resource, int fermentationValue, String output) {
|
||||
if (RecipeManagers.fermenterManager == null)
|
||||
return;
|
||||
@@ -67,4 +74,53 @@ public class RecipeUtil {
|
||||
result[9] = output;
|
||||
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;
|
||||
|
||||
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.INBTTagable;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gui.ContainerDummy;
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.GuiId;
|
||||
@@ -35,309 +20,27 @@ import forestry.core.network.PacketTileNBT;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.PlainInventory;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.RecipeUtil;
|
||||
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 {
|
||||
|
||||
/* CONSTANTS */
|
||||
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 short SLOT_INVENTORY_1 = 0;
|
||||
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 */
|
||||
private Recipe currentRecipe;
|
||||
private RecipeMemory.Recipe currentRecipe;
|
||||
private InventoryCrafting currentCrafting;
|
||||
private final RecipeMemory memorized;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
memorized.validate(worldObj);
|
||||
}
|
||||
|
||||
/* RECIPE SELECTION */
|
||||
public RecipeMemory getMemory() {
|
||||
return memorized;
|
||||
@@ -405,9 +114,7 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
return;
|
||||
}
|
||||
|
||||
Recipe recipe = memorized.getRecipe(recipeIndex);
|
||||
recipe.sanitizeMatrix();
|
||||
IInventory matrix = recipe.getMatrix();
|
||||
IInventory matrix = memorized.getRecipeMatrix(recipeIndex);
|
||||
if (matrix == null)
|
||||
return;
|
||||
|
||||
@@ -419,20 +126,20 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
/* CRAFTING */
|
||||
public void setRecipe(InventoryCrafting crafting) {
|
||||
|
||||
ItemStack recipeOutput = RECIPE_BRIDGE.findMatchingRecipe(crafting, worldObj);
|
||||
ItemStack recipeOutput = CraftingManager.getInstance().findMatchingRecipe(crafting, worldObj);
|
||||
if (recipeOutput == null) {
|
||||
currentRecipe = null;
|
||||
currentCrafting = null;
|
||||
} else {
|
||||
currentRecipe = new Recipe(crafting);
|
||||
currentRecipe = new RecipeMemory.Recipe(crafting);
|
||||
currentCrafting = crafting;
|
||||
}
|
||||
updateCraftResult(currentCrafting);
|
||||
updateCraftResult();
|
||||
}
|
||||
|
||||
private void updateCraftResult(InventoryCrafting inventorycrafting) {
|
||||
private void updateCraftResult() {
|
||||
if (currentRecipe != null) {
|
||||
ItemStack result = currentRecipe.getCraftingResult(inventorycrafting);
|
||||
ItemStack result = currentRecipe.getRecipeOutput(worldObj);
|
||||
if (result != null) {
|
||||
craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, result.copy());
|
||||
return;
|
||||
@@ -446,56 +153,11 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
if (currentRecipe == null)
|
||||
return false;
|
||||
|
||||
// Need at least one matched set
|
||||
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
|
||||
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
if (StackUtils.containsSets(set, stock, true, true) == 0)
|
||||
return false;
|
||||
ItemStack[] recipeItems = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
|
||||
ItemStack[] inventory = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj);
|
||||
|
||||
// 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 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());
|
||||
return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory);
|
||||
}
|
||||
|
||||
private boolean removeResources(EntityPlayer player) {
|
||||
@@ -518,8 +180,8 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
if (Proxies.common.isSimulating(worldObj))
|
||||
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
|
||||
|
||||
updateCraftResult(currentCrafting);
|
||||
return currentRecipe.getRecipeOutput().copy();
|
||||
updateCraftResult();
|
||||
return currentRecipe.getRecipeOutput(worldObj).copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -527,8 +189,8 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
if (currentRecipe == null)
|
||||
return null;
|
||||
|
||||
if (currentRecipe.getRecipeOutput() != null)
|
||||
return currentRecipe.getRecipeOutput().copy();
|
||||
if (currentRecipe.getRecipeOutput(worldObj) != null)
|
||||
return currentRecipe.getRecipeOutput(worldObj).copy();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
||||
|
||||
private final MachineFabricator tile;
|
||||
|
||||
public ContainerFabricator(InventoryPlayer player, MachineFabricator tile) {
|
||||
public ContainerFabricator(InventoryPlayer playerInventory, MachineFabricator tile) {
|
||||
super(tile, tile);
|
||||
this.tile = tile;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
||||
this.addSlot(new Slot(tile, MachineFabricator.SLOT_PLAN, 139, 17));
|
||||
|
||||
// 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
|
||||
for (int l = 0; l < 3; l++)
|
||||
@@ -46,10 +46,10 @@ public class ContainerFabricator extends ContainerLiquidTanks {
|
||||
// Player inventory
|
||||
for (int i = 0; i < 3; i++)
|
||||
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
|
||||
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
|
||||
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
|
||||
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.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
||||
@@ -29,14 +30,16 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
||||
private class MemorizedSlot extends Widget {
|
||||
|
||||
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);
|
||||
this.slotNumber = slot;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
private ItemStack getOutputStack() {
|
||||
return worktable.getMemory().getRecipeOutput(slotNumber);
|
||||
return worktable.getMemory().getRecipeOutput(world, slotNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +114,7 @@ public class GuiWorktable extends GuiForestryTitled<TileWorktable> {
|
||||
int yPos = 20 + (y * spacing);
|
||||
for (int x = 0; x < 3; x++) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
definitionAnalyzer.register();
|
||||
definitionApiary.register();
|
||||
definitionBeehouse.register();
|
||||
definitionChest.register();
|
||||
|
||||
GameRegistry.registerTileEntity(TileAlvearyPlain.class, "forestry.Alveary");
|
||||
GameRegistry.registerTileEntity(TileSwarm.class, "forestry.Swarm");
|
||||
GameRegistry.registerTileEntity(TileAlvearySwarmer.class, "forestry.AlvearySwarmer");
|
||||
@@ -715,6 +710,11 @@ public class PluginApiculture extends ForestryPlugin {
|
||||
|
||||
// ANALYZER
|
||||
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) {
|
||||
|
||||
@@ -173,12 +173,6 @@ public class PluginIC2 extends ForestryPlugin {
|
||||
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_EFFICIENCY_I, "forestry.energyEfficiency1");
|
||||
ChipsetManager.circuitRegistry.registerLegacyMapping(CircuitId.ELECTRIC_BOOST_I, "forestry.energyBoost1");
|
||||
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
|
||||
@@ -188,6 +182,16 @@ public class PluginIC2 extends ForestryPlugin {
|
||||
|
||||
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();
|
||||
definitionGenerator.register();
|
||||
|
||||
|
||||
@@ -222,21 +222,7 @@ public class ItemBackpack extends ItemInventoried {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
|
||||
ItemInventory inventory = new ItemInventory(ItemBackpack.class, getBackpackSize(), 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++;
|
||||
}
|
||||
int occupied = ItemInventory.getOccupiedSlotCount(itemstack);
|
||||
|
||||
BackpackMode mode = getMode(itemstack);
|
||||
if (mode == BackpackMode.LOCKED)
|
||||
|
||||
Reference in new issue
Block a user