diff --git a/.gitignore b/.gitignore index 172724f05..05b1bfc97 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ !/forestry_techne !/gradle/wrapper !/src +!/api # files !/.gitignore diff --git a/.gitmodules b/.gitmodules index 8739ca90f..a49c244e4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "lang"] path = lang url = https://github.com/ForestryMC/Forestry-Localization.git -[submodule "api"] - path = api - url = https://github.com/ForestryMC/ForestryAPI.git +[submodule "api/redstoneflux"] + path = api/redstoneflux + url = https://github.com/CoFH/RedstoneFlux-API.git diff --git a/api b/api deleted file mode 160000 index 2bb45e18b..000000000 --- a/api +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2bb45e18be423c110d61a5b393671dd11ffa7dc8 diff --git a/api/redstoneflux b/api/redstoneflux new file mode 160000 index 000000000..10e10af21 --- /dev/null +++ b/api/redstoneflux @@ -0,0 +1 @@ +Subproject commit 10e10af21489e351624813120ed6474c44b09ff6 diff --git a/application.properties b/application.properties index 8c91f8142..22eb084d3 100644 --- a/application.properties +++ b/application.properties @@ -1,5 +1,5 @@ mcversion=1.7.10 -forgeversion=10.13.0.1207 +forgeversion=10.13.2.1286 version_major=3 version_minor=3 version_patch=0 diff --git a/build.gradle b/build.gradle index 2d32dfbb6..d3175fa11 100755 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,9 @@ archivesBaseName = "forestry_" + mcversion ext.dirDest = './build/dist' ext.dirLang = "./lang" -ext.dirApi = "./api" + +ext.apiForestry = "./api/forestry" +ext.apiRedstoneFlux = "./api/redstoneflux" ext.CraftGuideRepo = "https://github.com/Uristqwerty/CraftGuide.git" ext.CraftGuideTmp = "build/tmp/CraftGuide" @@ -54,7 +56,8 @@ sourceSets { main { java { - srcDir project.dirApi + srcDir project.apiForestry + srcDir project.apiRedstoneFlux + "/src/main/java" } resources { srcDir project.dirLang @@ -70,13 +73,13 @@ repositories { } configurations { - apis - compile.extendsFrom apis + api + compile.extendsFrom api } dependencies { - compile 'net.industrial-craft:industrialcraft-2:2.2.575-experimental:api' - apis 'com.mod-buildcraft:buildcraft:6.2.1:dev' + api 'net.industrial-craft:industrialcraft-2:2.2.575-experimental:api' + api 'com.mod-buildcraft:buildcraft:6.3.1:dev' } processResources { @@ -178,12 +181,15 @@ jar { destinationDir = file("build/tmp") archiveName = "main.jar" - from { - configurations.apis.collect { - it.isDirectory() ? it : zipTree(it).matching { - include '**/api/**' - } - } + // Copy various READMEs and Licensing files into the jar + into ('forestry/api') { + from project.apiForestry + "/LICENSE.txt" + } + into ('cofh/api') { + from project.apiRedstoneFlux + "/LICENSE - LGPLv3.txt" + } + into ('buildcraft/api') { + from "./src/main/java/buildcraft/LICENSE-API" } } @@ -191,7 +197,6 @@ task mainJarSigned ( type: Jar, dependsOn: 'reobf' ) { from (zipTree(jar.getArchivePath())) { exclude '**/api/**' exclude '**/codechicken/**' - exclude '**/old/lang/**' } duplicatesStrategy = DuplicatesStrategy.EXCLUDE @@ -218,7 +223,6 @@ task mainJar ( type: Zip, dependsOn: mainJarSigned ) { from (zipTree(jar.getArchivePath())) { include '**' exclude '**/codechicken/**' - exclude '**/old/lang/**' } duplicatesStrategy = DuplicatesStrategy.EXCLUDE @@ -231,7 +235,6 @@ task devJarSigned ( type: Jar, dependsOn: 'classes' ) { from(sourceSets.main.output) { exclude '**/api/**' exclude '**/codechicken/**' - exclude '**/old/lang/**' } destinationDir = file("build/tmp") @@ -257,21 +260,11 @@ task devJar ( type: Zip, dependsOn: devJarSigned ) { from(sourceSets.main.allSource) { include '**' exclude '**/codechicken/**' - exclude '**/old/lang/**' } from(sourceSets.main.output) { include '**' exclude '**/codechicken/**' - exclude '**/old/lang/**' - } - - from { - configurations.apis.collect { - it.isDirectory() ? it : zipTree(it).matching { - include '**/api/**' - } - } } duplicatesStrategy = DuplicatesStrategy.EXCLUDE @@ -282,9 +275,7 @@ task devJar ( type: Zip, dependsOn: devJarSigned ) { } task apiJar(type: Jar, dependsOn: 'classes') { - from (dirApi) { - include '**' - } + from project.apiForestry from (sourceSets.main.output) { include 'forestry/api/**' @@ -295,14 +286,19 @@ task apiJar(type: Jar, dependsOn: 'classes') { classifier = 'api' } -task release(dependsOn: [apiJar, devJar, mainJar]) { - doLast { - println '*************************************************************' - println 'This build will be version: ' + project.version - println '*************************************************************' - } +task releaseInit << { + println '*************************************************************' + println 'This build will be version: ' + rootProject.version + println '*************************************************************' } +task release (dependsOn: [releaseInit, apiJar, devJar, mainJar]) { +} + +mainJar.shouldRunAfter releaseInit +devJar.shouldRunAfter releaseInit +apiJar.shouldRunAfter releaseInit + afterEvaluate { compileApiJava.dependsOn initCraftGuide } diff --git a/lang b/lang index 3c34adcc5..f461a7b02 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 3c34adcc54f2e1dc0d06b6720261fcd77c4e2f24 +Subproject commit f461a7b0222fba3b4518da94da14b9b5d10c898e diff --git a/src/main/java/buildcraft/LICENSE-API b/src/main/java/buildcraft/LICENSE-API new file mode 100644 index 000000000..95f750db0 --- /dev/null +++ b/src/main/java/buildcraft/LICENSE-API @@ -0,0 +1,21 @@ +BuildCraft API License + +Copyright (c) 2011-2014 SpaceToad and the BuildCraft team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/main/java/buildcraft/api/tools/IToolWrench.java b/src/main/java/buildcraft/api/tools/IToolWrench.java new file mode 100644 index 000000000..517f3e79b --- /dev/null +++ b/src/main/java/buildcraft/api/tools/IToolWrench.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. + * Please check the contents of the license, which should be located + * as "LICENSE.API" in the BuildCraft source code distribution. + */ +package buildcraft.api.tools; + +import net.minecraft.entity.player.EntityPlayer; + +/*** + * Implement this interface on subclasses of Item to have that item work as a wrench for buildcraft + */ +public interface IToolWrench { + + /*** + * Called to ensure that the wrench can be used. To get the ItemStack that is used, check player.inventory.getCurrentItem() + * + * @param player + * - The player doing the wrenching + * @param x + * ,y,z - The coordinates for the block being wrenched + * + * @return true if wrenching is allowed, false if not + */ + boolean canWrench(EntityPlayer player, int x, int y, int z); + + /*** + * Callback after the wrench has been used. This can be used to decrease durability or for other purposes. To get the ItemStack that was used, check + * player.inventory.getCurrentItem() + * + * @param player + * - The player doing the wrenching + * @param x + * ,y,z - The coordinates of the block being wrenched + */ + void wrenchUsed(EntityPlayer player, int x, int y, int z); +} diff --git a/src/main/java/buildcraft/api/tools/package-info.java b/src/main/java/buildcraft/api/tools/package-info.java new file mode 100644 index 000000000..9c131641e --- /dev/null +++ b/src/main/java/buildcraft/api/tools/package-info.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. + * Please check the contents of the license, which should be located + * as "LICENSE.API" in the BuildCraft source code distribution. + */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tools") +package buildcraft.api.tools; +import cpw.mods.fml.common.API; diff --git a/src/main/java/cofh/api/CoFHAPIProps.java b/src/main/java/cofh/api/CoFHAPIProps.java deleted file mode 100644 index 22096377f..000000000 --- a/src/main/java/cofh/api/CoFHAPIProps.java +++ /dev/null @@ -1,11 +0,0 @@ -package cofh.api; - -public class CoFHAPIProps { - - private CoFHAPIProps() { - - } - - public static final String VERSION = "1.7.10R1.0.1"; - -} diff --git a/src/main/java/cofh/api/energy/EnergyStorage.java b/src/main/java/cofh/api/energy/EnergyStorage.java deleted file mode 100644 index 2dfd2b1b6..000000000 --- a/src/main/java/cofh/api/energy/EnergyStorage.java +++ /dev/null @@ -1,158 +0,0 @@ -package cofh.api.energy; - -import net.minecraft.nbt.NBTTagCompound; - -/** - * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. - * - * @author King Lemming - * - */ -public class EnergyStorage implements IEnergyStorage { - - protected int energy; - protected int capacity; - protected int maxReceive; - protected int maxExtract; - - public EnergyStorage(int capacity) { - - this(capacity, capacity, capacity); - } - - public EnergyStorage(int capacity, int maxTransfer) { - - this(capacity, maxTransfer, maxTransfer); - } - - public EnergyStorage(int capacity, int maxReceive, int maxExtract) { - - this.capacity = capacity; - this.maxReceive = maxReceive; - this.maxExtract = maxExtract; - } - - public EnergyStorage readFromNBT(NBTTagCompound nbt) { - - this.energy = nbt.getInteger("Energy"); - - if (energy > capacity) { - energy = capacity; - } - return this; - } - - public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - - if (energy < 0) { - energy = 0; - } - nbt.setInteger("Energy", energy); - return nbt; - } - - public void setCapacity(int capacity) { - - this.capacity = capacity; - - if (energy > capacity) { - energy = capacity; - } - } - - public void setMaxTransfer(int maxTransfer) { - - setMaxReceive(maxTransfer); - setMaxExtract(maxTransfer); - } - - public void setMaxReceive(int maxReceive) { - - this.maxReceive = maxReceive; - } - - public void setMaxExtract(int maxExtract) { - - this.maxExtract = maxExtract; - } - - public int getMaxReceive() { - - return maxReceive; - } - - public int getMaxExtract() { - - return maxExtract; - } - - /** - * This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are - * guaranteed to have it. - * - * @param energy - */ - public void setEnergyStored(int energy) { - - this.energy = energy; - - if (this.energy > capacity) { - this.energy = capacity; - } else if (this.energy < 0) { - this.energy = 0; - } - } - - /** - * This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this - * externally, as not all IEnergyHandlers are guaranteed to have it. - * - * @param energy - */ - public void modifyEnergyStored(int energy) { - - this.energy += energy; - - if (this.energy > capacity) { - this.energy = capacity; - } else if (this.energy < 0) { - this.energy = 0; - } - } - - /* IEnergyStorage */ - @Override - public int receiveEnergy(int maxReceive, boolean simulate) { - - int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); - - if (!simulate) { - energy += energyReceived; - } - return energyReceived; - } - - @Override - public int extractEnergy(int maxExtract, boolean simulate) { - - int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); - - if (!simulate) { - energy -= energyExtracted; - } - return energyExtracted; - } - - @Override - public int getEnergyStored() { - - return energy; - } - - @Override - public int getMaxEnergyStored() { - - return capacity; - } - -} diff --git a/src/main/java/cofh/api/energy/IEnergyConnection.java b/src/main/java/cofh/api/energy/IEnergyConnection.java deleted file mode 100644 index 63faffb9f..000000000 --- a/src/main/java/cofh/api/energy/IEnergyConnection.java +++ /dev/null @@ -1,21 +0,0 @@ -package cofh.api.energy; - -import net.minecraftforge.common.util.ForgeDirection; - -/** - * Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not - * accept it; otherwise just use IEnergyHandler. - * - * Note that {@link IEnergyHandler} is an extension of this. - * - * @author King Lemming - * - */ -public interface IEnergyConnection { - - /** - * Returns TRUE if the TileEntity can connect on a given side. - */ - boolean canConnectEnergy(ForgeDirection from); - -} diff --git a/src/main/java/cofh/api/energy/IEnergyContainerItem.java b/src/main/java/cofh/api/energy/IEnergyContainerItem.java deleted file mode 100644 index 0bcfda600..000000000 --- a/src/main/java/cofh/api/energy/IEnergyContainerItem.java +++ /dev/null @@ -1,52 +0,0 @@ -package cofh.api.energy; - -import net.minecraft.item.ItemStack; - -/** - * Implement this interface on Item classes that support external manipulation of their internal energy storages. - * - * A reference implementation is provided {@link ItemEnergyContainer}. - * - * @author King Lemming - * - */ -public interface IEnergyContainerItem { - - /** - * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. - * - * @param container - * ItemStack to be charged. - * @param maxReceive - * Maximum amount of energy to be sent into the item. - * @param simulate - * If TRUE, the charge will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) received by the item. - */ - int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); - - /** - * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally - * discharged. - * - * @param container - * ItemStack to be discharged. - * @param maxExtract - * Maximum amount of energy to be extracted from the item. - * @param simulate - * If TRUE, the discharge will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) extracted from the item. - */ - int extractEnergy(ItemStack container, int maxExtract, boolean simulate); - - /** - * Get the amount of energy currently stored in the container item. - */ - int getEnergyStored(ItemStack container); - - /** - * Get the max amount of energy that can be stored in the container item. - */ - int getMaxEnergyStored(ItemStack container); - -} diff --git a/src/main/java/cofh/api/energy/IEnergyHandler.java b/src/main/java/cofh/api/energy/IEnergyHandler.java deleted file mode 100644 index 3df312346..000000000 --- a/src/main/java/cofh/api/energy/IEnergyHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package cofh.api.energy; - -import net.minecraftforge.common.util.ForgeDirection; - -/** - * Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. - * - * A reference implementation is provided {@link TileEnergyHandler}. - * - * @author King Lemming - * - */ -public interface IEnergyHandler extends IEnergyConnection { - - /** - * Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. - * - * @param from - * Orientation the energy is received from. - * @param maxReceive - * Maximum amount of energy to receive. - * @param simulate - * If TRUE, the charge will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) received. - */ - int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate); - - /** - * Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. - * - * @param from - * Orientation the energy is extracted from. - * @param maxExtract - * Maximum amount of energy to extract. - * @param simulate - * If TRUE, the extraction will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) extracted. - */ - int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); - - /** - * Returns the amount of energy currently stored. - */ - int getEnergyStored(ForgeDirection from); - - /** - * Returns the maximum amount of energy that can be stored. - */ - int getMaxEnergyStored(ForgeDirection from); - -} diff --git a/src/main/java/cofh/api/energy/IEnergyStorage.java b/src/main/java/cofh/api/energy/IEnergyStorage.java deleted file mode 100644 index 1e84bc221..000000000 --- a/src/main/java/cofh/api/energy/IEnergyStorage.java +++ /dev/null @@ -1,45 +0,0 @@ -package cofh.api.energy; - -/** - * An energy storage is the unit of interaction with Energy inventories. - * - * A reference implementation can be found at {@link EnergyStorage}. - * - * @author King Lemming - * - */ -public interface IEnergyStorage { - - /** - * Adds energy to the storage. Returns quantity of energy that was accepted. - * - * @param maxReceive - * Maximum amount of energy to be inserted. - * @param simulate - * If TRUE, the insertion will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) accepted by the storage. - */ - int receiveEnergy(int maxReceive, boolean simulate); - - /** - * Removes energy from the storage. Returns quantity of energy that was removed. - * - * @param maxExtract - * Maximum amount of energy to be extracted. - * @param simulate - * If TRUE, the extraction will only be simulated. - * @return Amount of energy that was (or would have been, if simulated) extracted from the storage. - */ - int extractEnergy(int maxExtract, boolean simulate); - - /** - * Returns the amount of energy currently stored. - */ - int getEnergyStored(); - - /** - * Returns the maximum amount of energy that can be stored. - */ - int getMaxEnergyStored(); - -} diff --git a/src/main/java/cofh/api/energy/ItemEnergyContainer.java b/src/main/java/cofh/api/energy/ItemEnergyContainer.java deleted file mode 100644 index 055ae45bc..000000000 --- a/src/main/java/cofh/api/energy/ItemEnergyContainer.java +++ /dev/null @@ -1,110 +0,0 @@ -package cofh.api.energy; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -/** - * Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own. - * - * @author King Lemming - * - */ -public class ItemEnergyContainer extends Item implements IEnergyContainerItem { - - protected int capacity; - protected int maxReceive; - protected int maxExtract; - - public ItemEnergyContainer() { - - } - - public ItemEnergyContainer(int capacity) { - - this(capacity, capacity, capacity); - } - - public ItemEnergyContainer(int capacity, int maxTransfer) { - - this(capacity, maxTransfer, maxTransfer); - } - - public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { - - this.capacity = capacity; - this.maxReceive = maxReceive; - this.maxExtract = maxExtract; - } - - public ItemEnergyContainer setCapacity(int capacity) { - - this.capacity = capacity; - return this; - } - - public void setMaxTransfer(int maxTransfer) { - - setMaxReceive(maxTransfer); - setMaxExtract(maxTransfer); - } - - public void setMaxReceive(int maxReceive) { - - this.maxReceive = maxReceive; - } - - public void setMaxExtract(int maxExtract) { - - this.maxExtract = maxExtract; - } - - /* IEnergyContainerItem */ - @Override - public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { - - if (container.stackTagCompound == null) { - container.stackTagCompound = new NBTTagCompound(); - } - int energy = container.stackTagCompound.getInteger("Energy"); - int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); - - if (!simulate) { - energy += energyReceived; - container.stackTagCompound.setInteger("Energy", energy); - } - return energyReceived; - } - - @Override - public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { - - if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) { - return 0; - } - int energy = container.stackTagCompound.getInteger("Energy"); - int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); - - if (!simulate) { - energy -= energyExtracted; - container.stackTagCompound.setInteger("Energy", energy); - } - return energyExtracted; - } - - @Override - public int getEnergyStored(ItemStack container) { - - if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) { - return 0; - } - return container.stackTagCompound.getInteger("Energy"); - } - - @Override - public int getMaxEnergyStored(ItemStack container) { - - return capacity; - } - -} diff --git a/src/main/java/cofh/api/energy/TileEnergyHandler.java b/src/main/java/cofh/api/energy/TileEnergyHandler.java deleted file mode 100644 index 86436b014..000000000 --- a/src/main/java/cofh/api/energy/TileEnergyHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package cofh.api.energy; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own. - * - * @author King Lemming - * - */ -public class TileEnergyHandler extends TileEntity implements IEnergyHandler { - - protected final EnergyStorage storage = new EnergyStorage(32000); - - @Override - public void readFromNBT(NBTTagCompound nbt) { - - super.readFromNBT(nbt); - storage.readFromNBT(nbt); - } - - @Override - public void writeToNBT(NBTTagCompound nbt) { - - super.writeToNBT(nbt); - storage.writeToNBT(nbt); - } - - /* IEnergyHandler */ - @Override - public boolean canConnectEnergy(ForgeDirection from) { - - return true; - } - - @Override - public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { - - return storage.receiveEnergy(maxReceive, simulate); - } - - @Override - public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { - - return storage.extractEnergy(maxExtract, simulate); - } - - @Override - public int getEnergyStored(ForgeDirection from) { - - return storage.getEnergyStored(); - } - - @Override - public int getMaxEnergyStored(ForgeDirection from) { - - return storage.getMaxEnergyStored(); - } - -} diff --git a/src/main/java/cofh/api/energy/package-info.java b/src/main/java/cofh/api/energy/package-info.java deleted file mode 100644 index 7379702b8..000000000 --- a/src/main/java/cofh/api/energy/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub - * http://www.teamcofh.com - */ -@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy") -package cofh.api.energy; - -import cofh.api.CoFHAPIProps; -import cpw.mods.fml.common.API; - diff --git a/src/main/java/cofh/api/package-info.java b/src/main/java/cofh/api/package-info.java deleted file mode 100644 index 08ff5fcb6..000000000 --- a/src/main/java/cofh/api/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub - * http://www.teamcofh.com - */ -@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI") -package cofh.api; - -import cpw.mods.fml.common.API; - diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 9661e460e..9d42c573b 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -39,6 +39,9 @@ import forestry.core.utils.FluidMap; import forestry.core.utils.ItemStackMap; import forestry.core.utils.StringUtil; import java.io.File; +import java.util.HashMap; +import java.util.Map; + import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -63,6 +66,22 @@ public class Forestry { public static Forestry instance; private File configFolder; + private static final Map mappedItems = new HashMap(); + + static { + mappedItems.put("Forestry:builderBackpack", ForestryItem.builderBackpack); + mappedItems.put("Forestry:builderBackpackT2", ForestryItem.builderBackpackT2); + mappedItems.put("Forestry:adventurerBackpack", ForestryItem.adventurerBackpack); + mappedItems.put("Forestry:adventurerBackpackT2", ForestryItem.adventurerBackpackT2); + mappedItems.put("Forestry:shortMead", ForestryItem.beverage); + mappedItems.put("Forestry:waterCan", ForestryItem.canWater); + mappedItems.put("Forestry:biofuelCan", ForestryItem.canEthanol); + mappedItems.put("Forestry:biomassCan", ForestryItem.canBiomass); + mappedItems.put("Forestry:bucketBiofuel", ForestryItem.bucketEthanol); + mappedItems.put("Forestry:refractoryBiofuel", ForestryItem.refractoryEthanol); + mappedItems.put("Forestry:waxCapsuleBiofuel", ForestryItem.waxCapsuleEthanol); + } + public Forestry() { FuelManager.fermenterFuel = new ItemStackMap(); FuelManager.moistenerResource = new ItemStackMap(); @@ -129,21 +148,12 @@ public class Forestry { if (block != null) { mapping.remap(Item.getItemFromBlock(block)); Proxies.log.warning("Remapping item " + mapping.name + " to " + StringUtil.cleanBlockName(block)); - } else if (mapping.name.equals("Forestry:builderBackpack")) { - mapping.remap(ForestryItem.builderBackpack.item()); - Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.builderBackpack.name()); - } else if (mapping.name.equals("Forestry:builderBackpackT2")) { - mapping.remap(ForestryItem.builderBackpackT2.item()); - Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.builderBackpackT2.name()); - } else if (mapping.name.equals("Forestry:adventurerBackpack")) { - mapping.remap(ForestryItem.adventurerBackpack.item()); - Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.adventurerBackpack.name()); - } else if (mapping.name.equals("Forestry:adventurerBackpackT2")) { - mapping.remap(ForestryItem.adventurerBackpackT2.item()); - Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.adventurerBackpackT2.name()); - } else if (mapping.name.equals("Forestry:shortMead")) { - mapping.remap(ForestryItem.beverage.item()); - Proxies.log.warning("Remapping item " + mapping.name + " to " + ForestryItem.beverage.name()); + } else { + ForestryItem mappedItem = mappedItems.get(mapping.name); + if (mappedItem != null) { + mapping.remap(mappedItem.item()); + Proxies.log.warning("Remapping item " + mapping.name + " to " + mappedItem.name()); + } } } } diff --git a/src/main/java/forestry/apiculture/BeekeepingLogic.java b/src/main/java/forestry/apiculture/BeekeepingLogic.java index fa1c70e86..032b401af 100755 --- a/src/main/java/forestry/apiculture/BeekeepingLogic.java +++ b/src/main/java/forestry/apiculture/BeekeepingLogic.java @@ -10,24 +10,23 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.Stack; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IApiaristTracker; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeekeepingLogic; +import forestry.api.core.IErrorState; import forestry.api.genetics.IEffectData; import forestry.api.genetics.IIndividual; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.proxy.Proxies; import forestry.plugins.PluginApiculture; +import java.util.Stack; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; public class BeekeepingLogic implements IBeekeepingLogic { @@ -261,7 +260,7 @@ public class BeekeepingLogic implements IBeekeepingLogic { try { boolean canWork = true; // Not while raining, at night or without light - EnumErrorCode state = queen.canWork(housing); + IErrorState state = queen.canWork(housing); if (state != EnumErrorCode.OK) { housing.setErrorState(state); canWork = false; @@ -270,6 +269,7 @@ public class BeekeepingLogic implements IBeekeepingLogic { } return canWork; } catch (Error e) { + Proxies.log.logErrorAPI("Forestry", e, IBee.class); return queenCanWorkDeprecated(); } } diff --git a/src/main/java/forestry/apiculture/FlowerProviderCacti.java b/src/main/java/forestry/apiculture/FlowerProviderCacti.java index c3cc19896..8d718419b 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderCacti.java +++ b/src/main/java/forestry/apiculture/FlowerProviderCacti.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderCacti implements IFlowerProvider { @@ -42,10 +40,7 @@ public class FlowerProviderCacti implements IFlowerProvider { } private boolean checkFlowerPot(int meta) { - if (meta == 9) - return true; - else - return false; + return meta == 9; } @Override diff --git a/src/main/java/forestry/apiculture/FlowerProviderEnd.java b/src/main/java/forestry/apiculture/FlowerProviderEnd.java index 7aabb4c71..f904428a4 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderEnd.java +++ b/src/main/java/forestry/apiculture/FlowerProviderEnd.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderEnd implements IFlowerProvider { diff --git a/src/main/java/forestry/apiculture/FlowerProviderGourd.java b/src/main/java/forestry/apiculture/FlowerProviderGourd.java index 10eb185da..29b2ff473 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderGourd.java +++ b/src/main/java/forestry/apiculture/FlowerProviderGourd.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderGourd implements IFlowerProvider { diff --git a/src/main/java/forestry/apiculture/FlowerProviderJungle.java b/src/main/java/forestry/apiculture/FlowerProviderJungle.java index e223a6ae3..cedada411 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderJungle.java +++ b/src/main/java/forestry/apiculture/FlowerProviderJungle.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderJungle implements IFlowerProvider { @@ -46,10 +43,7 @@ public class FlowerProviderJungle implements IFlowerProvider { } private boolean checkFlowerPot(int meta) { - if (meta == 11) - return true; - else - return false; + return meta == 11; } @Override diff --git a/src/main/java/forestry/apiculture/FlowerProviderMushroom.java b/src/main/java/forestry/apiculture/FlowerProviderMushroom.java index ad6b1c705..9b6465529 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderMushroom.java +++ b/src/main/java/forestry/apiculture/FlowerProviderMushroom.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderMushroom implements IFlowerProvider { @@ -45,10 +42,7 @@ public class FlowerProviderMushroom implements IFlowerProvider { } private boolean checkFlowerPot(int meta) { - if (meta == 7 || meta == 8) - return true; - else - return false; + return meta == 7 || meta == 8; } @Override diff --git a/src/main/java/forestry/apiculture/FlowerProviderNetherwart.java b/src/main/java/forestry/apiculture/FlowerProviderNetherwart.java index 66eb64f6c..898b5f89c 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderNetherwart.java +++ b/src/main/java/forestry/apiculture/FlowerProviderNetherwart.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderNetherwart implements IFlowerProvider { diff --git a/src/main/java/forestry/apiculture/FlowerProviderVanilla.java b/src/main/java/forestry/apiculture/FlowerProviderVanilla.java index 1698c85a4..29007add9 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderVanilla.java +++ b/src/main/java/forestry/apiculture/FlowerProviderVanilla.java @@ -10,16 +10,6 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.Collections; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.apiculture.FlowerManager; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; @@ -27,6 +17,13 @@ import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StackUtils; import forestry.core.utils.StringUtil; +import java.util.Collections; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderVanilla implements IFlowerProvider { @@ -56,10 +53,7 @@ public class FlowerProviderVanilla implements IFlowerProvider { } private boolean checkFlowerPot(int meta) { - if (meta == 1 || meta == 2) - return true; - else - return false; + return meta == 1 || meta == 2; } @Override diff --git a/src/main/java/forestry/apiculture/FlowerProviderWheat.java b/src/main/java/forestry/apiculture/FlowerProviderWheat.java index ce2e5eaca..76c9f9d6a 100755 --- a/src/main/java/forestry/apiculture/FlowerProviderWheat.java +++ b/src/main/java/forestry/apiculture/FlowerProviderWheat.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.apiculture; -import java.util.EnumSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProviderWheat implements IFlowerProvider { diff --git a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java index 3814ca8b8..569932e52 100755 --- a/src/main/java/forestry/apiculture/GuiHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/GuiHandlerApiculture.java @@ -26,7 +26,6 @@ import forestry.apiculture.gui.ContainerAlvearyHygroregulator; import forestry.apiculture.gui.ContainerAlvearySieve; import forestry.apiculture.gui.ContainerAlvearySwarmer; import forestry.apiculture.gui.ContainerApiary; -import forestry.apiculture.gui.ContainerBeealyzer; import forestry.apiculture.gui.ContainerHabitatLocator; import forestry.apiculture.gui.ContainerImprinter; import forestry.apiculture.gui.GuiAlveary; @@ -41,6 +40,7 @@ import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; import forestry.apiculture.items.ItemImprinter.ImprinterInventory; import forestry.core.GuiHandlerBase; +import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; import forestry.plugins.PluginApiculture; @@ -73,7 +73,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z)); case BeealyzerGUI: - equipped = getEquippedItem(player); + equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; @@ -83,7 +83,7 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z)); case HabitatLocatorGUI: - equipped = getEquippedItem(player); + equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; @@ -93,7 +93,10 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new GuiAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z)); case ImprinterGUI: - return new GuiImprinter(player.inventory, new ImprinterInventory(player)); + equipped = player.getCurrentEquippedItem(); + if (equipped == null) + return null; + return new GuiImprinter(player.inventory, new ImprinterInventory(player, equipped)); default: return null; @@ -130,19 +133,19 @@ public class GuiHandlerApiculture extends GuiHandlerBase { return new ContainerApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z), true); case BeealyzerGUI: - equipped = getEquippedItem(player); + equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; synchApiaristTracker(world, player); - return new ContainerBeealyzer(player.inventory, new BeealyzerInventory(player, equipped)); + return new ContainerAlyzer(new BeealyzerInventory(player, equipped), player); case BeehouseGUI: synchApiaristTracker(world, player); return new ContainerApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z), false); case HabitatLocatorGUI: - equipped = getEquippedItem(player); + equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; @@ -153,7 +156,10 @@ public class GuiHandlerApiculture extends GuiHandlerBase { case ImprinterGUI: synchApiaristTracker(world, player); - return new ContainerImprinter(player.inventory, new ImprinterInventory(player)); + equipped = player.getCurrentEquippedItem(); + if (equipped == null) + return null; + return new ContainerImprinter(player.inventory, new ImprinterInventory(player, equipped)); default: return null; diff --git a/src/main/java/forestry/apiculture/PacketHandlerApiculture.java b/src/main/java/forestry/apiculture/PacketHandlerApiculture.java index 2337a7b32..1549ea933 100755 --- a/src/main/java/forestry/apiculture/PacketHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/PacketHandlerApiculture.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.apiculture; -import java.io.DataInputStream; - -import net.minecraft.entity.player.EntityPlayer; - import forestry.apiculture.gui.ContainerImprinter; import forestry.core.interfaces.IPacketHandler; import forestry.core.network.PacketCoordinates; import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; +import java.io.DataInputStream; +import net.minecraft.entity.player.EntityPlayer; public class PacketHandlerApiculture implements IPacketHandler { diff --git a/src/main/java/forestry/apiculture/SaveEventHandlerApiculture.java b/src/main/java/forestry/apiculture/SaveEventHandlerApiculture.java index 1a2ae4d05..c45213340 100755 --- a/src/main/java/forestry/apiculture/SaveEventHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/SaveEventHandlerApiculture.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.apiculture; -import net.minecraft.world.World; - import forestry.core.interfaces.ISaveEventHandler; import forestry.plugins.PluginApiculture; +import net.minecraft.world.World; public class SaveEventHandlerApiculture implements ISaveEventHandler { diff --git a/src/main/java/forestry/apiculture/VillageHandlerApiculture.java b/src/main/java/forestry/apiculture/VillageHandlerApiculture.java index c592a3229..c95b27bd0 100755 --- a/src/main/java/forestry/apiculture/VillageHandlerApiculture.java +++ b/src/main/java/forestry/apiculture/VillageHandlerApiculture.java @@ -10,9 +10,19 @@ ******************************************************************************/ package forestry.apiculture; +import cpw.mods.fml.common.registry.VillagerRegistry.IVillageCreationHandler; +import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; +import forestry.api.apiculture.EnumBeeType; +import forestry.apiculture.genetics.BeeTemplates; +import forestry.apiculture.items.ItemHoneycomb; +import forestry.apiculture.worldgen.ComponentVillageBeeHouse; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.config.ForestryItem; +import forestry.core.proxy.Proxies; +import forestry.plugins.PluginApiculture; import java.util.List; import java.util.Random; - import net.minecraft.entity.passive.EntityVillager; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -23,24 +33,13 @@ import net.minecraft.village.MerchantRecipeList; import net.minecraft.world.gen.structure.MapGenStructureIO; import net.minecraft.world.gen.structure.StructureVillagePieces; -import cpw.mods.fml.common.registry.VillagerRegistry.IVillageCreationHandler; -import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; - -import forestry.api.apiculture.EnumBeeType; -import forestry.apiculture.genetics.BeeTemplates; -import forestry.apiculture.items.ItemHoneycomb; -import forestry.apiculture.worldgen.ComponentVillageBeeHouse; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.config.ForestryItem; -import forestry.plugins.PluginApiculture; - public class VillageHandlerApiculture implements IVillageCreationHandler, IVillageTradeHandler { public static void registerVillageComponents() { try { MapGenStructureIO.func_143031_a(ComponentVillageBeeHouse.class, "Forestry:BeeHouse"); } catch (Throwable e) { + Proxies.log.severe("Failed to register village beehouse."); } } diff --git a/src/main/java/forestry/apiculture/commands/BeeModeHelper.java b/src/main/java/forestry/apiculture/commands/BeeModeHelper.java new file mode 100644 index 000000000..7590864f2 --- /dev/null +++ b/src/main/java/forestry/apiculture/commands/BeeModeHelper.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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.commands; + +import forestry.api.apiculture.IBeekeepingMode; +import forestry.core.commands.ICommandModeHelper; +import forestry.plugins.PluginApiculture; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.world.World; + +public class BeeModeHelper implements ICommandModeHelper { + + @Override + public String[] getModeNames() { + ArrayList beekeepingModes = PluginApiculture.beeInterface.getBeekeepingModes(); + int modeStringCount = beekeepingModes.size(); + List modeStrings = new ArrayList(modeStringCount); + for (IBeekeepingMode mode : beekeepingModes) + modeStrings.add(mode.getName()); + + return modeStrings.toArray(new String[modeStringCount]); + } + + @Override + public String getModeNameMatching(String desired) { + IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(desired); + if (mode == null) + return null; + return mode.getName(); + } + + @Override + public String getModeName(World world) { + return PluginApiculture.beeInterface.getBeekeepingMode(world).getName(); + } + + @Override + public void setMode(World world, String modeName) { + PluginApiculture.beeInterface.setBeekeepingMode(world, modeName); + } + + @Override + public Iterable getDescription(String modeName) { + IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(modeName); + return mode.getDescription(); + } + +} diff --git a/src/main/java/forestry/apiculture/commands/BeeStatsSaveHelper.java b/src/main/java/forestry/apiculture/commands/BeeStatsSaveHelper.java new file mode 100644 index 000000000..2cd81afc5 --- /dev/null +++ b/src/main/java/forestry/apiculture/commands/BeeStatsSaveHelper.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.commands; + +import com.mojang.authlib.GameProfile; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IApiaristTracker; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; +import forestry.core.commands.IStatsSaveHelper; +import forestry.core.utils.StringUtil; +import forestry.plugins.PluginApiculture; +import java.util.ArrayList; +import java.util.Collection; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; + +public class BeeStatsSaveHelper implements IStatsSaveHelper { + + @Override + public String getUnlocalizedSaveStatsString() { + return "for.chat.command.forestry.bee.save.stats"; + } + + @Override + public void addExtraInfo(Collection statistics, IBreedingTracker breedingTracker) { + IApiaristTracker tracker = (IApiaristTracker)breedingTracker; + String discoveredLine = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered") + ":"; + statistics.add(discoveredLine); + statistics.add(StringUtil.line(discoveredLine.length())); + + String queen = StatCollector.translateToLocal("for.bees.grammar.queen.type"); + String princess = StatCollector.translateToLocal("for.bees.grammar.princess.type"); + String drone = StatCollector.translateToLocal("for.bees.grammar.drone.type"); + statistics.add(queen + ":\t\t" + tracker.getQueenCount()); + statistics.add(princess + ":\t" + tracker.getPrincessCount()); + statistics.add(drone + ":\t\t" + tracker.getDroneCount()); + statistics.add(""); + } + + @Override + public Collection getSpecies() { + Collection species = new ArrayList(); + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) + if (allele instanceof IAlleleBeeSpecies) + species.add((IAlleleBeeSpecies) allele); + return species; + } + + @Override + public String getFileSuffix() { + return "bees"; + } + + @Override + public IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile) { + return PluginApiculture.beeInterface.getBreedingTracker(world, gameProfile); + } + +} diff --git a/src/main/java/forestry/apiculture/commands/CommandBee.java b/src/main/java/forestry/apiculture/commands/CommandBee.java new file mode 100644 index 000000000..9cf050973 --- /dev/null +++ b/src/main/java/forestry/apiculture/commands/CommandBee.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.commands; + +import forestry.core.commands.CommandMode; +import forestry.core.commands.CommandSaveStats; +import forestry.core.commands.ICommandModeHelper; +import forestry.core.commands.IStatsSaveHelper; +import forestry.core.commands.SubCommand; + +public class CommandBee extends SubCommand { + + public CommandBee() { + super("bee"); + addAlias("beekeeping"); + + IStatsSaveHelper saveHelper = new BeeStatsSaveHelper(); + ICommandModeHelper modeHelper = new BeeModeHelper(); + + addChildCommand(new CommandMode(modeHelper)); + addChildCommand(new CommandSaveStats(saveHelper, modeHelper)); + addChildCommand(new CommandBeeGive()); + } +} diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java b/src/main/java/forestry/apiculture/commands/CommandBeeGive.java similarity index 81% rename from src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java rename to src/main/java/forestry/apiculture/commands/CommandBeeGive.java index 4c94c1db9..e3da4d890 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java +++ b/src/main/java/forestry/apiculture/commands/CommandBeeGive.java @@ -16,25 +16,24 @@ import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeGenome; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; -import forestry.apiculture.SpeciesNotFoundException; -import forestry.apiculture.TemplateNotFoundException; import forestry.core.commands.CommandHelpers; +import forestry.core.commands.SpeciesNotFoundException; import forestry.core.commands.SubCommand; +import forestry.core.commands.TemplateNotFoundException; import forestry.plugins.PluginApiculture; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class CommandBeekeepingGiveBee extends SubCommand { +public class CommandBeeGive extends SubCommand { private final String beeTypeHelpString; private final String[] beeTypeArr; - public CommandBeekeepingGiveBee() { + public CommandBeeGive() { super("give"); setPermLevel(PermLevel.ADMIN); @@ -61,26 +60,46 @@ public class CommandBeekeepingGiveBee extends SubCommand { @Override public void processSubCommand(ICommandSender sender, String[] arguments) { - if (arguments.length < 3) { + if (arguments.length < 2) { printHelp(sender); return; } - EnumBeeType beeType = getBeeType(arguments[0]); + IBeeGenome beeGenome = getBeeGenome(arguments[0]); + EnumBeeType beeType = getBeeType(arguments[1]); if (beeType == EnumBeeType.NONE) { printHelp(sender); return; } - EntityPlayer player = CommandHelpers.getPlayer(sender, arguments[1]); + EntityPlayer player; + if (arguments.length == 3) { + player = CommandHelpers.getPlayer(sender, arguments[2]); + } else { + player = CommandHelpers.getPlayer(sender, sender.getCommandSenderName()); + } + if (player == null) { + printHelp(sender); + return; + } - String parameter = arguments[2]; + IBee bee = PluginApiculture.beeInterface.getBee(player.worldObj, beeGenome); + if(beeType == EnumBeeType.QUEEN) + bee.mate(bee); + + ItemStack beeStack = PluginApiculture.beeInterface.getMemberStack(bee, beeType.ordinal()); + player.dropPlayerItemWithRandomChoice(beeStack, true); + + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.bee.give.given", player.getCommandSenderName(), bee.getGenome().getPrimary().getName(), beeType.getName()); + } + + private static IBeeGenome getBeeGenome(String speciesName) { IAlleleBeeSpecies species = null; for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) { - if (!uid.equals(parameter)) + if (!uid.equals(speciesName)) continue; if (AlleleManager.alleleRegistry.getAllele(uid) instanceof IAlleleBeeSpecies) { @@ -91,7 +110,7 @@ public class CommandBeekeepingGiveBee extends SubCommand { if (species == null) { for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) { - if (allele instanceof IAlleleBeeSpecies && allele.getName().equals(parameter)) { + if (allele instanceof IAlleleBeeSpecies && allele.getName().equals(speciesName)) { species = (IAlleleBeeSpecies) allele; break; } @@ -99,36 +118,26 @@ public class CommandBeekeepingGiveBee extends SubCommand { } if (species == null) - throw new SpeciesNotFoundException(parameter); + throw new SpeciesNotFoundException(speciesName); IAllele[] template = PluginApiculture.beeInterface.getTemplate(species.getUID()); if (template == null) throw new TemplateNotFoundException(species); - IBeeGenome genome = PluginApiculture.beeInterface.templateAsGenome(template); - - IBee bee = PluginApiculture.beeInterface.getBee(player.worldObj, genome); - - if(beeType == EnumBeeType.QUEEN) - bee.mate(bee); - - ItemStack beeStack = PluginApiculture.beeInterface.getMemberStack(bee, beeType.ordinal()); - player.dropPlayerItemWithRandomChoice(beeStack, true); - - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.give.given", player.getCommandSenderName(), template[0].getName(), beeType.getName()); + return PluginApiculture.beeInterface.templateAsGenome(template); } @Override public List addTabCompletionOptions(ICommandSender sender, String[] parameters) { if (parameters.length == 1) { - List tabCompletion = CommandHelpers.getListOfStringsMatchingLastWord(parameters, beeTypeArr); + List tabCompletion = CommandHelpers.getListOfStringsMatchingLastWord(parameters, getSpecies()); tabCompletion.add("help"); return tabCompletion; } else if (parameters.length == 2) { - return CommandHelpers.getListOfStringsMatchingLastWord(parameters, CommandHelpers.getPlayers()); + return CommandHelpers.getListOfStringsMatchingLastWord(parameters, beeTypeArr); } else if (parameters.length == 3) { - return CommandHelpers.getListOfStringsMatchingLastWord(parameters, getSpecies()); + return CommandHelpers.getListOfStringsMatchingLastWord(parameters, CommandHelpers.getPlayers()); } return null; } diff --git a/src/main/java/forestry/apiculture/entities/EntityBee.java b/src/main/java/forestry/apiculture/entities/EntityBee.java index d5716ddb5..3208ec398 100755 --- a/src/main/java/forestry/apiculture/entities/EntityBee.java +++ b/src/main/java/forestry/apiculture/entities/EntityBee.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.apiculture.entities; -import net.minecraft.entity.EntityCreature; -import net.minecraft.entity.passive.IAnimals; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBee; import forestry.core.config.Defaults; import forestry.core.utils.ForestryResource; import forestry.plugins.PluginApiculture; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.passive.IAnimals; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; public class EntityBee extends EntityCreature implements IAnimals { diff --git a/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java b/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java index 231e9ae1f..6bae0eed5 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockAlveary.java @@ -10,9 +10,14 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.Tabs; +import forestry.apiculture.MaterialBeehive; +import forestry.core.gadgets.BlockStructure; +import forestry.core.render.TextureManager; import java.util.ArrayList; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -23,14 +28,6 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.core.Tabs; -import forestry.apiculture.MaterialBeehive; -import forestry.core.gadgets.BlockStructure; -import forestry.core.render.TextureManager; - public class BlockAlveary extends BlockStructure { public BlockAlveary() { diff --git a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java index d4ac8c93d..f0f33c111 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockBeehives.java @@ -13,12 +13,18 @@ package forestry.apiculture.gadgets; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.api.apiculture.IHiveDrop; -import forestry.api.apiculture.hives.HiveManager; +import forestry.apiculture.worldgen.HiveRegistry; import forestry.api.core.Tabs; import forestry.apiculture.MaterialBeehive; import forestry.core.config.Config; +import forestry.core.inventory.InvTools; import forestry.core.render.TextureManager; import forestry.core.utils.StackUtils; +import forestry.plugins.PluginApiculture; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import net.minecraft.block.BlockContainer; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -31,10 +37,6 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - public class BlockBeehives extends BlockContainer { public BlockBeehives() { @@ -42,6 +44,7 @@ public class BlockBeehives extends BlockContainer { setLightLevel(0.8f); setHardness(1.0f); setCreativeTab(Tabs.tabApiculture); + setHarvestLevel("scoop", 0); } @Override @@ -63,7 +66,7 @@ public class BlockBeehives extends BlockContainer { if (tile instanceof TileSwarm) { TileSwarm swarm = (TileSwarm) tile; if (swarm.containsBees()) - for (ItemStack beeStack : swarm.contained.getStacks()) + for (ItemStack beeStack : InvTools.getStacks(swarm.contained)) if (beeStack != null) StackUtils.dropItemStackAsEntity(beeStack, world, x, y, z); } @@ -125,18 +128,18 @@ public class BlockBeehives extends BlockContainer { String hiveName = getHiveNameForMeta(meta); if (hiveName == null) return Collections.emptyList(); - return HiveManager.get(hiveName).getDrops(); + return PluginApiculture.hiveRegistry.getDrops(hiveName); } private String getHiveNameForMeta(int meta) { switch (meta) { - case 1: return HiveManager.forest; - case 2: return HiveManager.meadows; - case 3: return HiveManager.desert; - case 4: return HiveManager.jungle; - case 5: return HiveManager.end; - case 6: return HiveManager.snow; - case 7: return HiveManager.swamp; + case 1: return HiveRegistry.forest; + case 2: return HiveRegistry.meadows; + case 3: return HiveRegistry.desert; + case 4: return HiveRegistry.jungle; + case 5: return HiveRegistry.end; + case 6: return HiveRegistry.snow; + case 7: return HiveRegistry.swamp; } return null; } diff --git a/src/main/java/forestry/apiculture/gadgets/BlockCandle.java b/src/main/java/forestry/apiculture/gadgets/BlockCandle.java index 5111fee49..649c3379a 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockCandle.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockCandle.java @@ -10,10 +10,17 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.Tabs; +import forestry.core.ForestryClient; +import forestry.core.config.Defaults; +import forestry.core.render.TextureManager; +import forestry.core.utils.StackUtils; +import forestry.core.utils.StringUtil; import java.util.ArrayList; import java.util.List; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.block.BlockTorch; import net.minecraft.client.renderer.texture.IIconRegister; @@ -29,20 +36,9 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; -import forestry.api.core.Tabs; -import forestry.core.ForestryClient; -import forestry.core.config.Defaults; -import forestry.core.render.TextureManager; -import forestry.core.utils.StackUtils; -import forestry.core.utils.StringUtil; - public class BlockCandle extends BlockTorch { private final ArrayList lightingItems = new ArrayList(); @@ -111,7 +107,7 @@ public class BlockCandle extends BlockTorch { @SideOnly(Side.CLIENT) public IIcon getTextureFromPassAndMeta(int meta, int pass) { - IIcon i = this.unlitStump; + IIcon i; if (pass == 0) { if (isLit(meta)) { i = this.litTip; @@ -180,6 +176,7 @@ public class BlockCandle extends BlockTorch { TileCandle te = (TileCandle)world.getTileEntity(x, y, z); if (te == null) { world.setTileEntity(x, y, z, this.createTileEntity(world, meta)); + te = (TileCandle)world.getTileEntity(x, y, z); } if (StackUtils.equals(this, held)) { diff --git a/src/main/java/forestry/apiculture/gadgets/BlockStump.java b/src/main/java/forestry/apiculture/gadgets/BlockStump.java index 53eca9bf4..ad797b592 100755 --- a/src/main/java/forestry/apiculture/gadgets/BlockStump.java +++ b/src/main/java/forestry/apiculture/gadgets/BlockStump.java @@ -10,9 +10,16 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.Tabs; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.render.TextureManager; +import forestry.core.utils.StackUtils; +import forestry.core.utils.StringUtil; import java.util.List; import java.util.Random; - import net.minecraft.block.BlockTorch; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -23,16 +30,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.core.Tabs; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.render.TextureManager; -import forestry.core.utils.StackUtils; -import forestry.core.utils.StringUtil; - public class BlockStump extends BlockTorch { public BlockStump() { diff --git a/src/main/java/forestry/apiculture/gadgets/StructureLogicAlveary.java b/src/main/java/forestry/apiculture/gadgets/StructureLogicAlveary.java index 57846bbb0..fbe2fad36 100755 --- a/src/main/java/forestry/apiculture/gadgets/StructureLogicAlveary.java +++ b/src/main/java/forestry/apiculture/gadgets/StructureLogicAlveary.java @@ -10,12 +10,6 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import java.util.HashSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; - import forestry.api.apiculture.IAlvearyComponent; import forestry.api.core.ITileStructure; import forestry.core.config.ForestryBlock; @@ -23,7 +17,11 @@ import forestry.core.gadgets.BlockStructure.EnumStructureState; import forestry.core.gadgets.StructureLogic; import forestry.core.utils.Schemata; import forestry.core.utils.Schemata.EnumStructureBlock; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.HashSet; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; public class StructureLogicAlveary extends StructureLogic { @@ -35,13 +33,11 @@ public class StructureLogicAlveary extends StructureLogic { public static final HashSet slabBlocks = new HashSet(); static { - slabBlocks.add(Blocks.stone_slab); slabBlocks.add(Blocks.wooden_slab); slabBlocks.add(ForestryBlock.slabs1.block()); slabBlocks.add(ForestryBlock.slabs2.block()); slabBlocks.add(ForestryBlock.slabs3.block()); - if (ForestryBlock.slabs4.block() != null) - slabBlocks.add(ForestryBlock.slabs4.block()); + slabBlocks.add(ForestryBlock.slabs4.block()); } public StructureLogicAlveary(ITileStructure structure) { diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlveary.java b/src/main/java/forestry/apiculture/gadgets/TileAlveary.java index a4a28c98e..04e86449f 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlveary.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlveary.java @@ -10,8 +10,16 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import buildcraft.api.statements.ITriggerExternal; +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.common.Optional; + import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBeeListener; import forestry.api.apiculture.IBeeModifier; @@ -21,18 +29,13 @@ import forestry.apiculture.trigger.ApicultureTriggers; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.gadgets.TileForestry; +import forestry.core.inventory.FakeInventoryAdapter; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import java.util.Collection; -import java.util.LinkedList; +import buildcraft.api.statements.ITriggerExternal; public abstract class TileAlveary extends TileForestry implements IAlvearyComponent { @@ -40,8 +43,6 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon private boolean isMaster; protected int masterX, masterZ; protected int masterY = -99; - - protected TileInventoryAdapter inventory; protected final int componentBlockMeta; public TileAlveary(int componentBlockMeta) { @@ -92,8 +93,6 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon /* LOADING & SAVING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - this.isMaster = nbttagcompound.getBoolean("IsMaster"); this.masterX = nbttagcompound.getInteger("MasterX"); this.masterY = nbttagcompound.getInteger("MasterY"); @@ -101,7 +100,9 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon // Init for master state if (isMaster) - makeMaster(); + makeMaster(); + + super.readFromNBT(nbttagcompound); structureLogic.readFromNBT(nbttagcompound); } @@ -122,16 +123,26 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon } @Override - public void fromPacketPayload(PacketPayload payload) { + public PacketPayload getPacketPayload() { + PacketPayload payload = new PacketPayload(0, 2); + payload.shortPayload[0] = (short) (isMaster() ? 1 : 0); + + // so the client can know if it is part of an integrated structure + payload.shortPayload[1] = (short) this.masterY; + + return payload; } @Override - public PacketPayload getPacketPayload() { - return null; + public void fromPacketPayload(PacketPayload payload) { + if (payload.shortPayload[0] > 0) + makeMaster(); + + // so the client can know if it is part of an integrated structure + this.masterY = payload.shortPayload[1]; } /* ITILESTRUCTURE */ - @Override public String getTypeUID() { return structureLogic.getTypeUID(); @@ -147,7 +158,7 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon setCentralTE(null); isMaster = true; - if (inventory == null) + if (getInternalInventory() instanceof FakeInventoryAdapter) createInventory(); } @@ -214,8 +225,13 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon } @Override - public IInventory getInventory() { - return inventory; + public final IInventoryAdapter getInventory() { + return getStructureInventory(); + } + + @Override + public IInventoryAdapter getStructureInventory() { + return getInternalInventory(); } /* IALVEARY COMPONENT */ @@ -258,9 +274,4 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon return res; } - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord); - } - } diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java index 823693d88..5a0c8d5bf 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyHygroregulator.java @@ -19,22 +19,20 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.core.ForestryAPI; import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; public class TileAlvearyHygroregulator extends TileAlveary implements IInventory, ILiquidTankContainer { @@ -43,6 +41,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory /* RECIPE MANAGMENT */ private static class HygroregulatorRecipe { + public final FluidStack liquid; public final int transferTime; public final float humidChange; @@ -56,10 +55,11 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory } } + public static final short SLOT_INPUT = 0; + private final HygroregulatorRecipe[] recipes; /* MEMBERS */ - private final InventoryAdapter canInventory = new InventoryAdapter(1, "CanInv"); private final TankManager tankManager; private final FilteredTank liquidTank; @@ -69,16 +69,27 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory public TileAlvearyHygroregulator() { super(BLOCK_META); - Fluid water = LiquidHelper.getFluid(Defaults.LIQUID_WATER); - Fluid lava = LiquidHelper.getFluid(Defaults.LIQUID_LAVA); - Fluid liquidIce = LiquidHelper.getFluid(Defaults.LIQUID_ICE); + setInternalInventory(new TileInventoryAdapter(this, 1, "CanInv") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return liquidTank.accepts(fluid); + } + return false; + } + }); + + Fluid water = Fluids.WATER.getFluid(); + Fluid lava = Fluids.LAVA.getFluid(); + Fluid liquidIce = Fluids.ICE.getFluid(); liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, water, lava, liquidIce); tankManager = new TankManager(liquidTank); - recipes = new HygroregulatorRecipe[] { new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.01f, -0.005f), - new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.01f, +0.005f), - new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.02f, -0.01f) }; + recipes = new HygroregulatorRecipe[]{new HygroregulatorRecipe(new FluidStack(water, 1), 1, 0.01f, -0.005f), + new HygroregulatorRecipe(new FluidStack(lava, 1), 10, -0.01f, +0.005f), + new HygroregulatorRecipe(new FluidStack(liquidIce, 1), 10, 0.02f, -0.01f)}; } @Override @@ -86,19 +97,15 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory player.openGui(ForestryAPI.instance, GuiId.HygroregulatorGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - /* UPDATING */ private HygroregulatorRecipe getRecipe(FluidStack liquid) { HygroregulatorRecipe recipe = null; - for (HygroregulatorRecipe rec : recipes) + for (HygroregulatorRecipe rec : recipes) { if (rec.liquid.isFluidEqual(liquid)) { recipe = rec; break; } + } return recipe; } @@ -131,17 +138,11 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory if (worldObj.getTotalWorldTime() % 20 * 10 != 0) return; - // Check if we have suitable items waiting in the item slot - if (canInventory.getStackInSlot(0) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(canInventory.getStackInSlot(0)); - if (container != null && - (container.fluid.getFluid() == FluidRegistry.WATER || container.fluid.getFluid() == FluidRegistry.LAVA)) { + IInventoryAdapter canInventory = getInternalInventory(); - canInventory.setInventorySlotContents(0, StackUtils.replenishByContainer(this, canInventory.getStackInSlot(0), container, liquidTank)); - if (canInventory.getStackInSlot(0).stackSize <= 0) - canInventory.setInventorySlotContents(0, null); - } - } + // Check if we have suitable items waiting in the item slot + if (canInventory.getStackInSlot(0) != null) + FluidHelper.drainContainers(tankManager, canInventory, 0); } @@ -154,9 +155,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - - canInventory.readFromNBT(nbttagcompound); - tankManager.readTanksFromNBT(nbttagcompound); transferTime = nbttagcompound.getInteger("TransferTime"); @@ -170,9 +168,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - - canInventory.writeToNBT(nbttagcompound); - tankManager.writeTanksToNBT(nbttagcompound); nbttagcompound.setInteger("TransferTime", transferTime); @@ -190,101 +185,6 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory return BlockAlveary.ALVEARY_HYGRO; } - @Override - public IInventory getInventory() { - return canInventory; - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - if (canInventory != null) - return canInventory.getSizeInventory(); - else - return 0; - } - - @Override - public ItemStack getStackInSlot(int slotIndex) { - if (canInventory != null) - return canInventory.getStackInSlot(slotIndex); - else - return null; - } - - @Override - public ItemStack decrStackSize(int slotIndex, int amount) { - if (canInventory != null) - return canInventory.decrStackSize(slotIndex, amount); - else - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slotIndex) { - if (canInventory != null) - return canInventory.getStackInSlotOnClosing(slotIndex); - else - return null; - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - // Client side handling for container synch - if (canInventory == null && !Proxies.common.isSimulating(worldObj)) - createInventory(); - - if (canInventory != null) - canInventory.setInventorySlotContents(slotIndex, itemstack); - } - - @Override - public int getInventoryStackLimit() { - if (canInventory != null) - return canInventory.getInventoryStackLimit(); - else - return 0; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - if (slotIndex == 0) { - FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack); - if (fluid == null || fluid.amount <= 0) - return false; - return liquidTank.accepts(fluid.getFluid()); - } - - return super.isItemValidForSlot(slotIndex, itemstack); - } - /* ILIQUIDTANKCONTAINER */ @Override public TankManager getTankManager() { @@ -296,6 +196,7 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory return tankManager.fill(from, resource, doFill); } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } @@ -321,8 +222,10 @@ public class TileAlvearyHygroregulator extends TileAlveary implements IInventory } @Override - public void getGUINetworkData(int messageId, int data) {} + public void getGUINetworkData(int messageId, int data) { + } @Override - public void sendGUINetworkData(Container container, ICrafting iCrafting) {} + public void sendGUINetworkData(Container container, ICrafting iCrafting) { + } } diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java index 13c3ff600..2069e4ec1 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyPlain.java @@ -10,35 +10,9 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import com.mojang.authlib.GameProfile; -import forestry.api.apiculture.IBee; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.apiculture.IBeeListener; -import forestry.api.apiculture.IBeeModifier; -import forestry.api.apiculture.IBeekeepingLogic; -import forestry.api.core.BiomeHelper; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; -import forestry.api.core.ITileStructure; -import forestry.api.genetics.IIndividual; -import forestry.apiculture.gui.ContainerAlveary; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.interfaces.IClimatised; -import forestry.core.interfaces.IErrorSource; -import forestry.core.interfaces.IHintSource; -import forestry.core.network.GuiId; -import forestry.core.network.PacketIds; -import forestry.core.network.PacketInventoryStack; -import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; -import forestry.plugins.PluginApiculture; +import java.util.LinkedHashSet; +import java.util.Set; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -47,12 +21,40 @@ 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.util.ForgeDirection; -import java.util.LinkedHashSet; -import java.util.Set; +import com.mojang.authlib.GameProfile; -public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, ISpecialInventory, IBeeHousing, IClimatised, IHintSource { +import forestry.api.apiculture.IBee; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeListener; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.api.core.BiomeHelper; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ForestryAPI; +import forestry.api.core.IErrorState; +import forestry.api.core.ITileStructure; +import forestry.api.genetics.IIndividual; +import forestry.apiculture.gui.ContainerAlveary; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.interfaces.IClimatised; +import forestry.core.interfaces.IErrorSource; +import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.network.PacketIds; +import forestry.core.network.PacketInventoryStack; +import forestry.core.proxy.Proxies; +import forestry.core.utils.Utils; +import forestry.plugins.PluginApiculture; + +public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IBeeHousing, IClimatised, IHintSource { // / CONSTANTS public static final int SLOT_QUEEN = 0; @@ -100,8 +102,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS this.tempChange = nbttagcompound.getFloat("TempChange"); this.humidChange = nbttagcompound.getFloat("HumidChange"); - if (inventory != null) - inventory.readFromNBT(nbttagcompound); if (beekeepingLogic != null) beekeepingLogic.readFromNBT(nbttagcompound); @@ -114,8 +114,6 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS nbttagcompound.setFloat("TempChange", tempChange); nbttagcompound.setFloat("HumidChange", humidChange); - if (inventory != null) - inventory.writeToNBT(nbttagcompound); if (beekeepingLogic != null) beekeepingLogic.writeToNBT(nbttagcompound); @@ -147,8 +145,12 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS return; // Add swarm effects - if (worldObj.getTotalWorldTime() % 200 * 10 == 0) - onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); + if (worldObj.getTotalWorldTime() % 200 == 0) { + ISidedInventory inventory = getStructureInventory(); + if (inventory != null) + onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); + } + if (getErrorState() == EnumErrorCode.OK) queen.doFX(beekeepingLogic.getEffectData(), this); @@ -173,13 +175,15 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS if (!isMaster()) return; + ISidedInventory inventory = getStructureInventory(); if (inventory == null) return; // / Multiplayer FX - if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN))) { + ItemStack queenStack = inventory.getStackInSlot(SLOT_QUEEN); + if (PluginApiculture.beeInterface.isMated(queenStack)) { if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) { - IBee displayQueen = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)); + IBee displayQueen = PluginApiculture.beeInterface.getMember(queenStack); displayQueen.doFX(beekeepingLogic.getEffectData(), this); } } @@ -205,6 +209,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS /* STATE INFORMATION */ private int getHealthDisplay() { + IInventory inventory = getStructureInventory(); if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -217,6 +222,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS } private int getMaxHealthDisplay() { + IInventory inventory = getStructureInventory(); if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -235,18 +241,24 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS return (getHealthDisplay() * i) / getMaxHealthDisplay(); } - @Override - public boolean allowsInteraction(EntityPlayer player) { - if (!super.allowsInteraction(player)) - return false; - - return this.isIntegratedIntoStructure(); - } - /* STRUCTURE MANAGMENT */ @Override protected void createInventory() { - this.inventory = new TileInventoryAdapter(this, 9, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 9, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_QUEEN) { + return PluginApiculture.beeInterface.isMember(itemStack) && !PluginApiculture.beeInterface.isDrone(itemStack); + } else if (slotIndex == SLOT_DRONE) { + return PluginApiculture.beeInterface.isDrone(itemStack); + } + return false; + } + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex != SLOT_QUEEN && slotIndex != SLOT_DRONE; + } + }); } @Override @@ -424,7 +436,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS @Override public int getErrorOrdinal() { - return getErrorState().ordinal(); + return getErrorState().getID(); } @Override @@ -434,10 +446,11 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS @Override public boolean addProduct(ItemStack product, boolean all) { + IInventoryAdapter inventory = getStructureInventory(); if (inventory == null) return false; - return inventory.tryAddStack(product, SLOT_PRODUCT_1, inventory.getSizeInventory() - SLOT_PRODUCT_1, all); + return InvTools.tryAddStack(inventory, product, SLOT_PRODUCT_1, inventory.getSizeInventory() - SLOT_PRODUCT_1, all); } @Override @@ -533,259 +546,37 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS /* IINVENTORY */ @Override - public InventoryAdapter getInternalInventory() { - return (InventoryAdapter) getStructureInventory(); - } - - private IInventory getStructureInventory() { - - if (inventory != null) { - if (isMaster() || !Proxies.common.isSimulating(worldObj)) - return inventory; + public IInventoryAdapter getInternalInventory() { + IInventoryAdapter inventory = super.getInternalInventory(); + if (isMaster()) { + return inventory; } else if (hasMaster()) { ITileStructure central = getCentralTE(); - if (central != null) - return central.getInventory(); + if (central instanceof TileAlveary) + return ((TileAlveary) central).getInternalInventory(); } - - return null; - } - - @Override - public int getSizeInventory() { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getSizeInventory(); - else - return 0; - } - - @Override - public ItemStack getStackInSlot(int slotIndex) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlot(slotIndex); - else - return null; - } - - @Override - public ItemStack decrStackSize(int slotIndex, int amount) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.decrStackSize(slotIndex, amount); - else - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slotIndex) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlotOnClosing(slotIndex); - else - return null; - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - // Client side handling for container synch - if (inventory == null && !Proxies.common.isSimulating(worldObj)) - createInventory(); - - IInventory inv = getStructureInventory(); - if (inv != null) - inv.setInventorySlotContents(slotIndex, itemstack); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - @Override - public int getInventoryStackLimit() { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getInventoryStackLimit(); - else - return 0; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex != SLOT_QUEEN && slotIndex != SLOT_DRONE) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack) - && !PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - if (slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - - IInventory inv = getStructureInventory(); - if (inv == null) - return 0; - - // Princesses && Queens - if (ForestryItem.beePrincessGE.isItemEqual(stack) || ForestryItem.beeQueenGE.isItemEqual(stack)) - if (inv.getStackInSlot(SLOT_QUEEN) == null) { - if (doAdd) { - inv.setInventorySlotContents(SLOT_QUEEN, stack.copy()); - inv.getStackInSlot(SLOT_QUEEN).stackSize = 1; - } - return 1; - } - - // Drones - if (ForestryItem.beeDroneGE.isItemEqual(stack)) { - - ItemStack droneStack = inv.getStackInSlot(SLOT_DRONE); - if (droneStack == null) { - if (doAdd) - inv.setInventorySlotContents(SLOT_DRONE, stack.copy()); - return stack.stackSize; - } else { - if (!droneStack.isItemEqual(stack)) - return 0; - if (!ItemStack.areItemStackTagsEqual(droneStack, stack)) - return 0; - int space = droneStack.getMaxStackSize() - droneStack.stackSize; - if (space <= 0) - return 0; - - int added = space > stack.stackSize ? stack.stackSize : space; - if (doAdd) - droneStack.stackSize += added; - return added; - } - } - - return 0; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - - IInventory inv = getStructureInventory(); - if (inv == null) - return new ItemStack[0]; - - ItemStack product = null; - - for (int i = SLOT_PRODUCT_1; i < inv.getSizeInventory(); i++) { - if (inv.getStackInSlot(i) == null) - continue; - - ItemStack stack = inv.getStackInSlot(i); - - if (doRemove) - product = inv.decrStackSize(i, 1); - else { - product = stack.copy(); - product.stackSize = 1; - } - break; - } - - return new ItemStack[] { product }; + return inventory; } /* SMP GUI */ public void getGUINetworkData(int i, int j) { switch (i) { - case 0: - displayHealth = j; - break; - case 1: - displayHealthMax = j; - break; - case 4: - this.tempChange = (float) j / 100; - break; - case 5: - this.humidChange = (float) j / 100; - break; - case 6: { - this.biome = BiomeGenBase.getBiome(j); - break; - } + case 0: + displayHealth = j; + break; + case 1: + displayHealthMax = j; + break; + case 4: + this.tempChange = (float) j / 100; + break; + case 5: + this.humidChange = (float) j / 100; + break; + case 6: { + this.biome = BiomeGenBase.getBiome(j); + break; + } } } @@ -803,7 +594,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS /* IERRORSOURCE */ @Override - public EnumErrorCode getErrorState() { + public IErrorState getErrorState() { if (hasMaster()) { ITileStructure tile = this.getCentralTE(); if (tile != null) @@ -845,7 +636,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS public boolean isOwnable() { return true; } - + /* IHousing */ @Override public GameProfile getOwnerName() { diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java index d5d21d206..c42a9f247 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java @@ -12,7 +12,6 @@ package forestry.apiculture.gadgets; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBee; @@ -21,9 +20,12 @@ import forestry.api.arboriculture.EnumGermlingType; import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; +import forestry.core.config.ForestryItem; import forestry.core.interfaces.ICrafter; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; +import forestry.core.utils.StackUtils; public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListener { @@ -33,11 +35,15 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe public static final int SLOT_POLLEN_1 = 0; public static final int SLOTS_POLLEN_COUNT = 4; public static final int SLOT_SIEVE = 4; - - private final InventoryAdapter inventory = new InventoryAdapter(5, "Items", 1); public TileAlvearySieve() { super(BLOCK_META); + setInternalInventory(new TileInventoryAdapter(this, 5, "Items", 1) { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return StackUtils.isIdenticalItem(ForestryItem.craftingMaterial.getItemStack(1, 3), itemStack); + } + }); } @Override @@ -45,7 +51,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe player.openGui(ForestryAPI.instance, GuiId.AlvearySieveGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); } - @Override public boolean hasFunction() { return true; @@ -62,7 +67,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe ((IAlvearyComponent)getCentralTE()).registerBeeListener(this); } - @Override protected void updateServerSide() { super.updateServerSide(); @@ -75,19 +79,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe ((IAlvearyComponent)getCentralTE()).registerBeeListener(this); } - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); - } - /* TEXTURES & INTERNAL */ @Override public int getIcon(int side, int metadata) { @@ -97,15 +88,19 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe } private void destroySieve() { + IInventoryAdapter inventory = getInternalInventory(); inventory.setInventorySlotContents(SLOT_SIEVE, null); } + private void destroyPollen() { + IInventoryAdapter inventory = getInternalInventory(); for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { inventory.setInventorySlotContents(i, null); } } private boolean canStorePollen() { + IInventoryAdapter inventory = getInternalInventory(); if(inventory.getStackInSlot(SLOT_SIEVE) == null) return false; @@ -118,6 +113,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe } private void storePollenStack(ItemStack itemstack) { + IInventoryAdapter inventory = getInternalInventory(); for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) { if(inventory.getStackInSlot(i) == null) { inventory.setInventorySlotContents(i, itemstack); @@ -125,11 +121,6 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe } } } - - /* INVENTORY */ - public InventoryAdapter getInternalInventory() { - return inventory; - } /* ICRAFTER */ @Override @@ -139,6 +130,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe @Override public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { + IInventoryAdapter inventory = getInternalInventory(); if(slotIndex == SLOT_SIEVE) { destroyPollen(); return inventory.getStackInSlot(SLOT_SIEVE); @@ -163,7 +155,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe public boolean onPollenRetrieved(IBee queen, IIndividual pollen, boolean isHandled) { if(isHandled) - return isHandled; + return true; if(!canStorePollen()) return false; diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java index a2da88c4c..c59947690 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearyStabiliser.java @@ -53,6 +53,7 @@ public class TileAlvearyStabiliser extends TileAlveary implements IBeeModifier { } /* TEXTURES */ + @Override public int getIcon(int side, int metadata) { if(side == 0 || side == 1) return BlockAlveary.BOTTOM; diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java index 4ea11717a..74d6e05ac 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySwarmer.java @@ -10,49 +10,48 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import java.util.Map.Entry; +import java.util.Stack; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; +import forestry.apiculture.worldgen.Hive; import forestry.apiculture.worldgen.HiveDecorator; -import forestry.apiculture.worldgen.HiveSwarmer; +import forestry.apiculture.worldgen.HiveDescriptionSwarmer; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryIterator; 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 { +public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory { /* CONSTANTS */ public static final int BLOCK_META = 2; - TileInventoryAdapter swarmerInventory; private final Stack pendingSpawns = new Stack(); private boolean isActive; public TileAlvearySwarmer() { super(BLOCK_META); - } - - @Override - public void initialize() { - super.initialize(); - if (swarmerInventory == null) - createInventory(); + setInternalInventory(new TileInventoryAdapter(this, 4, "SwarmInv") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return StackUtils.containsItemStack(BeeManager.inducers.keySet(), itemStack); + } + }); } @Override @@ -69,9 +68,8 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory setIsActive(true); if (worldObj.getTotalWorldTime() % 1000 == 0) trySpawnSwarm(); - } else { + } else setIsActive(false); - } if (worldObj.getTotalWorldTime() % 500 != 0) return; @@ -111,14 +109,14 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory } private int consumeInducerAndGetChance() { - if (swarmerInventory == null) + if (getInternalInventory() == null) return 0; - for (int i = 0; i < swarmerInventory.getSizeInventory(); i++) { - ItemStack stack = swarmerInventory.getStackInSlot(i); + for (IInvSlot slot : InventoryIterator.getIterable(getInternalInventory())) { + ItemStack stack = slot.getStackInSlot(); for (Entry entry : BeeManager.inducers.entrySet()) { if (StackUtils.isIdenticalItem(entry.getKey(), stack)) { - swarmerInventory.decrStackSize(i, 1); + slot.decreaseStackInSlot(); return entry.getValue(); } } @@ -130,14 +128,14 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory private void trySpawnSwarm() { ItemStack toSpawn = pendingSpawns.peek(); - HiveSwarmer hive = new HiveSwarmer(128, toSpawn); + HiveDescriptionSwarmer hiveDescription = new HiveDescriptionSwarmer(toSpawn); + Hive hive = new Hive(hiveDescription); 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)) { + if (HiveDecorator.instance().genHive(worldObj, worldObj.rand, chunkX, chunkZ, hive)) pendingSpawns.pop(); - } } private void setIsActive(boolean isActive) { @@ -150,9 +148,9 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory /* NETWORK */ @Override public void fromPacketPayload(PacketPayload payload) { - boolean isActive = payload.shortPayload[0] > 0; - if (this.isActive != isActive) { - this.isActive = isActive; + boolean act = payload.shortPayload[0] > 0; + if (this.isActive != act) { + this.isActive = act; worldObj.func_147479_m(xCoord, yCoord, zCoord); } } @@ -172,7 +170,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory /* TEXTURES */ @Override public int getIcon(int side, int metadata) { - if(side == 0 || side == 1) + if (side == 0 || side == 1) return BlockAlveary.BOTTOM; if (isActive) @@ -185,9 +183,6 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - if (swarmerInventory == null) - createInventory(); - swarmerInventory.readFromNBT(nbttagcompound); NBTTagList nbttaglist = nbttagcompound.getTagList("PendingSpawns", 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { @@ -200,126 +195,18 @@ public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - if (swarmerInventory != null) - swarmerInventory.writeToNBT(nbttagcompound); NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingSpawns.toArray(new ItemStack[pendingSpawns.size()]); - for (int i = 0; i < offspring.length; i++) + for (int i = 0; i < offspring.length; i++) { if (offspring[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); offspring[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingSpawns", nbttaglist); } - - @Override - protected void createInventory() { - swarmerInventory = new TileInventoryAdapter(this, 4, "SwarmInv"); - } - - @Override - public IInventory getInventory() { - return swarmerInventory; - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (swarmerInventory != null) - return swarmerInventory.addStack(stack, false, doAdd); - else - return 0; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - return null; - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - if (swarmerInventory != null) - return swarmerInventory.getSizeInventory(); - else - return 0; - } - - @Override - public ItemStack getStackInSlot(int slotIndex) { - if (swarmerInventory != null) - return swarmerInventory.getStackInSlot(slotIndex); - else - return null; - } - - @Override - public ItemStack decrStackSize(int slotIndex, int amount) { - if (swarmerInventory != null) - return swarmerInventory.decrStackSize(slotIndex, amount); - else - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slotIndex) { - if (swarmerInventory != null) - return swarmerInventory.getStackInSlotOnClosing(slotIndex); - else - return null; - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - // Client side handling for container synch - if (swarmerInventory == null && !Proxies.common.isSimulating(worldObj)) - createInventory(); - - if (swarmerInventory != null) - swarmerInventory.setInventorySlotContents(slotIndex, itemstack); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - @Override - public int getInventoryStackLimit() { - if (swarmerInventory != null) - return swarmerInventory.getInventoryStackLimit(); - else - return 0; - } - - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } } diff --git a/src/main/java/forestry/apiculture/gadgets/TileApiary.java b/src/main/java/forestry/apiculture/gadgets/TileApiary.java index 0f59ae39a..7353a46c5 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileApiary.java +++ b/src/main/java/forestry/apiculture/gadgets/TileApiary.java @@ -10,29 +10,31 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import buildcraft.api.statements.ITriggerExternal; +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.common.Optional; + import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IHiveFrame; import forestry.api.core.ForestryAPI; import forestry.apiculture.trigger.ApicultureTriggers; import forestry.core.gadgets.TileBase; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.GuiId; import forestry.plugins.PluginApiculture; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import java.util.Collection; -import java.util.LinkedList; +import buildcraft.api.statements.ITriggerExternal; -public class TileApiary extends TileBeehouse implements ISidedInventory { +public class TileApiary extends TileBeehouse { - @Override - public String getInventoryName() { - return getUnlocalizedName(); + public TileApiary() { + setInternalInventory(new BeehouseInventoryAdapter(this, 12, "Items")); } @Override @@ -43,6 +45,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { /* IBEEHOUSING */ @Override public float getTerritoryModifier(IBeeGenome genome, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 1.0f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -55,6 +58,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public float getProductionModifier(IBeeGenome genome, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 0.1f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -67,6 +71,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 1.0f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -79,6 +84,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 1.0f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -91,6 +97,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public float getFloweringModifier(IBeeGenome genome, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 1f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -103,6 +110,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public float getGeneticDecay(IBeeGenome genome, float currentModifier) { + IInventoryAdapter inventory = getInternalInventory(); float mod = 1f; for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { if (inventory.getStackInSlot(i) == null) @@ -115,6 +123,7 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { @Override public void wearOutEquipment(int amount) { + IInventoryAdapter inventory = getInternalInventory(); int wear = Math.round(amount * PluginApiculture.beeInterface.getBeekeepingMode(worldObj).getWearModifier()); for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) { @@ -130,128 +139,6 @@ public class TileApiary extends TileBeehouse implements ISidedInventory { } } - /* IINVENTORY */ - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - switch (slotIndex) { - case SLOT_QUEEN: - case SLOT_DRONE: - case SLOT_FRAMES_1: - case SLOT_FRAMES_2: - case SLOT_FRAMES_3: - return false; - default: - return true; - } - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack) - && !PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - - if (slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack)) - return true; - - return false; - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public ItemStack getStackInSlot(int i) { - return super.getStackInSlot(i); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - super.setSlotContents(i, itemstack); - } - - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - /* ISPECIALINVENTORY */ // @Override // public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { diff --git a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java index d343f4a03..7165d75ee 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java +++ b/src/main/java/forestry/apiculture/gadgets/TileBeehouse.java @@ -10,28 +10,6 @@ ******************************************************************************/ package forestry.apiculture.gadgets; -import com.mojang.authlib.GameProfile; -import forestry.api.apiculture.IBee; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.apiculture.IBeekeepingLogic; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.api.core.ForestryAPI; -import forestry.api.genetics.IIndividual; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.gadgets.TileBase; -import forestry.core.interfaces.IClimatised; -import forestry.core.network.GuiId; -import forestry.core.network.PacketIds; -import forestry.core.network.PacketInventoryStack; -import forestry.core.network.PacketTileUpdate; -import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.Utils; -import forestry.plugins.PluginApiculture; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -40,22 +18,69 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; +import com.mojang.authlib.GameProfile; + +import forestry.api.apiculture.IBee; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.api.apiculture.IHiveFrame; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.ForestryAPI; +import forestry.api.genetics.IIndividual; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.ForestryItem; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TileForestry; +import forestry.core.interfaces.IClimatised; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.network.PacketIds; +import forestry.core.network.PacketInventoryStack; +import forestry.core.network.PacketTileUpdate; +import forestry.core.proxy.Proxies; +import forestry.core.utils.GuiUtil; +import forestry.core.utils.Utils; +import forestry.plugins.PluginApiculture; + public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { + protected static class BeehouseInventoryAdapter extends TileInventoryAdapter { + public BeehouseInventoryAdapter(TileForestry tile, int size, String name) { + super(tile, size, name); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_QUEEN) { + return PluginApiculture.beeInterface.isMember(itemStack) && !PluginApiculture.beeInterface.isDrone(itemStack); + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_FRAMES_1, SLOT_FRAMES_COUNT)) { + return itemStack.getItem() instanceof IHiveFrame; + } else if (slotIndex == SLOT_DRONE) { + return PluginApiculture.beeInterface.isDrone(itemStack); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT); + } + } + // CONSTANTS public static final int SLOT_QUEEN = 0; public static final int SLOT_DRONE = 1; - public static final int SLOT_INVENTORY_1 = 2; public static final int SLOT_PRODUCT_1 = 2; public static final int SLOT_PRODUCT_COUNT = 7; public static final int SLOT_FRAMES_1 = 9; public static final int SLOT_FRAMES_2 = 10; public static final int SLOT_FRAMES_3 = 11; - public static final int SLOT_INVENTORY_COUNT = 7; public static final int SLOT_FRAMES_COUNT = 3; - - // Inventory - protected final InventoryAdapter inventory = new InventoryAdapter(12, "Items"); private final IBeekeepingLogic logic; private BiomeGenBase biome; private int displayHealthMax = 0; @@ -64,6 +89,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { public TileBeehouse() { setHints(Config.hints.get("apiary")); logic = PluginApiculture.beeInterface.createBeekeepingLogic(this); + setInternalInventory(new BeehouseInventoryAdapter(this, 12, "Items").disableAutomation()); } @Override @@ -77,8 +103,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { super.writeToNBT(nbttagcompound); nbttagcompound.setInteger("BiomeId", biome.biomeID); - - inventory.writeToNBT(nbttagcompound); if (logic != null) logic.writeToNBT(nbttagcompound); } @@ -89,8 +113,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { int biomeId = nbttagcompound.getInteger("BiomeId"); biome = BiomeGenBase.getBiome(biomeId); - - inventory.readFromNBT(nbttagcompound); logic.readFromNBT(nbttagcompound); } @@ -114,7 +136,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { @Override public EnumTemperature getTemperature() { - return EnumTemperature.getFromValue(getExactTemperature()); + return EnumTemperature.getFromBiome(biome); } @Override @@ -137,12 +159,11 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { public void updateClientSide() { // / Multiplayer FX - if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN))) { + if (PluginApiculture.beeInterface.isMated(getInternalInventory().getStackInSlot(SLOT_QUEEN))) if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0) { - IBee displayQueen = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)); + IBee displayQueen = PluginApiculture.beeInterface.getMember(getInternalInventory().getStackInSlot(SLOT_QUEEN)); displayQueen.doFX(logic.getEffectData(), this); } - } } @@ -157,7 +178,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { // Add swarm effects if (worldObj.getTotalWorldTime() % 200 * 10 == 0) - onQueenChange(inventory.getStackInSlot(SLOT_QUEEN)); + onQueenChange(getInternalInventory().getStackInSlot(SLOT_QUEEN)); /* These should get already done on the client / doesn't work server-side anyway if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0) queen.doFX(logic.getEffectData(), this); @@ -184,7 +205,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { @Override public boolean addProduct(ItemStack product, boolean all) { - return inventory.tryAddStack(product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all, true); + return InvTools.tryAddStack(getInternalInventory(), product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all, true); } /* NETWORK SYNCH */ @@ -200,6 +221,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { /* STATE INFORMATION */ private int getHealthDisplay() { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -212,6 +234,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { } private int getMaxHealthDisplay() { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_QUEEN) == null) return 0; @@ -225,9 +248,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { /** * Returns scaled queen health or breeding progress - * - * @param i - * @return */ public int getHealthScaled(int i) { if (getMaxHealthDisplay() == 0) @@ -279,20 +299,6 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { iCrafting.sendProgressBarUpdate(container, 1, logic.getTotalBreedingTime()); } - /* INVENTORY MANAGMENT */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - public void setSlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - // / IBEEHOUSING @Override public int getXCoord() { @@ -331,12 +337,12 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { @Override public void setQueen(ItemStack itemstack) { - setSlotContents(SLOT_QUEEN, itemstack); + setInventorySlotContents(SLOT_QUEEN, itemstack); } @Override public void setDrone(ItemStack itemstack) { - setSlotContents(SLOT_DRONE, itemstack); + setInventorySlotContents(SLOT_DRONE, itemstack); } @Override @@ -351,7 +357,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { @Override public int getErrorOrdinal() { - return getErrorState().ordinal(); + return getErrorState().getID(); } @Override @@ -430,7 +436,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised { public boolean onEggLaid(IBee queen) { return false; } - + /* IHousing */ @Override public GameProfile getOwnerName() { diff --git a/src/main/java/forestry/apiculture/gadgets/TileSwarm.java b/src/main/java/forestry/apiculture/gadgets/TileSwarm.java index 509566fe9..e0bb93925 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileSwarm.java +++ b/src/main/java/forestry/apiculture/gadgets/TileSwarm.java @@ -10,12 +10,12 @@ ******************************************************************************/ package forestry.apiculture.gadgets; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import forestry.core.utils.InventoryAdapter; - public class TileSwarm extends TileEntity { public final InventoryAdapter contained = new InventoryAdapter(2, "Contained"); @@ -27,7 +27,7 @@ public class TileSwarm extends TileEntity { public TileSwarm setContained(ItemStack[] bees) { for (ItemStack itemstack : bees) - contained.addStack(itemstack, false, true); + InvTools.addStack(contained, itemstack, false, true); return this; } diff --git a/src/main/java/forestry/apiculture/genetics/AlleleBeeSpecies.java b/src/main/java/forestry/apiculture/genetics/AlleleBeeSpecies.java index d8178791f..071545876 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleBeeSpecies.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleBeeSpecies.java @@ -29,15 +29,14 @@ import forestry.core.config.Defaults; import forestry.core.genetics.AlleleSpecies; import forestry.core.render.TextureManager; import forestry.core.utils.StackUtils; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Locale; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; public class AlleleBeeSpecies extends AlleleSpecies implements IAlleleBeeSpecies, IIconProvider { @@ -52,7 +51,7 @@ public class AlleleBeeSpecies extends AlleleSpecies implements IAlleleBeeSpecies private final int primaryColour; private final int secondaryColour; - private final String iconType = "default"; + private static final String iconType = "default"; public AlleleBeeSpecies(String uid, boolean dominant, String name, IClassification branch, int primaryColor, int secondaryColor) { this(uid, dominant, name, branch, null, primaryColor, secondaryColor); @@ -112,7 +111,7 @@ public class AlleleBeeSpecies extends AlleleSpecies implements IAlleleBeeSpecies int highest = 0; exclude.add(species); - for(IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES.ordinal())) { + for(IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES)) { if(!exclude.contains(mutation.getAllele0())) { int otherAdvance = getGeneticAdvancement(mutation.getAllele0(), exclude); if(otherAdvance > highest) diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectAggressive.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectAggressive.java index ecfd9b7c3..7f38a2fd7 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectAggressive.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectAggressive.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.apiculture.items.ItemArmorApiarist; import forestry.core.utils.DamageSourceForestry; +import java.util.List; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; public class AlleleEffectAggressive extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectCreeper.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectCreeper.java index f3b932bf2..7177a271d 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectCreeper.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectCreeper.java @@ -10,22 +10,20 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.apiculture.items.ItemArmorApiarist; import forestry.core.genetics.EffectData; +import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; public class AlleleEffectCreeper extends AlleleEffectThrottled { - private final int explosionChance = 50; - private final byte defaultForce = 12; + private static final int explosionChance = 50; + private static final byte defaultForce = 12; private final byte indexExplosionTimer = 1; private final byte indexExplosionForce = 2; diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectExploration.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectExploration.java index 1d73a289f..3a9dee87f 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectExploration.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectExploration.java @@ -10,14 +10,12 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; +import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; public class AlleleEffectExploration extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectFertile.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectFertile.java new file mode 100644 index 000000000..989efc8ac --- /dev/null +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectFertile.java @@ -0,0 +1,59 @@ +package forestry.apiculture.genetics; + +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public class AlleleEffectFertile extends AlleleEffectThrottled { + + public static final int MAX_BLOCK_FIND_TRIES = 5; + + public AlleleEffectFertile(String uid) { + super(uid, "fertile", false, 6, true, false); + } + + @Override + public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) { + + if (isHalted(storedData, housing)) { + return storedData; + } + + World world = housing.getWorld(); + int territorySize[] = getModifiedArea(genome, housing); + + int blockX = getRandomOffset(world.rand, housing.getXCoord(), territorySize[0]); + int blockZ = getRandomOffset(world.rand, housing.getZCoord(), territorySize[2]); + int blockMaxY = housing.getYCoord() + territorySize[1] / 2 + 1; + int blockMinY = housing.getYCoord() - (territorySize[1] / 2) - 1; + + for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) { + if (tryTickColumn(world, blockX, blockZ, blockMaxY, blockMinY)) { + break; + } + blockX = getRandomOffset(world.rand, housing.getXCoord(), territorySize[0]); + blockZ = getRandomOffset(world.rand, housing.getZCoord(), territorySize[2]); + } + + return storedData; + } + + private int getRandomOffset(Random random, int centrePos, int offset) { + return centrePos + random.nextInt(offset) - (offset / 2); + } + + private boolean tryTickColumn(World world, int x, int z, int maxY, int minY) { + for (int y = maxY; y >= minY; --y) { + if (!world.isAirBlock(x, y, z)) { + Block block = world.getBlock(x, y, z); + world.scheduleBlockUpdate(x, y, z, block, 5); + return true; + } + } + return false; + } + +} diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectFungification.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectFungification.java new file mode 100644 index 000000000..6cc5bc5d9 --- /dev/null +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectFungification.java @@ -0,0 +1,128 @@ +package forestry.apiculture.genetics; + +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import forestry.core.genetics.EffectData; +import java.util.List; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityMooshroom; +import net.minecraft.init.Blocks; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenBigMushroom; + +public class AlleleEffectFungification extends AlleleEffectThrottled { + + public static final int MAX_BLOCK_FIND_TRIES = 10; + public static final int ENTITY_THROTTLE = 6; + + public AlleleEffectFungification(String uid) { + super(uid, "mycophilic", true, 10, false, false); + } + + @Override + public IEffectData validateStorage(IEffectData storedData) { + if (storedData instanceof EffectData && ((EffectData) storedData).getIntSize() == 2) { + return storedData; + } + + return new EffectData(2, 0); + } + + @Override + public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) { + if (isHalted(storedData, housing)) { + return storedData; + } + + doBlockEffect(genome, housing); + + int entityThrottle = storedData.getInteger(1); + if (entityThrottle >= ENTITY_THROTTLE) { + doEntityEffect(genome, housing); + entityThrottle = 0; + } else { + ++entityThrottle; + } + storedData.setInteger(1, entityThrottle); + + return storedData; + } + + private void doBlockEffect(IBeeGenome genome, IBeeHousing housing) { + World world = housing.getWorld(); + int territorySize[] = getModifiedArea(genome, housing); + + int blockX = getRandomOffset(world.rand, housing.getXCoord(), territorySize[0]); + int blockY = getRandomOffset(world.rand, housing.getYCoord(), territorySize[1]); + int blockZ = getRandomOffset(world.rand, housing.getZCoord(), territorySize[2]); + + for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) { + Block block = world.getBlock(blockX, blockY, blockZ); + if (isSuitableForMycelium(world, block, blockX, blockY, blockZ)) { + world.setBlock(blockX, blockY, blockZ, Blocks.mycelium); + break; + } else if (isSuitableForGrowth(block)) { + doMushroomGrowth(block, world, blockX, blockY, blockZ); + break; + } + blockX = getRandomOffset(world.rand, housing.getXCoord(), territorySize[0]); + blockY = getRandomOffset(world.rand, housing.getYCoord(), territorySize[1]); + blockZ = getRandomOffset(world.rand, housing.getZCoord(), territorySize[2]); + } + + } + + private void doEntityEffect(IBeeGenome genome, IBeeHousing housing) { + AxisAlignedBB aabb = this.getBounding(genome, housing, 1f); + World world = housing.getWorld(); + @SuppressWarnings("unchecked") // Quiets warnings. Eventually returns a list of entities. + List entities = (List)world.getEntitiesWithinAABB(EntityCow.class, aabb); + for (Entity entity : entities) { + if (entity instanceof EntityCow && !(entity instanceof EntityMooshroom)) { + convertCowToMooshroom((EntityCow)entity); + break; + } + } + } + + private int getRandomOffset(Random random, int centrePos, int offset) { + return centrePos + random.nextInt(offset) - (offset / 2); + } + + private boolean isSuitableForMycelium(World world, Block block, int blockX, int blockY, int blockZ) { + return block == Blocks.grass || (block == Blocks.dirt && world.canBlockSeeTheSky(blockX, blockY, blockZ)); + } + + private boolean isSuitableForGrowth(Block block) { + return block == Blocks.red_mushroom || block == Blocks.brown_mushroom; + } + + private static void convertCowToMooshroom(EntityCow cow) { + World worldObj = cow.worldObj; + cow.setDead(); + EntityMooshroom mooshroom = new EntityMooshroom(worldObj); + mooshroom.setLocationAndAngles(cow.posX, cow.posY, cow.posZ, cow.rotationYaw, cow.rotationPitch); + mooshroom.setHealth(cow.getHealth()); + mooshroom.renderYawOffset = cow.renderYawOffset; + worldObj.spawnEntityInWorld(mooshroom); + worldObj.spawnParticle("largeexplode", cow.posX, cow.posY + (double)(cow.height / 2.0F), cow.posZ, 0.0D, 0.0D, 0.0D); + } + + private void doMushroomGrowth(Block block, World world, int blockX, int blockY, int blockZ) { + WorldGenBigMushroom giantMushroomGenerator; + + if (block == Blocks.brown_mushroom) { + giantMushroomGenerator = new WorldGenBigMushroom(0); + } else { + giantMushroomGenerator = new WorldGenBigMushroom(1); + } + + world.setBlockToAir(blockX, blockY, blockZ); + giantMushroomGenerator.generate(world, world.rand, blockX, blockY, blockZ); + } +} diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectGlacial.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectGlacial.java index 7bb55b61f..15c4f0bfb 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectGlacial.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectGlacial.java @@ -10,17 +10,16 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IEffectData; import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; public class AlleleEffectGlacial extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectHeroic.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectHeroic.java index bfb0524e1..580eabeff 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectHeroic.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectHeroic.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.monster.EntityMob; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; +import java.util.List; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; public class AlleleEffectHeroic extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectIgnition.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectIgnition.java index b834d766f..e51aa6edb 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectIgnition.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectIgnition.java @@ -10,23 +10,21 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.apiculture.items.ItemArmorApiarist; import forestry.plugins.PluginApiculture; +import java.util.List; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; public class AlleleEffectIgnition extends AlleleEffectThrottled { - private final int ignitionChance = 50; - private final int fireDuration = 500; + private static final int ignitionChance = 50; + private static final int fireDuration = 500; public AlleleEffectIgnition(String uid) { super(uid, "ignition", false, 20, false, true); diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectMiasmic.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectMiasmic.java index 715db439d..8e61a26cb 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectMiasmic.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectMiasmic.java @@ -10,23 +10,21 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import forestry.apiculture.items.ItemArmorApiarist; +import forestry.plugins.PluginApiculture; import java.util.List; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.genetics.IEffectData; -import forestry.apiculture.items.ItemArmorApiarist; -import forestry.plugins.PluginApiculture; - public class AlleleEffectMiasmic extends AlleleEffectThrottled { - private final int infectionChance = 50; + private static final int infectionChance = 50; public AlleleEffectMiasmic(String uid) { super(uid, "misasmic", false, 50, false, false); diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectMisanthrope.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectMisanthrope.java index 9599517b5..a45d208a1 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectMisanthrope.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectMisanthrope.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.apiculture.items.ItemArmorApiarist; import forestry.core.utils.DamageSourceForestry; +import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; public class AlleleEffectMisanthrope extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectNone.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectNone.java index d7a4e799c..a7ac786a0 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectNone.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectNone.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.world.World; - import forestry.api.apiculture.IAlleleBeeEffect; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; import forestry.core.genetics.Allele; import forestry.plugins.PluginApiculture; +import net.minecraft.world.World; public class AlleleEffectNone extends Allele implements IAlleleBeeEffect { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java index 568d8b91c..0d0795022 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectPotion.java @@ -10,25 +10,28 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import cpw.mods.fml.relauncher.ReflectionHelper; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import forestry.apiculture.items.ItemArmorApiarist; +import forestry.core.proxy.Proxies; import java.util.List; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.genetics.IEffectData; - public class AlleleEffectPotion extends AlleleEffectThrottled { - private int potionId = 0; + private final Potion potion; + private final boolean isBadEffect; private final int duration; public AlleleEffectPotion(String uid, String name, boolean isDominant, Potion potion, int duration, boolean requiresWorking) { super(uid, name, isDominant, 200, requiresWorking, false); - potionId = potion.getId(); + this.potion = potion; + this.isBadEffect = isBadEffect(potion); this.duration = duration; } @@ -39,15 +42,42 @@ public class AlleleEffectPotion extends AlleleEffectThrottled { return storedData; AxisAlignedBB beatifyBox = getBounding(genome, housing, 1.0f); - @SuppressWarnings("rawtypes") List list = housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, beatifyBox); - for (Object obj : list) { - EntityPlayer player = (EntityPlayer) obj; - player.addPotionEffect(new PotionEffect(potionId, duration, 0)); + for (Object entity : list) { + if (!(entity instanceof EntityPlayer)) + continue; + + EntityPlayer player = (EntityPlayer) entity; + + int dur = this.duration; + if (isBadEffect) { + // Players are not attacked if they wear a full set of apiarist's armor. + int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true); + if (count >= 4) + continue; // Full set, no damage/effect + else if (count == 3) + dur = this.duration / 4; + else if (count == 2) + dur = this.duration / 2; + else if (count == 1) + dur = this.duration * 3 / 4; + } + + player.addPotionEffect(new PotionEffect(potion.getId(), dur, 0)); } return storedData; } + //FIXME: remove when Potion.isBadEffect() is available server-side + private static boolean isBadEffect(Potion potion) { + try { + return (Boolean) ReflectionHelper.getPrivateValue(Potion.class, potion, "field_76418_K", "isBadEffect"); + } catch (ReflectionHelper.UnableToFindFieldException e) { + Proxies.log.severe("Could not access potion field isBadEffect."); + return false; + } + } + } diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectRadioactive.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectRadioactive.java index fb7601ad9..a36b42ae5 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectRadioactive.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectRadioactive.java @@ -10,17 +10,6 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; -import net.minecraft.world.World; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; @@ -28,7 +17,16 @@ import forestry.apiculture.gadgets.BlockAlveary; import forestry.apiculture.gadgets.TileAlveary; import forestry.apiculture.items.ItemArmorApiarist; import forestry.core.utils.DamageSourceForestry; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.List; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; public class AlleleEffectRadioactive extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectRepulsion.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectRepulsion.java index 72c070217..3bfc605c1 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectRepulsion.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectRepulsion.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry; -import net.minecraft.entity.monster.EntityMob; -import net.minecraft.util.AxisAlignedBB; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; +import java.util.List; +import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.util.AxisAlignedBB; public class AlleleEffectRepulsion extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectResurrection.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectResurrection.java index 65e2381d7..6039ac567 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectResurrection.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectResurrection.java @@ -10,10 +10,14 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.genetics.IEffectData; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; import java.util.ArrayList; import java.util.Collections; import java.util.List; - import net.minecraft.entity.EntityLiving; import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.item.EntityItem; @@ -30,12 +34,6 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; -import forestry.api.apiculture.IBeeGenome; -import forestry.api.apiculture.IBeeHousing; -import forestry.api.genetics.IEffectData; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; - public class AlleleEffectResurrection extends AlleleEffectThrottled { public static class Resurrectable { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectSnowing.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectSnowing.java index 9117fad58..d6e13c735 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectSnowing.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectSnowing.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IEffectData; import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.util.ForgeDirection; public class AlleleEffectSnowing extends AlleleEffectThrottled { diff --git a/src/main/java/forestry/apiculture/genetics/AlleleEffectThrottled.java b/src/main/java/forestry/apiculture/genetics/AlleleEffectThrottled.java index dfd554053..83d2dcf56 100755 --- a/src/main/java/forestry/apiculture/genetics/AlleleEffectThrottled.java +++ b/src/main/java/forestry/apiculture/genetics/AlleleEffectThrottled.java @@ -10,17 +10,16 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.util.AxisAlignedBB; - import forestry.api.apiculture.IAlleleBeeEffect; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IEffectData; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.genetics.Allele; import forestry.core.genetics.EffectData; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import forestry.plugins.PluginApiculture; +import net.minecraft.util.AxisAlignedBB; public abstract class AlleleEffectThrottled extends Allele implements IAlleleBeeEffect { @@ -55,14 +54,14 @@ public abstract class AlleleEffectThrottled extends Allele implements IAlleleBee public boolean isHalted(IEffectData storedData, IBeeHousing housing) { - if (requiresWorkingQueen && housing.getErrorOrdinal() != EnumErrorCode.OK.ordinal()) + if (requiresWorkingQueen && housing.getErrorState() != EnumErrorCode.OK) return true; - int throttle = storedData.getInteger(0); - throttle++; - storedData.setInteger(0, throttle); + int throt = storedData.getInteger(0); + throt++; + storedData.setInteger(0, throt); - if (throttle < getThrottle()) + if (throt < getThrottle()) return true; // Reset since we are done throttling. diff --git a/src/main/java/forestry/apiculture/genetics/ApiaristTracker.java b/src/main/java/forestry/apiculture/genetics/ApiaristTracker.java index f8e85a44b..56ca40a02 100755 --- a/src/main/java/forestry/apiculture/genetics/ApiaristTracker.java +++ b/src/main/java/forestry/apiculture/genetics/ApiaristTracker.java @@ -10,16 +10,15 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; - import com.mojang.authlib.GameProfile; - +import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.IApiaristTracker; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.IIndividual; import forestry.core.genetics.BreedingTracker; import forestry.plugins.PluginApiculture; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; public class ApiaristTracker extends BreedingTracker implements IApiaristTracker { @@ -61,7 +60,7 @@ public class ApiaristTracker extends BreedingTracker implements IApiaristTracker public void registerPickup(IIndividual individual) { if(!individual.getGenome().getPrimary().getRoot().getUID().equals(BeeHelper.UID)) return; - if(!individual.isPureBred(0)) + if(!individual.isPureBred(EnumBeeChromosome.SPECIES)) return; if(PluginApiculture.beeInterface.getCombinations(individual.getGenome().getPrimary()).size() > 0) return; diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index 45e056863..b181fd8cd 100755 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -10,6 +10,20 @@ ******************************************************************************/ package forestry.apiculture.genetics; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.IAlleleBeeEffect; import forestry.api.apiculture.IAlleleBeeSpecies; @@ -20,7 +34,6 @@ import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeeMutation; import forestry.api.apiculture.IBeekeepingMode; import forestry.api.core.BiomeHelper; -import forestry.api.core.EnumErrorCode; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; @@ -32,29 +45,23 @@ import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IGenome; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; +import forestry.core.EnumErrorCode; import forestry.core.config.Defaults; import forestry.core.genetics.Chromosome; import forestry.core.genetics.GenericRatings; import forestry.core.genetics.IndividualLiving; import forestry.core.proxy.Proxies; -import forestry.core.utils.StackUtils; +import forestry.core.utils.GeneticsUtil; import forestry.core.utils.StringUtil; -import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.MutableVect; +import forestry.core.vect.Vect; import forestry.plugins.PluginApiculture; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; public class Bee extends IndividualLiving implements IBee { + protected int generation; + protected boolean isNatural = true; + public IBeeGenome genome; public IBeeGenome mate; @@ -63,28 +70,20 @@ public class Bee extends IndividualLiving implements IBee { readFromNBT(nbttagcompound); } - public Bee(World world, IBeeGenome genome, IBee mate) { - this(world, genome); + public Bee(IBeeGenome genome, IBee mate) { + this(genome); this.mate = mate.getGenome(); - this.isIrregularMating = mate.isNatural() != this.isNatural; - } - - public Bee(World world, IBeeGenome genome) { - this(world, genome, true, 0); } public Bee(IBeeGenome genome) { this(genome, true, 0); } - public Bee(World world, IBeeGenome genome, boolean isNatural, int generation) { - super(genome.getLifespan(), isNatural, generation); - this.genome = genome; - } - public Bee(IBeeGenome genome, boolean isNatural, int generation) { - super(genome.getLifespan(), isNatural, generation); + super(genome.getLifespan()); this.genome = genome; + this.isNatural = isNatural; + this.generation = generation; } /* SAVING & LOADING */ @@ -98,15 +97,51 @@ public class Bee extends IndividualLiving implements IBee { super.readFromNBT(nbttagcompound); + if (nbttagcompound.hasKey("NA")) + isNatural = nbttagcompound.getBoolean("NA"); + + if (nbttagcompound.hasKey("GEN")) + generation = nbttagcompound.getInteger("GEN"); + if (nbttagcompound.hasKey("Genome")) genome = new BeeGenome(nbttagcompound.getCompoundTag("Genome")); else genome = PluginApiculture.beeInterface.templateAsGenome(BeeTemplates.getForestTemplate()); + if (nbttagcompound.hasKey("Mate")) mate = new BeeGenome(nbttagcompound.getCompoundTag("Mate")); } + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + + super.writeToNBT(nbttagcompound); + + if (!isNatural) + nbttagcompound.setBoolean("NA", false); + + if (generation > 0) + nbttagcompound.setInteger("GEN", generation); + } + + public void setIsNatural(boolean flag) { + this.isNatural = flag; + } + + @Override + public boolean isIrregularMating() { + return false; + } + + public boolean isNatural() { + return this.isNatural; + } + + public int getGeneration() { + return generation; + } + @Override public void mate(IIndividual individual) { if(!(individual instanceof IBee)) @@ -114,7 +149,6 @@ public class Bee extends IndividualLiving implements IBee { IBee drone = (IBee)individual; mate = drone.getGenome(); - this.isIrregularMating = drone.isNatural() != this.isNatural; } /* EFFECTS */ @@ -131,7 +165,7 @@ public class Bee extends IndividualLiving implements IBee { if (!effect.isCombinable()) return storedData; - IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal()); + IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT); if (!secondary.isCombinable()) return storedData; @@ -158,7 +192,7 @@ public class Bee extends IndividualLiving implements IBee { if (!effect.isCombinable()) return storedData; - IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal()); + IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT); if (!secondary.isCombinable()) return storedData; @@ -266,26 +300,16 @@ public class Bee extends IndividualLiving implements IBee { IFlowerProvider provider = genome.getFlowerProvider(); - Vect coords = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()); - Vect posCurrent = new Vect(0, 0, 0); - int[] areaAr = genome.getTerritory(); - Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)); - - if (area.x < 1) - area.x = 1; - if (area.y < 1) - area.y = 1; - if (area.z < 1) - area.z = 1; - - Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2)); + Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()); + Vect area = getArea(genome, housing); + Vect offset = new Vect(-area.x / 2, -area.y / 2, -area.z / 2); boolean hasFlower = false; - while (advancePosition(posCurrent, area)) { + MutableVect posCurrent = new MutableVect(0, 0, 0); + while (posCurrent.advancePositionInArea(area)) { - Vect posBlock = posCurrent.add(coords); - posBlock = posBlock.add(offset); + Vect posBlock = Vect.add(housingPos, posCurrent, offset); if (provider.isAcceptedFlower(housing.getWorld(), this, posBlock.x, posBlock.y, posBlock.z)) { hasFlower = true; @@ -297,28 +321,6 @@ public class Bee extends IndividualLiving implements IBee { return hasFlower; } - private boolean advancePosition(Vect posCurrent, Vect area) { - // Increment z first until end reached - if (posCurrent.z < area.z - 1) - posCurrent.z++; - else { - posCurrent.z = 0; - - if (posCurrent.x < area.x - 1) - posCurrent.x++; - else { - posCurrent.x = 0; - - if (posCurrent.y < area.y - 1) - posCurrent.y++; - else - return false; - } - } - - return true; - } - @Override public ArrayList getSuitableBiomeIds() { ArrayList suitableBiomes = new ArrayList(); @@ -351,27 +353,48 @@ public class Bee extends IndividualLiving implements IBee { // You analyzed it? Juicy tooltip coming up! IAlleleBeeSpecies primary = genome.getPrimary(); IAlleleBeeSpecies secondary = genome.getSecondary(); - if (!isPureBred(EnumBeeChromosome.SPECIES.ordinal())) - list.add("\u00A79" + StringUtil.localize("bees.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); + if (!isPureBred(EnumBeeChromosome.SPECIES)) + list.add(EnumChatFormatting.BLUE + StringUtil.localize("bees.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); - IAllele speed = genome.getActiveAllele(EnumBeeChromosome.SPEED.ordinal()); - String customWorker = "tooltip.worker." + speed.getUnlocalizedName().replaceFirst("gui.", ""); - if (StringUtil.canTranslate(customWorker)) - list.add(StringUtil.localize(customWorker)); + if (generation > 0) { + EnumRarity rarity; + if (generation >= 1000) + rarity = EnumRarity.epic; + else if (generation >= 100) + rarity = EnumRarity.rare; + else if (generation >= 10) + rarity = EnumRarity.uncommon; + else + rarity = EnumRarity.common; + + String generationString = rarity.rarityColor + StringUtil.localizeAndFormat("gui.beealyzer.generations", generation); + list.add(generationString); + } + + IAllele speedAllele = genome.getActiveAllele(EnumBeeChromosome.SPEED); + IAlleleTolerance tempToleranceAllele = (IAlleleTolerance)getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE); + IAlleleTolerance humidToleranceAllele = (IAlleleTolerance)getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE); + + String unlocalizedCustomSpeed = "tooltip.worker." + speedAllele.getUnlocalizedName().replaceFirst("gui.", ""); + String speed; + if (StringUtil.canTranslate(unlocalizedCustomSpeed)) + speed = StringUtil.localize(unlocalizedCustomSpeed); else - list.add(speed.getName() + " " + StringUtil.localize("gui.worker")); + speed = speedAllele.getName() + " " + StringUtil.localize("gui.worker"); - list.add(genome.getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName() + " " + StringUtil.localize("gui.life")); + String lifespan = genome.getActiveAllele(EnumBeeChromosome.LIFESPAN).getName() + " " + StringUtil.localize("gui.life"); + String tempTolerance = EnumChatFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempToleranceAllele.getName(); + String humidTolerance = EnumChatFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidToleranceAllele.getName(); + String flowers = genome.getFlowerProvider().getDescription(); - IAlleleTolerance tempTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()); - list.add("\u00A7aT: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempTolerance.getName()); + list.add(lifespan); + list.add(speed); + list.add(tempTolerance); + list.add(humidTolerance); + list.add(flowers); - IAlleleTolerance humidTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()); - list.add("\u00A7aH: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidTolerance.getName()); - - list.add(genome.getFlowerProvider().getDescription()); if (genome.getNocturnal()) - list.add("\u00A7c" + GenericRatings.rateActivityTime(genome.getNocturnal(), false)); + list.add(EnumChatFormatting.RED + GenericRatings.rateActivityTime(genome.getNocturnal(), false)); } @Override @@ -499,7 +522,7 @@ public class Bee extends IndividualLiving implements IBee { toCreate = 1; for (int i = 0; i < toCreate; i++) { - IBee offspring = createOffspring(housing, -1); + IBee offspring = createOffspring(housing, 0); if (offspring != null) { offspring.setIsNatural(true); bees.add(offspring); @@ -534,7 +557,7 @@ public class Bee extends IndividualLiving implements IBee { chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]); IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(world); - IBee offspring = new Bee(world, new BeeGenome(chromosomes), mode.isNaturalOffspring(this), generation); + IBee offspring = new Bee(new BeeGenome(chromosomes), mode.isNaturalOffspring(this), generation); /* Disabling the mutation rate nerf // All mutation and no play makes queen a dull girl. @@ -571,14 +594,12 @@ public class Bee extends IndividualLiving implements IBee { } for (IBeeMutation mutation : PluginApiculture.beeInterface.getMutations(true)) { - float chance = 0; - - if ((chance = mutation.getChance(housing, allele0, allele1, genome0, genome1)) > 0) - if (world.rand.nextFloat()*100 < chance) { - IApiaristTracker breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(world, housing.getOwnerName()); - breedingTracker.registerMutation(mutation); - return PluginApiculture.beeInterface.templateAsChromosomes(mutation.getTemplate()); - } + float chance = mutation.getChance(housing, allele0, allele1, genome0, genome1); + if (chance > world.rand.nextFloat() * 100) { + IApiaristTracker breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(world, housing.getOwnerName()); + breedingTracker.registerMutation(mutation); + return PluginApiculture.beeInterface.templateAsChromosomes(mutation.getTemplate()); + } } return null; @@ -588,56 +609,34 @@ public class Bee extends IndividualLiving implements IBee { @Override public IIndividual retrievePollen(IBeeHousing housing) { - int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f)); + int chance = Math.round(genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f)); + + World world = housing.getWorld(); + Random random = world.rand; // Correct speed - if (housing.getWorld().rand.nextInt(100) >= chance) + if (random.nextInt(100) >= chance) return null; - int[] areaAr = genome.getTerritory(); - Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f); - Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2)); + Vect area = getArea(genome, housing); + Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2); + Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()); - if (area.x < 1) - area.x = 1; - if (area.y < 1) - area.y = 1; - if (area.z < 1) - area.z = 1; + IIndividual pollen = null; - // We have up to ten attempts for (int i = 0; i < 20; i++) { + Vect randomPos = Vect.getRandomPositionInArea(random, area); + Vect blockPos = Vect.add(housingPos, randomPos, offset); + TileEntity tile = world.getTileEntity(blockPos.x, blockPos.y, blockPos.z); - Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z)); - - Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord())); - posBlock = posBlock.add(offset); - - TileEntity tile = housing.getWorld().getTileEntity(posBlock.x, posBlock.y, posBlock.z); - if (!(tile instanceof IPollinatable)) { - if (housing.getWorld().isAirBlock(posBlock.x, posBlock.y, posBlock.z)) - continue; - - // Test for ersatz genomes - for (Map.Entry entry : AlleleManager.ersatzSpecimen.entrySet()) { - if (!StackUtils.equals(housing.getWorld().getBlock(posBlock.x, posBlock.y, posBlock.z), entry.getKey())) - continue; - if (entry.getKey().getItemDamage() != housing.getWorld().getBlockMetadata(posBlock.x, posBlock.y, posBlock.z)) - continue; - - // We matched, return ersatz genome - return entry.getValue().copy(); - } - - continue; + if (tile instanceof IPollinatable) { + IPollinatable pitcher = (IPollinatable) tile; + if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher)) + pollen = pitcher.getPollen(); + } else { + pollen = GeneticsUtil.getErsatzPollen(world, blockPos.x, blockPos.y, blockPos.z); } - IPollinatable pitcher = (IPollinatable) tile; - if (!genome.getFlowerProvider().isAcceptedPollinatable(housing.getWorld(), pitcher)) - continue; - - IIndividual pollen = pitcher.getPollen(); - if (pollen != null) return pollen; } @@ -650,34 +649,27 @@ public class Bee extends IndividualLiving implements IBee { int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f)); + World world = housing.getWorld(); + Random random = world.rand; + // Correct speed - if (housing.getWorld().rand.nextInt(100) >= chance) + if (random.nextInt(100) >= chance) return false; - int[] areaAr = genome.getTerritory(); - Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f); - Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 4), -Math.round(area.z / 2)); + Vect area = getArea(genome, housing); + Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2); + Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()); - if (area.x < 1) - area.x = 1; - if (area.y < 1) - area.y = 1; - if (area.z < 1) - area.z = 1; - - // We have up to ten attempts for (int i = 0; i < 30; i++) { - Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z)); + Vect randomPos = Vect.getRandomPositionInArea(random, area); + Vect posBlock = Vect.add(housingPos, randomPos, offset); - Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord())); - posBlock = posBlock.add(offset); - - IPollinatable receiver = Utils.getOrCreatePollinatable(housing.getOwnerName(), housing.getWorld(), posBlock.x, posBlock.y, posBlock.z); + IPollinatable receiver = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z); if(receiver == null) continue; - if (!genome.getFlowerProvider().isAcceptedPollinatable(housing.getWorld(), receiver)) + if (!genome.getFlowerProvider().isAcceptedPollinatable(world, receiver)) continue; if (!receiver.canMateWith(pollen)) continue; @@ -692,35 +684,33 @@ public class Bee extends IndividualLiving implements IBee { @Override public void plantFlowerRandom(IBeeHousing housing) { - int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f)); + int chance = Math.round(genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f)); + + World world = housing.getWorld(); + Random random = world.rand; // Correct speed - if (housing.getWorld().rand.nextInt(100) >= chance) + if (random.nextInt(100) >= chance) return; // Gather required info IFlowerProvider provider = genome.getFlowerProvider(); - int[] areaAr = genome.getTerritory(); - Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f); - Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 4), -Math.round(area.z / 2)); + Vect area = getArea(genome, housing); + Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2); + Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()); - if (area.x < 1) - area.x = 1; - if (area.y < 1) - area.y = 1; - if (area.z < 1) - area.z = 1; - - // We have up to ten attempts for (int i = 0; i < 10; i++) { + Vect randomPos = Vect.getRandomPositionInArea(random, area); + Vect posBlock = Vect.add(housingPos, randomPos, offset); - Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z)); - - Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord())); - posBlock = posBlock.add(offset); - - if (provider.growFlower(housing.getWorld(), this, posBlock.x, posBlock.y, posBlock.z)) + if (provider.growFlower(world, this, posBlock.x, posBlock.y, posBlock.z)) break; } } + + private static Vect getArea(IBeeGenome genome, IBeeHousing housing) { + int[] genomeTerritory = genome.getTerritory(); + float housingModifier = housing.getTerritoryModifier(genome, 1f); + return new Vect(genomeTerritory).multiply(housingModifier * 3.0f); + } } diff --git a/src/main/java/forestry/apiculture/genetics/BeeGenome.java b/src/main/java/forestry/apiculture/genetics/BeeGenome.java index 6a698b69b..9601a7fc6 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeGenome.java +++ b/src/main/java/forestry/apiculture/genetics/BeeGenome.java @@ -26,7 +26,7 @@ import forestry.core.genetics.AlleleArea; import forestry.core.genetics.AlleleBoolean; import forestry.core.genetics.AlleleTolerance; import forestry.core.genetics.Genome; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import forestry.plugins.PluginApiculture; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -72,7 +72,7 @@ public class BeeGenome extends Genome implements IBeeGenome { // NBT RETRIEVAL public static IAlleleBeeSpecies getSpecies(ItemStack itemStack) { - IAllele speciesAllele = Genome.getPrimaryAllele(itemStack, EnumBeeChromosome.SPECIES); + IAllele speciesAllele = Genome.getActiveAllele(itemStack, EnumBeeChromosome.SPECIES); if (speciesAllele instanceof IAlleleBeeSpecies) return (IAlleleBeeSpecies)speciesAllele; else @@ -82,73 +82,73 @@ public class BeeGenome extends Genome implements IBeeGenome { // / INFORMATION RETRIEVAL @Override public IAlleleBeeSpecies getPrimary() { - return (IAlleleBeeSpecies) getActiveAllele(EnumBeeChromosome.SPECIES.ordinal()); + return (IAlleleBeeSpecies) getActiveAllele(EnumBeeChromosome.SPECIES); } @Override public IAlleleBeeSpecies getSecondary() { - return (IAlleleBeeSpecies) getInactiveAllele(EnumBeeChromosome.SPECIES.ordinal()); + return (IAlleleBeeSpecies) getInactiveAllele(EnumBeeChromosome.SPECIES); } @Override public float getSpeed() { - return ((IAlleleFloat) getActiveAllele(EnumBeeChromosome.SPEED.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumBeeChromosome.SPEED)).getValue(); } @Override public int getLifespan() { - return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.LIFESPAN)).getValue(); } @Override public int getFertility() { - return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FERTILITY.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FERTILITY)).getValue(); } @Override public EnumTolerance getToleranceTemp() { - return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal())).getValue(); + return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE)).getValue(); } @Override public boolean getNocturnal() { - return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.NOCTURNAL.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.NOCTURNAL)).getValue(); } @Override public EnumTolerance getToleranceHumid() { - return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal())).getValue(); + return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE)).getValue(); } @Override public boolean getTolerantFlyer() { - return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.TOLERANT_FLYER.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.TOLERANT_FLYER)).getValue(); } @Override public boolean getCaveDwelling() { - return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.CAVE_DWELLING.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.CAVE_DWELLING)).getValue(); } @Override public IFlowerProvider getFlowerProvider() { - return ((IAlleleFlowers) getActiveAllele(EnumBeeChromosome.FLOWER_PROVIDER.ordinal())).getProvider(); + return ((IAlleleFlowers) getActiveAllele(EnumBeeChromosome.FLOWER_PROVIDER)).getProvider(); } @Override public int getFlowering() { - return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FLOWERING.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FLOWERING)).getValue(); } @Override public int[] getTerritory() { - Vect area = ((AlleleArea) getActiveAllele(EnumBeeChromosome.TERRITORY.ordinal())).getArea(); + Vect area = ((AlleleArea) getActiveAllele(EnumBeeChromosome.TERRITORY)).getArea(); return new int[] { area.x, area.y, area.z }; } @Override public IAlleleBeeEffect getEffect() { - return (IAlleleBeeEffect) getActiveAllele(EnumBeeChromosome.EFFECT.ordinal()); + return (IAlleleBeeEffect) getActiveAllele(EnumBeeChromosome.EFFECT); } @Override diff --git a/src/main/java/forestry/apiculture/genetics/BeeHelper.java b/src/main/java/forestry/apiculture/genetics/BeeHelper.java index 6bc34f5ba..bcb490671 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeHelper.java +++ b/src/main/java/forestry/apiculture/genetics/BeeHelper.java @@ -13,7 +13,6 @@ package forestry.apiculture.genetics; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.Locale; import java.util.Map.Entry; @@ -22,10 +21,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import cpw.mods.fml.common.FMLCommonHandler; - import com.mojang.authlib.GameProfile; +import cpw.mods.fml.common.FMLCommonHandler; + import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IAlleleBeeSpecies; @@ -69,9 +68,7 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { public int getSpeciesCount() { if (beeSpeciesCount < 0) { beeSpeciesCount = 0; - Iterator > it = AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); + for (Entry entry : AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet()) { if (entry.getValue() instanceof IAlleleBeeSpecies) if (((IAlleleBeeSpecies) entry.getValue()).isCounted()) beeSpeciesCount++; @@ -101,7 +98,7 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { if (!isMember(bee)) return null; - Item beeItem = null; + Item beeItem; switch (EnumBeeType.VALUES[type]) { case QUEEN: beeItem = ForestryItem.beeQueenGE.item(); @@ -117,7 +114,6 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { break; default: throw new RuntimeException("Cannot instantiate a bee of type " + type); - } NBTTagCompound nbttagcompound = new NBTTagCompound(); @@ -160,8 +156,7 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { @Override public IBee getMember(ItemStack stack) { - if (!ForestryItem.beeQueenGE.isItemEqual(stack) && !ForestryItem.beePrincessGE.isItemEqual(stack) - && !ForestryItem.beeDroneGE.isItemEqual(stack) && !ForestryItem.beeLarvaeGE.isItemEqual(stack)) + if (!isMember(stack)) return null; return new Bee(stack.getTagCompound()); @@ -174,12 +169,12 @@ public class BeeHelper extends SpeciesRoot implements IBeeRoot { @Override public IBee getBee(World world, IBeeGenome genome) { - return new Bee(world, genome); + return new Bee(genome); } @Override public IBee getBee(World world, IBeeGenome genome, IBee mate) { - return new Bee(world, genome, mate); + return new Bee(genome, mate); } /* GENOME CONVERSIONS */ diff --git a/src/main/java/forestry/apiculture/genetics/BeeMutation.java b/src/main/java/forestry/apiculture/genetics/BeeMutation.java index 184650b0a..4013e01ba 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeMutation.java +++ b/src/main/java/forestry/apiculture/genetics/BeeMutation.java @@ -10,13 +10,6 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.ArrayList; - -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - -import net.minecraftforge.common.BiomeDictionary; - import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeeMutation; @@ -26,6 +19,10 @@ import forestry.api.genetics.IAllele; import forestry.api.genetics.IGenome; import forestry.core.genetics.Mutation; import forestry.plugins.PluginApiculture; +import java.util.ArrayList; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeDictionary; public class BeeMutation extends Mutation implements IBeeMutation { diff --git a/src/main/java/forestry/apiculture/genetics/BeeTemplates.java b/src/main/java/forestry/apiculture/genetics/BeeTemplates.java index 7a57519bf..dbc0f5b90 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeTemplates.java +++ b/src/main/java/forestry/apiculture/genetics/BeeTemplates.java @@ -14,7 +14,6 @@ import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.genetics.IAllele; import forestry.api.genetics.IMutation; import forestry.core.genetics.Allele; - import java.util.Arrays; public class BeeTemplates { @@ -548,6 +547,24 @@ public class BeeTemplates { alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesRural; return alleles; } + + public static IAllele[] getFarmerlyTemplate() { + IAllele[] alleles = getAgrarianBranchTemplate(); + alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesFarmerly; + alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow; + alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryLarge; + return alleles; + } + + public static IAllele[] getAgrarianTemplate() { + IAllele[] alleles = getAgrarianBranchTemplate(); + alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesArgrarian; + alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow; + alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceBoth2; + alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectFertile; + alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryLarge; + return alleles; + } // / BOGGY BRANCH public static IAllele[] getBoggyBranchTemplate() { @@ -564,6 +581,25 @@ public class BeeTemplates { alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMarshy; return alleles; } + + public static IAllele[] getMiryTemplate() { + IAllele[] alleles = getBoggyBranchTemplate(); + alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMiry; + alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityMaximum; + alleles[EnumBeeChromosome.TOLERANT_FLYER.ordinal()] = Allele.boolTrue; + alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue; + return alleles; + } + + public static IAllele[] getBoggyTemplate() { + IAllele[] alleles = getBoggyBranchTemplate(); + alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesBoggy; + alleles[EnumBeeChromosome.TOLERANT_FLYER.ordinal()] = Allele.boolTrue; + alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue; + alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectMycophilic; + alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryLarger; + return alleles; + } /* MONASTIC BRANCH */ public static IAllele[] getMonasticBranchTemplate() { diff --git a/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java b/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java index 1b928a23e..d731fa7d1 100755 --- a/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java +++ b/src/main/java/forestry/apiculture/genetics/BeekeepingMode.java @@ -10,16 +10,14 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.ArrayList; -import java.util.Locale; -import java.util.Random; - -import net.minecraft.world.World; - import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IBeekeepingMode; +import java.util.ArrayList; +import java.util.Locale; +import java.util.Random; +import net.minecraft.world.World; public class BeekeepingMode implements IBeekeepingMode { @@ -143,10 +141,7 @@ public class BeekeepingMode implements IBeekeepingMode { @Override public boolean isNaturalOffspring(IBee queen) { - if (!queen.isNatural()) - return false; - - return true; + return queen.isNatural(); } @Override diff --git a/src/main/java/forestry/apiculture/genetics/HiveDrop.java b/src/main/java/forestry/apiculture/genetics/HiveDrop.java index 11c20ea35..da3c881fc 100755 --- a/src/main/java/forestry/apiculture/genetics/HiveDrop.java +++ b/src/main/java/forestry/apiculture/genetics/HiveDrop.java @@ -15,11 +15,10 @@ import forestry.api.apiculture.IBee; import forestry.api.apiculture.IHiveDrop; import forestry.api.genetics.IAllele; import forestry.plugins.PluginApiculture; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import java.util.ArrayList; import java.util.Collections; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class HiveDrop implements IHiveDrop { diff --git a/src/main/java/forestry/apiculture/genetics/JubilanceDefault.java b/src/main/java/forestry/apiculture/genetics/JubilanceDefault.java index adcc05f01..2d1baf043 100755 --- a/src/main/java/forestry/apiculture/genetics/JubilanceDefault.java +++ b/src/main/java/forestry/apiculture/genetics/JubilanceDefault.java @@ -10,15 +10,14 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.biome.BiomeGenBase; - import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.biome.BiomeGenBase; public class JubilanceDefault implements IJubilanceProvider { diff --git a/src/main/java/forestry/apiculture/genetics/JubilanceProviderHermit.java b/src/main/java/forestry/apiculture/genetics/JubilanceProviderHermit.java index 0285d8e3d..2758ff16c 100755 --- a/src/main/java/forestry/apiculture/genetics/JubilanceProviderHermit.java +++ b/src/main/java/forestry/apiculture/genetics/JubilanceProviderHermit.java @@ -10,14 +10,12 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.List; - -import net.minecraft.entity.EntityLiving; -import net.minecraft.util.AxisAlignedBB; - import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; +import java.util.List; +import net.minecraft.entity.EntityLiving; +import net.minecraft.util.AxisAlignedBB; /** * Hermits will not produce if there are any other living creatures nearby. @@ -30,10 +28,7 @@ public class JubilanceProviderHermit extends JubilanceDefault { @SuppressWarnings("rawtypes") List list = housing.getWorld().getEntitiesWithinAABB(EntityLiving.class, bounding); - if (list.size() > 0) - return false; - - return true; + return list.size() <= 0; } } diff --git a/src/main/java/forestry/apiculture/genetics/JubilanceReqRes.java b/src/main/java/forestry/apiculture/genetics/JubilanceReqRes.java index ffef6a5f1..3e11a8411 100755 --- a/src/main/java/forestry/apiculture/genetics/JubilanceReqRes.java +++ b/src/main/java/forestry/apiculture/genetics/JubilanceReqRes.java @@ -10,13 +10,13 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.core.utils.StackUtils; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class JubilanceReqRes implements IJubilanceProvider { @@ -32,12 +32,11 @@ public class JubilanceReqRes implements IJubilanceProvider { if (blockRequired == null) return true; - Block block = housing.getWorld().getBlock(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord()); - int meta = housing.getWorld().getBlockMetadata(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord()); - if (StackUtils.equals(block, blockRequired) && meta == blockRequired.getItemDamage()) - return true; - else - return false; + World world = housing.getWorld(); + + Block block = world.getBlock(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord()); + int meta = world.getBlockMetadata(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord()); + return StackUtils.equals(block, meta, blockRequired); } } diff --git a/src/main/java/forestry/apiculture/genetics/MutationEMC.java b/src/main/java/forestry/apiculture/genetics/MutationEMC.java index 1b18779ff..3a929bdc0 100755 --- a/src/main/java/forestry/apiculture/genetics/MutationEMC.java +++ b/src/main/java/forestry/apiculture/genetics/MutationEMC.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.lang.reflect.Field; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IAllele; import forestry.api.genetics.IGenome; import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.lang.reflect.Field; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; public class MutationEMC extends MutationReqRes { diff --git a/src/main/java/forestry/apiculture/genetics/MutationReqRes.java b/src/main/java/forestry/apiculture/genetics/MutationReqRes.java index 4a51d2d6b..6d7a6fb60 100755 --- a/src/main/java/forestry/apiculture/genetics/MutationReqRes.java +++ b/src/main/java/forestry/apiculture/genetics/MutationReqRes.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IAllele; import forestry.api.genetics.IGenome; import forestry.core.utils.StackUtils; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class MutationReqRes extends BeeMutation { diff --git a/src/main/java/forestry/apiculture/genetics/MutationTimeLimited.java b/src/main/java/forestry/apiculture/genetics/MutationTimeLimited.java index 244c1a07b..9a8eaf9e5 100755 --- a/src/main/java/forestry/apiculture/genetics/MutationTimeLimited.java +++ b/src/main/java/forestry/apiculture/genetics/MutationTimeLimited.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import java.util.Calendar; - import forestry.api.apiculture.IBeeHousing; import forestry.api.genetics.IAllele; import forestry.api.genetics.IGenome; +import java.util.Calendar; public class MutationTimeLimited extends BeeMutation { diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java index 6c1d21c4a..55d80f31d 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlveary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlveary.java @@ -15,10 +15,9 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileAlvearyPlain; -import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; public class ContainerAlveary extends ContainerForestry { @@ -31,27 +30,27 @@ public class ContainerAlveary extends ContainerForestry { tile.sendNetworkUpdate(); // Queen/Princess - this.addSlot(new SlotCustom(tile, TileAlvearyPlain.SLOT_QUEEN, 29, 39, ForestryItem.beePrincessGE, ForestryItem.beeQueenGE)); + this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyPlain.SLOT_QUEEN, 29, 39)); // Drone - this.addSlot(new SlotCustom(tile, TileAlvearyPlain.SLOT_DRONE, 29, 65, ForestryItem.beeDroneGE)); + this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyPlain.SLOT_DRONE, 29, 65)); // Product Inventory - this.addSlot(new SlotClosed(tile, 2, 116, 52)); - this.addSlot(new SlotClosed(tile, 3, 137, 39)); - this.addSlot(new SlotClosed(tile, 4, 137, 65)); - this.addSlot(new SlotClosed(tile, 5, 116, 78)); - this.addSlot(new SlotClosed(tile, 6, 95, 65)); - this.addSlot(new SlotClosed(tile, 7, 95, 39)); - this.addSlot(new SlotClosed(tile, 8, 116, 26)); + this.addSlotToContainer(new SlotOutput(tile, 2, 116, 52)); + this.addSlotToContainer(new SlotOutput(tile, 3, 137, 39)); + this.addSlotToContainer(new SlotOutput(tile, 4, 137, 65)); + this.addSlotToContainer(new SlotOutput(tile, 5, 116, 78)); + this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); + this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); + this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); // Player inventory for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 108 + i * 18)); + addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 108 + i * 18)); // Player hotbar for (int i = 0; i < 9; i++) - addSlot(new Slot(player, i, 8 + i * 18, 166)); + addSlotToContainer(new Slot(player, i, 8 + i * 18, 166)); } @Override diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java index dfe03c829..3359f0913 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearyHygroregulator.java @@ -10,28 +10,26 @@ ******************************************************************************/ package forestry.apiculture.gui; -import forestry.apiculture.gadgets.TileAlvearyHygroregulator; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotLiquidContainer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import forestry.apiculture.gadgets.TileAlvearyHygroregulator; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; + public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks { - private final TileAlvearyHygroregulator tile; + public ContainerAlvearyHygroregulator(IInventory playerInventory, TileAlvearyHygroregulator tile) { + super(tile); - public ContainerAlvearyHygroregulator(IInventory inventory, TileAlvearyHygroregulator tile) { - super(inventory, tile); - - this.tile = tile; - this.addSlot(new SlotLiquidContainer(tile, 0, 56, 38)); + this.addSlotToContainer(new SlotFiltered(tile, TileAlvearyHygroregulator.SLOT_INPUT, 56, 38)); for (int i = 0; i < 3; ++i) for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(inventory, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + this.addSlotToContainer(new Slot(playerInventory, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(inventory, i, 8 + i * 18, 142)); + this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142)); } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java index 20eeedf67..a1f3bd127 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearySieve.java @@ -10,48 +10,37 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import forestry.apiculture.gadgets.TileAlvearySieve; -import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; public class ContainerAlvearySieve extends ContainerForestry { - private final TileAlvearySieve tile; - public ContainerAlvearySieve(InventoryPlayer player, TileAlvearySieve tile) { - super(tile.getInternalInventory()); + super(tile); - this.tile = tile; - IInventory inventory = tile.getInternalInventory(); + addSlotToContainer(new SlotOutput(tile, 0, 94, 52).setCrafter(tile)); + addSlotToContainer(new SlotOutput(tile, 1, 115, 39).setCrafter(tile)); + addSlotToContainer(new SlotOutput(tile, 2, 73, 39).setCrafter(tile)); + addSlotToContainer(new SlotOutput(tile, 3, 94, 26).setCrafter(tile)); - addSlot(new SlotCustom(inventory, 0, 94, 52).setCrafter(tile)); - addSlot(new SlotCustom(inventory, 1, 115, 39).setCrafter(tile)); - addSlot(new SlotCustom(inventory, 2, 73, 39).setCrafter(tile)); - addSlot(new SlotCustom(inventory, 3, 94, 26).setCrafter(tile)); - - addSlot(new SlotCustom(inventory, TileAlvearySieve.SLOT_SIEVE, 43, 39, ForestryItem.craftingMaterial.getItemStack(1, 3)).setCrafter(tile)); + addSlotToContainer(new SlotFiltered(tile, TileAlvearySieve.SLOT_SIEVE, 43, 39).setCrafter(tile)); // Player inventory for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { - addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); + addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); } } // Player hotbar for (int i = 0; i < 9; i++) { - addSlot(new Slot(player, i, 8 + i * 18, 145)); + addSlotToContainer(new Slot(player, i, 8 + i * 18, 145)); } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java b/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java index bd1f62461..a2093fb6f 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gui/ContainerAlvearySwarmer.java @@ -10,38 +10,30 @@ ******************************************************************************/ package forestry.apiculture.gui; -import forestry.api.apiculture.BeeManager; -import forestry.apiculture.gadgets.TileAlvearySwarmer; -import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotCustom; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import java.util.Set; +import forestry.apiculture.gadgets.TileAlvearySwarmer; +import forestry.core.gui.ContainerForestry; +import forestry.core.gui.slots.SlotFiltered; public class ContainerAlvearySwarmer extends ContainerForestry { public ContainerAlvearySwarmer(InventoryPlayer player, TileAlvearySwarmer tile) { super(tile); - this.addSlot(new SlotCustom(tile, 0, 79, 52, getInducerItems())); - this.addSlot(new SlotCustom(tile, 1, 100, 39, getInducerItems())); - this.addSlot(new SlotCustom(tile, 2, 58, 39, getInducerItems())); - this.addSlot(new SlotCustom(tile, 3, 79, 26, getInducerItems())); + this.addSlotToContainer(new SlotFiltered(tile, 0, 79, 52)); + this.addSlotToContainer(new SlotFiltered(tile, 1, 100, 39)); + this.addSlotToContainer(new SlotFiltered(tile, 2, 58, 39)); + this.addSlotToContainer(new SlotFiltered(tile, 3, 79, 26)); // Player inventory for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); + addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18)); // Player hotbar for (int i = 0; i < 9; i++) - addSlot(new Slot(player, i, 8 + i * 18, 145)); + addSlotToContainer(new Slot(player, i, 8 + i * 18, 145)); } - - private Object[] getInducerItems() { - Set inducers = BeeManager.inducers.keySet(); - return inducers.toArray(new Object[inducers.size()]); - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerApiary.java b/src/main/java/forestry/apiculture/gui/ContainerApiary.java index 7a3af8172..9506d28a5 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerApiary.java +++ b/src/main/java/forestry/apiculture/gui/ContainerApiary.java @@ -10,62 +10,56 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import forestry.api.apiculture.IHiveFrame; import forestry.apiculture.gadgets.TileBeehouse; -import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.utils.Utils; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; public class ContainerApiary extends ContainerForestry { private final TileBeehouse tile; public ContainerApiary(InventoryPlayer player, TileBeehouse tile, boolean hasFrames) { - super(tile.getInternalInventory()); + super(tile); this.tile = tile; tile.sendNetworkUpdate(); - IInventory inventory = tile.getInternalInventory(); // Queen/Princess - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_QUEEN, 29, 39, ForestryItem.beePrincessGE, ForestryItem.beeQueenGE)); + this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_QUEEN, 29, 39)); // Drone - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_DRONE, 29, 65, ForestryItem.beeDroneGE)); + this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_DRONE, 29, 65)); // Frames if (hasFrames) { - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1, 66, 23, IHiveFrame.class)); - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 1, 66, 52, IHiveFrame.class)); - this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 2, 66, 81, IHiveFrame.class)); + this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_FRAMES_1, 66, 23)); + this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_FRAMES_1 + 1, 66, 52)); + this.addSlotToContainer(new SlotFiltered(tile, TileBeehouse.SLOT_FRAMES_1 + 2, 66, 81)); } // Product Inventory - this.addSlot(new SlotClosed(inventory, 2, 116, 52)); - this.addSlot(new SlotClosed(inventory, 3, 137, 39)); - this.addSlot(new SlotClosed(inventory, 4, 137, 65)); - this.addSlot(new SlotClosed(inventory, 5, 116, 78)); - this.addSlot(new SlotClosed(inventory, 6, 95, 65)); - this.addSlot(new SlotClosed(inventory, 7, 95, 39)); - this.addSlot(new SlotClosed(inventory, 8, 116, 26)); + this.addSlotToContainer(new SlotOutput(tile, 2, 116, 52)); + this.addSlotToContainer(new SlotOutput(tile, 3, 137, 39)); + this.addSlotToContainer(new SlotOutput(tile, 4, 137, 65)); + this.addSlotToContainer(new SlotOutput(tile, 5, 116, 78)); + this.addSlotToContainer(new SlotOutput(tile, 6, 95, 65)); + this.addSlotToContainer(new SlotOutput(tile, 7, 95, 39)); + this.addSlotToContainer(new SlotOutput(tile, 8, 116, 26)); // Player inventory for (int i1 = 0; i1 < 3; i1++) { for (int l1 = 0; l1 < 9; l1++) { - addSlot(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 108 + i1 * 18)); + addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 108 + i1 * 18)); } } // Player hotbar for (int j1 = 0; j1 < 9; j1++) { - addSlot(new Slot(player, j1, 8 + j1 * 18, 166)); + addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 166)); } } @@ -82,8 +76,4 @@ public class ContainerApiary extends ContainerForestry { } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return Utils.isUseableByPlayer(entityplayer, tile, tile.getWorld(), tile.xCoord, tile.yCoord, tile.zCoord); - } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java index af5b2bbe2..6772a9fa6 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/ContainerHabitatLocator.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import forestry.apiculture.items.ItemBeeGE; import forestry.apiculture.items.ItemBiomefinder; import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.proxy.Proxies; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; public class ContainerHabitatLocator extends ContainerItemInventory { @@ -32,12 +30,12 @@ public class ContainerHabitatLocator extends ContainerItemInventory { this.inventory = inventory; // Energy - this.addSlot(new SlotCustom(inventory, 2, 152, 8, ForestryItem.honeydew, ForestryItem.honeyDrop)); + this.addSlotToContainer(new SlotFiltered(inventory, 2, 152, 8)); // Bee to analyze - this.addSlot(new SlotCustom(inventory, 0, 152, 32, ItemBeeGE.class)); + this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 32)); // Analyzed bee - this.addSlot(new SlotCustom(inventory, 1, 152, 75, ItemBeeGE.class)); + this.addSlotToContainer(new SlotFiltered(inventory, 1, 152, 75)); // Player inventory for (int i1 = 0; i1 < 3; i1++) @@ -69,9 +67,4 @@ public class ContainerHabitatLocator extends ContainerItemInventory { } - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return false; - } - } diff --git a/src/main/java/forestry/apiculture/gui/ContainerImprinter.java b/src/main/java/forestry/apiculture/gui/ContainerImprinter.java index 1e871c94e..e7e14ac26 100755 --- a/src/main/java/forestry/apiculture/gui/ContainerImprinter.java +++ b/src/main/java/forestry/apiculture/gui/ContainerImprinter.java @@ -16,11 +16,11 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.apiculture.items.ItemBeeGE; import forestry.apiculture.items.ItemImprinter.ImprinterInventory; import forestry.core.gui.ContainerForestry; import forestry.core.gui.IGuiSelectable; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; @@ -36,17 +36,17 @@ public class ContainerImprinter extends ContainerForestry implements IGuiSelecta this.inventory = inventory; // Input - this.addSlot(new SlotCustom(inventory, 0, 152, 12, ItemBeeGE.class)); + this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); // Output - this.addSlot(new SlotCustom(inventory, 1, 152, 72, ItemBeeGE.class)); + this.addSlotToContainer(new SlotOutput(inventory, 1, 152, 72)); // Player inventory for (int i1 = 0; i1 < 3; i1++) for (int l1 = 0; l1 < 9; l1++) - addSlot(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); + addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); // Player hotbar for (int j1 = 0; j1 < 9; j1++) - addSlot(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); + addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); } @Override diff --git a/src/main/java/forestry/apiculture/gui/GuiAlveary.java b/src/main/java/forestry/apiculture/gui/GuiAlveary.java index 4285f6889..75d5b67fa 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlveary.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlveary.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.apiculture.gadgets.TileAlvearyPlain; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.utils.EnumTankLevel; import forestry.core.utils.Utils; +import net.minecraft.entity.player.InventoryPlayer; public class GuiAlveary extends GuiForestryTitled { diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java index 6a7c16190..ce8051f14 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearyHygroregulator.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.apiculture.gadgets.TileAlvearyHygroregulator; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; +import net.minecraft.entity.player.InventoryPlayer; public class GuiAlvearyHygroregulator extends GuiForestryTitled { diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java b/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java index 3a57d0801..75fb66a89 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearySieve.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.apiculture.gadgets.TileAlvearySieve; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; +import net.minecraft.entity.player.InventoryPlayer; public class GuiAlvearySieve extends GuiForestry { diff --git a/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java b/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java index a07ac33bf..80e2043c3 100755 --- a/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java +++ b/src/main/java/forestry/apiculture/gui/GuiAlvearySwarmer.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.apiculture.gadgets.TileAlvearySwarmer; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; +import net.minecraft.entity.player.InventoryPlayer; public class GuiAlvearySwarmer extends GuiForestry { diff --git a/src/main/java/forestry/apiculture/gui/GuiApiary.java b/src/main/java/forestry/apiculture/gui/GuiApiary.java index 1a73b16a3..c366a2c3b 100755 --- a/src/main/java/forestry/apiculture/gui/GuiApiary.java +++ b/src/main/java/forestry/apiculture/gui/GuiApiary.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.apiculture.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.apiculture.gadgets.TileApiary; import forestry.apiculture.gadgets.TileBeehouse; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.utils.EnumTankLevel; import forestry.core.utils.Utils; +import net.minecraft.entity.player.InventoryPlayer; public class GuiApiary extends GuiForestryTitled { diff --git a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java index 2c0e012a2..183be6b2b 100755 --- a/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java +++ b/src/main/java/forestry/apiculture/gui/GuiBeealyzer.java @@ -10,45 +10,38 @@ ******************************************************************************/ package forestry.apiculture.gui; +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.EnumBeeType; -import forestry.api.apiculture.IAlleleBeeEffect; import forestry.api.apiculture.IBee; import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAlleleFlowers; +import forestry.api.genetics.IAlleleArea; import forestry.api.genetics.IAlleleInteger; import forestry.api.genetics.IAlleleTolerance; import forestry.apiculture.genetics.BeeGenome; import forestry.apiculture.items.ItemBeeGE; import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; import forestry.core.config.ForestryItem; -import forestry.core.genetics.AlleleArea; import forestry.core.genetics.AlleleBoolean; +import forestry.core.gui.ContainerAlyzer; import forestry.core.gui.GuiAlyzer; import forestry.core.utils.StringUtil; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import forestry.plugins.PluginApiculture; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; public class GuiBeealyzer extends GuiAlyzer { - private ItemStack[] tempProductList; - public GuiBeealyzer(EntityPlayer player, BeealyzerInventory inventory) { - super(AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"), player, - new ContainerBeealyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - - guiName = "gui.beealyzer"; + super("rootBees", player, new ContainerAlyzer(inventory, player), inventory, "gui.beealyzer"); ArrayList beeList = new ArrayList(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); for (ItemStack beeStack : beeList) iconStacks.put(BeeGenome.getSpecies(beeStack).getUID(), beeStack); - - breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(player.worldObj, player.getGameProfile()); } @Override @@ -58,7 +51,8 @@ public class GuiBeealyzer extends GuiAlyzer { int page = 0; IBee bee = null; EnumBeeType beeType = EnumBeeType.DRONE; - for (int k = 1; k < BeealyzerInventory.SLOT_ANALYZE_5 + 1; k++) { + + for (int k = BeealyzerInventory.SLOT_SPECIMEN; k <= BeealyzerInventory.SLOT_ANALYZE_5; k++) { if (k == BeealyzerInventory.SLOT_ENERGY) continue; @@ -111,37 +105,30 @@ public class GuiBeealyzer extends GuiAlyzer { drawSpeciesRow(StringUtil.localize("gui.species"), bee, EnumBeeChromosome.SPECIES, checkCustomName(customPrimaryBeeKey), checkCustomName(customSecondaryBeeKey)); } - drawRow(StringUtil.localize("gui.lifespan"), bee.getGenome().getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName(), - bee.getGenome().getInactiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName(), bee, - EnumBeeChromosome.LIFESPAN); + drawChromosomeRow(StringUtil.localize("gui.lifespan"), bee, EnumBeeChromosome.LIFESPAN); - drawRow(StringUtil.localize("gui.speed"), bee.getGenome().getActiveAllele(EnumBeeChromosome.SPEED.ordinal()).getName(), - bee.getGenome().getInactiveAllele(EnumBeeChromosome.SPEED.ordinal()).getName(), bee, EnumBeeChromosome.SPEED); + drawChromosomeRow(StringUtil.localize("gui.speed"), bee, EnumBeeChromosome.SPEED); - drawRow(StringUtil.localize("gui.pollination"), bee.getGenome().getActiveAllele(EnumBeeChromosome.FLOWERING.ordinal()).getName(), - bee.getGenome().getInactiveAllele(EnumBeeChromosome.FLOWERING.ordinal()).getName(), bee, - EnumBeeChromosome.FLOWERING); + drawChromosomeRow(StringUtil.localize("gui.pollination"), bee, EnumBeeChromosome.FLOWERING); - drawRow(StringUtil.localize("gui.flowers"), bee.getGenome().getFlowerProvider().getDescription(), - ((IAlleleFlowers) bee.getGenome().getInactiveAllele(EnumBeeChromosome.FLOWER_PROVIDER.ordinal())).getProvider() - .getDescription(), bee, EnumBeeChromosome.FLOWER_PROVIDER); + drawChromosomeRow(StringUtil.localize("gui.flowers"), bee, EnumBeeChromosome.FLOWER_PROVIDER); drawLine(StringUtil.localize("gui.fertility"), COLUMN_0); - drawFertilityInfo(bee.getGenome().getFertility(), COLUMN_1, getColorCoding(bee.getGenome().getActiveAllele(EnumBeeChromosome.FERTILITY.ordinal()) - .isDominant()), 0); - drawFertilityInfo(((IAlleleInteger) bee.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY.ordinal())).getValue(), COLUMN_2, getColorCoding(bee - .getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY.ordinal()).isDominant()), 0); + IAlleleInteger primaryFertility = (IAlleleInteger)bee.getGenome().getActiveAllele(EnumBeeChromosome.FERTILITY); + IAlleleInteger secondaryFertility = (IAlleleInteger)bee.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY); + drawFertilityInfo(primaryFertility.getValue(), COLUMN_1, getColorCoding(primaryFertility.isDominant()), 0); + drawFertilityInfo(secondaryFertility.getValue(), COLUMN_2, getColorCoding(secondaryFertility.isDominant()), 0); newLine(); - int[] areaAr = bee.getGenome().getTerritory(); - Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]); - drawRow(StringUtil.localize("gui.area"), area.toString(), ((AlleleArea) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TERRITORY.ordinal())) - .getArea().toString(), bee, EnumBeeChromosome.TERRITORY); + IAlleleArea activeTerritory = (IAlleleArea)bee.getGenome().getActiveAllele(EnumBeeChromosome.TERRITORY); + IAlleleArea inactiveTerritory = (IAlleleArea)bee.getGenome().getInactiveAllele(EnumBeeChromosome.TERRITORY); + drawRow(StringUtil.localize("gui.area"), + new Vect(activeTerritory.getValue()).toString(), + new Vect(inactiveTerritory.getValue()).toString(), + bee, EnumBeeChromosome.TERRITORY); - drawRow(StringUtil.localize("gui.effect"), bee.getGenome().getEffect().getName(), - bee.getGenome().getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal()).getName(), bee, - EnumBeeChromosome.EFFECT); + drawChromosomeRow(StringUtil.localize("gui.effect"), bee, EnumBeeChromosome.EFFECT); newLine(); @@ -161,8 +148,8 @@ public class GuiBeealyzer extends GuiAlyzer { drawRow(StringUtil.localize("gui.climate"), AlleleManager.climateHelper.toDisplay(bee.getGenome().getPrimary().getTemperature()), AlleleManager.climateHelper.toDisplay(bee.getGenome().getSecondary().getTemperature()), bee, EnumBeeChromosome.SPECIES); - IAlleleTolerance tempToleranceActive = (IAlleleTolerance)bee.getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()); - IAlleleTolerance tempToleranceInactive = (IAlleleTolerance)bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()); + IAlleleTolerance tempToleranceActive = (IAlleleTolerance)bee.getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE); + IAlleleTolerance tempToleranceInactive = (IAlleleTolerance)bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE); drawLine(StringUtil.localize("gui.temptol"), COLUMN_0); drawToleranceInfo(tempToleranceActive, COLUMN_1); drawToleranceInfo(tempToleranceInactive, COLUMN_2); @@ -172,8 +159,8 @@ public class GuiBeealyzer extends GuiAlyzer { drawRow(StringUtil.localize("gui.humidity"), AlleleManager.climateHelper.toDisplay(bee.getGenome().getPrimary().getHumidity()), AlleleManager.climateHelper.toDisplay(bee.getGenome().getSecondary().getHumidity()), bee, EnumBeeChromosome.SPECIES); - IAlleleTolerance humidToleranceActive = (IAlleleTolerance)bee.getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()); - IAlleleTolerance humidToleranceInactive = (IAlleleTolerance)bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()); + IAlleleTolerance humidToleranceActive = (IAlleleTolerance)bee.getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE); + IAlleleTolerance humidToleranceInactive = (IAlleleTolerance)bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE); drawLine(StringUtil.localize("gui.humidtol"), COLUMN_0); drawToleranceInfo(humidToleranceActive, COLUMN_1); drawToleranceInfo(humidToleranceInactive, COLUMN_2); @@ -191,7 +178,7 @@ public class GuiBeealyzer extends GuiAlyzer { nocturnal0 = bee.getGenome().getPrimary().isNocturnal() ? yes : no; diurnal0 = !bee.getGenome().getPrimary().isNocturnal() ? yes : no; } - if(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.NOCTURNAL.ordinal())).getValue()) { + if(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.NOCTURNAL)).getValue()) { nocturnal1 = diurnal1 = yes; } else { nocturnal1 = bee.getGenome().getSecondary().isNocturnal() ? yes : no; @@ -209,13 +196,13 @@ public class GuiBeealyzer extends GuiAlyzer { newLine(); String primary = StringUtil.readableBoolean(bee.getGenome().getTolerantFlyer(), yes, no); - String secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TOLERANT_FLYER.ordinal())).getValue(), yes, + String secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TOLERANT_FLYER)).getValue(), yes, no); drawRow(StringUtil.localize("gui.flyer"), primary, secondary, bee, EnumBeeChromosome.TOLERANT_FLYER); primary = StringUtil.readableBoolean(bee.getGenome().getCaveDwelling(), yes, no); - secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.CAVE_DWELLING.ordinal())).getValue(), yes, + secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.CAVE_DWELLING)).getValue(), yes, no); drawRow(StringUtil.localize("gui.cave"), primary, secondary, bee, EnumBeeChromosome.CAVE_DWELLING); @@ -246,8 +233,6 @@ public class GuiBeealyzer extends GuiAlyzer { float factor = this.factor; this.setFactor(1.0f); - tempProductList = bee.getProduceList(); - startPage(COLUMN_0, COLUMN_1, COLUMN_2); drawLine(StringUtil.localize("gui.beealyzer.produce") + ":", COLUMN_0); @@ -255,7 +240,7 @@ public class GuiBeealyzer extends GuiAlyzer { newLine(); int x = COLUMN_0; - for (ItemStack stack : tempProductList) { + for (ItemStack stack : bee.getProduceList()) { widgetManager.add(new ItemStackWidget(adjustToFactor(x), adjustToFactor(getLineY()), stack)); x += 18; @@ -270,6 +255,7 @@ public class GuiBeealyzer extends GuiAlyzer { newLine(); drawLine(StringUtil.localize("gui.beealyzer.specialty") + ":", COLUMN_0); + newLine(); x = COLUMN_0; for (ItemStack stack : bee.getSpecialtyList()) { diff --git a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java index bee2019f2..24d232510 100755 --- a/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java +++ b/src/main/java/forestry/apiculture/gui/GuiHabitatLocator.java @@ -10,17 +10,6 @@ ******************************************************************************/ package forestry.apiculture.gui; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.IIcon; -import net.minecraft.world.biome.BiomeGenBase; - -import org.lwjgl.opengl.GL11; - import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory; import forestry.core.config.Defaults; import forestry.core.gadgets.TileForestry; @@ -30,6 +19,14 @@ import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Locale; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.IIcon; +import net.minecraft.world.biome.BiomeGenBase; +import org.lwjgl.opengl.GL11; public class GuiHabitatLocator extends GuiForestry { diff --git a/src/main/java/forestry/apiculture/gui/GuiImprinter.java b/src/main/java/forestry/apiculture/gui/GuiImprinter.java index 7eaf63246..40a714296 100755 --- a/src/main/java/forestry/apiculture/gui/GuiImprinter.java +++ b/src/main/java/forestry/apiculture/gui/GuiImprinter.java @@ -10,6 +10,15 @@ ******************************************************************************/ package forestry.apiculture.gui; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; + import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.apiculture.genetics.BeeGenome; import forestry.apiculture.items.ItemBeeGE; @@ -20,11 +29,6 @@ import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.HashMap; public class GuiImprinter extends GuiForestry { @@ -34,7 +38,7 @@ public class GuiImprinter extends GuiForestry { private int startX; private int startY; - private final HashMap iconStacks = new HashMap(); + private final Map iconStacks = new HashMap(); public GuiImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) { super(Defaults.TEXTURE_PATH_GUI + "/imprinter.png", new ContainerImprinter(inventoryplayer, inventory), inventory); @@ -45,7 +49,7 @@ public class GuiImprinter extends GuiForestry { xSize = 176; ySize = 185; - ArrayList beeList = new ArrayList(); + List beeList = new ArrayList(); ((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false); for (ItemStack beeStack : beeList) iconStacks.put(BeeGenome.getSpecies(beeStack).getUID(), beeStack); @@ -75,21 +79,9 @@ public class GuiImprinter extends GuiForestry { } private void drawBeeSpeciesIcon(IAlleleBeeSpecies bee, int x, int y) { - - /* - * GL11.glDisable(GL11.GL_LIGHTING); mc.renderEngine.func_98187_b(Defaults.TEXTURE_BEES); - * - * for (int i = 0; i < ForestryItem.beeDroneGE.getRenderPasses(0); ++i) { - * - * int iconIndex = ForestryItem.beeDroneGE.getIconIndex(iconStacks.get(bee.getUID()), i); int color = ((ItemGE) - * ForestryItem.beeDroneGE).getColorFromItemStack(iconStacks.get(bee.getUID()), i); float colorR = (color >> 16 & 255) / 255.0F; float colorG = (color - * >> 8 & 255) / 255.0F; float colorB = (color & 255) / 255.0F; - * - * GL11.glColor4f(colorR, colorG, colorB, 1.0F); drawTexturedModalRect(x, y, iconIndex % 16 * 16, iconIndex / 16 * 16, 16, 16); - * - * } GL11.glEnable(GL11.GL_LIGHTING); - */ - + RenderHelper.enableStandardItemLighting(); + drawItemStack(iconStacks.get(bee.getUID()), x, y); + RenderHelper.disableStandardItemLighting(); } private int getHabitatSlotAtPosition(int i, int j) { @@ -110,8 +102,8 @@ public class GuiImprinter extends GuiForestry { int cornerX = (width - xSize) / 2; int cornerY = (height - ySize) / 2; - int slot = 0; - if ((slot = getHabitatSlotAtPosition(i - cornerX, j - cornerY)) < 0) + int slot = getHabitatSlotAtPosition(i - cornerX, j - cornerY); + if (slot < 0) return; if (k == 0) diff --git a/src/main/java/forestry/apiculture/items/ItemAlvearyBlock.java b/src/main/java/forestry/apiculture/items/ItemAlvearyBlock.java index 90f6f7b8c..fa37001c6 100755 --- a/src/main/java/forestry/apiculture/items/ItemAlvearyBlock.java +++ b/src/main/java/forestry/apiculture/items/ItemAlvearyBlock.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.apiculture.items; -import net.minecraft.block.Block; - import forestry.core.gadgets.IStructureBlockItem; import forestry.core.items.ItemForestryBlock; +import net.minecraft.block.Block; /** * diff --git a/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java b/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java index 5a5efabe4..8466cd361 100755 --- a/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java +++ b/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java @@ -10,16 +10,8 @@ ******************************************************************************/ package forestry.apiculture.items; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemArmor; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.apiculture.IArmorApiarist; import forestry.api.core.IArmorNaturalist; import forestry.api.core.Tabs; @@ -27,6 +19,12 @@ import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; public class ItemArmorApiarist extends ItemArmor implements IArmorApiarist, IArmorNaturalist { diff --git a/src/main/java/forestry/apiculture/items/ItemBeeGE.java b/src/main/java/forestry/apiculture/items/ItemBeeGE.java index 5f19e8b7f..fa746f871 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeeGE.java +++ b/src/main/java/forestry/apiculture/items/ItemBeeGE.java @@ -27,16 +27,16 @@ import forestry.core.config.Config; import forestry.core.genetics.ItemGE; import forestry.core.utils.StringUtil; import forestry.plugins.PluginApiculture; +import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; -import java.util.List; - public class ItemBeeGE extends ItemGE { private final EnumBeeType type; @@ -50,7 +50,7 @@ public class ItemBeeGE extends ItemGE { } @Override - protected IIndividual getIndividual(ItemStack itemstack) { + public IBee getIndividual(ItemStack itemstack) { return new Bee(itemstack.getTagCompound()); } @@ -95,9 +95,9 @@ public class ItemBeeGE extends ItemGE { if(type != EnumBeeType.DRONE) { IBee individual = new Bee(itemstack.getTagCompound()); if (individual.isNatural()) - list.add("\u00A7e\u00A7o" + StringUtil.localize("bees.stock.pristine")); + list.add(EnumChatFormatting.YELLOW + EnumChatFormatting.ITALIC.toString() + StringUtil.localize("bees.stock.pristine")); else - list.add("\u00A7e" + StringUtil.localize("bees.stock.ignoble")); + list.add(EnumChatFormatting.YELLOW + StringUtil.localize("bees.stock.ignoble")); } super.addInformation(itemstack, player, list, flag); diff --git a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java index d5a8210d5..544cc093e 100755 --- a/src/main/java/forestry/apiculture/items/ItemBeealyzer.java +++ b/src/main/java/forestry/apiculture/items/ItemBeealyzer.java @@ -10,7 +10,6 @@ ******************************************************************************/ package forestry.apiculture.items; -import forestry.core.utils.AlyzerInventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -19,11 +18,11 @@ import net.minecraft.world.World; import forestry.api.apiculture.IBee; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Config; -import forestry.core.config.ForestryItem; import forestry.core.interfaces.IErrorSource; import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.AlyzerInventory; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; @@ -33,30 +32,17 @@ public class ItemBeealyzer extends ItemInventoried { public static class BeealyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { - public BeealyzerInventory(EntityPlayer player) { - super(ItemBeealyzer.class, 7); - this.player = player; - } - public BeealyzerInventory(EntityPlayer player, ItemStack itemStack) { super(ItemBeealyzer.class, 7, itemStack); this.player = player; } - private boolean isEnergy(ItemStack itemstack) { - if (itemstack == null || itemstack.stackSize <= 0) - return false; - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + @Override + protected boolean isSpecimen(ItemStack itemStack) { + return PluginApiculture.beeInterface.isMember(itemStack); } private void tryAnalyze() { - - // Analyzed slot occupied, abort - if (inventoryStacks[SLOT_ANALYZE_1] != null || inventoryStacks[SLOT_ANALYZE_2] != null || inventoryStacks[SLOT_ANALYZE_3] != null - || inventoryStacks[SLOT_ANALYZE_4] != null || inventoryStacks[SLOT_ANALYZE_5] != null) - return; - // Source slot to analyze empty if (getStackInSlot(SLOT_SPECIMEN) == null) return; @@ -133,8 +119,7 @@ public class ItemBeealyzer extends ItemInventoried { @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { if (Proxies.common.isSimulating(world)) - entityplayer.openGui(ForestryAPI.instance, GuiId.BeealyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, - (int) entityplayer.posZ); + entityplayer.openGui(ForestryAPI.instance, GuiId.BeealyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ); return itemstack; } diff --git a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java b/src/main/java/forestry/apiculture/items/ItemBiomefinder.java index a77af1765..d665c9c5e 100755 --- a/src/main/java/forestry/apiculture/items/ItemBiomefinder.java +++ b/src/main/java/forestry/apiculture/items/ItemBiomefinder.java @@ -10,12 +10,29 @@ ******************************************************************************/ package forestry.apiculture.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.apiculture.IBee; +import forestry.api.core.ForestryAPI; +import forestry.api.core.Tabs; +import forestry.apiculture.render.TextureBiomefinder; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.ForestryItem; +import forestry.core.interfaces.IErrorSource; +import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.ItemInventory; +import forestry.core.items.ItemInventoried; +import forestry.core.network.GuiId; +import forestry.core.proxy.Proxies; +import forestry.core.vect.Vect; +import forestry.plugins.PluginApiculture; import java.util.ArrayList; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -23,25 +40,6 @@ import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.apiculture.IBee; -import forestry.api.core.ForestryAPI; -import forestry.api.core.Tabs; -import forestry.apiculture.render.TextureBiomefinder; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.ForestryItem; -import forestry.core.interfaces.IErrorSource; -import forestry.core.interfaces.IHintSource; -import forestry.core.items.ItemInventoried; -import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; -import forestry.core.utils.Vect; -import forestry.plugins.PluginApiculture; - public class ItemBiomefinder extends ItemInventoried { public static class BiomefinderInventory extends ItemInventory implements IErrorSource, IHintSource { @@ -52,10 +50,6 @@ public class ItemBiomefinder extends ItemInventoried { private final short specimenSlot = 0; private final short analyzeSlot = 1; - public BiomefinderInventory() { - super(ItemBiomefinder.class, 3); - } - public BiomefinderInventory(ItemStack itemstack) { super(ItemBiomefinder.class, 3, itemstack); } @@ -140,6 +134,17 @@ public class ItemBiomefinder extends ItemInventoried { return EnumErrorCode.OK; } + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == energySlot) { + Item item = itemStack.getItem(); + return item == ForestryItem.honeydew.item() || item == ForestryItem.honeyDrop.item(); + } else if (slotIndex == specimenSlot || slotIndex == analyzeSlot) { + return PluginApiculture.beeInterface.isMember(itemStack); + } + return false; + } + } public ItemBiomefinder() { diff --git a/src/main/java/forestry/apiculture/items/ItemCandleBlock.java b/src/main/java/forestry/apiculture/items/ItemCandleBlock.java index 951beb0c4..f76cf7f25 100755 --- a/src/main/java/forestry/apiculture/items/ItemCandleBlock.java +++ b/src/main/java/forestry/apiculture/items/ItemCandleBlock.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.apiculture.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.apiculture.gadgets.BlockCandle; +import forestry.core.items.ItemForestryBlock; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.apiculture.gadgets.BlockCandle; -import forestry.core.items.ItemForestryBlock; - public class ItemCandleBlock extends ItemForestryBlock { public ItemCandleBlock(Block block) { diff --git a/src/main/java/forestry/apiculture/items/ItemHiveFrame.java b/src/main/java/forestry/apiculture/items/ItemHiveFrame.java index c23d3edcf..2a7f25e88 100755 --- a/src/main/java/forestry/apiculture/items/ItemHiveFrame.java +++ b/src/main/java/forestry/apiculture/items/ItemHiveFrame.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.apiculture.items; -import net.minecraft.item.ItemStack; - import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IHiveFrame; import forestry.api.core.Tabs; import forestry.core.items.ItemForestry; +import net.minecraft.item.ItemStack; public class ItemHiveFrame extends ItemForestry implements IHiveFrame { diff --git a/src/main/java/forestry/apiculture/items/ItemHoneycomb.java b/src/main/java/forestry/apiculture/items/ItemHoneycomb.java index 1c2ba6041..c75dc42a2 100755 --- a/src/main/java/forestry/apiculture/items/ItemHoneycomb.java +++ b/src/main/java/forestry/apiculture/items/ItemHoneycomb.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture.items; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - import forestry.api.core.Tabs; import forestry.core.config.Config; import forestry.core.config.ForestryItem; import forestry.core.items.ItemForestryMultiPass; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; public class ItemHoneycomb extends ItemForestryMultiPass { diff --git a/src/main/java/forestry/apiculture/items/ItemImprinter.java b/src/main/java/forestry/apiculture/items/ItemImprinter.java index 3c61ff934..0f970e572 100755 --- a/src/main/java/forestry/apiculture/items/ItemImprinter.java +++ b/src/main/java/forestry/apiculture/items/ItemImprinter.java @@ -11,7 +11,6 @@ package forestry.apiculture.items; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -21,6 +20,7 @@ import forestry.api.apiculture.IBee; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.apiculture.genetics.Bee; +import forestry.core.inventory.ItemInventory; import forestry.core.items.ItemForestry; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; @@ -28,9 +28,8 @@ import forestry.plugins.PluginApiculture; public class ItemImprinter extends ItemForestry { - public static class ImprinterInventory implements IInventory { + public static class ImprinterInventory extends ItemInventory { - private final ItemStack[] inventoryStacks = new ItemStack[2]; private final short specimenSlot = 0; private final short imprintedSlot = 1; @@ -39,7 +38,8 @@ public class ItemImprinter extends ItemForestry { private final EntityPlayer player; - public ImprinterInventory(EntityPlayer player) { + public ImprinterInventory(EntityPlayer player, ItemStack itemStack) { + super(ItemImprinter.class, 2, itemStack); this.player = player; } @@ -126,25 +126,6 @@ public class ItemImprinter extends ItemForestry { inventoryStacks[specimenSlot] = null; } - @Override - public ItemStack decrStackSize(int i, int j) { - if (inventoryStacks[i] == null) - return null; - - ItemStack product; - if (inventoryStacks[i].stackSize <= j) { - product = inventoryStacks[i]; - inventoryStacks[i] = null; - return product; - } else { - product = inventoryStacks[i].splitStack(j); - if (inventoryStacks[i].stackSize == 0) - inventoryStacks[i] = null; - - return product; - } - } - @Override public void markDirty() { if (!Proxies.common.isSimulating(player.worldObj)) @@ -152,61 +133,14 @@ public class ItemImprinter extends ItemForestry { tryImprint(); } - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventoryStacks[i] = itemstack; - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventoryStacks[i]; - } - - @Override - public int getSizeInventory() { - return inventoryStacks.length; - } - @Override public String getInventoryName() { return "Imprinter"; } @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return true; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - if (inventoryStacks[slot] == null) - return null; - ItemStack toReturn = inventoryStacks[slot]; - inventoryStacks[slot] = null; - return toReturn; - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return true; + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return PluginApiculture.beeInterface.isMember(itemStack); } } diff --git a/src/main/java/forestry/apiculture/items/ItemWaxCast.java b/src/main/java/forestry/apiculture/items/ItemWaxCast.java index dae81a1be..df600f0b5 100755 --- a/src/main/java/forestry/apiculture/items/ItemWaxCast.java +++ b/src/main/java/forestry/apiculture/items/ItemWaxCast.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.apiculture.items; -import net.minecraft.item.ItemStack; - import forestry.core.interfaces.ICraftingPlan; import forestry.core.items.ItemForestry; +import net.minecraft.item.ItemStack; public class ItemWaxCast extends ItemForestry implements ICraftingPlan { diff --git a/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java b/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java index 167b26122..bb6516859 100755 --- a/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java +++ b/src/main/java/forestry/apiculture/proxy/ClientProxyApiculture.java @@ -10,13 +10,7 @@ ******************************************************************************/ package forestry.apiculture.proxy; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.world.World; - import cpw.mods.fml.client.registry.RenderingRegistry; - -import net.minecraftforge.client.MinecraftForgeClient; - import forestry.apiculture.entities.EntityBee; import forestry.apiculture.render.BeeItemRenderer; import forestry.apiculture.render.EntityBeeFX; @@ -28,6 +22,9 @@ import forestry.core.interfaces.IBlockRenderer; import forestry.core.render.RenderAnalyzer; import forestry.core.render.TextureManager; import forestry.plugins.PluginApiculture; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.world.World; +import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxyApiculture extends ProxyApiculture { diff --git a/src/main/java/forestry/apiculture/proxy/ProxyApiculture.java b/src/main/java/forestry/apiculture/proxy/ProxyApiculture.java index 267396f1b..939dd6b42 100755 --- a/src/main/java/forestry/apiculture/proxy/ProxyApiculture.java +++ b/src/main/java/forestry/apiculture/proxy/ProxyApiculture.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.apiculture.proxy; -import net.minecraft.world.World; - import forestry.core.interfaces.IBlockRenderer; +import net.minecraft.world.World; public class ProxyApiculture { public void addBeeHiveFX(String texture, World world, double xCoord, double yCoord, double zCoord, int color, int areaX, int areaY, int areaZ) { diff --git a/src/main/java/forestry/apiculture/render/BeeItemRenderer.java b/src/main/java/forestry/apiculture/render/BeeItemRenderer.java index 130114b50..9da52204e 100755 --- a/src/main/java/forestry/apiculture/render/BeeItemRenderer.java +++ b/src/main/java/forestry/apiculture/render/BeeItemRenderer.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.apiculture.render; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.item.ItemStack; - -import net.minecraftforge.client.IItemRenderer; - -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - import forestry.api.apiculture.IBee; import forestry.apiculture.entities.EntityBee; import forestry.core.proxy.Proxies; import forestry.plugins.PluginApiculture; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.IItemRenderer; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; public class BeeItemRenderer implements IItemRenderer { @@ -47,7 +44,7 @@ public class BeeItemRenderer implements IItemRenderer { public static float getIrregularWingYaw(long flapping, float flap) { long irregular = flapping / 1000; - float wingYaw = 1f; + float wingYaw; if(irregular % 11 == 0) { wingYaw = 0.75f; diff --git a/src/main/java/forestry/apiculture/render/BlockCandleRenderer.java b/src/main/java/forestry/apiculture/render/BlockCandleRenderer.java index c525fbc99..40c18927d 100755 --- a/src/main/java/forestry/apiculture/render/BlockCandleRenderer.java +++ b/src/main/java/forestry/apiculture/render/BlockCandleRenderer.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.apiculture.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import forestry.apiculture.gadgets.BlockCandle; +import forestry.apiculture.gadgets.TileCandle; +import forestry.core.ForestryClient; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - -import forestry.apiculture.gadgets.BlockCandle; -import forestry.apiculture.gadgets.TileCandle; -import forestry.core.ForestryClient; - public class BlockCandleRenderer implements ISimpleBlockRenderingHandler { @Override diff --git a/src/main/java/forestry/apiculture/render/ModelAnalyzer.java b/src/main/java/forestry/apiculture/render/ModelAnalyzer.java index 1cd316b8b..80fcd495c 100755 --- a/src/main/java/forestry/apiculture/render/ModelAnalyzer.java +++ b/src/main/java/forestry/apiculture/render/ModelAnalyzer.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.apiculture.render; +import forestry.core.proxy.Proxies; +import forestry.core.utils.ForestryResource; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.util.ResourceLocation; - import net.minecraftforge.common.util.ForgeDirection; - import org.lwjgl.opengl.GL11; -import forestry.core.proxy.Proxies; -import forestry.core.utils.ForestryResource; - public class ModelAnalyzer extends ModelBase { private final ModelRenderer pedestal; diff --git a/src/main/java/forestry/apiculture/render/ModelBee.java b/src/main/java/forestry/apiculture/render/ModelBee.java index 56ff58961..c3c715640 100755 --- a/src/main/java/forestry/apiculture/render/ModelBee.java +++ b/src/main/java/forestry/apiculture/render/ModelBee.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.apiculture.render; +import forestry.api.apiculture.EnumBeeType; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; - import org.lwjgl.opengl.GL11; -import forestry.api.apiculture.EnumBeeType; - public class ModelBee extends ModelBase { //fields diff --git a/src/main/java/forestry/apiculture/render/ParticleRenderer.java b/src/main/java/forestry/apiculture/render/ParticleRenderer.java index 805f4b2f6..ea5633154 100755 --- a/src/main/java/forestry/apiculture/render/ParticleRenderer.java +++ b/src/main/java/forestry/apiculture/render/ParticleRenderer.java @@ -10,28 +10,24 @@ ******************************************************************************/ package forestry.apiculture.render; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.particle.EntityFX; -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.entity.EntityLivingBase; - import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.EntityLivingBase; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; - import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/apiculture/render/RenderBee.java b/src/main/java/forestry/apiculture/render/RenderBee.java index 61ff1608c..02cf0fb6e 100755 --- a/src/main/java/forestry/apiculture/render/RenderBee.java +++ b/src/main/java/forestry/apiculture/render/RenderBee.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.apiculture.render; +import forestry.apiculture.entities.EntityBee; import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; -import forestry.apiculture.entities.EntityBee; - public class RenderBee extends RenderLiving { private final ModelBee beeModel; diff --git a/src/main/java/forestry/apiculture/render/TextureBiomefinder.java b/src/main/java/forestry/apiculture/render/TextureBiomefinder.java index 65c909ef9..548bd9116 100755 --- a/src/main/java/forestry/apiculture/render/TextureBiomefinder.java +++ b/src/main/java/forestry/apiculture/render/TextureBiomefinder.java @@ -47,7 +47,7 @@ public class TextureBiomefinder extends TextureAtlasSprite { public void updateCompass(World world, double playerX, double playerZ, double playerYaw, boolean par8, boolean hasSpin) { - double targetAngle = 0.0d; + double targetAngle; if(world == null || targetBiome == null) { // No target has the locator spinning wildly. diff --git a/src/main/java/forestry/apiculture/trigger/TriggerMissingDrone.java b/src/main/java/forestry/apiculture/trigger/TriggerMissingDrone.java index 7a8199113..5d3e99c2b 100644 --- a/src/main/java/forestry/apiculture/trigger/TriggerMissingDrone.java +++ b/src/main/java/forestry/apiculture/trigger/TriggerMissingDrone.java @@ -12,7 +12,7 @@ package forestry.apiculture.trigger; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.interfaces.IErrorSource; import forestry.core.triggers.Trigger; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/forestry/apiculture/trigger/TriggerMissingQueen.java b/src/main/java/forestry/apiculture/trigger/TriggerMissingQueen.java index 12f38c772..89c2005a4 100644 --- a/src/main/java/forestry/apiculture/trigger/TriggerMissingQueen.java +++ b/src/main/java/forestry/apiculture/trigger/TriggerMissingQueen.java @@ -12,7 +12,7 @@ package forestry.apiculture.trigger; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.interfaces.IErrorSource; import forestry.core.triggers.Trigger; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java index f3001bb05..01c195fb4 100755 --- a/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java +++ b/src/main/java/forestry/apiculture/worldgen/ComponentVillageBeeHouse.java @@ -37,23 +37,27 @@ import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; import forestry.apiculture.gadgets.TileBeehouse; +import forestry.arboriculture.gadgets.BlockFireproofLog; +import forestry.arboriculture.gadgets.BlockFireproofPlanks; +import forestry.arboriculture.gadgets.BlockLog; +import forestry.arboriculture.gadgets.BlockPlanks; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.utils.StackUtils; import forestry.plugins.PluginApiculture; +import forestry.plugins.PluginManager; public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { - protected final ItemStack[] buildingBlocks = new ItemStack[]{ForestryBlock.planks1.getItemStack(1, 15), new ItemStack(Blocks.log, 1, 0),}; + private static final Random random = new Random(); + protected final ItemStack[] buildingBlocks; protected int averageGroundLevel = -1; protected boolean isInDesert = false; protected boolean hasChest = false; public ComponentVillageBeeHouse() { - // Populate buildingblocks with some defaults so it doesn't explode. - buildingBlocks[0] = ForestryBlock.planks1.getItemStack(); - buildingBlocks[1] = ForestryBlock.log1.getItemStack(); + buildingBlocks = createBuildingBlocks(random); } public ComponentVillageBeeHouse(StructureVillagePieces.Start startPiece, int componentType, Random random, StructureBoundingBox boundingBox, int coordBaseMode) { @@ -61,25 +65,41 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { isInDesert = startPiece.inDesert; - buildingBlocks[0] = ForestryBlock.planks1.getItemStack(1, random.nextInt(16)); + buildingBlocks = createBuildingBlocks(random); + } - Block woodBlock; - switch (random.nextInt(4)) { - case 1: - woodBlock = ForestryBlock.log2.block(); - break; - case 2: - woodBlock = ForestryBlock.log3.block(); - break; - case 3: - woodBlock = ForestryBlock.log4.block(); - break; - default: - woodBlock = ForestryBlock.log1.block(); - break; + private static ItemStack[] createBuildingBlocks(Random random) { + int plankMeta = random.nextInt(16); + int blockMeta = random.nextInt(4); + Block plankBlock = Blocks.planks; + Block woodBlock = Blocks.log; + + if (PluginManager.Module.ARBORICULTURE.isEnabled()) { + switch (random.nextInt(4)) { + case 1: + woodBlock = ForestryBlock.log2.block(); + break; + case 2: + woodBlock = ForestryBlock.log3.block(); + break; + case 3: + woodBlock = ForestryBlock.log4.block(); + break; + default: + woodBlock = ForestryBlock.log1.block(); + break; + } + + plankBlock = ForestryBlock.planks1.block(); + + // chance for the house to have fireproof components + if (random.nextInt(4) == 0) { + woodBlock = BlockFireproofLog.getFireproofLog((BlockLog) woodBlock).block(); + plankBlock = BlockFireproofPlanks.getFireproofPlanks((BlockPlanks) plankBlock).block(); + } } - buildingBlocks[1] = new ItemStack(woodBlock, 1, random.nextInt(4)); + return new ItemStack[]{new ItemStack(plankBlock, 1, plankMeta), new ItemStack(woodBlock, 1, blockMeta)}; } /*@Override @@ -96,7 +116,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { @SuppressWarnings("rawtypes") public static ComponentVillageBeeHouse buildComponent(StructureVillagePieces.Start startPiece, List par1List, Random random, int par3, int par4, int par5, int par6, int par7) { - StructureBoundingBox bbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 9, 9, 6, par6); + StructureBoundingBox bbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 9, 9, 10, par6); return canVillageGoDeeper(bbox) && StructureComponent.findIntersecting(par1List, bbox) == null ? new ComponentVillageBeeHouse(startPiece, par7, random, bbox, par6) : null; } @@ -276,19 +296,19 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { if (tile instanceof TileBeehouse) { TileBeehouse apiary = ((TileBeehouse) tile); apiary.initialize(); - apiary.setSlotContents(TileBeehouse.SLOT_QUEEN, + apiary.setInventorySlotContents(TileBeehouse.SLOT_QUEEN, PluginApiculture.beeInterface.getMemberStack(getVillageBee(world, xCoord, yCoord, zCoord), EnumBeeType.PRINCESS.ordinal())); - apiary.setSlotContents(TileBeehouse.SLOT_DRONE, + apiary.setInventorySlotContents(TileBeehouse.SLOT_DRONE, PluginApiculture.beeInterface.getMemberStack(getVillageBee(world, xCoord, yCoord, zCoord), EnumBeeType.DRONE.ordinal())); for (int i = TileBeehouse.SLOT_FRAMES_1; i < TileBeehouse.SLOT_FRAMES_1 + TileBeehouse.SLOT_FRAMES_COUNT; i++) { float roll = world.rand.nextFloat(); if (roll < 0.2f) - apiary.setSlotContents(i, ForestryItem.frameUntreated.getItemStack()); + apiary.setInventorySlotContents(i, ForestryItem.frameUntreated.getItemStack()); else if (roll < 0.4f) - apiary.setSlotContents(i, ForestryItem.frameImpregnated.getItemStack()); + apiary.setInventorySlotContents(i, ForestryItem.frameImpregnated.getItemStack()); else if (roll < 0.6) - apiary.setSlotContents(i, ForestryItem.frameProven.getItemStack()); + apiary.setInventorySlotContents(i, ForestryItem.frameProven.getItemStack()); } } @@ -325,11 +345,8 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { EnumTolerance temperatureTolerance = genome.getToleranceTemp(); Collection toleratedTemperatures = AlleleManager.climateHelper.getToleratedTemperature(beeTemperature, temperatureTolerance); - boolean validTemp = false; - validTemp = toleratedTemperatures.contains(EnumTemperature.getFromValue(temperature)); - - if (!validTemp) + if (!toleratedTemperatures.contains(EnumTemperature.getFromValue(temperature))) return false; EnumHumidity beeHumidity = genome.getPrimary().getHumidity(); @@ -337,11 +354,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { Collection toleratedHumidity = AlleleManager.climateHelper.getToleratedHumidity(beeHumidity, humidityTolerance); - boolean validHumidity = false; - - validHumidity = toleratedHumidity.contains(EnumHumidity.getFromValue(humidity)); - - return validHumidity; + return toleratedHumidity.contains(EnumHumidity.getFromValue(humidity)); } protected void fillBoxWith(World world, StructureBoundingBox box, int par3, int par4, int par5, int par6, int par7, int par8, ItemStack buildingBlock, @@ -372,8 +385,7 @@ public class ComponentVillageBeeHouse extends StructureVillagePieces.House1 { } private boolean isAirBlockAtCurrentPosition(World world, int x, int y, int z, StructureBoundingBox box) { - // TODO: replace with isAir - return getBlockAtCurrentPosition(world, x, y, z, box) == Blocks.air; + return getBlockAtCurrentPosition(world, x, y, z, box).isAir(world, x, y, z); } } diff --git a/src/main/java/forestry/apiculture/worldgen/Hive.java b/src/main/java/forestry/apiculture/worldgen/Hive.java new file mode 100644 index 000000000..ee26e6eb4 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/Hive.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import forestry.api.apiculture.IHiveDrop; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; + +public final class Hive { + + private final IHiveDescription hiveDescription; + private final List drops = new ArrayList(); + + public Hive(IHiveDescription hiveDescription) { + if (hiveDescription == null) + throw new IllegalArgumentException("Tried to create hive with null hive description"); + this.hiveDescription = hiveDescription; + } + + public Block getHiveBlock() { + return hiveDescription.getBlock(); + } + + public int getHiveMeta() { + return hiveDescription.getMeta(); + } + + public void addDrops(List drops) { + this.drops.addAll(drops); + } + + public List getDrops() { + return drops; + } + + public float genChance() { + return hiveDescription.getGenChance(); + } + + public void postGen(World world, int x, int y, int z) { + hiveDescription.postGen(world, x, y, z); + } + + public boolean isGoodBiome(BiomeGenBase biome) { + return hiveDescription.isGoodBiome(biome); + } + + public boolean isGoodHumidity(EnumHumidity humidity) { + return hiveDescription.isGoodHumidity(humidity); + } + + public boolean isGoodTemperature(EnumTemperature temperature) { + return hiveDescription.isGoodTemperature(temperature); + } + + public boolean isValidLocation(World world, int x, int y, int z) { + return hiveDescription.getHiveGen().isValidLocation(world, x, y, z); + } + + public boolean canReplace(World world, int x, int y, int z) { + return hiveDescription.getHiveGen().canReplace(world, x, y, z); + } + + public int getYForHive(World world, int x, int z) { + return hiveDescription.getHiveGen().getYForHive(world, x, z); + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java index 65ea83051..719180f9a 100755 --- a/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDecorator.java @@ -10,22 +10,24 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import forestry.api.apiculture.hives.HiveManager; -import forestry.api.apiculture.hives.IHive; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.IChunkProvider; + +import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType; +import net.minecraftforge.event.terraingen.TerrainGen; + import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.core.config.Config; import forestry.core.config.Defaults; -import net.minecraft.block.Block; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.util.EnumHelper; -import net.minecraftforge.event.terraingen.PopulateChunkEvent; -import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType; -import net.minecraftforge.event.terraingen.TerrainGen; - -import java.util.Random; +import forestry.plugins.PluginApiculture; /** * @@ -47,23 +49,31 @@ public class HiveDecorator { private HiveDecorator() { } - @SubscribeEvent - public void generate(PopulateChunkEvent.Post event) { - if (!TerrainGen.populate(event.chunkProvider, event.world, event.rand, event.chunkX, event.chunkZ, event.hasVillageGenerated, EVENT_TYPE)) { + public void decorateHives(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) { + if (!TerrainGen.populate(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated, EVENT_TYPE)) { return; } - decorateHives(event.world, event.rand, event.chunkX, event.chunkZ); + + decorateHives(world, rand, chunkX, chunkZ); } - private void decorateHives(World world, Random rand, int chunkX, int chunkZ) { - for (IHive hive : HiveManager.getHives()) - if (Config.generateBeehivesDebug) - genHiveDebug(world, chunkX, chunkZ, hive); - else - genHive(world, rand, chunkX, chunkZ, hive); + public void decorateHives(World world, Random rand, int chunkX, int chunkZ) { + List hives = PluginApiculture.hiveRegistry.getHives(); + + if (Config.generateBeehivesDebug) { + decorateHivesDebug(world, chunkX, chunkZ, hives); + return; + } + + Collections.shuffle(hives, rand); + for (Hive hive : hives) { + if (genHive(world, rand, chunkX, chunkZ, hive)) { + return; + } + } } - public boolean genHive(World world, Random rand, int chunkX, int chunkZ, IHive hive) { + public boolean genHive(World world, Random rand, int chunkX, int chunkZ, Hive hive) { if (hive.genChance() < rand.nextFloat() * 128.0f) return false; @@ -87,19 +97,26 @@ public class HiveDecorator { return false; } - private void genHiveDebug(World world, int worldX, int worldZ, IHive hive) { + private void decorateHivesDebug(World world, int chunkX, int chunkZ, List hives) { + 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; + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + Collections.shuffle(hives, world.rand); + for (Hive hive : hives) { + if (!hive.isGoodBiome(biome) || !hive.isGoodHumidity(humidity)) + continue; - for (int x = 0; x < 16; x++) - for (int z = 0; z < 16; z++) - tryGenHive(world, worldX + x, worldZ + z, hive); + tryGenHive(world, worldX + x, worldZ + z, hive); + } + } + } } - private boolean tryGenHive(World world, int x, int z, IHive hive) { + private boolean tryGenHive(World world, int x, int z, Hive hive) { int y = hive.getYForHive(world, x, z); @@ -114,13 +131,13 @@ public class HiveDecorator { if (!hive.isGoodTemperature(temperature)) return false; - if (!hive.isGoodLocation(world, x, y, z)) + if (!hive.isValidLocation(world, x, y, z)) return false; return setHive(world, x, y, z, hive); } - protected boolean setHive(World world, int x, int y, int z, IHive hive) { + protected boolean setHive(World world, int x, int y, int z, Hive hive) { Block hiveBlock = hive.getHiveBlock(); boolean placed = world.setBlock(x, y, z, hiveBlock, hive.getHiveMeta(), Defaults.FLAG_BLOCK_SYNCH); if (!placed) @@ -133,7 +150,9 @@ public class HiveDecorator { hiveBlock.onBlockAdded(world, x, y, z); world.markBlockForUpdate(x, y, z); - hive.postGen(world, x, y, z); + if (!Config.generateBeehivesDebug) { + hive.postGen(world, x, y, z); + } return true; } } diff --git a/src/main/java/forestry/apiculture/worldgen/HiveDescription.java b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java new file mode 100644 index 000000000..d11418b54 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescription.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + +import forestry.api.apiculture.hives.HiveManager; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.core.BiomeHelper; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.core.config.ForestryBlock; + +public enum HiveDescription implements IHiveDescription { + + FOREST(1, 3.0f, EnumSet.of(EnumHumidity.NORMAL), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.tree()), + MEADOWS(2, 1.0f, EnumSet.of(EnumHumidity.NORMAL), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass)), + DESERT(3, 1.0f, EnumSet.of(EnumHumidity.ARID), EnumSet.of(EnumTemperature.HOT), HiveManager.genHelper.ground(Blocks.sand, Blocks.sandstone)), + JUNGLE(4, 4.0f, EnumSet.of(EnumHumidity.DAMP), EnumSet.of(EnumTemperature.WARM), HiveManager.genHelper.tree()), + END(5, 4.0f, EnumSet.allOf(EnumHumidity.class), EnumSet.allOf(EnumTemperature.class), HiveManager.genHelper.ground(Blocks.end_stone)) { + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return biome.biomeID == BiomeGenBase.sky.biomeID; + } + }, + SNOW(6, 2.0f, EnumSet.allOf(EnumHumidity.class), EnumSet.of(EnumTemperature.COLD, EnumTemperature.ICY), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass, Blocks.snow)) { + @Override + public void postGen(World world, int x, int y, int z) { + if (world.isAirBlock(x, y + 1, z)) + world.setBlock(x, y + 1, z, Blocks.snow_layer, 0, 0); + } + }, + SWAMP(7, 2.0f, EnumSet.of(EnumHumidity.DAMP), EnumSet.of(EnumTemperature.NORMAL), HiveManager.genHelper.ground(Blocks.dirt, Blocks.grass)), + ; + + private final int meta; + private final float genChance; + private final EnumSet humidities; + private final EnumSet temperatures; + private final IHiveGen hiveGen; + + private HiveDescription(int meta, float genChance, EnumSet humidities, EnumSet temperatures, IHiveGen hiveGen) { + this.meta = meta; + this.genChance = genChance; + this.humidities = humidities; + this.temperatures = temperatures; + this.hiveGen = hiveGen; + } + + @Override + public IHiveGen getHiveGen() { + return hiveGen; + } + + @Override + public Block getBlock() { + return ForestryBlock.beehives.block(); + } + + @Override + public int getMeta() { + return meta; + } + + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return !BiomeHelper.isBiomeHellish(biome); + } + + @Override + public boolean isGoodHumidity(EnumHumidity humidity) { + return humidities.contains(humidity); + } + + @Override + public boolean isGoodTemperature(EnumTemperature temperature) { + return temperatures.contains(temperature); + } + + @Override + public float getGenChance() { + return genChance; + } + + @Override + public void postGen(World world, int x, int y, int z) { + + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java similarity index 54% rename from src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java rename to src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java index e06dca4bb..b796d70e4 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveSwarmer.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveDescriptionSwarmer.java @@ -10,23 +10,63 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import forestry.api.apiculture.hives.HiveGround; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; import forestry.apiculture.gadgets.TileSwarm; import forestry.core.config.ForestryBlock; + +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; -public class HiveSwarmer extends HiveGround { +public class HiveDescriptionSwarmer implements IHiveDescription { private final ItemStack[] bees; - public HiveSwarmer(float genChance, ItemStack... bees) { - super(ForestryBlock.beehives.block(), 8, genChance, Blocks.dirt, Blocks.grass); + public HiveDescriptionSwarmer(ItemStack... bees) { this.bees = bees; } + @Override + public IHiveGen getHiveGen() { + return new HiveGenGround(Blocks.dirt, Blocks.grass); + } + + @Override + public Block getBlock() { + return ForestryBlock.beehives.block(); + } + + @Override + public int getMeta() { + return 8; + } + + @Override + public boolean isGoodBiome(BiomeGenBase biome) { + return true; + } + + @Override + public boolean isGoodHumidity(EnumHumidity humidity) { + return true; + } + + @Override + public boolean isGoodTemperature(EnumTemperature temperature) { + return true; + } + + @Override + public float getGenChance() { + return 128.0f; + } + @Override public void postGen(World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); diff --git a/src/main/java/forestry/apiculture/worldgen/HiveForest.java b/src/main/java/forestry/apiculture/worldgen/HiveForest.java deleted file mode 100644 index fdc25a5d7..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveForest.java +++ /dev/null @@ -1,33 +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 forestry.api.apiculture.hives.HiveTree; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; - -public class HiveForest extends HiveTree { - - public HiveForest(float genChance) { - super(ForestryBlock.beehives.block(), 1, genChance); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.NORMAL; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveJungle.java b/src/main/java/forestry/apiculture/worldgen/HiveGen.java similarity index 54% rename from src/main/java/forestry/apiculture/worldgen/HiveJungle.java rename to src/main/java/forestry/apiculture/worldgen/HiveGen.java index 59e1b341d..9bf270b22 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveJungle.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveGen.java @@ -10,24 +10,20 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import forestry.api.apiculture.hives.HiveTree; -import forestry.api.core.EnumHumidity; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; -public class HiveJungle extends HiveTree { +import forestry.api.apiculture.hives.IHiveGen; - public HiveJungle(float genChance) { - super(ForestryBlock.beehives.block(), 4, genChance); - } +public abstract class HiveGen implements IHiveGen { @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.DAMP; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.WARM; + public boolean canReplace(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + Material material = block.getMaterial(); + return (material.isReplaceable() && !material.isLiquid()) || + material == Material.air || + material == Material.plants; } } diff --git a/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java b/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java new file mode 100644 index 000000000..8d7c8da33 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenGround.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.apiculture.worldgen; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +public class HiveGenGround extends HiveGen { + + private final Set groundMaterials = new HashSet(); + + public HiveGenGround(Block... groundBlocks) { + for (Block block : groundBlocks) + groundMaterials.add(block.getMaterial()); + } + + @Override + public boolean isValidLocation(World world, int x, int y, int z) { + Block ground = world.getBlock(x, y - 1, z); + return groundMaterials.contains(ground.getMaterial()); + } + + @Override + public int getYForHive(World world, int x, int z) { + int y = world.getHeightValue(x, z); + + // get to the ground + while (y >= 0 && (world.getBlock(x, y - 1, z).isLeaves(world, x, y - 1, z) || canReplace(world, x, y - 1, z))) { + y--; + } + + return y; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveEnd.java b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java similarity index 60% rename from src/main/java/forestry/apiculture/worldgen/HiveEnd.java rename to src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java index 1a675700a..b748e0791 100644 --- a/src/main/java/forestry/apiculture/worldgen/HiveEnd.java +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenHelper.java @@ -10,19 +10,22 @@ ******************************************************************************/ package forestry.apiculture.worldgen; -import forestry.api.apiculture.hives.HiveGround; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; -import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.block.Block; -public class HiveEnd extends HiveGround { +import forestry.api.apiculture.hives.IHiveGen; +import forestry.api.apiculture.hives.IHiveGenHelper; - public HiveEnd(float genChance) { - super(ForestryBlock.beehives.block(), 5, genChance, Blocks.end_stone); +public class HiveGenHelper implements IHiveGenHelper { + + private static IHiveGen treeGen = new HiveGenTree(); + + @Override + public IHiveGen ground(Block... validGroundBlocks) { + return new HiveGenGround(validGroundBlocks); } @Override - public boolean isGoodBiome(BiomeGenBase biome) { - return biome.biomeID == BiomeGenBase.sky.biomeID; + public IHiveGen tree() { + return treeGen; } } diff --git a/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java b/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java new file mode 100644 index 000000000..32e0079c7 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveGenTree.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * 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 net.minecraft.block.Block; +import net.minecraft.world.World; + +public class HiveGenTree extends HiveGen { + + @Override + public boolean isValidLocation(World world, int x, int y, int z) { + Block blockAbove = world.getBlock(x, y + 1, z); + if (!blockAbove.isLeaves(world, x, y + 1, z)) + return false; + + // not a good location if right on top of something + return canReplace(world, x, y - 1, z); + } + + @Override + public int getYForHive(World world, int x, int z) { + // get top leaf block + int y = world.getHeightValue(x, z) - 1; + if (!world.getBlock(x, y, z).isLeaves(world, x, y, z)) + return -1; + + // get to the bottom of the leaves + do { y--; } while (world.getBlock(x, y, z).isLeaves(world, x, y, z)); + + return y; + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java b/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java deleted file mode 100644 index 4917582cc..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveMeadows.java +++ /dev/null @@ -1,34 +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 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; - -public class HiveMeadows extends HiveGround { - - public HiveMeadows(float genChance) { - super(ForestryBlock.beehives.block(), 2, genChance, Blocks.dirt, Blocks.grass); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.NORMAL; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveParched.java b/src/main/java/forestry/apiculture/worldgen/HiveParched.java deleted file mode 100644 index 45e478258..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveParched.java +++ /dev/null @@ -1,41 +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 forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.BiomeHelper; -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 HiveParched extends HiveGround { - - public HiveParched(float genChance) { - super(ForestryBlock.beehives.block(), 3, genChance, Blocks.sand, Blocks.sandstone); - } - - @Override - public boolean isGoodBiome(BiomeGenBase biome) { - return !BiomeHelper.canRainOrSnow(biome); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.ARID; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.HOT; - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java b/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java new file mode 100644 index 000000000..d15b3bc86 --- /dev/null +++ b/src/main/java/forestry/apiculture/worldgen/HiveRegistry.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import forestry.api.apiculture.IHiveDrop; +import forestry.api.apiculture.hives.IHiveDescription; +import forestry.api.apiculture.hives.IHiveRegistry; + +public class HiveRegistry implements IHiveRegistry { + + private final Map hives = new HashMap(); + + @Override + public void registerHive(String hiveName, IHiveDescription hiveDescription) { + if (hives.containsKey(hiveName)) + throw new IllegalArgumentException("Hive already exists with name: " + hiveName); + + Hive hive = new Hive(hiveDescription); + hives.put(hiveName, hive); + } + + @Override + public void addDrops(String hiveName, List drops) { + Hive hive = hives.get(hiveName); + if (hive == null) + throw new IllegalArgumentException("No hive registered with name: " + hiveName); + + hive.addDrops(drops); + } + + public List getHives() { + return new ArrayList(hives.values()); + } + + public List getDrops(String hiveName) { + Hive hive = hives.get(hiveName); + if (hive == null) + throw new IllegalArgumentException("No hive registered with name: " + hiveName); + + return hive.getDrops(); + } +} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSnow.java b/src/main/java/forestry/apiculture/worldgen/HiveSnow.java deleted file mode 100644 index deafc8802..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveSnow.java +++ /dev/null @@ -1,35 +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 forestry.api.apiculture.hives.HiveGround; -import forestry.api.core.EnumTemperature; -import forestry.core.config.ForestryBlock; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - -public class HiveSnow extends HiveGround { - - public HiveSnow(float genChance) { - super(ForestryBlock.beehives.block(), 6, genChance, Blocks.dirt, Blocks.grass, Blocks.snow); - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.COLD || temperature == EnumTemperature.ICY; - } - - @Override - public void postGen(World world, int x, int y, int z) { - if (world.isAirBlock(x, y + 1, z)) - world.setBlock(x, y + 1, z, Blocks.snow_layer, 0, 0); - } -} diff --git a/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java b/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java deleted file mode 100644 index efa47f548..000000000 --- a/src/main/java/forestry/apiculture/worldgen/HiveSwamp.java +++ /dev/null @@ -1,34 +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 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; - -public class HiveSwamp extends HiveGround { - - public HiveSwamp(float genChance) { - super(ForestryBlock.beehives.block(), 7, genChance, Blocks.dirt, Blocks.grass); - } - - @Override - public boolean isGoodHumidity(EnumHumidity humidity) { - return humidity == EnumHumidity.DAMP; - } - - @Override - public boolean isGoodTemperature(EnumTemperature temperature) { - return temperature == EnumTemperature.NORMAL; - } -} diff --git a/src/main/java/forestry/arboriculture/CommandSpawnForest.java b/src/main/java/forestry/arboriculture/CommandSpawnForest.java deleted file mode 100755 index 2cb959d0b..000000000 --- a/src/main/java/forestry/arboriculture/CommandSpawnForest.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.gen.feature.WorldGenerator; - -import forestry.api.world.ITreeGenData; -import forestry.arboriculture.genetics.TreeTemplates; -import forestry.arboriculture.worldgen.WorldGenBalsa; -import forestry.core.utils.CommandMC; -import forestry.plugins.PluginArboriculture; - -public class CommandSpawnForest extends CommandMC { - - @Override - public String getCommandName() { - return "spawnforest"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + getCommandName() + " "; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - EntityPlayer player = getCommandSenderAsPlayer(sender); - - int x = (int) player.posX - 16; - int y = (int) (player.posY); - int z = (int) player.posZ - 16; - - WorldGenerator gen = new WorldGenBalsa((ITreeGenData) PluginArboriculture.treeInterface.getTree(player.worldObj, - TreeTemplates.templateAsGenome(PluginArboriculture.treeInterface.getTemplate("treeBalsa")))); - - for (int i = 0; i < 16; i++) - gen.generate(player.worldObj, player.worldObj.rand, x + player.worldObj.rand.nextInt(32), y, z + player.worldObj.rand.nextInt(32)); - } -} diff --git a/src/main/java/forestry/arboriculture/CommandSpawnTree.java b/src/main/java/forestry/arboriculture/CommandSpawnTree.java deleted file mode 100755 index 9ad8e744a..000000000 --- a/src/main/java/forestry/arboriculture/CommandSpawnTree.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.gen.feature.WorldGenerator; - -import forestry.api.world.ITreeGenData; -import forestry.arboriculture.genetics.TreeTemplates; -import forestry.arboriculture.worldgen.WorldGenBalsa; -import forestry.core.utils.CommandMC; -import forestry.plugins.PluginArboriculture; - -public class CommandSpawnTree extends CommandMC { - - public CommandSpawnTree() { - } - - @Override - public String getCommandName() { - return "spawntree"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + getCommandName() + " "; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - EntityPlayer player = getCommandSenderAsPlayer(sender); - - int x = (int) player.posX; - int y = (int) (player.posY); - int z = (int) player.posZ; - - WorldGenerator gen = new WorldGenBalsa((ITreeGenData) PluginArboriculture.treeInterface.getTree(player.worldObj, - TreeTemplates.templateAsGenome(PluginArboriculture.treeInterface.getTemplate("treeBalsa")))); - - gen.generate(player.worldObj, player.worldObj.rand, x, y, z); - - } -} diff --git a/src/main/java/forestry/arboriculture/CommandTreekeepingMode.java b/src/main/java/forestry/arboriculture/CommandTreekeepingMode.java deleted file mode 100755 index d21ca6daa..000000000 --- a/src/main/java/forestry/arboriculture/CommandTreekeepingMode.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommand; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.World; - -import com.mojang.authlib.GameProfile; - -import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.api.arboriculture.IArboristTracker; -import forestry.api.arboriculture.ITreekeepingMode; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAllele; -import forestry.core.config.Defaults; -import forestry.core.config.Version; -import forestry.core.proxy.Proxies; -import forestry.core.utils.CommandMC; -import forestry.core.utils.StringUtil; -import forestry.plugins.PluginArboriculture; - -public class CommandTreekeepingMode extends CommandMC { - - private final String[] modeStrings; - - public CommandTreekeepingMode() { - modeStrings = new String[PluginArboriculture.treeInterface.getTreekeepingModes().size()]; - for (int i = 0; i < PluginArboriculture.treeInterface.getTreekeepingModes().size(); i++) - modeStrings[i] = PluginArboriculture.treeInterface.getTreekeepingModes().get(i).getName(); - } - - @Override - public int compareTo(Object arg0) { - return this.getCommandName().compareTo(((ICommand) arg0).getCommandName()); - } - - @Override - public String getCommandName() { - return "treekeeping"; - } - - @Override - public String getCommandUsage(ICommandSender var1) { - return "/" + this.getCommandName() + " help"; - } - - @SuppressWarnings("rawtypes") - @Override - public List getCommandAliases() { - return null; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - - if (arguments.length <= 0) - throw new WrongUsageException(StringUtil.localizeAndFormat("chat.help", this.getCommandUsage(sender))); - - if (arguments[0].matches("list")) - listModes(sender, arguments); - else if (arguments[0].matches("info")) - listModeInfo(sender, arguments); - else if (arguments[0].matches("set")) { - if (arguments.length <= 1) - throw new WrongUsageException("/" + this.getCommandName() + " set [] "); - - World world = getWorld(sender, arguments); - String desired = arguments[arguments.length - 1]; - - ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(desired); - if (mode == null) - throw new CommandException(StringUtil.localize("chat.trees.command.treekeeping.error"), desired); - - PluginArboriculture.treeInterface.setTreekeepingMode(world, mode.getName()); - func_152373_a(sender, this, StringUtil.localize("chat.trees.command.treekeeping.set"), mode.getName()); - - } else if (arguments[0].matches("save")) { - if (arguments.length <= 1) - throw new WrongUsageException("/" + this.getCommandName() + " save "); - - saveStatistics(sender, arguments); - } else if (arguments[0].matches("help")) { - sendChatMessage(sender, StringUtil.localizeAndFormat("chat.trees.command.help.0", this.getCommandName())); - sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.1")); - sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.2")); - sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.3")); - sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.4")); - sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.5")); - } - } - - private void saveStatistics(ICommandSender sender, String[] arguments) { - - String newLine = System.getProperty("line.separator"); - World world = getWorld(sender, arguments); - - String player = arguments[1]; - Collection statistics = new ArrayList(); - - statistics.add(String.format("Treekeeping statistics for %s on %s:", player, DateFormat.getInstance().format(new Date()))); - statistics.add(""); - statistics.add("MODE: " + PluginArboriculture.treeInterface.getTreekeepingMode(world).getName()); - statistics.add(""); - - GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(player); - IArboristTracker tracker = PluginArboriculture.treeInterface.getBreedingTracker(world, profile); - if (tracker == null) - statistics.add("No statistics found."); - else { - statistics.add("BRED:"); - statistics.add("-----"); - statistics.add(""); - - Collection species = new ArrayList(); - for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) - if (allele instanceof IAlleleTreeSpecies) - species.add((IAlleleTreeSpecies) allele); - - statistics.add(String.format("SPECIES (%s):", species.size())); - statistics.add("-------------"); - statistics.add(""); - - for (IAlleleTreeSpecies allele : species) - statistics.add(generateSpeciesListEntry(allele, tracker)); - } - - File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player + ".log"); - try { - - if (file.getParentFile() != null) - file.getParentFile().mkdirs(); - - if (!file.exists() && !file.createNewFile()) { - sendChatMessage(sender, "Log file could not be created. Failed to save statistics."); - return; - } - - if (!file.canWrite()) { - sendChatMessage(sender, "Cannot write to log file. Failed to save statistics."); - return; - } - - FileOutputStream fileout = new FileOutputStream(file); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileout, "UTF-8")); - - writer.write("# " + Defaults.MOD + newLine + "# " + Version.getVersion() + newLine); - - for (String line : statistics) - writer.write(line + newLine); - - writer.close(); - - } catch (Exception ex) { - sendChatMessage(sender, "Write operation threw an exception. Failed to save statistics."); - ex.printStackTrace(); - } - - sendChatMessage(sender, "Saved statistics for player " + player); - } - - private String generateSpeciesListEntry(IAlleleTreeSpecies species, IArboristTracker tracker) { - String discovered = "[ ]"; - if (tracker.isDiscovered(species)) - discovered = "[ X ]"; - String blacklisted = "[ ]"; - if (AlleleManager.alleleRegistry.isBlacklisted(species.getUID())) - blacklisted = "[ BL ]"; - String notcounted = "[ ]"; - if (!species.isCounted()) - notcounted = "[ NC ]"; - - return String.format("%s %s %s\t%-40s %-20s %-20s", discovered, blacklisted, notcounted, species.getUID(), species.getName(), species.getAuthority()); - } - - private void listModes(ICommandSender sender, String[] arguments) { - World world = getWorld(sender, arguments); - - sendChatMessage(sender, "Current: " + PluginArboriculture.treeInterface.getTreekeepingMode(world).getName() + " (#" + world.getWorldInfo().getSaveVersion() - + ")"); - - String help = ""; - for (ITreekeepingMode mode : PluginArboriculture.treeInterface.getTreekeepingModes()) { - if (!help.isEmpty()) - help += ", "; - help += mode.getName(); - } - sendChatMessage(sender, "Available modes: " + help); - } - - private void listModeInfo(ICommandSender sender, String[] arguments) { - if (arguments.length <= 1) - throw new WrongUsageException("/" + this.getCommandName() + " info "); - - ITreekeepingMode found = null; - for (ITreekeepingMode mode : PluginArboriculture.treeInterface.getTreekeepingModes()) - if (mode.getName().equalsIgnoreCase(arguments[1])) { - found = mode; - break; - } - - if (found == null) - throw new CommandException("No treekeeping mode called '%s' is available.", arguments[1]); - - sendChatMessage(sender, "\u00A7aMode: " + found.getName()); - for (String desc : found.getDescription()) - sendChatMessage(sender, StringUtil.localize(desc)); - } - - @Override - public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof EntityPlayer) - return Proxies.common.isOp((EntityPlayer) sender); - else - return sender.canCommandSenderUseCommand(4, getCommandName()); - } - - @SuppressWarnings("rawtypes") - @Override - public List addTabCompletionOptions(ICommandSender sender, String[] incomplete) { - return getListOfStringsMatchingLastWord(incomplete, modeStrings); - } - -} diff --git a/src/main/java/forestry/arboriculture/FruitProviderNone.java b/src/main/java/forestry/arboriculture/FruitProviderNone.java index b9b6ead28..1e2a5832b 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderNone.java +++ b/src/main/java/forestry/arboriculture/FruitProviderNone.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.arboriculture; -import java.util.HashMap; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.arboriculture.IFruitProvider; import forestry.api.arboriculture.ITreeGenome; import forestry.api.genetics.IFruitFamily; import forestry.core.render.TextureManager; +import java.util.HashMap; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; public class FruitProviderNone implements IFruitProvider { @@ -46,8 +43,8 @@ public class FruitProviderNone implements IFruitProvider { overlayTypes.put("plums", new OverlayType("plums", (short) 1004)); } - String key; - IFruitFamily family = null; + private final String key; + private final IFruitFamily family; int ripeningPeriod = 10; diff --git a/src/main/java/forestry/arboriculture/FruitProviderPod.java b/src/main/java/forestry/arboriculture/FruitProviderPod.java index 8e3b8ab1d..15aa29c52 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderPod.java +++ b/src/main/java/forestry/arboriculture/FruitProviderPod.java @@ -10,17 +10,8 @@ ******************************************************************************/ package forestry.arboriculture; -import java.util.Locale; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; import forestry.api.arboriculture.ITreeGenome; @@ -28,6 +19,12 @@ import forestry.api.genetics.IFruitFamily; import forestry.core.render.TextureManager; import forestry.core.utils.BlockUtil; import forestry.plugins.PluginArboriculture; +import java.util.Locale; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; public class FruitProviderPod extends FruitProviderNone { @@ -42,7 +39,7 @@ public class FruitProviderPod extends FruitProviderNone { } } - private static ItemStack[] DUMMY = new ItemStack[0]; + private static final ItemStack[] DUMMY = new ItemStack[0]; private final EnumPodType type; private final ItemStack[] drop; @@ -82,7 +79,7 @@ public class FruitProviderPod extends FruitProviderNone { if (type == EnumPodType.COCOA) return BlockUtil.tryPlantPot(world, x, y, z, Blocks.cocoa); else { - return PluginArboriculture.treeInterface.setFruitBlock(world, (IAlleleFruit) genome.getActiveAllele(EnumTreeChromosome.FRUITS.ordinal()), + return PluginArboriculture.treeInterface.setFruitBlock(world, (IAlleleFruit) genome.getActiveAllele(EnumTreeChromosome.FRUITS), genome.getSappiness(), type.uids, x, y, z); } } diff --git a/src/main/java/forestry/arboriculture/FruitProviderRandom.java b/src/main/java/forestry/arboriculture/FruitProviderRandom.java index c9194eae2..e353d1def 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderRandom.java +++ b/src/main/java/forestry/arboriculture/FruitProviderRandom.java @@ -13,14 +13,13 @@ package forestry.arboriculture; import forestry.api.arboriculture.ITreeGenome; import forestry.api.genetics.IFruitFamily; import forestry.plugins.PluginArboriculture; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; /** * Simple fruit provider which drops from any leaf block according to yield and either marks all leave blocks as fruit leaves or none. diff --git a/src/main/java/forestry/arboriculture/FruitProviderRipening.java b/src/main/java/forestry/arboriculture/FruitProviderRipening.java index 3d7c83320..69ba7afcd 100755 --- a/src/main/java/forestry/arboriculture/FruitProviderRipening.java +++ b/src/main/java/forestry/arboriculture/FruitProviderRipening.java @@ -13,14 +13,13 @@ package forestry.arboriculture; import forestry.api.arboriculture.ITreeGenome; import forestry.api.genetics.IFruitFamily; import forestry.plugins.PluginArboriculture; -import net.minecraft.item.ItemStack; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; public class FruitProviderRipening extends FruitProviderNone { diff --git a/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java b/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java index b0c9fa378..416038e0c 100755 --- a/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java +++ b/src/main/java/forestry/arboriculture/GuiHandlerArboriculture.java @@ -15,10 +15,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.arboriculture.genetics.TreeHelper; -import forestry.arboriculture.gui.ContainerTreealyzer; import forestry.arboriculture.gui.GuiTreealyzer; import forestry.arboriculture.items.ItemTreealyzer.TreealyzerInventory; import forestry.core.GuiHandlerBase; +import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; public class GuiHandlerArboriculture extends GuiHandlerBase { @@ -36,11 +36,11 @@ public class GuiHandlerArboriculture extends GuiHandlerBase { return this.getNaturalistChestContainer(TreeHelper.UID, player, world, x, y, z, decodeGuiData(id)); case TreealyzerGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; - return new ContainerTreealyzer(player.inventory, new TreealyzerInventory(player, equipped)); + return new ContainerAlyzer(new TreealyzerInventory(player, equipped), player); default: return null; @@ -62,7 +62,7 @@ public class GuiHandlerArboriculture extends GuiHandlerBase { return this.getNaturalistChestGui(TreeHelper.UID, player, world, x, y, z, decodeGuiData(id)); case TreealyzerGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; diff --git a/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java b/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java index 9f275d5c2..69388547d 100755 --- a/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java +++ b/src/main/java/forestry/arboriculture/PacketHandlerArboriculture.java @@ -10,17 +10,17 @@ ******************************************************************************/ package forestry.arboriculture; -import java.io.DataInputStream; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; - import forestry.arboriculture.gadgets.TileLeaves; import forestry.arboriculture.network.PacketLeafUpdate; +import forestry.arboriculture.network.PacketRipeningUpdate; import forestry.core.interfaces.IPacketHandler; -import forestry.core.network.ILocatedPacket; import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; +import forestry.storage.proxy.ProxyStorage; + +import java.io.DataInputStream; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; public class PacketHandlerArboriculture implements IPacketHandler { @@ -29,11 +29,18 @@ public class PacketHandlerArboriculture implements IPacketHandler { try { switch (packetID) { - case PacketIds.LEAF_UPDATE: - PacketLeafUpdate packet = new PacketLeafUpdate(); - packet.readData(data); - onLeafUpdate(packet); - break; + case PacketIds.LEAF_UPDATE: { + PacketLeafUpdate packet = new PacketLeafUpdate(); + packet.readData(data); + onLeafUpdate(packet); + break; + } + case PacketIds.RIPENING_UPDATE: { + PacketRipeningUpdate packet = new PacketRipeningUpdate(); + packet.readData(data); + onRipeningUpdate(packet); + break; + } } } catch(Exception ex) { @@ -49,5 +56,12 @@ public class PacketHandlerArboriculture implements IPacketHandler { } + private void onRipeningUpdate(PacketRipeningUpdate packet) { + + TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld()); + if (tile instanceof TileLeaves) + ((TileLeaves) tile).fromRipeningPacket(packet); + + } } diff --git a/src/main/java/forestry/arboriculture/VillageHandlerArboriculture.java b/src/main/java/forestry/arboriculture/VillageHandlerArboriculture.java index d661c3a04..bd8340ca7 100755 --- a/src/main/java/forestry/arboriculture/VillageHandlerArboriculture.java +++ b/src/main/java/forestry/arboriculture/VillageHandlerArboriculture.java @@ -10,8 +10,12 @@ ******************************************************************************/ package forestry.arboriculture; +import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.core.config.ForestryBlock; +import forestry.core.config.ForestryItem; +import forestry.plugins.PluginArboriculture; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.init.Items; @@ -19,13 +23,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.village.MerchantRecipe; import net.minecraft.village.MerchantRecipeList; -import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; - -import forestry.api.arboriculture.EnumGermlingType; -import forestry.core.config.ForestryBlock; -import forestry.core.config.ForestryItem; -import forestry.plugins.PluginArboriculture; - public class VillageHandlerArboriculture implements IVillageTradeHandler { @SuppressWarnings("unchecked") @@ -41,10 +38,7 @@ public class VillageHandlerArboriculture implements IVillageTradeHandler { WoodType sells = WoodType.VALUES[random.nextInt(WoodType.VALUES.length)]; Block plankBlock; int meta; - if(!sells.hasPlank) { - plankBlock = ForestryBlock.planks1.block(); - meta = 0; - } else if(sells.ordinal() > 15) { + if(sells.ordinal() > 15) { plankBlock = ForestryBlock.planks2.block(); meta = sells.ordinal() - 16; } else { diff --git a/src/main/java/forestry/arboriculture/WoodType.java b/src/main/java/forestry/arboriculture/WoodType.java index 0086a0317..e9a60777b 100755 --- a/src/main/java/forestry/arboriculture/WoodType.java +++ b/src/main/java/forestry/arboriculture/WoodType.java @@ -10,36 +10,33 @@ ******************************************************************************/ package forestry.arboriculture; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.render.TextureManager; import java.util.Locale; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.render.TextureManager; - public enum WoodType { - LARCH, TEAK, ACACIA, LIME, CHESTNUT, WENGE, BAOBAB, SEQUOIA(4.0f), KAPOK, EBONY, MAHOGANY, BALSA(1.0f), WILLOW, WALNUT, GREENHEART(7.5f), CHERRY, MAHOE, POPLAR, PALM, PAPAYA, PINE( - 3.0f), PLUM, MAPLE, CITRUS, GIGANTEUM(2.0f, false); + LARCH, TEAK, ACACIA, LIME, + CHESTNUT, WENGE, BAOBAB, SEQUOIA(4.0f), + KAPOK, EBONY, MAHOGANY, BALSA(1.0f), + WILLOW, WALNUT, GREENHEART(7.5f), CHERRY, + MAHOE, POPLAR, PALM, PAPAYA, + PINE(3.0f), PLUM, MAPLE, CITRUS, + GIGANTEUM(2.0f), IPE, PADAUK, COCOBOLO, + ZEBRAWOOD; public static final WoodType[] VALUES = values(); private final float hardness; - public final boolean hasPlank; private WoodType() { - this(2.0f, true); + this(2.0f); } private WoodType(float hardness) { - this(hardness, true); - } - - private WoodType(float hardness, boolean hasPlank) { this.hardness = hardness; - this.hasPlank = hasPlank; } @SideOnly(Side.CLIENT) @@ -52,10 +49,7 @@ public enum WoodType { WoodType woodType = VALUES[i]; String woodName = woodType.toString().toLowerCase(Locale.ENGLISH); - if (woodType.hasPlank) - icons[0][i] = TextureManager.getInstance().registerTex(register, "wood/planks." + woodName); - else - icons[0][i] = null; + icons[0][i] = TextureManager.getInstance().registerTex(register, "wood/planks." + woodName); icons[1][i] = TextureManager.getInstance().registerTex(register, "wood/bark." + woodName); icons[2][i] = TextureManager.getInstance().registerTex(register, "wood/heart." + woodName); } @@ -95,4 +89,9 @@ public enum WoodType { return WoodType.LARCH; } + @Override + public String toString() { + return super.toString().toLowerCase(Locale.ENGLISH); + } + } diff --git a/src/main/java/forestry/arboriculture/commands/CommandTree.java b/src/main/java/forestry/arboriculture/commands/CommandTree.java new file mode 100644 index 000000000..f15d86448 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTree.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import forestry.core.commands.CommandMode; +import forestry.core.commands.CommandSaveStats; +import forestry.core.commands.ICommandModeHelper; +import forestry.core.commands.IStatsSaveHelper; +import forestry.core.commands.SubCommand; + +public class CommandTree extends SubCommand { + + public CommandTree() { + super("tree"); + + IStatsSaveHelper saveHelper = new TreeStatsSaveHelper(); + ICommandModeHelper modeHelper = new TreeModeHelper(); + + addChildCommand(new CommandTreeSpawn("spawnTree", new TreeSpawner())); + addChildCommand(new CommandTreeSpawn("spawnForest", new ForestSpawner())); + addChildCommand(new CommandMode(modeHelper)); + addChildCommand(new CommandSaveStats(saveHelper, modeHelper)); + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/CommandTreeSpawn.java b/src/main/java/forestry/arboriculture/commands/CommandTreeSpawn.java new file mode 100644 index 000000000..eb273dc58 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTreeSpawn.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.core.commands.CommandHelpers; +import forestry.core.commands.SubCommand; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.PlayerNotFoundException; +import net.minecraft.entity.player.EntityPlayer; +import org.apache.commons.lang3.StringUtils; + +public final class CommandTreeSpawn extends SubCommand { + + private final ITreeSpawner treeSpawner; + + public CommandTreeSpawn(String name, ITreeSpawner treeSpawner) { + super(name); + setPermLevel(PermLevel.ADMIN); + this.treeSpawner = treeSpawner; + } + + @Override + public final void processSubCommand(ICommandSender sender, String[] arguments) { + if (arguments.length < 1 || arguments.length > 2) { + printHelp(sender); + return; + } + + EntityPlayer player; + String treeName; + try { + player = CommandHelpers.getPlayer(sender, arguments[arguments.length - 1]); + String[] argumentsWithoutPlayer = new String[arguments.length - 1]; + System.arraycopy(arguments, 0, argumentsWithoutPlayer, 0, arguments.length - 1); + treeName = StringUtils.join(argumentsWithoutPlayer, " "); + } catch (PlayerNotFoundException e) { + player = CommandHelpers.getPlayer(sender, sender.getCommandSenderName()); + treeName = StringUtils.join(arguments, " "); + } + + boolean success = treeSpawner.spawn(sender, treeName, player); + if (!success) + printHelp(sender); + } + + @Override + public List addTabCompletionOptions(ICommandSender sender, String[] parameters) { + if (parameters.length == 1) { + List tabCompletion = CommandHelpers.getListOfStringsMatchingLastWord(parameters, getSpecies()); + tabCompletion.add("help"); + return tabCompletion; + } else if (parameters.length == 2) { + return CommandHelpers.getListOfStringsMatchingLastWord(parameters, CommandHelpers.getPlayers()); + } + return null; + } + + private static String[] getSpecies() { + List species = new ArrayList(); + + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) + if (allele instanceof IAlleleTreeSpecies) + species.add(allele.getName().replaceAll("\\s", "")); + + return species.toArray(new String[species.size()]); + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/ForestSpawner.java b/src/main/java/forestry/arboriculture/commands/ForestSpawner.java new file mode 100644 index 000000000..002f9b962 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/ForestSpawner.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class ForestSpawner implements ITreeSpawner { + + public boolean spawn(ICommandSender sender, String treeName, EntityPlayer player) { + Vec3 look = player.getLookVec(); + + int x = (int)Math.round(player.posX + (16 * look.xCoord)); + int y = (int)Math.round(player.posY); + int z = (int)Math.round(player.posZ + (16 * look.zCoord)); + + for (int i = 0; i < 16; i++) { + int spawnX = x + player.worldObj.rand.nextInt(32) - 16; + int spawnZ = z + player.worldObj.rand.nextInt(32) - 16; + + WorldGenerator gen = TreeGenHelper.getWorldGen(treeName, player, spawnX, y, spawnZ); + if (gen == null) { + return false; + } + TreeGenHelper.generateTree(gen, player, spawnX, y, spawnZ); + } + return true; + } + +} diff --git a/src/main/java/forestry/core/network/EntityNetData.java b/src/main/java/forestry/arboriculture/commands/ITreeSpawner.java old mode 100755 new mode 100644 similarity index 67% rename from src/main/java/forestry/core/network/EntityNetData.java rename to src/main/java/forestry/arboriculture/commands/ITreeSpawner.java index 311bdc863..ddeec9b99 --- a/src/main/java/forestry/core/network/EntityNetData.java +++ b/src/main/java/forestry/arboriculture/commands/ITreeSpawner.java @@ -4,20 +4,17 @@ * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.txt - * + * * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.network; +package forestry.arboriculture.commands; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; + +public interface ITreeSpawner { + + boolean spawn(ICommandSender sender, String treeName, EntityPlayer player); -/** - * Simple annotation to mark a field for synchronization in SMP. - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface EntityNetData { - // Needs to be set for arrays - int staticSize() default -1; } diff --git a/src/main/java/forestry/arboriculture/commands/TreeGenHelper.java b/src/main/java/forestry/arboriculture/commands/TreeGenHelper.java new file mode 100644 index 000000000..977d3c318 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/TreeGenHelper.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.ITreeGenome; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.core.commands.SpeciesNotFoundException; +import forestry.core.commands.TemplateNotFoundException; +import forestry.core.worldgen.WorldGenBase; +import forestry.plugins.PluginArboriculture; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.gen.feature.WorldGenerator; + +public final class TreeGenHelper { + + public static WorldGenerator getWorldGen(String treeName, EntityPlayer player, int x, int y, int z) { + ITreeGenome treeGenome = getTreeGenome(treeName); + if (treeGenome == null) { + return null; + } + + ITree tree = PluginArboriculture.treeInterface.getTree(player.worldObj, treeGenome); + return tree.getTreeGenerator(player.worldObj, x, y, z, true); + } + + public static void generateTree(WorldGenerator gen, EntityPlayer player, int x, int y, int z) { + if (gen instanceof WorldGenBase) { + ((WorldGenBase) gen).generate(player.worldObj, player.worldObj.rand, x, y, z, true); + } else { + gen.generate(player.worldObj, player.worldObj.rand, x, y, z); + } + } + + private static ITreeGenome getTreeGenome(String speciesName) { + IAlleleTreeSpecies species = null; + + for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) { + + if (!uid.equals(speciesName)) + continue; + + IAllele allele = AlleleManager.alleleRegistry.getAllele(uid); + if (allele instanceof IAlleleTreeSpecies) { + species = (IAlleleTreeSpecies) allele; + break; + } + } + + if (species == null) { + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) { + if (allele instanceof IAlleleTreeSpecies && allele.getName().replaceAll("\\s", "").equals(speciesName)) { + species = (IAlleleTreeSpecies) allele; + break; + } + } + } + + if (species == null) + throw new SpeciesNotFoundException(speciesName); + + IAllele[] template = PluginArboriculture.treeInterface.getTemplate(species.getUID()); + + if (template == null) + throw new TemplateNotFoundException(species); + + return PluginArboriculture.treeInterface.templateAsGenome(template); + } +} diff --git a/src/main/java/forestry/arboriculture/commands/TreeModeHelper.java b/src/main/java/forestry/arboriculture/commands/TreeModeHelper.java new file mode 100644 index 000000000..cf84d8016 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/TreeModeHelper.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import forestry.api.arboriculture.ITreekeepingMode; +import forestry.core.commands.ICommandModeHelper; +import forestry.plugins.PluginArboriculture; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.world.World; + +public class TreeModeHelper implements ICommandModeHelper { + + @Override + public String[] getModeNames() { + ArrayList treekeepingModes = PluginArboriculture.treeInterface.getTreekeepingModes(); + int modeStringCount = treekeepingModes.size(); + List modeStrings = new ArrayList(modeStringCount); + for (ITreekeepingMode mode : treekeepingModes) + modeStrings.add(mode.getName()); + + return modeStrings.toArray(new String[modeStringCount]); + } + + @Override + public String getModeNameMatching(String desired) { + ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(desired); + if (mode == null) + return null; + return mode.getName(); + } + + @Override + public String getModeName(World world) { + return PluginArboriculture.treeInterface.getTreekeepingMode(world).getName(); + } + + @Override + public void setMode(World world, String modeName) { + PluginArboriculture.treeInterface.setTreekeepingMode(world, modeName); + } + + @Override + public Iterable getDescription(String modeName) { + ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(modeName); + return mode.getDescription(); + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/TreeSpawner.java b/src/main/java/forestry/arboriculture/commands/TreeSpawner.java new file mode 100644 index 000000000..6e47c368a --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/TreeSpawner.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class TreeSpawner implements ITreeSpawner { + + @Override + public boolean spawn(ICommandSender sender, String treeName, EntityPlayer player) { + Vec3 look = player.getLookVec(); + + int x = (int)Math.round(player.posX + (3 * look.xCoord)); + int y = (int)Math.round(player.posY); + int z = (int)Math.round(player.posZ + (3 * look.zCoord)); + + WorldGenerator gen = TreeGenHelper.getWorldGen(treeName, player, x, y, z); + if (gen == null) { + return false; + } + + TreeGenHelper.generateTree(gen, player, x, y, z); + return true; + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/TreeStatsSaveHelper.java b/src/main/java/forestry/arboriculture/commands/TreeStatsSaveHelper.java new file mode 100644 index 000000000..94f5a7f9e --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/TreeStatsSaveHelper.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import com.mojang.authlib.GameProfile; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; +import forestry.core.commands.IStatsSaveHelper; +import forestry.plugins.PluginArboriculture; +import java.util.ArrayList; +import java.util.Collection; +import net.minecraft.world.World; + +public class TreeStatsSaveHelper implements IStatsSaveHelper { + + @Override + public String getUnlocalizedSaveStatsString() { + return "for.chat.command.forestry.tree.save.stats"; + } + + @Override + public void addExtraInfo(Collection statistics, IBreedingTracker breedingTracker) { + } + + @Override + public Collection getSpecies() { + Collection species = new ArrayList(); + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) + if (allele instanceof IAlleleTreeSpecies) + species.add((IAlleleTreeSpecies) allele); + return species; + } + + @Override + public String getFileSuffix() { + return "trees"; + } + + @Override + public IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile) { + return PluginArboriculture.treeInterface.getBreedingTracker(world, gameProfile); + } + +} diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java b/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java index ade3bccf6..2d949a96f 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockArbFence.java @@ -16,11 +16,14 @@ import forestry.api.core.Tabs; import forestry.arboriculture.IWoodTyped; import forestry.arboriculture.WoodType; import forestry.plugins.PluginArboriculture; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockFence; +import net.minecraft.block.BlockFenceGate; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; @@ -28,14 +31,13 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.List; - public class BlockArbFence extends BlockFence implements IWoodTyped { public static enum FenceCat { CAT0, CAT1 } + public static final int fencesPerCat = 16; private final FenceCat cat; public BlockArbFence(FenceCat cat) { @@ -50,7 +52,8 @@ public class BlockArbFence extends BlockFence implements IWoodTyped { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { - int count = (cat == FenceCat.CAT0 ? 16 : 8); + int totalWoods = WoodType.values().length; + int count = Math.min(totalWoods - (cat.ordinal() * fencesPerCat), fencesPerCat); for (int i = 0; i < count; i++) itemList.add(new ItemStack(this, 1, i)); } @@ -69,7 +72,10 @@ public class BlockArbFence extends BlockFence implements IWoodTyped { public boolean canConnectFenceTo(IBlockAccess world, int x, int y, int z) { if (!isFence(world, x, y, z)) { Block block = world.getBlock(x, y, z); - return block != null && block.getMaterial().isOpaque() && block.renderAsNormalBlock() && block.getMaterial() != Material.gourd; + if (block == this || block instanceof BlockFenceGate) + return true; + + return block.getMaterial().isOpaque() && block.renderAsNormalBlock() && block.getMaterial() != Material.gourd; } else return true; } @@ -89,15 +95,15 @@ public class BlockArbFence extends BlockFence implements IWoodTyped { @SideOnly(Side.CLIENT) @Override public IIcon getIcon(int side, int meta) { - return getWoodType(meta).getPlankIcon(); + WoodType woodType = getWoodType(meta); + if (woodType == null) + return null; + return woodType.getPlankIcon(); } public boolean isFence(IBlockAccess world, int x, int y, int z) { Block block = world.getBlock(x, y, z); - if (PluginArboriculture.validFences.contains(block)) - return true; - - return false; + return PluginArboriculture.validFences.contains(block); } /* PROPERTIES */ @@ -123,10 +129,11 @@ public class BlockArbFence extends BlockFence implements IWoodTyped { @Override public WoodType getWoodType(int meta) { - if(cat.ordinal() * 16 + meta < WoodType.VALUES.length) - return WoodType.VALUES[cat.ordinal() * 16 + meta]; + int woodOrdinal = cat.ordinal() * fencesPerCat + meta; + if(woodOrdinal < WoodType.VALUES.length) + return WoodType.VALUES[woodOrdinal]; else - return WoodType.LARCH; + return null; } @Override diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockArbStairs.java b/src/main/java/forestry/arboriculture/gadgets/BlockArbStairs.java index 89ae9b7a8..79e379ba1 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockArbStairs.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockArbStairs.java @@ -10,9 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.api.core.Tabs; +import forestry.arboriculture.WoodType; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StackUtils; import java.util.ArrayList; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; import net.minecraft.client.renderer.texture.IIconRegister; @@ -23,17 +29,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.core.Tabs; -import forestry.arboriculture.WoodType; -import forestry.core.proxy.Proxies; -import forestry.core.utils.StackUtils; - public class BlockArbStairs extends BlockStairs { public BlockArbStairs(Block par2Block, int par3) { @@ -56,8 +55,6 @@ public class BlockArbStairs extends BlockStairs { @SideOnly(Side.CLIENT) public void getSubBlocks(Item item, CreativeTabs tab, List list) { for (WoodType type : WoodType.VALUES) { - if(!type.hasPlank) - continue; ItemStack stack = new ItemStack(item, 1, 0); NBTTagCompound compound = new NBTTagCompound(); type.saveToCompound(compound); @@ -109,6 +106,25 @@ public class BlockArbStairs extends BlockStairs { return new TileStairs(); } + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) { + ItemStack itemStack = super.getPickBlock(target, world, x, y, z, player); + NBTTagCompound stairsNBT = getTagCompoundForStairs(world, x, y, z); + itemStack.setTagCompound(stairsNBT); + return itemStack; + } + + private static NBTTagCompound getTagCompoundForStairs(IBlockAccess world, int x, int y, int z) { + TileStairs stairs = getStairTile(world, x, y, z); + + NBTTagCompound nbttagcompound = new NBTTagCompound(); + if (stairs == null || stairs.getType() == null) + return nbttagcompound; + + stairs.getType().saveToCompound(nbttagcompound); + return nbttagcompound; + } + /* ICONS */ @SideOnly(Side.CLIENT) @Override diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockFruitPod.java b/src/main/java/forestry/arboriculture/gadgets/BlockFruitPod.java index ee1fedd29..14d768c90 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockFruitPod.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockFruitPod.java @@ -10,9 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import forestry.core.utils.BlockUtil; +import forestry.core.utils.StackUtils; +import forestry.plugins.PluginArboriculture; import java.util.ArrayList; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.block.BlockCocoa; import net.minecraft.client.renderer.texture.IIconRegister; @@ -23,15 +29,6 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.BlockUtil; -import forestry.core.utils.StackUtils; -import forestry.plugins.PluginArboriculture; - public class BlockFruitPod extends BlockCocoa { public BlockFruitPod() { diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockLog.java b/src/main/java/forestry/arboriculture/gadgets/BlockLog.java index 86279c6a2..bab6b6521 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockLog.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockLog.java @@ -10,8 +10,12 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.Tabs; +import forestry.arboriculture.IWoodTyped; +import forestry.arboriculture.WoodType; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -22,21 +26,14 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.common.util.ForgeDirection; -import forestry.api.core.Tabs; -import forestry.arboriculture.IWoodTyped; -import forestry.arboriculture.WoodType; - public class BlockLog extends Block implements IWoodTyped { public enum LogCat { CAT0, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7 } + public static final short logsPerCat = 4; protected final LogCat cat; @@ -104,12 +101,9 @@ public class BlockLog extends Block implements IWoodTyped { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { - if(cat == LogCat.CAT6) { - itemList.add(new ItemStack(this, 1, 0)); - return; - } - - for (int i = 0; i < 4; i++) + int totalWoods = WoodType.values().length; + int count = Math.min(totalWoods - (cat.ordinal() * logsPerCat), logsPerCat); + for (int i = 0; i < count; i++) itemList.add(new ItemStack(this, 1, i)); } @@ -199,8 +193,9 @@ public class BlockLog extends Block implements IWoodTyped { @Override public WoodType getWoodType(int meta) { meta = getTypeFromMeta(meta); - if(meta + cat.ordinal() * 4 < WoodType.VALUES.length) - return WoodType.VALUES[meta + cat.ordinal() * 4]; + int woodOrdinal = meta + cat.ordinal() * logsPerCat; + if(woodOrdinal < WoodType.VALUES.length) + return WoodType.VALUES[woodOrdinal]; else return null; } diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java b/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java index 2404d5f62..6ebb7f3c4 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockPlanks.java @@ -10,8 +10,12 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.Tabs; +import forestry.arboriculture.IWoodTyped; +import forestry.arboriculture.WoodType; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -21,22 +25,15 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.common.util.ForgeDirection; -import forestry.api.core.Tabs; -import forestry.arboriculture.IWoodTyped; -import forestry.arboriculture.WoodType; - public class BlockPlanks extends Block implements IWoodTyped { public static enum PlankCat { CAT0, CAT1 } + public static final int planksPerCat = 16; protected final PlankCat cat; public BlockPlanks(PlankCat cat) { @@ -54,7 +51,8 @@ public class BlockPlanks extends Block implements IWoodTyped { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { - int count = (cat == PlankCat.CAT0 ? 16 : 8); + int totalWoods = WoodType.values().length; + int count = Math.min(totalWoods - (cat.ordinal() * planksPerCat), planksPerCat); for (int i = 0; i < count; i++) itemList.add(new ItemStack(this, 1, i)); } @@ -69,7 +67,10 @@ public class BlockPlanks extends Block implements IWoodTyped { @SideOnly(Side.CLIENT) @Override public IIcon getIcon(int side, int meta) { - return getWoodType(meta).getPlankIcon(); + WoodType woodType = getWoodType(meta); + if (woodType == null) + return null; + return woodType.getPlankIcon(); } @Override @@ -105,10 +106,11 @@ public class BlockPlanks extends Block implements IWoodTyped { @Override public WoodType getWoodType(int meta) { - if(cat.ordinal() * 16 + meta < WoodType.VALUES.length) - return WoodType.VALUES[cat.ordinal() * 16 + meta]; + int woodOrdinal = cat.ordinal() * planksPerCat + meta; + if(woodOrdinal < WoodType.VALUES.length) + return WoodType.VALUES[woodOrdinal]; else - return WoodType.LARCH; + return null; } @Override diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java b/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java index 0c1365832..2b043f5ae 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockSapling.java @@ -10,8 +10,18 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.IAlleleFruit; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import forestry.core.utils.StackUtils; +import forestry.plugins.PluginArboriculture; import java.util.ArrayList; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -24,19 +34,6 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.arboriculture.EnumGermlingType; -import forestry.api.arboriculture.IAlleleFruit; -import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAllele; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.StackUtils; -import forestry.plugins.PluginArboriculture; - public class BlockSapling extends BlockTreeContainer { public static TileSapling getSaplingTile(IBlockAccess world, int x, int y, int z) { @@ -133,6 +130,7 @@ public class BlockSapling extends BlockTreeContainer { @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbour) { + super.onNeighborBlockChange(world, x, y, z, neighbour); if (Proxies.common.isSimulating(world) && !this.canBlockStay(world, x, y, z)) { dropAsSapling(world, x, y, z); world.setBlockToAir(x, y, z); @@ -147,7 +145,7 @@ public class BlockSapling extends BlockTreeContainer { } @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) { TileSapling sapling = getSaplingTile(world, x, y, z); if (sapling == null || sapling.getTree() == null) return null; diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java b/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java index 7f6e61789..0c3ad2497 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockSlab.java @@ -23,11 +23,11 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.core.Tabs; import forestry.arboriculture.IWoodTyped; import forestry.arboriculture.WoodType; @@ -35,9 +35,10 @@ import forestry.arboriculture.WoodType; public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyped { public static enum SlabCat { - CAT0, CAT1, CAT2 + CAT0, CAT1, CAT2, CAT3 } + public static final int slabsPerCat = 8; private final SlabCat cat; public BlockSlab(SlabCat cat) { @@ -64,7 +65,9 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp @Override public IIcon getIcon(int side, int meta) { - WoodType type = WoodType.VALUES[(8 * cat.ordinal()) + (meta & 7)]; + WoodType type = getWoodType(meta); + if (type == null) + return null; return type.getPlankIcon(); } @@ -73,21 +76,6 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp return Item.getItemFromBlock(this); } - /** - * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) - */ - /*public int idPicked(World world, int x, int y, int z) { - return blockID; - }*/ - - /** - * Get the block's damage value (for use with pick block). - */ - @Override - public int getDamageValue(World world, int x, int y, int z) { - return super.getDamageValue(world, x, y, z) & 7; - } - @Override protected ItemStack createStackedBlock(int meta) { return new ItemStack(Blocks.wooden_slab, 2, meta & 7); @@ -101,8 +89,10 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { - for (int i = 0; i < 8; ++i) - itemList.add(new ItemStack(item, 1, i)); + int totalWoods = WoodType.values().length; + int count = Math.min(totalWoods - (cat.ordinal() * slabsPerCat), slabsPerCat); + for (int i = 0; i < count; i++) + itemList.add(new ItemStack(this, 1, i)); } /* PROPERTIES */ @@ -123,10 +113,11 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp @Override public WoodType getWoodType(int meta) { - if(meta + cat.ordinal() * 8 < WoodType.VALUES.length) - return WoodType.VALUES[meta + cat.ordinal() * 8]; + int woodOrdinal = (meta % slabsPerCat) + cat.ordinal() * slabsPerCat; + if(woodOrdinal < WoodType.VALUES.length) + return WoodType.VALUES[woodOrdinal]; else - return WoodType.LARCH; + return null; } @Override @@ -138,4 +129,11 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp public boolean getUseNeighborBrightness() { return true; } + + // Minecraft's BlockSlab overrides this for their slabs, so we change it back to normal here + @Override + @SideOnly(Side.CLIENT) + public Item getItem(World world, int x, int y, int z) { + return Item.getItemFromBlock(this); + } } diff --git a/src/main/java/forestry/arboriculture/gadgets/BlockTreeContainer.java b/src/main/java/forestry/arboriculture/gadgets/BlockTreeContainer.java index 897f98536..ac5f3cc30 100755 --- a/src/main/java/forestry/arboriculture/gadgets/BlockTreeContainer.java +++ b/src/main/java/forestry/arboriculture/gadgets/BlockTreeContainer.java @@ -11,7 +11,6 @@ package forestry.arboriculture.gadgets; import java.util.Random; - import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.tileentity.TileEntity; diff --git a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java index 652a3b447..29d675ab6 100644 --- a/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/ForestryBlockLeaves.java @@ -24,6 +24,10 @@ import forestry.core.render.TextureManager; import forestry.core.utils.StackUtils; import forestry.plugins.PluginArboriculture; import forestry.plugins.PluginLepidopterology; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; import net.minecraft.block.BlockNewLeaf; import net.minecraft.block.ITileEntityProvider; import net.minecraft.client.renderer.texture.IIconRegister; @@ -40,11 +44,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; - public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProvider { public ForestryBlockLeaves() { @@ -59,10 +58,9 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv public static TileLeaves getLeafTile(IBlockAccess world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); - if (!(tile instanceof TileLeaves)) - return null; - - return (TileLeaves) tile; + if (tile instanceof TileLeaves) + return (TileLeaves) tile; + return null; } private static NBTTagCompound getTagCompoundForTree(IBlockAccess world, int x, int y, int z) { @@ -153,9 +151,9 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv } @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) { - ItemStack itemStack = super.getPickBlock(target, world, x, y, z); + ItemStack itemStack = super.getPickBlock(target, world, x, y, z, player); NBTTagCompound treeNBT = getTagCompoundForTree(world, x, y, z); itemStack.setTagCompound(treeNBT); return itemStack; @@ -179,10 +177,12 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv @Override public void beginLeavesDecay(World world, int x, int y, int z) { - if (getLeafTile(world, x, y, z).isDecorative()) + TileLeaves tile = getLeafTile(world, x, y, z); + if (tile == null || tile.isDecorative()) return; super.beginLeavesDecay(world, x, y, z); } + @Override public void updateTick(World world, int x, int y, int z, Random random) { @@ -192,6 +192,10 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv super.updateTick(world, x, y, z, random); + // check leaves tile again because they can decay in super.updateTick + if (tileLeaves.isInvalid()) + return; + if (world.rand.nextFloat() > 0.1) return; tileLeaves.onBlockTick(); @@ -287,7 +291,7 @@ public class ForestryBlockLeaves extends BlockNewLeaf implements ITileEntityProv ItemStack heldItem = player.getHeldItem(); TileEntity tile = world.getTileEntity(x, y, z); IButterfly caterpillar = tile instanceof TileLeaves ? ((TileLeaves) tile).getCaterpillar() : null; - if(heldItem != null && (heldItem.getItem() instanceof IToolScoop) && caterpillar != null) { + if (heldItem != null && (heldItem.getItem() instanceof IToolScoop) && caterpillar != null) { ItemStack butterfly = PluginLepidopterology.butterflyInterface.getMemberStack(caterpillar, EnumFlutterType.CATERPILLAR.ordinal()); StackUtils.dropItemStackAsEntity(butterfly, world, x, y, z); ((TileLeaves) tile).setCaterpillar(null); diff --git a/src/main/java/forestry/arboriculture/gadgets/TileFruitPod.java b/src/main/java/forestry/arboriculture/gadgets/TileFruitPod.java index 90834d341..fd3599612 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileFruitPod.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileFruitPod.java @@ -10,19 +10,8 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.arboriculture.IAlleleFruit; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; @@ -35,6 +24,14 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruitBearer { diff --git a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java index 21c07f8ce..095aeb2f8 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileLeaves.java @@ -10,16 +10,34 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; + import com.mojang.authlib.GameProfile; + +import net.minecraftforge.common.EnumPlantType; + import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + import forestry.api.arboriculture.IAlleleFruit; import forestry.api.arboriculture.IFruitProvider; import forestry.api.arboriculture.ILeafTickHandler; import forestry.api.arboriculture.ITree; -import forestry.api.core.EnumErrorCode; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; +import forestry.api.core.IErrorState; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IEffectData; import forestry.api.genetics.IFruitBearer; @@ -30,26 +48,15 @@ import forestry.api.lepidopterology.IButterfly; import forestry.api.lepidopterology.IButterflyNursery; import forestry.api.lepidopterology.IButterflyRoot; import forestry.arboriculture.network.PacketLeafUpdate; +import forestry.arboriculture.network.PacketRipeningUpdate; +import forestry.core.utils.GeneticsUtil; +import forestry.core.EnumErrorCode; import forestry.core.genetics.Allele; import forestry.core.network.ForestryPacket; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.core.utils.Utils; import forestry.plugins.PluginArboriculture; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.EnumPlantType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.EnumSet; public class TileLeaves extends TileTreeContainer implements IPollinatable, IFruitBearer, IButterflyNursery { @@ -175,7 +182,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru } public int getFoliageColour(EntityPlayer player) { - return isPollinatedState & Utils.hasNaturalistEye(player) ? 0xffffff : colourLeaves; + return isPollinatedState & GeneticsUtil.hasNaturalistEye(player) ? 0xffffff : colourLeaves; } public int getFruitColour() { @@ -306,27 +313,26 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru } private void sendNetworkUpdateRipening() { - Proxies.net.sendNetworkPacket(new PacketLeafUpdate(this, determineFruitColour()), xCoord, yCoord, zCoord); + Proxies.net.sendNetworkPacket(new PacketRipeningUpdate(this, determineFruitColour()), xCoord, yCoord, zCoord); } @Override public void fromPacket(ForestryPacket packetRaw) { + super.fromPacket(packetRaw); PacketLeafUpdate packet = (PacketLeafUpdate)packetRaw; - if(packet.isRipeningUpdate()) { - colourFruits = packet.colourFruits; - } else { - readFromNBT(packet.getTagCompound()); - isFruitLeaf = packet.isFruitLeaf(); - isPollinatedState = packet.isPollinated(); - textureIndexFancy = packet.textureIndexFancy; - textureIndexPlain = packet.textureIndexPlain; - textureIndexFruits = packet.textureIndexFruit; - colourLeaves = packet.colourLeaves; - colourFruits = packet.colourFruits; - } - worldObj.func_147479_m(xCoord, yCoord, zCoord); + isFruitLeaf = packet.isFruitLeaf(); + isPollinatedState = packet.isPollinated(); + textureIndexFancy = packet.textureIndexFancy; + textureIndexPlain = packet.textureIndexPlain; + textureIndexFruits = packet.textureIndexFruit; + colourLeaves = packet.colourLeaves; + colourFruits = packet.colourFruits; + } + + public void fromRipeningPacket(PacketRipeningUpdate packet) { + colourFruits = packet.colourFruits; } /** @@ -335,9 +341,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru **/ @Override public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z) { - if (!Block.isEqualTo(oldBlock, newBlock)) - return true; - return false; + return !Block.isEqualTo(oldBlock, newBlock); } /* IFRUITBEARER */ @@ -442,7 +446,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru @Override public void setErrorState(int state) {} @Override - public void setErrorState(EnumErrorCode state) { + public void setErrorState(IErrorState state) { } @Override public int getErrorOrdinal() { return 0; } diff --git a/src/main/java/forestry/arboriculture/gadgets/TileSapling.java b/src/main/java/forestry/arboriculture/gadgets/TileSapling.java index 93e5f5968..39bc6c663 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileSapling.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileSapling.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; +import forestry.plugins.PluginArboriculture; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.gen.feature.WorldGenerator; -import forestry.plugins.PluginArboriculture; - public class TileSapling extends TileTreeContainer { private int timesTicked = 0; diff --git a/src/main/java/forestry/arboriculture/gadgets/TileStairs.java b/src/main/java/forestry/arboriculture/gadgets/TileStairs.java index 7af38b34b..d659b1766 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileStairs.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileStairs.java @@ -10,16 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.gadgets; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; -import net.minecraft.tileentity.TileEntity; - import forestry.arboriculture.WoodType; import forestry.core.network.ForestryPacket; import forestry.core.network.INetworkedEntity; import forestry.core.network.PacketIds; import forestry.core.network.PacketTileNBT; import forestry.core.proxy.Proxies; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.tileentity.TileEntity; public class TileStairs extends TileEntity implements INetworkedEntity { diff --git a/src/main/java/forestry/arboriculture/gadgets/TileTreeContainer.java b/src/main/java/forestry/arboriculture/gadgets/TileTreeContainer.java index ecc93c0bb..30207dc41 100755 --- a/src/main/java/forestry/arboriculture/gadgets/TileTreeContainer.java +++ b/src/main/java/forestry/arboriculture/gadgets/TileTreeContainer.java @@ -119,16 +119,6 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked return true; } - @Override - public boolean allowsInteraction(EntityPlayer player) { - return true; - } - - @Override - public EnumAccess getAccess() { - return EnumAccess.SHARED; - } - @Override public boolean isOwnable() { return false; @@ -158,9 +148,4 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked return PlayerUtil.isSameGameProfile(owner, player.getGameProfile()); } - @Override - public boolean switchAccessRule(EntityPlayer player) { - return false; - } - } diff --git a/src/main/java/forestry/arboriculture/genetics/AlleleLeafEffectNone.java b/src/main/java/forestry/arboriculture/genetics/AlleleLeafEffectNone.java index 8013dc1ae..e6e8dde43 100755 --- a/src/main/java/forestry/arboriculture/genetics/AlleleLeafEffectNone.java +++ b/src/main/java/forestry/arboriculture/genetics/AlleleLeafEffectNone.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; - import forestry.api.arboriculture.IAlleleLeafEffect; import forestry.api.arboriculture.ITreeGenome; import forestry.api.genetics.IEffectData; import forestry.core.genetics.Allele; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; public class AlleleLeafEffectNone extends Allele implements IAlleleLeafEffect { diff --git a/src/main/java/forestry/arboriculture/genetics/AlleleTreeSpecies.java b/src/main/java/forestry/arboriculture/genetics/AlleleTreeSpecies.java index d42d2e990..16144fe76 100755 --- a/src/main/java/forestry/arboriculture/genetics/AlleleTreeSpecies.java +++ b/src/main/java/forestry/arboriculture/genetics/AlleleTreeSpecies.java @@ -10,21 +10,8 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import java.util.ArrayList; -import java.util.HashMap; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.WorldGenerator; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.IAlleleTreeSpecies; @@ -43,6 +30,15 @@ import forestry.core.config.ForestryItem; import forestry.core.genetics.AlleleSpecies; import forestry.core.render.TextureManager; import forestry.core.utils.Utils; +import java.util.ArrayList; +import java.util.HashMap; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; +import net.minecraftforge.common.EnumPlantType; public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpecies, IIconProvider { @@ -144,7 +140,7 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci int highest = 0; exclude.add(species); - for(IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES.ordinal())) { + for(IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES)) { if(!exclude.contains(mutation.getAllele0())) { int otherAdvance = getGeneticAdvancement(mutation.getAllele0(), exclude); if(otherAdvance > highest) diff --git a/src/main/java/forestry/arboriculture/genetics/ArboristTracker.java b/src/main/java/forestry/arboriculture/genetics/ArboristTracker.java index 35ff15bd4..eb42b0197 100755 --- a/src/main/java/forestry/arboriculture/genetics/ArboristTracker.java +++ b/src/main/java/forestry/arboriculture/genetics/ArboristTracker.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import net.minecraft.entity.player.EntityPlayer; - import com.mojang.authlib.GameProfile; - import forestry.api.arboriculture.IArboristTracker; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.IIndividual; import forestry.core.genetics.BreedingTracker; import forestry.plugins.PluginArboriculture; +import net.minecraft.entity.player.EntityPlayer; public class ArboristTracker extends BreedingTracker implements IArboristTracker { diff --git a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java index 9f367b6d2..a180dce2d 100755 --- a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java +++ b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java @@ -10,18 +10,17 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import forestry.core.utils.StringUtil; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - import forestry.api.arboriculture.EnumGrowthConditions; import forestry.api.arboriculture.IGrowthProvider; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.ITreeGenome; import forestry.arboriculture.gadgets.TileSapling; +import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; public class GrowthProvider implements IGrowthProvider { diff --git a/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java b/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java index 2c3125665..879e4e892 100755 --- a/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java +++ b/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java @@ -10,14 +10,12 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import java.util.EnumSet; - -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.World; - import forestry.api.arboriculture.EnumGrowthConditions; import forestry.api.arboriculture.ITreeGenome; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; public class GrowthProviderTropical extends GrowthProvider { diff --git a/src/main/java/forestry/arboriculture/genetics/Tree.java b/src/main/java/forestry/arboriculture/genetics/Tree.java index 993d6150a..022794d3b 100755 --- a/src/main/java/forestry/arboriculture/genetics/Tree.java +++ b/src/main/java/forestry/arboriculture/genetics/Tree.java @@ -31,9 +31,14 @@ import forestry.core.genetics.Chromosome; import forestry.core.genetics.Individual; import forestry.core.utils.StringUtil; import forestry.plugins.PluginArboriculture; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -42,11 +47,6 @@ import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.List; - public class Tree extends Individual implements ITree, ITreeGenData, IPlantable { private ITreeGenome genome; @@ -108,7 +108,7 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable /* EFFECTS */ @Override public IEffectData[] doEffect(IEffectData[] storedData, World world, int biomeid, int x, int y, int z) { - IAlleleLeafEffect effect = (IAlleleLeafEffect) getGenome().getActiveAllele(EnumTreeChromosome.EFFECT.ordinal()); + IAlleleLeafEffect effect = (IAlleleLeafEffect) getGenome().getActiveAllele(EnumTreeChromosome.EFFECT); if (effect == null) return null; @@ -119,7 +119,7 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable if (!effect.isCombinable()) return storedData; - IAlleleLeafEffect secondary = (IAlleleLeafEffect) getGenome().getInactiveAllele(EnumTreeChromosome.EFFECT.ordinal()); + IAlleleLeafEffect secondary = (IAlleleLeafEffect) getGenome().getInactiveAllele(EnumTreeChromosome.EFFECT); if (!secondary.isCombinable()) return storedData; @@ -219,10 +219,7 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable return false; Collection suitable = genome.getPrimary().getSuitableFruit(); - if (!suitable.contains(provider.getFamily())) - return false; - - return true; + return suitable.contains(provider.getFamily()); } @Override @@ -255,7 +252,7 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable @Override public boolean isPureBred(EnumTreeChromosome chromosome) { - return genome.getActiveAllele(chromosome.ordinal()).getUID().equals(genome.getInactiveAllele(chromosome.ordinal()).getUID()); + return genome.getActiveAllele(chromosome).getUID().equals(genome.getInactiveAllele(chromosome).getUID()); } @Override @@ -278,22 +275,28 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable IAlleleTreeSpecies primary = genome.getPrimary(); IAlleleTreeSpecies secondary = genome.getSecondary(); if (!isPureBred(EnumTreeChromosome.SPECIES)) - list.add("\u00A79" + StringUtil.localize("trees.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); - list.add(String.format("\u00A76S: %s, \u00A7cM: %s", genome.getActiveAllele(EnumTreeChromosome.SAPPINESS.ordinal()).getName(), genome.getActiveAllele(EnumTreeChromosome.MATURATION.ordinal()).getName())); - list.add(String.format("\u00A7dH: %s, \u00A7bG: %sx%s", genome.getActiveAllele(EnumTreeChromosome.HEIGHT.ordinal()).getName(), genome.getGirth(), genome.getGirth())); + list.add(EnumChatFormatting.BLUE + StringUtil.localize("trees.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); - list.add(String.format("\u00A7eS: %s, \u00A7fY: %s", genome.getActiveAllele(EnumTreeChromosome.FERTILITY.ordinal()).getName(), genome.getActiveAllele(EnumTreeChromosome.YIELD.ordinal()).getName())); + String sappiness = EnumChatFormatting.GOLD + "S: " + genome.getActiveAllele(EnumTreeChromosome.SAPPINESS).getName(); + String maturation = EnumChatFormatting.RED + "M: " + genome.getActiveAllele(EnumTreeChromosome.MATURATION).getName(); + String height = EnumChatFormatting.LIGHT_PURPLE + "H: " + genome.getActiveAllele(EnumTreeChromosome.HEIGHT).getName(); + String girth = EnumChatFormatting.AQUA + "G: " + String.format("%sx%s", genome.getGirth(), genome.getGirth()); + String saplings = EnumChatFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getName(); + String yield = EnumChatFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getName(); + list.add(String.format("%s, %s", saplings, maturation)); + list.add(String.format("%s, %s", height, girth)); + list.add(String.format("%s, %s", yield, sappiness)); - IAlleleBoolean primaryFireproof = (IAlleleBoolean)genome.getActiveAllele(EnumTreeChromosome.FIREPROOF.ordinal()); + IAlleleBoolean primaryFireproof = (IAlleleBoolean)genome.getActiveAllele(EnumTreeChromosome.FIREPROOF); if (primaryFireproof.getValue()) - list.add(String.format("\u00A7c%s", StatCollector.translateToLocal("for.gui.fireresist"))); + list.add(EnumChatFormatting.RED + StatCollector.translateToLocal("for.gui.fireresist")); - IAllele fruit = getGenome().getActiveAllele(EnumTreeChromosome.FRUITS.ordinal()); + IAllele fruit = getGenome().getActiveAllele(EnumTreeChromosome.FRUITS); if(fruit != Allele.fruitNone) { String strike = ""; if (!canBearFruit()) - strike = "\u00A7m"; - list.add(strike + "\u00A7aF: " + StringUtil.localize(genome.getFruitProvider().getDescription())); + strike = EnumChatFormatting.STRIKETHROUGH.toString(); + list.add(strike + EnumChatFormatting.GREEN + "F: " + StringUtil.localize(genome.getFruitProvider().getDescription())); } } @@ -361,18 +364,17 @@ public class Tree extends Individual implements ITree, ITreeGenData, IPlantable } for (ITreeMutation mutation : PluginArboriculture.treeInterface.getMutations(true)) { - float chance = 0; // Stop blacklisted species. // if (BeeManager.breedingManager.isBlacklisted(mutation.getTemplate()[0].getUID())) { // continue; // } - - if ((chance = mutation.getChance(world, x, y, z, allele0, allele1, genome0, genome1)) > 0) - if (world.rand.nextFloat()*100 < chance) - // IApiaristTracker breedingTracker = BeeManager.breedingManager.getApiaristTracker(world); - // breedingTracker.registerMutation(mutation); - return PluginArboriculture.treeInterface.templateAsChromosomes(mutation.getTemplate()); + float chance = mutation.getChance(world, x, y, z, allele0, allele1, genome0, genome1); + if (chance > world.rand.nextFloat() * 100) { + // IApiaristTracker breedingTracker = BeeManager.breedingManager.getApiaristTracker(world); + // breedingTracker.registerMutation(mutation); + return PluginArboriculture.treeInterface.templateAsChromosomes(mutation.getTemplate()); + } } return null; diff --git a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java index d569fe62f..73f571436 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java @@ -10,13 +10,6 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import java.util.EnumSet; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; import forestry.api.arboriculture.IAlleleGrowth; @@ -35,6 +28,10 @@ import forestry.core.genetics.AllelePlantType; import forestry.core.genetics.Chromosome; import forestry.core.genetics.Genome; import forestry.plugins.PluginArboriculture; +import java.util.EnumSet; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.EnumPlantType; public class TreeGenome extends Genome implements ITreeGenome { @@ -48,7 +45,7 @@ public class TreeGenome extends Genome implements ITreeGenome { // NBT RETRIEVAL public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) { - IAllele speciesAllele = Genome.getPrimaryAllele(itemStack, EnumTreeChromosome.SPECIES); + IAllele speciesAllele = Genome.getActiveAllele(itemStack, EnumTreeChromosome.SPECIES); if (speciesAllele instanceof IAlleleTreeSpecies) return (IAlleleTreeSpecies)speciesAllele; else @@ -57,37 +54,37 @@ public class TreeGenome extends Genome implements ITreeGenome { @Override public IAlleleTreeSpecies getPrimary() { - return (IAlleleTreeSpecies) getActiveAllele(EnumTreeChromosome.SPECIES.ordinal()); + return (IAlleleTreeSpecies) getActiveAllele(EnumTreeChromosome.SPECIES); } @Override public IAlleleTreeSpecies getSecondary() { - return (IAlleleTreeSpecies) getInactiveAllele(EnumTreeChromosome.SPECIES.ordinal()); + return (IAlleleTreeSpecies) getInactiveAllele(EnumTreeChromosome.SPECIES); } @Override public IFruitProvider getFruitProvider() { - return ((IAlleleFruit) getActiveAllele(EnumTreeChromosome.FRUITS.ordinal())).getProvider(); + return ((IAlleleFruit) getActiveAllele(EnumTreeChromosome.FRUITS)).getProvider(); } @Override public IGrowthProvider getGrowthProvider() { - return ((IAlleleGrowth) getActiveAllele(EnumTreeChromosome.GROWTH.ordinal())).getProvider(); + return ((IAlleleGrowth) getActiveAllele(EnumTreeChromosome.GROWTH)).getProvider(); } @Override public float getHeight() { - return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.HEIGHT.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.HEIGHT)).getValue(); } @Override public float getFertility() { - return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.FERTILITY.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.FERTILITY)).getValue(); } @Override public float getYield() { - return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.YIELD.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.YIELD)).getValue(); } @Override @@ -96,7 +93,7 @@ public class TreeGenome extends Genome implements ITreeGenome { if (getChromosomes()[EnumTreeChromosome.SAPPINESS.ordinal()] == null) getChromosomes()[EnumTreeChromosome.SAPPINESS.ordinal()] = new Chromosome(Allele.sappinessLowest); - IAllele allele = getActiveAllele(EnumTreeChromosome.SAPPINESS.ordinal()); + IAllele allele = getActiveAllele(EnumTreeChromosome.SAPPINESS); // FIXME: More legacy handling if (allele instanceof IAlleleFloat) return ((IAlleleFloat) allele).getValue(); @@ -109,10 +106,10 @@ public class TreeGenome extends Genome implements ITreeGenome { @Override public EnumSet getPlantTypes() { // / FIXME: Needs some legacy handling. - if (!(getActiveAllele(EnumTreeChromosome.PLANT.ordinal()) instanceof AllelePlantType)) + if (!(getActiveAllele(EnumTreeChromosome.PLANT) instanceof AllelePlantType)) getChromosomes()[EnumTreeChromosome.PLANT.ordinal()] = new Chromosome(Allele.plantTypeNone); - return ((AllelePlantType) getActiveAllele(EnumTreeChromosome.PLANT.ordinal())).getPlantTypes(); + return ((AllelePlantType) getActiveAllele(EnumTreeChromosome.PLANT)).getPlantTypes(); } @Override @@ -120,7 +117,7 @@ public class TreeGenome extends Genome implements ITreeGenome { if (getChromosomes()[EnumTreeChromosome.MATURATION.ordinal()] == null) getChromosomes()[EnumTreeChromosome.MATURATION.ordinal()] = new Chromosome(Allele.maturationSlowest); - return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.MATURATION.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.MATURATION)).getValue(); } private IAllele translateGirth(int girth) { @@ -136,12 +133,12 @@ public class TreeGenome extends Genome implements ITreeGenome { @Override public int getGirth() { - return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.GIRTH.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.GIRTH)).getValue(); } @Override public IAlleleLeafEffect getEffect() { - return (IAlleleLeafEffect) getActiveAllele(EnumTreeChromosome.EFFECT.ordinal()); + return (IAlleleLeafEffect) getActiveAllele(EnumTreeChromosome.EFFECT); } @Override diff --git a/src/main/java/forestry/arboriculture/genetics/TreeHelper.java b/src/main/java/forestry/arboriculture/genetics/TreeHelper.java index 03150c448..a1e7d6cdc 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeHelper.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeHelper.java @@ -13,7 +13,6 @@ package forestry.arboriculture.genetics; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.Locale; import java.util.Map.Entry; @@ -25,10 +24,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import cpw.mods.fml.common.FMLCommonHandler; - import com.mojang.authlib.GameProfile; +import cpw.mods.fml.common.FMLCommonHandler; + import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; @@ -46,6 +45,7 @@ import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IMutation; import forestry.arboriculture.gadgets.BlockFruitPod; +import forestry.arboriculture.gadgets.ForestryBlockLeaves; import forestry.arboriculture.gadgets.TileFruitPod; import forestry.arboriculture.gadgets.TileLeaves; import forestry.arboriculture.gadgets.TileSapling; @@ -83,9 +83,7 @@ public class TreeHelper extends SpeciesRoot implements ITreeRoot { public int getSpeciesCount() { if (treeSpeciesCount < 0) { treeSpeciesCount = 0; - Iterator> it = AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); + for (Entry entry : AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet()) { if (entry.getValue() instanceof IAlleleTreeSpecies) if (((IAlleleTreeSpecies) entry.getValue()).isCounted()) treeSpeciesCount++; @@ -217,20 +215,19 @@ public class TreeHelper extends SpeciesRoot implements ITreeRoot { if (!ForestryBlock.leaves.isBlockEqual(world, x, y, z)) return false; - TileLeaves tileLeaves = new TileLeaves(); - tileLeaves.setTree((ITree) tree.copy()); - tileLeaves.setOwner(owner); - if (decorative) - tileLeaves.setDecorative(); - - world.setTileEntity(x, y, z, tileLeaves); - - TileEntity tile = world.getTileEntity(x, y, z); - if (!(tile instanceof TileLeaves)) { + TileEntity tile = ForestryBlockLeaves.getLeafTile(world, x, y, z); + if (tile == null) { world.setBlockToAir(x, y, z); return false; } + TileLeaves tileLeaves = (TileLeaves) tile; + tileLeaves.setOwner(owner); + tileLeaves.setTree((ITree) tree.copy()); + if (decorative) + tileLeaves.setDecorative(); + world.markBlockForUpdate(x, y, z); + return true; } diff --git a/src/main/java/forestry/arboriculture/genetics/TreeMutation.java b/src/main/java/forestry/arboriculture/genetics/TreeMutation.java index 043572ee5..2ebaadb06 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeMutation.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeMutation.java @@ -10,9 +10,6 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; - import forestry.api.arboriculture.ITreeGenome; import forestry.api.arboriculture.ITreeMutation; import forestry.api.arboriculture.ITreeRoot; @@ -21,6 +18,8 @@ import forestry.api.genetics.IAllele; import forestry.api.genetics.IGenome; import forestry.core.genetics.Mutation; import forestry.plugins.PluginArboriculture; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; public class TreeMutation extends Mutation implements ITreeMutation { diff --git a/src/main/java/forestry/arboriculture/genetics/TreeTemplates.java b/src/main/java/forestry/arboriculture/genetics/TreeTemplates.java index 13e0d11ad..bfe6e893e 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeTemplates.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeTemplates.java @@ -64,6 +64,11 @@ public class TreeTemplates { public static IMutation papayaA; public static IMutation dateA; + public static IMutation ipeA; + public static TreeMutation padaukA; + public static TreeMutation cocoboloA; + public static TreeMutation zebrawoodA; + /* TEMPLATES */ public static IAllele[] getDefaultTemplate() { IAllele[] alleles = new IAllele[EnumTreeChromosome.values().length]; @@ -376,6 +381,38 @@ public class TreeTemplates { return alleles; } + public static IAllele[] getIpeTemplate() { + IAllele[] alleles = getDefaultTemplate(); + alleles[EnumTreeChromosome.SPECIES.ordinal()] = Allele.treeIpe; + alleles[EnumTreeChromosome.SAPPINESS.ordinal()] = Allele.sappinessLower; + alleles[EnumTreeChromosome.HEIGHT.ordinal()] = Allele.heightLarge; + alleles[EnumTreeChromosome.GIRTH.ordinal()] = Allele.int2; + return alleles; + } + + public static IAllele[] getPadaukTemplate() { + IAllele[] alleles = getDefaultTemplate(); + alleles[EnumTreeChromosome.SPECIES.ordinal()] = Allele.treePadauk; + alleles[EnumTreeChromosome.SAPPINESS.ordinal()] = Allele.sappinessLower; + alleles[EnumTreeChromosome.HEIGHT.ordinal()] = Allele.heightLarge; + return alleles; + } + + public static IAllele[] getCocoboloTemplate() { + IAllele[] alleles = getDefaultTemplate(); + alleles[EnumTreeChromosome.SPECIES.ordinal()] = Allele.treeCocobolo; + alleles[EnumTreeChromosome.HEIGHT.ordinal()] = Allele.heightLargest; + return alleles; + } + + public static IAllele[] getZebrawoodTemplate() { + IAllele[] alleles = getDefaultTemplate(); + alleles[EnumTreeChromosome.SPECIES.ordinal()] = Allele.treeZebrawood; + alleles[EnumTreeChromosome.HEIGHT.ordinal()] = Allele.heightLarge; + alleles[EnumTreeChromosome.GIRTH.ordinal()] = Allele.int2; + return alleles; + } + // / HELPER FUNCTIONS public static Chromosome[] templateAsChromosomes(IAllele[] template) { diff --git a/src/main/java/forestry/arboriculture/genetics/TreekeepingMode.java b/src/main/java/forestry/arboriculture/genetics/TreekeepingMode.java index e7083d3d9..04e623520 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreekeepingMode.java +++ b/src/main/java/forestry/arboriculture/genetics/TreekeepingMode.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import java.util.ArrayList; -import java.util.Locale; - import forestry.api.arboriculture.ITreeGenome; import forestry.api.arboriculture.ITreekeepingMode; +import java.util.ArrayList; +import java.util.Locale; public class TreekeepingMode implements ITreekeepingMode { diff --git a/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java b/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java deleted file mode 100755 index 6d92cae38..000000000 --- a/src/main/java/forestry/arboriculture/gui/ContainerTreealyzer.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture.gui; - -import forestry.api.genetics.AlleleManager; -import forestry.core.gui.ContainerAlyzer; -import forestry.core.config.ForestryItem; -import forestry.arboriculture.items.ItemGermlingGE; -import forestry.arboriculture.items.ItemTreealyzer.TreealyzerInventory; - -import net.minecraft.entity.player.InventoryPlayer; -import org.apache.commons.lang3.ArrayUtils; - -public class ContainerTreealyzer extends ContainerAlyzer { - - TreealyzerInventory inventory; - private static Object[] acceptedEnergy = new Object[] {ForestryItem.honeydew, ForestryItem.honeyDrop}; - private static Object[] acceptedSpecimens = ArrayUtils.addAll(AlleleManager.ersatzSaplings.keySet().toArray(), ItemGermlingGE.class); - - public ContainerTreealyzer(InventoryPlayer inventoryplayer, TreealyzerInventory inventory) { - super(inventoryplayer, inventory, acceptedEnergy, acceptedSpecimens); - } - -} diff --git a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java index bae895bae..3a4bd1058 100755 --- a/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java +++ b/src/main/java/forestry/arboriculture/gui/GuiTreealyzer.java @@ -4,20 +4,29 @@ * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.txt - * + * * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ package forestry.arboriculture.gui; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import net.minecraftforge.common.EnumPlantType; + import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; import forestry.api.arboriculture.IAlleleGrowth; import forestry.api.arboriculture.ITree; -import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; -import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleInteger; import forestry.api.genetics.IFruitFamily; import forestry.arboriculture.genetics.TreeGenome; @@ -27,25 +36,15 @@ import forestry.core.config.ForestryItem; import forestry.core.genetics.Allele; import forestry.core.genetics.AlleleBoolean; import forestry.core.genetics.AllelePlantType; +import forestry.core.gui.ContainerAlyzer; import forestry.core.gui.GuiAlyzer; import forestry.core.utils.StringUtil; import forestry.plugins.PluginArboriculture; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.EnumPlantType; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; public class GuiTreealyzer extends GuiAlyzer { public GuiTreealyzer(EntityPlayer player, TreealyzerInventory inventory) { - super(AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"), player, - new ContainerTreealyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - - guiName = "gui.treealyzer"; + super("rootTrees", player, new ContainerAlyzer(inventory, player), inventory, "gui.treealyzer"); ArrayList treeList = new ArrayList(); ((ItemGermlingGE) ForestryItem.sapling.item()).addCreativeItems(treeList, false); @@ -76,23 +75,23 @@ public class GuiTreealyzer extends GuiAlyzer { } switch (page) { - case 1: - drawAnalyticsPage1(tree, treeType); - break; - case 2: - drawAnalyticsPage2(tree); - break; - case 3: - drawAnalyticsPage3(tree); - break; - case 4: - drawAnalyticsPage4(tree); - break; - case 6: - drawAnalyticsPageClassification(tree); - break; - default: - drawAnalyticsOverview(); + case 1: + drawAnalyticsPage1(tree, treeType); + break; + case 2: + drawAnalyticsPage2(tree); + break; + case 3: + drawAnalyticsPage3(tree); + break; + case 4: + drawAnalyticsPage4(tree); + break; + case 6: + drawAnalyticsPageClassification(tree); + break; + default: + drawAnalyticsOverview(); } } @@ -126,58 +125,26 @@ public class GuiTreealyzer extends GuiAlyzer { } newLine(); - drawLine(StringUtil.localize("gui.saplings"), COLUMN_0); - drawLine(tree.getGenome().getActiveAllele(EnumTreeChromosome.FERTILITY.ordinal()).getName(), COLUMN_1, tree, EnumTreeChromosome.FERTILITY, false); - drawLine(tree.getGenome().getInactiveAllele(EnumTreeChromosome.FERTILITY.ordinal()).getName(), COLUMN_2, tree, - EnumTreeChromosome.FERTILITY, true); - - newLine(); - - drawRow(StringUtil.localize("gui.maturity"), tree.getGenome().getActiveAllele(EnumTreeChromosome.MATURATION.ordinal()).getName(), - tree.getGenome().getInactiveAllele(EnumTreeChromosome.MATURATION.ordinal()).getName(), tree, - EnumTreeChromosome.MATURATION); - - drawLine(StringUtil.localize("gui.height"), COLUMN_0); - drawLine(tree.getGenome().getActiveAllele(EnumTreeChromosome.HEIGHT.ordinal()).getName(), COLUMN_1, tree, EnumTreeChromosome.HEIGHT, false); - drawLine(tree.getGenome().getInactiveAllele(EnumTreeChromosome.HEIGHT.ordinal()).getName(), COLUMN_2, tree, - EnumTreeChromosome.HEIGHT, true); - - newLine(); + drawChromosomeRow(StringUtil.localize("gui.saplings"), tree, EnumTreeChromosome.FERTILITY); + drawChromosomeRow(StringUtil.localize("gui.maturity"), tree, EnumTreeChromosome.MATURATION); + drawChromosomeRow(StringUtil.localize("gui.height"), tree, EnumTreeChromosome.HEIGHT); + IAlleleInteger activeGirth = (IAlleleInteger) tree.getGenome().getActiveAllele(EnumTreeChromosome.GIRTH); + IAlleleInteger inactiveGirth = (IAlleleInteger) tree.getGenome().getInactiveAllele(EnumTreeChromosome.GIRTH); drawLine(StringUtil.localize("gui.girth"), COLUMN_0); - drawLine(String.format("%sx%s", tree.getGenome().getGirth(), tree.getGenome().getGirth()), COLUMN_1, tree, EnumTreeChromosome.FERTILITY, false); - int secondGirth = ((IAlleleInteger) tree.getGenome().getInactiveAllele(EnumTreeChromosome.GIRTH.ordinal())).getValue(); - drawLine(String.format("%sx%s", secondGirth, secondGirth), COLUMN_2, tree, EnumTreeChromosome.FERTILITY, true); + drawLine(String.format("%sx%s", activeGirth.getValue(), activeGirth.getValue()), COLUMN_1, tree, EnumTreeChromosome.GIRTH, false); + drawLine(String.format("%sx%s", inactiveGirth.getValue(), inactiveGirth.getValue()), COLUMN_2, tree, EnumTreeChromosome.GIRTH, true); newLine(); - drawLine(StringUtil.localize("gui.yield"), COLUMN_0); - drawLine(tree.getGenome().getActiveAllele(EnumTreeChromosome.YIELD.ordinal()).getName(), COLUMN_1, tree, EnumTreeChromosome.YIELD, false); - drawLine(tree.getGenome().getInactiveAllele(EnumTreeChromosome.YIELD.ordinal()).getName(), COLUMN_2, tree, - EnumTreeChromosome.YIELD, true); - - newLine(); - - drawLine(StringUtil.localize("gui.sappiness"), COLUMN_0); - drawLine(tree.getGenome().getActiveAllele(EnumTreeChromosome.SAPPINESS.ordinal()).getName(), COLUMN_1, tree, EnumTreeChromosome.SAPPINESS, false); - - // FIXME: Legacy handling - IAllele sappiness = tree.getGenome().getInactiveAllele(EnumTreeChromosome.SAPPINESS.ordinal()); - String sap; - if (sappiness instanceof IAlleleFloat) - sap = sappiness.getName(); - else - sap = Allele.saplingsLowest.getName(); - - drawLine(sap, COLUMN_2, tree, EnumTreeChromosome.SAPPINESS, true); - - newLine(); + drawChromosomeRow(StringUtil.localize("gui.yield"), tree, EnumTreeChromosome.YIELD); + drawChromosomeRow(StringUtil.localize("gui.sappiness"), tree, EnumTreeChromosome.SAPPINESS); String yes = StringUtil.localize("yes"); String no = StringUtil.localize("no"); - AlleleBoolean primaryFireproof = (AlleleBoolean)tree.getGenome().getActiveAllele(EnumTreeChromosome.FIREPROOF.ordinal()); - AlleleBoolean secondaryFireproof = (AlleleBoolean)tree.getGenome().getInactiveAllele(EnumTreeChromosome.FIREPROOF.ordinal()); + AlleleBoolean primaryFireproof = (AlleleBoolean)tree.getGenome().getActiveAllele(EnumTreeChromosome.FIREPROOF); + AlleleBoolean secondaryFireproof = (AlleleBoolean)tree.getGenome().getInactiveAllele(EnumTreeChromosome.FIREPROOF); drawLine(StringUtil.localize("gui.fireproof"), COLUMN_0); drawLine(StringUtil.readableBoolean(primaryFireproof.getValue(), yes, no), COLUMN_1, tree, EnumTreeChromosome.FIREPROOF, false); @@ -185,12 +152,7 @@ public class GuiTreealyzer extends GuiAlyzer { newLine(); - drawRow(StringUtil.localize("gui.effect"), tree.getGenome().getEffect().getName(), - tree.getGenome().getInactiveAllele(EnumTreeChromosome.EFFECT.ordinal()).getName(), tree, - EnumTreeChromosome.EFFECT); - - newLine(); - newLine(); + drawChromosomeRow(StringUtil.localize("gui.effect"), tree, EnumTreeChromosome.EFFECT); endPage(); } @@ -210,7 +172,7 @@ public class GuiTreealyzer extends GuiAlyzer { drawLine(StringUtil.localize("gui.growth"), COLUMN_0); drawLine(tree.getGenome().getGrowthProvider().getDescription(), COLUMN_1, tree, EnumTreeChromosome.GROWTH, false); - drawLine(((IAlleleGrowth) tree.getGenome().getInactiveAllele(EnumTreeChromosome.GROWTH.ordinal())).getProvider().getDescription(), COLUMN_2, tree, + drawLine(((IAlleleGrowth) tree.getGenome().getInactiveAllele(EnumTreeChromosome.GROWTH)).getProvider().getDescription(), COLUMN_2, tree, EnumTreeChromosome.GROWTH, true); newLine(); @@ -225,22 +187,22 @@ public class GuiTreealyzer extends GuiAlyzer { drawLine(StringUtil.localize("gui.tolerated"), COLUMN_0); - List tolerated0 = new ArrayList(tree.getGenome().getPlantTypes()); - List tolerated1 = Collections.emptyList(); + List activeTolerated = new ArrayList(tree.getGenome().getPlantTypes()); + List inactiveTolerated = Collections.emptyList(); - IAllele allele1 = tree.getGenome().getInactiveAllele(EnumTreeChromosome.PLANT.ordinal()); - if (allele1 instanceof AllelePlantType) { - tolerated1 = new ArrayList(((AllelePlantType) allele1).getPlantTypes()); + IAllele inactiveAllelePlant = tree.getGenome().getInactiveAllele(EnumTreeChromosome.PLANT); + if (inactiveAllelePlant instanceof AllelePlantType) { + inactiveTolerated = new ArrayList(((AllelePlantType) inactiveAllelePlant).getPlantTypes()); } - int max = Math.max(tolerated0.size(), tolerated1.size()); + int max = Math.max(activeTolerated.size(), inactiveTolerated.size()); for (int i = 0; i < max; i++) { if (i > 0) newLine(); - if(tolerated0.size() > i) - drawLine(StringUtil.localize("gui." + tolerated0.get(i).toString().toLowerCase(Locale.ENGLISH)), COLUMN_1, tree, EnumTreeChromosome.PLANT, false); - if(tolerated1.size() > i) - drawLine(StringUtil.localize("gui." + tolerated1.get(i).toString().toLowerCase(Locale.ENGLISH)), COLUMN_2, tree, EnumTreeChromosome.PLANT, true); + if(activeTolerated.size() > i) + drawLine(StringUtil.localize("gui." + activeTolerated.get(i).toString().toLowerCase(Locale.ENGLISH)), COLUMN_1, tree, EnumTreeChromosome.PLANT, false); + if(inactiveTolerated.size() > i) + drawLine(StringUtil.localize("gui." + inactiveTolerated.get(i).toString().toLowerCase(Locale.ENGLISH)), COLUMN_2, tree, EnumTreeChromosome.PLANT, true); } newLine(); @@ -264,27 +226,27 @@ public class GuiTreealyzer extends GuiAlyzer { newLine(); newLine(); - int fruitDominance0 = getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS.ordinal()).isDominant()); - int fruitDominance1 = getColorCoding(tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS.ordinal()).isDominant()); + int fruitDominance0 = getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant()); + int fruitDominance1 = getColorCoding(tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS).isDominant()); drawLine(StringUtil.localize("gui.fruits"), COLUMN_0); String strike = ""; - IAllele fruit0 = tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS.ordinal()); + IAllele fruit0 = tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS); if (!tree.canBearFruit() && fruit0 != Allele.fruitNone) - strike = "\u00A7m"; + strike = EnumChatFormatting.STRIKETHROUGH.toString(); drawLine(strike + StringUtil.localize(tree.getGenome().getFruitProvider().getDescription()), COLUMN_1, fruitDominance0); strike = ""; - IAllele fruit1 = tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS.ordinal()); + IAllele fruit1 = tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS); if (!tree.getGenome().getSecondary().getSuitableFruit().contains(((IAlleleFruit) fruit1).getProvider().getFamily()) && fruit1 != Allele.fruitNone) - strike = "\u00A7m"; + strike = EnumChatFormatting.STRIKETHROUGH.toString(); drawLine(strike + StringUtil.localize(((IAlleleFruit) fruit1).getProvider().getDescription()), COLUMN_2, fruitDominance1); newLine(); drawLine(StringUtil.localize("gui.family"), COLUMN_0); IFruitFamily primary = tree.getGenome().getFruitProvider().getFamily(); - IFruitFamily secondary = ((IAlleleFruit) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS.ordinal())).getProvider().getFamily(); + IFruitFamily secondary = ((IAlleleFruit) tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS)).getProvider().getFamily(); if (primary != null) drawLine(primary.getName(), COLUMN_1, fruitDominance0); diff --git a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java index f31a42b97..8db0b9e45 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java +++ b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java @@ -31,6 +31,7 @@ import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; import forestry.plugins.PluginArboriculture; +import java.util.List; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -39,8 +40,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; -import java.util.List; - public class ItemGermlingGE extends ItemGE implements IVariableFermentable { private final EnumGermlingType type; @@ -52,7 +51,7 @@ public class ItemGermlingGE extends ItemGE implements IVariableFermentable { } @Override - protected IIndividual getIndividual(ItemStack itemstack) { + public ITree getIndividual(ItemStack itemstack) { return new Tree(itemstack.getTagCompound()); } diff --git a/src/main/java/forestry/arboriculture/items/ItemGrafter.java b/src/main/java/forestry/arboriculture/items/ItemGrafter.java index a97b60cfd..84d55f901 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGrafter.java +++ b/src/main/java/forestry/arboriculture/items/ItemGrafter.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.arboriculture.items; +import forestry.api.arboriculture.IToolGrafter; +import forestry.api.core.Tabs; +import forestry.core.items.ItemForestry; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; - import net.minecraftforge.common.ForgeHooks; -import forestry.api.arboriculture.IToolGrafter; -import forestry.api.core.Tabs; -import forestry.core.items.ItemForestry; - public class ItemGrafter extends ItemForestry implements IToolGrafter { private final float efficiencyOnProperMaterial; diff --git a/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java b/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java index c07e726fb..53b7685a8 100644 --- a/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java +++ b/src/main/java/forestry/arboriculture/items/ItemLeavesBlock.java @@ -9,7 +9,6 @@ import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class ItemLeavesBlock extends ItemForestryBlock { diff --git a/src/main/java/forestry/arboriculture/items/ItemStairs.java b/src/main/java/forestry/arboriculture/items/ItemStairs.java index 531e25b91..be32e9a67 100755 --- a/src/main/java/forestry/arboriculture/items/ItemStairs.java +++ b/src/main/java/forestry/arboriculture/items/ItemStairs.java @@ -21,6 +21,7 @@ import forestry.arboriculture.gadgets.TileStairs; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.items.ItemForestryBlock; +import forestry.core.utils.StringUtil; public class ItemStairs extends ItemForestryBlock { @@ -62,9 +63,23 @@ public class ItemStairs extends ItemForestryBlock { } @Override - public String getUnlocalizedName(ItemStack stack) { - WoodType type = WoodType.getFromCompound(stack.getTagCompound()); - return getBlock().getUnlocalizedName() + "." + type.ordinal(); //To change body of generated methods, choose Tools | Templates. + public String getItemStackDisplayName(ItemStack itemStack) { + WoodType woodType = WoodType.getFromCompound(itemStack.getTagCompound()); + if (woodType == null) + return null; + + String displayName; + String customUnlocalizedName = "stairs." + woodType.ordinal() + ".name"; + if (StringUtil.canTranslateTile(customUnlocalizedName)) { + displayName = StringUtil.localizeTile(customUnlocalizedName); + } else { + String woodGrammar = StringUtil.localize("stairs.grammar"); + String woodTypeName = StringUtil.localize("trees.woodType." + woodType); + + displayName = woodGrammar.replaceAll("%TYPE", woodTypeName); + } + + return displayName; } } diff --git a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java index d9156069e..5cfb37cca 100755 --- a/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java +++ b/src/main/java/forestry/arboriculture/items/ItemTreealyzer.java @@ -15,40 +15,32 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.core.utils.AlyzerInventory; import forestry.api.arboriculture.ITree; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Config; -import forestry.core.config.ForestryItem; import forestry.core.interfaces.IErrorSource; import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.AlyzerInventory; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.Utils; +import forestry.core.utils.GeneticsUtil; import forestry.plugins.PluginArboriculture; public class ItemTreealyzer extends ItemInventoried { public static class TreealyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { - public TreealyzerInventory(EntityPlayer player) { - super(ItemTreealyzer.class, 7); - this.player = player; - } - public TreealyzerInventory(EntityPlayer player, ItemStack itemStack) { super(ItemTreealyzer.class, 7, itemStack); this.player = player; } - private boolean isEnergy(ItemStack itemstack) { - if (itemstack == null || itemstack.stackSize <= 0) - return false; - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + @Override + protected boolean isSpecimen(ItemStack itemStack) { + return GeneticsUtil.getGeneticEquivalent(itemStack) instanceof ITree; } private void tryAnalyze() { @@ -63,7 +55,7 @@ public class ItemTreealyzer extends ItemInventoried { return; if (!PluginArboriculture.treeInterface.isMember(getStackInSlot(SLOT_SPECIMEN))) { - ItemStack ersatz = Utils.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_SPECIMEN)); + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_SPECIMEN)); if (ersatz != null) setInventorySlotContents(SLOT_SPECIMEN, ersatz); } diff --git a/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java b/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java index 6a1435151..e7cacc288 100755 --- a/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java +++ b/src/main/java/forestry/arboriculture/items/ItemWoodBlock.java @@ -11,13 +11,12 @@ package forestry.arboriculture.items; import forestry.arboriculture.IWoodFireproof; -import forestry.core.utils.StringUtil; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - import forestry.arboriculture.IWoodTyped; import forestry.arboriculture.WoodType; import forestry.core.items.ItemForestryBlock; +import forestry.core.utils.StringUtil; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; public class ItemWoodBlock extends ItemForestryBlock { @@ -34,8 +33,16 @@ public class ItemWoodBlock extends ItemForestryBlock { if (woodType == null) return null; - String unlocalizedName = block.getBlockKind() + "." + woodType.ordinal() + ".name"; - String displayName = StringUtil.localizeTile(unlocalizedName); + String displayName; + String customUnlocalizedName = block.getBlockKind() + "." + woodType.ordinal() + ".name"; + if (StringUtil.canTranslateTile(customUnlocalizedName)) { + displayName = StringUtil.localizeTile(customUnlocalizedName); + } else { + String woodGrammar = StringUtil.localize(block.getBlockKind() + ".grammar"); + String woodTypeName = StringUtil.localize("trees.woodType." + woodType); + + displayName = woodGrammar.replaceAll("%TYPE", woodTypeName); + } if (this.getBlock() instanceof IWoodFireproof) displayName = StringUtil.localizeAndFormatRaw("tile.for.fireproof", displayName); diff --git a/src/main/java/forestry/arboriculture/network/PacketLeafUpdate.java b/src/main/java/forestry/arboriculture/network/PacketLeafUpdate.java index abcff5967..0e1c2155a 100755 --- a/src/main/java/forestry/arboriculture/network/PacketLeafUpdate.java +++ b/src/main/java/forestry/arboriculture/network/PacketLeafUpdate.java @@ -14,14 +14,17 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.minecraft.world.World; + import forestry.arboriculture.gadgets.TileLeaves; import forestry.core.network.PacketIds; import forestry.core.network.PacketTileNBT; public class PacketLeafUpdate extends PacketTileNBT { - public byte isRipeningUpdate = 0; - + private static short hasFruitFlag = 1; + private static short isPollinatedFlag = 1 << 1; + private byte leafState = 0; public short textureIndexFancy; public short textureIndexPlain; @@ -38,9 +41,9 @@ public class PacketLeafUpdate extends PacketTileNBT { leafState = 0; if(leaves.hasFruit()) - leafState |= 1 << 0; + leafState |= hasFruitFlag; if(leaves.isPollinated()) - leafState |= 1 << 1; + leafState |= isPollinatedFlag; textureIndexFancy = leaves.determineTextureIndex(true); textureIndexPlain = leaves.determineTextureIndex(false); textureIndexFruit = leaves.determineOverlayIndex(); @@ -48,56 +51,35 @@ public class PacketLeafUpdate extends PacketTileNBT { colourFruits = leaves.determineFruitColour(); } - public PacketLeafUpdate(TileLeaves leaves, int fruitColour) { - super(PacketIds.LEAF_UPDATE, leaves); - - isRipeningUpdate = 1; - colourFruits = fruitColour; - } - @Override public void writeData(DataOutputStream data) throws IOException { super.writeData(data); - data.writeByte(isRipeningUpdate); - - if(isRipeningUpdate()) { - data.writeInt(colourFruits); - } else { - data.writeByte(leafState); - data.writeShort(textureIndexFancy); - data.writeShort(textureIndexPlain); - data.writeShort(textureIndexFruit); - data.writeInt(colourLeaves); - data.writeInt(colourFruits); - } + data.writeByte(leafState); + data.writeShort(textureIndexFancy); + data.writeShort(textureIndexPlain); + data.writeShort(textureIndexFruit); + data.writeInt(colourLeaves); + data.writeInt(colourFruits); } @Override public void readData(DataInputStream data) throws IOException { super.readData(data); - - isRipeningUpdate = data.readByte(); - if(isRipeningUpdate()) { - colourFruits = data.readInt(); - } else { - leafState = data.readByte(); - textureIndexFancy = data.readShort(); - textureIndexPlain = data.readShort(); - textureIndexFruit = data.readShort(); - colourLeaves = data.readInt(); - colourFruits = data.readInt(); - } + + leafState = data.readByte(); + textureIndexFancy = data.readShort(); + textureIndexPlain = data.readShort(); + textureIndexFruit = data.readShort(); + colourLeaves = data.readInt(); + colourFruits = data.readInt(); } - - public boolean isRipeningUpdate() { - return isRipeningUpdate != 0; - } - + public boolean isFruitLeaf() { - return (leafState & (1 << 0)) > 0; + return (leafState & hasFruitFlag) > 0; } + public boolean isPollinated() { - return (leafState & (1 << 1)) > 0; + return (leafState & isPollinatedFlag) > 0; } } diff --git a/src/main/java/forestry/arboriculture/network/PacketRipeningUpdate.java b/src/main/java/forestry/arboriculture/network/PacketRipeningUpdate.java new file mode 100644 index 000000000..5f5db8d32 --- /dev/null +++ b/src/main/java/forestry/arboriculture/network/PacketRipeningUpdate.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.network; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import forestry.arboriculture.gadgets.TileLeaves; +import forestry.core.network.ForestryPacket; +import forestry.core.network.PacketIds; + +public class PacketRipeningUpdate extends ForestryPacket { + + public int colourFruits; + private int posX, posY, posZ; + + public PacketRipeningUpdate() { + } + + public PacketRipeningUpdate(TileLeaves leaves, int fruitColour) { + super(PacketIds.RIPENING_UPDATE); + posX = leaves.xCoord; + posY = leaves.yCoord; + posZ = leaves.zCoord; + colourFruits = fruitColour; + } + + @Override + public void writeData(DataOutputStream data) throws IOException { + super.writeData(data); + + data.writeInt(posX); + data.writeInt(posY); + data.writeInt(posZ); + data.writeInt(colourFruits); + } + + @Override + public void readData(DataInputStream data) throws IOException { + super.readData(data); + + posX = data.readInt(); + posY = data.readInt(); + posZ = data.readInt(); + colourFruits = data.readInt(); + } + + public TileEntity getTarget(World world) { + return world.getTileEntity(posX, posY, posZ); + } +} diff --git a/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java b/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java index 1f3e27e96..dd163b039 100755 --- a/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java +++ b/src/main/java/forestry/arboriculture/proxy/ClientProxyArboriculture.java @@ -10,13 +10,7 @@ ******************************************************************************/ package forestry.arboriculture.proxy; -import net.minecraft.item.Item; -import net.minecraft.world.ColorizerFoliage; - import cpw.mods.fml.client.registry.RenderingRegistry; - -import net.minecraftforge.client.MinecraftForgeClient; - import forestry.arboriculture.render.FenceRenderingHandler; import forestry.arboriculture.render.FruitPodRenderingHandler; import forestry.arboriculture.render.LeavesRenderingHandler; @@ -24,6 +18,8 @@ import forestry.arboriculture.render.SaplingRenderHandler; import forestry.arboriculture.render.StairItemRenderer; import forestry.core.config.ForestryBlock; import forestry.plugins.PluginArboriculture; +import net.minecraft.world.ColorizerFoliage; +import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxyArboriculture extends ProxyArboriculture { @Override diff --git a/src/main/java/forestry/arboriculture/render/FenceRenderingHandler.java b/src/main/java/forestry/arboriculture/render/FenceRenderingHandler.java index 619fabf54..b06e6610d 100755 --- a/src/main/java/forestry/arboriculture/render/FenceRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/FenceRenderingHandler.java @@ -10,18 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.block.BlockFence; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.world.IBlockAccess; - -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - import org.lwjgl.opengl.GL11; -import forestry.plugins.PluginArboriculture; - public class FenceRenderingHandler implements ISimpleBlockRenderingHandler { @Override diff --git a/src/main/java/forestry/arboriculture/render/FruitPodRenderingHandler.java b/src/main/java/forestry/arboriculture/render/FruitPodRenderingHandler.java index 0c7a34959..dcf2d7b3a 100755 --- a/src/main/java/forestry/arboriculture/render/FruitPodRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/FruitPodRenderingHandler.java @@ -10,6 +10,10 @@ ******************************************************************************/ package forestry.arboriculture.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import forestry.arboriculture.gadgets.BlockFruitPod; +import forestry.arboriculture.gadgets.TileFruitPod; +import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.block.BlockDirectional; import net.minecraft.client.renderer.RenderBlocks; @@ -17,12 +21,6 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - -import forestry.arboriculture.gadgets.BlockFruitPod; -import forestry.arboriculture.gadgets.TileFruitPod; -import forestry.plugins.PluginArboriculture; - public class FruitPodRenderingHandler implements ISimpleBlockRenderingHandler { @Override diff --git a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java index 95d5bb74d..e11b1e4c9 100755 --- a/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java +++ b/src/main/java/forestry/arboriculture/render/LeavesRenderingHandler.java @@ -50,10 +50,8 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler implements I renderer.renderStandardBlock(block, x, y, z); // Render overlay for fruit leaves. - IIcon fruitIcon = null; - int fruitColor = 0xffffff; - fruitIcon = tile.getFruitTexture(); - fruitColor = tile.getFruitColour(); + IIcon fruitIcon = tile.getFruitTexture(); + int fruitColor = tile.getFruitColour(); if (fruitIcon != null) renderFruitOverlay(world, block, x, y, z, renderer, fruitIcon, fruitColor); diff --git a/src/main/java/forestry/arboriculture/render/SaplingRenderHandler.java b/src/main/java/forestry/arboriculture/render/SaplingRenderHandler.java index b65e70a9b..fb71c1f9e 100755 --- a/src/main/java/forestry/arboriculture/render/SaplingRenderHandler.java +++ b/src/main/java/forestry/arboriculture/render/SaplingRenderHandler.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.arboriculture.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.arboriculture.gadgets.BlockSapling; +import forestry.arboriculture.gadgets.TileSapling; +import forestry.plugins.PluginArboriculture; import net.minecraft.block.Block; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.renderer.RenderBlocks; @@ -17,14 +23,6 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - -import forestry.api.arboriculture.EnumGermlingType; -import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.arboriculture.gadgets.BlockSapling; -import forestry.arboriculture.gadgets.TileSapling; -import forestry.plugins.PluginArboriculture; - public class SaplingRenderHandler implements ISimpleBlockRenderingHandler { public static int renderLayer = 0; @@ -41,10 +39,10 @@ public class SaplingRenderHandler implements ISimpleBlockRenderingHandler { TileSapling tile = BlockSapling.getSaplingTile(world, x, y, z); - IAlleleTreeSpecies species = (IAlleleTreeSpecies) PluginArboriculture.treeInterface.getDefaultTemplate()[0]; if (tile == null || tile.getTree() == null) return true; - species = tile.getTree().getGenome().getPrimary(); + + IAlleleTreeSpecies species = tile.getTree().getGenome().getPrimary(); renderCrossedSquares(species, world, block, x, y, z); renderLayer = 1; diff --git a/src/main/java/forestry/arboriculture/render/StairItemRenderer.java b/src/main/java/forestry/arboriculture/render/StairItemRenderer.java index d2add95b1..8f9b0dbc4 100755 --- a/src/main/java/forestry/arboriculture/render/StairItemRenderer.java +++ b/src/main/java/forestry/arboriculture/render/StairItemRenderer.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.arboriculture.render; +import forestry.arboriculture.WoodType; +import forestry.core.utils.StackUtils; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; - import net.minecraftforge.client.IItemRenderer; - import org.lwjgl.opengl.GL11; -import forestry.arboriculture.WoodType; -import forestry.core.utils.StackUtils; - public class StairItemRenderer implements IItemRenderer { private void renderStairBlock(RenderBlocks renderBlocks, ItemStack item, float f, float g, float h) { diff --git a/src/main/java/forestry/arboriculture/worldgen/BlockTypeLeaf.java b/src/main/java/forestry/arboriculture/worldgen/BlockTypeLeaf.java index c2af659d4..0038053da 100755 --- a/src/main/java/forestry/arboriculture/worldgen/BlockTypeLeaf.java +++ b/src/main/java/forestry/arboriculture/worldgen/BlockTypeLeaf.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - import forestry.api.world.ITreeGenData; import forestry.core.config.ForestryBlock; import forestry.core.worldgen.BlockType; +import net.minecraft.world.World; public class BlockTypeLeaf extends BlockType { diff --git a/src/main/java/forestry/arboriculture/worldgen/BlockTypeVoid.java b/src/main/java/forestry/arboriculture/worldgen/BlockTypeVoid.java index 884e6da7a..6b9f06daf 100755 --- a/src/main/java/forestry/arboriculture/worldgen/BlockTypeVoid.java +++ b/src/main/java/forestry/arboriculture/worldgen/BlockTypeVoid.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; -import net.minecraft.world.World; - import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; +import net.minecraft.world.World; public class BlockTypeVoid extends BlockType { @@ -25,8 +24,6 @@ public class BlockTypeVoid extends BlockType { @Override public void setBlock(World world, ITreeGenData tree, int x, int y, int z) { world.setBlockToAir(x, y, z); - if (world.getTileEntity(x, y, z) != null) - world.removeTileEntity(x, y, z); } } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java index 56a233291..6f7e5c966 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcacia.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenAcacia extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java index 9fe119e25..fa0baa824 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenAcaciaVanilla.java @@ -10,9 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; public class WorldGenAcaciaVanilla extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java index 8d4f87a4a..3765ee6d8 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; - import com.mojang.authlib.GameProfile; - import forestry.api.world.ITreeGenData; import forestry.arboriculture.gadgets.TileSapling; import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import forestry.core.worldgen.BlockType; import forestry.core.worldgen.WorldGenBase; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; public abstract class WorldGenArboriculture extends WorldGenBase { @@ -43,7 +41,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } @Override - public boolean subGenerate(int x, int y, int z) { + public boolean subGenerate(int x, int y, int z, boolean forced) { this.startX = x; this.startY = y; this.startZ = z; @@ -53,9 +51,9 @@ public abstract class WorldGenArboriculture extends WorldGenBase { this.wood = getWood(); preGenerate(); - if (!canGrow()) + if (!forced && !canGrow()) { return false; - else { + } else { generate(); return true; } @@ -90,20 +88,14 @@ public abstract class WorldGenArboriculture extends WorldGenBase { protected void generateTreeTrunk(int height, int girth, float vines) { int offset = (girth - 1) / 2; - for (int x = 0; x < girth; x++) - for (int y = 0; y < girth; y++) - for (int i = 0; i < height; i++) { - addWood(x - offset, i, y - offset, EnumReplaceMode.ALL); - - if (rand.nextFloat() < vines) - addVine(x - offset - 1, i, y - offset); - if (rand.nextFloat() < vines) - addVine(x - offset + 1, i, y - offset); - if (rand.nextFloat() < vines) - addVine(x - offset, i, y - offset - 1); - if (rand.nextFloat() < vines) - addVine(x - offset, i, y - offset + 1); + for (int x = 0; x < girth; x++) { + for (int z = 0; z < girth; z++) { + for (int y = 0; y < height; y++) { + addWood(x - offset, y, z - offset, EnumReplaceMode.ALL); + addVines(x - offset, y, z - offset, vines); } + } + } if (!spawnPods) return; @@ -150,7 +142,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase { @Override protected void addBlock(int x, int y, int z, BlockType type, EnumReplaceMode replace) { if (replace == EnumReplaceMode.ALL - || replace == EnumReplaceMode.SOFT && Utils.isReplaceableBlock(world, startX + x, startY + y, startZ + z) + || (replace == EnumReplaceMode.SOFT && Utils.isReplaceableBlock(world, startX + x, startY + y, startZ + z)) || world.isAirBlock(startX + x, startY + y, startZ + z)) type.setBlock(world, tree, startX + x, startY + y, startZ + z); } @@ -162,7 +154,17 @@ public abstract class WorldGenArboriculture extends WorldGenBase { protected final void addWood(int x, int y, int z, EnumReplaceMode replace) { addBlock(x, y, z, wood, replace); } + + protected final void addXWood(int x, int y, int z, EnumReplaceMode replace) { + BlockType woodX = new BlockType(wood.getBlock(), wood.getMeta() + 4); + addBlock(x, y, z, woodX, replace); + } + protected final void addZWood(int x, int y, int z, EnumReplaceMode replace) { + BlockType woodZ = new BlockType(wood.getBlock(), wood.getMeta() + 8); + addBlock(x, y, z, woodZ, replace); + } + protected final void addLeaf(int x, int y, int z, EnumReplaceMode replace) { addBlock(x, y, z, leaf, replace); } @@ -171,4 +173,18 @@ public abstract class WorldGenArboriculture extends WorldGenBase { addBlock(x, y, z, vine, EnumReplaceMode.NONE); } + protected final void addVines(int x, int y, int z, float chance) { + if (chance <= 0) + return; + + if (rand.nextFloat() < chance) + addVine(x - 1, y, z); + if (rand.nextFloat() < chance) + addVine(x + 1, y, z); + if (rand.nextFloat() < chance) + addVine(x, y, z - 1); + if (rand.nextFloat() < chance) + addVine(x, y, z + 1); + } + } diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java index 0bdcde71b..605fae511 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBalsa.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenBalsa extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java index e4e22fb73..2b53012c8 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBaobab.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenBaobab extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java index 419c9ebf8..5dfc1c96b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenBirch.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; - import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; public class WorldGenBirch extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java index 775ae8030..a8f37be32 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCherry.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenCherry extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java index 28bfc8589..ab2e2208e 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenChestnut.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenChestnut extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java new file mode 100644 index 000000000..3c92f5fc5 --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCocobolo.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import forestry.api.world.ITreeGenData; + +public class WorldGenCocobolo extends WorldGenTree { + + public WorldGenCocobolo(ITreeGenData tree) { + super(tree); + } + + @Override + public void generate() { + generateTreeTrunk(height, girth); + + int leafSpawn = height; + + addLeaf(0, leafSpawn--, 0, EnumReplaceMode.NONE); + generateAdjustedCylinder(leafSpawn--, 1, 1, leaf); + + if (height > 10) + generateAdjustedCylinder(leafSpawn--, 2, 1, leaf); + generateAdjustedCylinder(leafSpawn, 0, 1, leaf); + + leafSpawn--; + + while (leafSpawn > 4) { + int offset = 1; + if (leafSpawn % 2 == 0) { + if (rand.nextBoolean()) + offset = -1; + generateAdjustedCylinder(leafSpawn, offset, 2, 1, leaf, EnumReplaceMode.NONE); + } else { + if (rand.nextBoolean()) + offset = -1; + generateAdjustedCylinder(leafSpawn, offset, 0, 1, leaf, EnumReplaceMode.NONE ); + } + leafSpawn--; + } + + } + + @Override + public void preGenerate() { + height = determineHeight(8, 8); + girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + } +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java new file mode 100644 index 000000000..4743541a9 --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenCrescentia.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import forestry.api.world.ITreeGenData; + +public class WorldGenCrescentia extends WorldGenTree { + + public WorldGenCrescentia(ITreeGenData tree) { + super(tree); + } + + @Override + public void generate() { + generateTreeTrunk(height, girth); + + int leafSpawn = height + 1; + + generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + + generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + if (rand.nextBoolean()) + generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + + generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + + } + + @Override + public void generateTreeTrunk(int height, int girth) { + + int offset = (girth - 1) / 2; + + + //Trunk generation + for (int x = 0; x < girth; x++) //offsets trunk in x direction + for (int z = 0; z < girth; z++) //offsets trunk in z direction + if (x==0 || x==girth-1) { //checks for edges in x direction + if (z==0 || z==girth-1) {//checks for corners + if (x==0 && z==0) {}//xz corner + if (x==girth-1 && z==0) {}//x-1z corner + if (x==0 && z==girth-1) {}//xz-1 corner + if (x==girth-1 && z==0) {} //x-1z-1 corner + } else { //these are the z only edges + if (x==0) { + + } else if (x==girth-1) { + + } + } + } else if (z==0 || z==girth-1) { //these are the x only edges + if (z==0) { + + } else if (z==girth-1) { + + } + } else { //these are center pieces + for (int i = 0; i < height; i++) { //grows trunk straight up in y direction to the correct height + addWood(x - offset, i, z - offset, EnumReplaceMode.ALL); + } + } + + //End trunk generation + + //Spawn pods + for (int y = minPodHeight; y < height; y++) + for (int x = 0; x < girth; x++) + for (int z = 0; z < girth; z++) { + + if ((x > 0 && x < girth) && (z > 0 && z < girth)) + continue; + + tree.trySpawnFruitBlock(world, startX + x + 1, startY + y, startZ + z); + tree.trySpawnFruitBlock(world, startX + x - 1, startY + y, startZ + z); + tree.trySpawnFruitBlock(world, startX + x, startY + y, startZ + z + 1); + tree.trySpawnFruitBlock(world, startX + x, startY + y, startZ + z - 1); + } + + + } + + @Override + public void preGenerate() { + height = determineHeight(6, 3); + girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + } +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java index 97c5bef38..7dbda55a8 100644 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenDarkOak.java @@ -10,9 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; public class WorldGenDarkOak extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java index 896debc79..f417707a0 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenDate.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenDate extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java index 7e876e6bf..8bc0b01cb 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenEbony.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenEbony extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java index ad32a8c94..0777a34f2 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenGiganteum.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenGiganteum extends WorldGenSequoia { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java index 3ebdf1b27..b89ff2e48 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenGreenheart.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenGreenheart extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java new file mode 100644 index 000000000..e461240d6 --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenIpe.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import forestry.api.world.ITreeGenData; + +public class WorldGenIpe extends WorldGenTree { + + public WorldGenIpe(ITreeGenData tree) { + super(tree); + } + + @Override + public void generate() { + generateTreeTrunk(height, girth); + + int leafSpawn = height + 1; + float adjustedGirth = girth*.65f; + + generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 0.2f*adjustedGirth, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 0.2f*adjustedGirth, 1, leaf); + + while (leafSpawn > 7) { + generateAdjustedCylinder(leafSpawn, (float) (1.25f*(adjustedGirth * .65)), 1, leaf); + leafSpawn--; + } + + generateAdjustedCylinder(leafSpawn--, 1.6f*adjustedGirth, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 1.6f*adjustedGirth, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 1.6f*adjustedGirth, 1, leaf); + + if (rand.nextBoolean()) + generateAdjustedCylinder(leafSpawn--, 1.25f*adjustedGirth, 1, leaf); + + generateAdjustedCylinder(leafSpawn--, 1f*adjustedGirth, 1, leaf); + + } + + @Override + public void preGenerate() { + height = determineHeight(8, 8); + girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + } +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java index a886f1e5b..60a438e7a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenJungle.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; - import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; /** * This is a dummy and needs to be replaced with something proper. diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java index bf5024372..093fda86b 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenKapok.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenKapok extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java index 5acc0af6c..9538e7bd8 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLarch.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenLarch extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java index 0dbf4ddc2..9046d47bf 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLemon.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenLemon extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java index aa17569fc..ae8c0a042 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenLime.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenLime extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java index 37256c938..06a9582cb 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahoe.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenMahoe extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java index e43b3246d..010403379 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMahogany.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenMahogany extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java index 239abd278..a6a543d01 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenMaple.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenMaple extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java index 488720a41..274b68da0 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenOak.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; - import forestry.api.world.ITreeGenData; import forestry.core.worldgen.BlockType; +import net.minecraft.init.Blocks; public class WorldGenOak extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java new file mode 100644 index 000000000..c5463d9ee --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPadauk.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import java.util.Random; + +import forestry.api.world.ITreeGenData; + +public class WorldGenPadauk extends WorldGenTree { + + public WorldGenPadauk(ITreeGenData tree) { + super(tree); + + minHeight = 7; + } + + @Override + public void generate() { + generateTreeTrunk(height, girth); + + + int leafSpawn = height + 1; + + generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 1.5f, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 3f, 1, leaf); + + int count = 0; + int max = 3; + int min = 1; + int canopyHeight = rand.nextInt(max - min + 1) + min; + + while (leafSpawn > 3 && count < canopyHeight) { + generateAdjustedCylinder(leafSpawn--, 4.5f, 1, leaf); + count++; + //Random Trunk Branches + for (int i = 0; i < girth*4; i++) { + if (rand.nextBoolean()){ + + int[] offset = {-1, 1}; + int offsetValue = (offset[new Random().nextInt(offset.length)]); + int maxBranchLength = 3; + int branchLength = new Random().nextInt(maxBranchLength+1); + char[] direction = {'z', 'x'}; + char directionValue = (direction[new Random().nextInt(direction.length)]); + int branchSpawn = leafSpawn; + + for (int j = 1; j < branchLength+1; j++) { + if (j == branchLength && rand.nextBoolean()) { //Just adding a bit of variation to the ends for character + branchSpawn += 1; + } + if (directionValue == 'z') { + addZWood(0, branchSpawn, j*offsetValue, EnumReplaceMode.ALL); + } else if (directionValue == 'x'){ + addXWood(j*offsetValue, branchSpawn, 0, EnumReplaceMode.ALL); + } + } + + } + } + } + } + + @Override + public void preGenerate() { + height = determineHeight(6, 6); + girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + } +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java index 1c86f58f9..5ec3d0830 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPapaya.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenPapaya extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java index 5c93ebedf..694aba393 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPine.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenPine extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java index 9036dbf7a..dc1080cb1 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPlum.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenPlum extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java index 9de0d72f0..c907db527 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenPoplar.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenPoplar extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java index b6ab46e0e..60e79b659 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenSequoia.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenSequoia extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java index 0889e7cf2..82b301495 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenSpruce.java @@ -10,10 +10,7 @@ ******************************************************************************/ package forestry.arboriculture.worldgen; -import net.minecraft.init.Blocks; - import forestry.api.world.ITreeGenData; -import forestry.core.worldgen.BlockType; public class WorldGenSpruce extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java index 1a7e0bd0b..b0adfd9df 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenTeak.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenTeak extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java index f0bde07ce..ff308cb79 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenTree.java @@ -11,7 +11,6 @@ package forestry.arboriculture.worldgen; import com.mojang.authlib.GameProfile; - import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.genetics.IAlleleBoolean; import forestry.api.world.ITreeGenData; @@ -109,7 +108,7 @@ public abstract class WorldGenTree extends WorldGenArboriculture { // if we have a fireproof tree, return the fireproof log if (block instanceof BlockLog) { - IAlleleBoolean fireproof = (IAlleleBoolean) tree.getGenome().getActiveAllele(EnumTreeChromosome.FIREPROOF.ordinal()); + IAlleleBoolean fireproof = (IAlleleBoolean) tree.getGenome().getActiveAllele(EnumTreeChromosome.FIREPROOF); if (fireproof.getValue()) { BlockLog blockLog = (BlockLog) block; ForestryBlock fireproofLogBlock = BlockFireproofLog.getFireproofLog(blockLog); diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java index 98e62a503..f5c0e0d72 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWalnut.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenWalnut extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java index f962592ed..451ae6a1a 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWenge.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenWenge extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java index a81ec973a..187314929 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenWillow.java @@ -11,8 +11,6 @@ package forestry.arboriculture.worldgen; import forestry.api.world.ITreeGenData; -import forestry.core.config.ForestryBlock; -import forestry.core.worldgen.BlockType; public class WorldGenWillow extends WorldGenTree { diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java new file mode 100644 index 000000000..259039f1c --- /dev/null +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenZebrawood.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.worldgen; + +import forestry.api.world.ITreeGenData; + +public class WorldGenZebrawood extends WorldGenTree { + + public WorldGenZebrawood(ITreeGenData tree) { + super(tree); + } + + @Override + public void generate() { + + generateTreeTrunk(height, girth); + + int leafSpawn = height + 1; + + generateAdjustedCylinder(leafSpawn--, 0, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 0.5f, 1, leaf); + + generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + + while (leafSpawn > height - 4) + generateAdjustedCylinder(leafSpawn--, 2.5f, 1, leaf); + generateAdjustedCylinder(leafSpawn--, 1.9f, 1, leaf); + + // Add some smaller twigs below for flavour + for (int times = 0; times < height / 4; times++) { + int h = 10 + rand.nextInt(Math.max(1, height - 10)); + if (rand.nextBoolean() && h < height / 2) + h = height / 2 + rand.nextInt(height / 2); + int x_off = -1 + rand.nextInt(3); + int y_off = -1 + rand.nextInt(3); + generateSphere(new Vector(x_off, h, y_off), 1 + rand.nextInt(1), leaf, EnumReplaceMode.NONE); + } + + } + + @Override + public void preGenerate() { + height = determineHeight(8, 8); + girth = determineGirth(tree.getGirth(world, startX, startY, startZ)); + } +} diff --git a/src/main/java/forestry/core/CreativeTabForestry.java b/src/main/java/forestry/core/CreativeTabForestry.java index 77172eeb5..a2026a194 100755 --- a/src/main/java/forestry/core/CreativeTabForestry.java +++ b/src/main/java/forestry/core/CreativeTabForestry.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.core; +import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.core.Tabs; +import forestry.core.config.ForestryItem; import forestry.plugins.PluginManager; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import cpw.mods.fml.common.registry.GameData; -import cpw.mods.fml.common.registry.GameRegistry; - -import forestry.api.core.Tabs; -import forestry.core.config.ForestryItem; - public class CreativeTabForestry extends CreativeTabs { static { diff --git a/src/main/java/forestry/core/EnumErrorCode.java b/src/main/java/forestry/core/EnumErrorCode.java new file mode 100644 index 000000000..0b910ed0b --- /dev/null +++ b/src/main/java/forestry/core/EnumErrorCode.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.core; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.ErrorStateRegistry; +import forestry.api.core.IErrorState; +import forestry.core.config.Defaults; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.util.IIcon; + +public enum EnumErrorCode implements IErrorState { + + UNKNOWN("unknown"), + OK("ok"), + INVALIDBIOME("invalidBiome"), + ISRAINING("isRaining"), + NOTRAINING("notRaining"), + NOFUEL("noFuel"), // Biogas & Peat-fired + NOHEAT("noHeat"), // Biogas engine + NODISPOSAL("noDisposal"), + NORESOURCE("noResource"), + NOTGLOOMY("notGloomy"), + NOTLUCID("notLucid"), + NOTDAY("notDay"), + NOTNIGHT("notNight"), + NOFLOWER("noFlower"), + NOQUEEN("noQueen"), + NODRONE("noDrone"), + NOSKY("noSky"), + NOSPACE("noSpace"), + NOSPACETANK("noSpaceTank", "noLiquid"), + NORECIPE("noRecipe"), + NOENERGYNET("noEnergyNet"), + NOTHINGANALYZE("noSpecimen"), + FORCEDCOOLDOWN("forcedCooldown"), + NOHONEY("noHoney"), + NOTPOSTPAID("notPostpaid", "noStamps"), + NORECIPIENT("noRecipient"), + NOTALPHANUMERIC("notAlphaNumeric"), + NOTUNIQUE("notUnique"), + NOSTAMPS("noStamps"), + NOCIRCUITBOARD("noCircuitBoard"), + NOCIRCUITLAYOUT("noCircuitLayout"), + WRONGSTACKSIZE("wrongStacksize"), + NOFERTILIZER("noFertilizer"), + NOFARMLAND("noFarmland"), + CIRCUITMISMATCH("circuitMismatch"), + NOLIQUID("noLiquid"), + NOPAPER("noPaper"), + NOSTAMPSNOPAPER("noStampsNoPaper", "noStamps"), + NOSUPPLIES("noSupplies", "noResource"), + NOTRADE("noTrade", "noResource"), + NOPOWER("noPower"); + + private final String name; + private final String iconName; + @SideOnly(Side.CLIENT) + private IIcon icon; + + private EnumErrorCode(String name) { + this(name, name); + } + + private EnumErrorCode(String name, String iconName) { + this.name = name; + this.iconName = iconName; + } + + @Override + public String getDescription() { + return "errors." + name + ".desc"; + } + + @Override + public String getHelp() { + return "errors." + name + ".help"; + } + + @SideOnly(Side.CLIENT) + @Override + public void registerIcons(IIconRegister register) { + icon = register.registerIcon("forestry:errors/" + iconName); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon() { + return icon; + } + + @Override + public short getID() { + return (short) ordinal(); + } + + @Override + public String getUniqueName() { + return Defaults.MOD + ":" + name; + } + + public static void init() { + for (IErrorState code : values()) { + ErrorStateRegistry.registerErrorState(code); + } + } +} diff --git a/src/main/java/forestry/core/EventHandlerCore.java b/src/main/java/forestry/core/EventHandlerCore.java index 4be006a84..6057cf491 100755 --- a/src/main/java/forestry/core/EventHandlerCore.java +++ b/src/main/java/forestry/core/EventHandlerCore.java @@ -10,23 +10,25 @@ ******************************************************************************/ package forestry.core; -import cpw.mods.fml.common.eventhandler.Event.Result; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.core.EnumErrorCode; -import forestry.core.interfaces.IOreDictionaryHandler; -import forestry.core.interfaces.IPickupHandler; -import forestry.core.interfaces.ISaveEventHandler; -import forestry.core.render.TextureManager; -import forestry.core.utils.LiquidHelper; -import forestry.plugins.PluginManager; import net.minecraft.item.ItemStack; + import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.eventhandler.Event.Result; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.api.core.ErrorStateRegistry; +import forestry.core.interfaces.IOreDictionaryHandler; +import forestry.core.interfaces.IPickupHandler; +import forestry.core.interfaces.ISaveEventHandler; +import forestry.core.render.TextureManager; +import forestry.plugins.PluginManager; + public class EventHandlerCore { public EventHandlerCore() { @@ -84,10 +86,9 @@ public class EventHandlerCore { @SideOnly(Side.CLIENT) public void handleTextureRemap(TextureStitchEvent.Pre event) { if(event.map.getTextureType() == 1) { - EnumErrorCode.initIcons(event.map); + ErrorStateRegistry.initIcons(event.map); TextureManager.getInstance().initDefaultIcons(event.map); - } else if(event.map.getTextureType() == 0) - LiquidHelper.resetLiquidIcons(event.map); + } } @SubscribeEvent diff --git a/src/main/java/forestry/core/ForestryClient.java b/src/main/java/forestry/core/ForestryClient.java index 616413cbe..ab3a36520 100755 --- a/src/main/java/forestry/core/ForestryClient.java +++ b/src/main/java/forestry/core/ForestryClient.java @@ -11,7 +11,6 @@ package forestry.core; import cpw.mods.fml.client.registry.RenderingRegistry; - import forestry.apiculture.render.BlockCandleRenderer; import forestry.core.proxy.Proxies; import forestry.core.render.BlockRenderingHandler; diff --git a/src/main/java/forestry/core/ForestryCore.java b/src/main/java/forestry/core/ForestryCore.java index 45156812c..9d20d965c 100755 --- a/src/main/java/forestry/core/ForestryCore.java +++ b/src/main/java/forestry/core/ForestryCore.java @@ -10,6 +10,8 @@ ******************************************************************************/ package forestry.core; +import com.google.common.collect.ImmutableList; + import java.io.File; import net.minecraft.init.Blocks; @@ -17,15 +19,13 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; +import net.minecraftforge.common.MinecraftForge; + import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; -import net.minecraftforge.common.MinecraftForge; - -import com.google.common.collect.ImmutableList; - import forestry.api.apiculture.FlowerManager; import forestry.api.core.ForestryAPI; import forestry.api.fuels.EngineBronzeFuel; @@ -38,11 +38,11 @@ import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.config.Version; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.TileEngine; import forestry.core.gadgets.TileMachine; import forestry.core.gadgets.TileMill; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; import forestry.plugins.PluginManager; public class ForestryCore { @@ -57,18 +57,13 @@ public class ForestryCore { Config.load(); if (!Config.disableVersionCheck) Version.versionCheck(); + + EnumErrorCode.init(); PluginManager.runPreInit(); } public void init(Object basemod) { - - // Register Liquids & Containers - registerLiquidContainers(); - - // Register world generator - GameRegistry.registerWorldGenerator(new WorldGenerator(), 0); - // Set fuels and resources for the fermenter FuelManager.fermenterFuel.put(ForestryItem.fertilizerCompound.getItemStack(), new FermenterFuel(ForestryItem.fertilizerCompound.getItemStack(), GameMode.getGameMode().getIntegerSetting("fermenter.value.fertilizer"), GameMode.getGameMode().getIntegerSetting("fermenter.cycles.fertilizer"))); @@ -89,17 +84,18 @@ public class ForestryCore { Defaults.ENGINE_COPPER_FUEL_VALUE_PEAT, Defaults.ENGINE_COPPER_CYCLE_DURATION_PEAT)); FuelManager.copperEngineFuel.put(ForestryItem.bituminousPeat.getItemStack(), new EngineCopperFuel(ForestryItem.bituminousPeat.getItemStack(), Defaults.ENGINE_COPPER_FUEL_VALUE_BITUMINOUS_PEAT, Defaults.ENGINE_COPPER_CYCLE_DURATION_BITUMINOUS_PEAT)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_BIOMASS), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_BIOMASS), + + FuelManager.bronzeEngineFuel.put(Fluids.BIOMASS.getFluid(), new EngineBronzeFuel(Fluids.BIOMASS.getFluid(), Defaults.ENGINE_FUEL_VALUE_BIOMASS, (int) (Defaults.ENGINE_CYCLE_DURATION_BIOMASS * GameMode.getGameMode().getFloatSetting("fuel.biomass.biogas")), 1)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_WATER), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_WATER), + FuelManager.bronzeEngineFuel.put(Fluids.WATER.getFluid(), new EngineBronzeFuel(Fluids.WATER.getFluid(), Defaults.ENGINE_FUEL_VALUE_WATER, Defaults.ENGINE_CYCLE_DURATION_WATER, 3)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_MILK), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_MILK), + FuelManager.bronzeEngineFuel.put(Fluids.MILK.getFluid(), new EngineBronzeFuel(Fluids.MILK.getFluid(), Defaults.ENGINE_FUEL_VALUE_MILK, Defaults.ENGINE_CYCLE_DURATION_MILK, 3)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_SEEDOIL), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_SEEDOIL), + FuelManager.bronzeEngineFuel.put(Fluids.SEEDOIL.getFluid(), new EngineBronzeFuel(Fluids.SEEDOIL.getFluid(), Defaults.ENGINE_FUEL_VALUE_SEED_OIL, Defaults.ENGINE_CYCLE_DURATION_SEED_OIL, 1)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_HONEY), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_HONEY), + FuelManager.bronzeEngineFuel.put(Fluids.HONEY.getFluid(), new EngineBronzeFuel(Fluids.HONEY.getFluid(), Defaults.ENGINE_FUEL_VALUE_HONEY, Defaults.ENGINE_CYCLE_DURATION_HONEY, 1)); - FuelManager.bronzeEngineFuel.put(LiquidHelper.getFluid(Defaults.LIQUID_JUICE), new EngineBronzeFuel(LiquidHelper.getFluid(Defaults.LIQUID_JUICE), + FuelManager.bronzeEngineFuel.put(Fluids.JUICE.getFluid(), new EngineBronzeFuel(Fluids.JUICE.getFluid(), Defaults.ENGINE_FUEL_VALUE_JUICE, Defaults.ENGINE_CYCLE_DURATION_JUICE, 1)); // Set rain substrates @@ -124,10 +120,14 @@ public class ForestryCore { } public void postInit() { - PluginManager.runPostInit(); - Proxies.common.registerTickHandlers(); + // Register world generator + WorldGenerator worldGenerator = new WorldGenerator(); + GameRegistry.registerWorldGenerator(worldGenerator, 0); + + // Register tick handlers + Proxies.common.registerTickHandlers(worldGenerator); // Handle IMC messages. processIMCMessages(FMLInterModComms.fetchRuntimeMessages(ForestryAPI.instance)); @@ -144,64 +144,4 @@ public class ForestryCore { public String getPriorities() { return "after:mod_IC2;after:mod_BuildCraftCore;after:mod_BuildCraftEnergy;after:mod_BuildCraftFactory;after:mod_BuildCraftSilicon;after:mod_BuildCraftTransport;after:mod_RedPowerWorld"; } - - private void registerLiquidContainers() { - // Add lava and water buckets to the API in case this has not been done yet. - if (LiquidHelper.isEmptyLiquidData()) { - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, new ItemStack(Items.lava_bucket), new ItemStack(Items.bucket)); - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, new ItemStack(Items.water_bucket), new ItemStack(Items.bucket)); - } - - // Glass - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_GLASS); - - // Set default lava, water and biofuel buckets - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_MILK); - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_MILK, Defaults.BUCKET_VOLUME, new ItemStack(Items.milk_bucket), new ItemStack(Items.bucket)); - - // Lava - LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, ForestryItem.canLava.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, ForestryItem.refractoryLava.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - // Water - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, new ItemStack(Items.potionitem, 1, 0), - new ItemStack(Items.glass_bottle)); - LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, ForestryItem.canWater.getItemStack(), - ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleWater.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, ForestryItem.refractoryWater.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_BIOMASS); - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_BIOMASS, Defaults.BUCKET_VOLUME, ForestryItem.bucketBiomass.getItemStack(), new ItemStack(Items.bucket)); - LiquidHelper.injectTinContainer(Defaults.LIQUID_BIOMASS, Defaults.BUCKET_VOLUME, ForestryItem.canBiomass.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_BIOMASS, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleBiomass.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_BIOMASS, Defaults.BUCKET_VOLUME, ForestryItem.refractoryBiomass.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_ETHANOL); - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_ETHANOL, Defaults.BUCKET_VOLUME, ForestryItem.bucketBiofuel.getItemStack(), new ItemStack(Items.bucket)); - LiquidHelper.injectTinContainer(Defaults.LIQUID_ETHANOL, Defaults.BUCKET_VOLUME, ForestryItem.canBiofuel.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_ETHANOL, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleBiofuel.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_ETHANOL, Defaults.BUCKET_VOLUME, ForestryItem.refractoryBiofuel.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_SEEDOIL); - LiquidHelper.injectTinContainer(Defaults.LIQUID_SEEDOIL, Defaults.BUCKET_VOLUME, ForestryItem.canSeedOil.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_SEEDOIL, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleSeedOil.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_SEEDOIL, Defaults.BUCKET_VOLUME, ForestryItem.refractorySeedOil.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_HONEY); - LiquidHelper.injectTinContainer(Defaults.LIQUID_HONEY, Defaults.BUCKET_VOLUME, ForestryItem.canHoney.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_HONEY, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleHoney.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_HONEY, Defaults.BUCKET_VOLUME, ForestryItem.refractoryHoney.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_JUICE); - LiquidHelper.injectTinContainer(Defaults.LIQUID_JUICE, Defaults.BUCKET_VOLUME, ForestryItem.canJuice.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_JUICE, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleJuice.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_JUICE, Defaults.BUCKET_VOLUME, ForestryItem.refractoryJuice.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_ICE); - LiquidHelper.injectTinContainer(Defaults.LIQUID_ICE, Defaults.BUCKET_VOLUME, ForestryItem.canIce.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_ICE, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleIce.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_ICE, Defaults.BUCKET_VOLUME, ForestryItem.refractoryIce.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - - } } diff --git a/src/main/java/forestry/core/GameMode.java b/src/main/java/forestry/core/GameMode.java index eb421fa6b..a278b7798 100755 --- a/src/main/java/forestry/core/GameMode.java +++ b/src/main/java/forestry/core/GameMode.java @@ -10,11 +10,6 @@ ******************************************************************************/ package forestry.core; -import java.util.HashMap; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - import forestry.api.core.ForestryAPI; import forestry.api.core.IGameMode; import forestry.core.config.Config; @@ -23,6 +18,9 @@ import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.config.Property; import forestry.core.proxy.Proxies; +import java.util.HashMap; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; public class GameMode implements IGameMode { @@ -129,20 +127,20 @@ public class GameMode implements IGameMode { private void initSetting(String ident, ItemStack def, String comment) { Property property = Config.config.get(ident, category, def.stackSize); - property.Comment = comment; + property.comment = comment; ItemStack changed = def.copy(); - changed.stackSize = Integer.parseInt(property.Value); + changed.stackSize = Integer.parseInt(property.value); stackSettings.put(ident, changed); } private void initSetting(String ident, int def, int max, String comment) { Property property = Config.config.get(ident, category, def); if (max < 0) { - property.Comment = comment; - integerSettings.put(ident, Integer.parseInt(property.Value)); + property.comment = comment; + integerSettings.put(ident, Integer.parseInt(property.value)); } else { - property.Comment = comment + " (max: " + max + ")"; - integerSettings.put(ident, Math.min(Integer.parseInt(property.Value), max)); + property.comment = comment + " (max: " + max + ")"; + integerSettings.put(ident, Math.min(Integer.parseInt(property.value), max)); } Config.config.set(ident, category, integerSettings.get(ident)); @@ -151,19 +149,19 @@ public class GameMode implements IGameMode { private void initSetting(String ident, float def, float max, String comment) { Property property = Config.config.get(ident, category, def); if (max < 0) { - property.Comment = comment; - floatSettings.put(ident, Float.parseFloat(property.Value)); + property.comment = comment; + floatSettings.put(ident, Float.parseFloat(property.value)); } else { - property.Comment = comment + " (max: " + max + ")"; - floatSettings.put(ident, Math.min(Float.parseFloat(property.Value), max)); + property.comment = comment + " (max: " + max + ")"; + floatSettings.put(ident, Math.min(Float.parseFloat(property.value), max)); } Config.config.set(ident, category, floatSettings.get(ident)); } private void initSetting(String ident, boolean def, String comment) { Property property = Config.config.get(ident, category, def); - property.Comment = comment; - booleanSettings.put(ident, Boolean.parseBoolean(property.Value)); + property.comment = comment; + booleanSettings.put(ident, Boolean.parseBoolean(property.value)); Config.config.set(ident, category, booleanSettings.get(ident)); } diff --git a/src/main/java/forestry/core/GuiHandler.java b/src/main/java/forestry/core/GuiHandler.java index 675d7fb68..1b0d0d015 100755 --- a/src/main/java/forestry/core/GuiHandler.java +++ b/src/main/java/forestry/core/GuiHandler.java @@ -11,6 +11,7 @@ package forestry.core; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; @@ -43,7 +44,10 @@ public class GuiHandler extends GuiHandlerBase { return new GuiEscritoire(player, (TileEscritoire) getTileForestry(world, x, y, z)); case SolderingIronGUI: - return new GuiSolderingIron(player.inventory, new SolderingInventory()); + ItemStack equipped = player.getCurrentEquippedItem(); + if (equipped == null) + return null; + return new GuiSolderingIron(player.inventory, new SolderingInventory(equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { @@ -72,7 +76,10 @@ public class GuiHandler extends GuiHandlerBase { return new ContainerEscritoire(player, (TileEscritoire) getTileForestry(world, x, y, z)); case SolderingIronGUI: - return new ContainerSolderingIron(player.inventory, new SolderingInventory()); + ItemStack equipped = player.getCurrentEquippedItem(); + if (equipped == null) + return null; + return new ContainerSolderingIron(player.inventory, new SolderingInventory(equipped)); default: for (IGuiHandler handler : PluginManager.guiHandlers) { diff --git a/src/main/java/forestry/core/GuiHandlerBase.java b/src/main/java/forestry/core/GuiHandlerBase.java index 83c96e77a..620f52c2b 100755 --- a/src/main/java/forestry/core/GuiHandlerBase.java +++ b/src/main/java/forestry/core/GuiHandlerBase.java @@ -10,12 +10,7 @@ ******************************************************************************/ package forestry.core; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import cpw.mods.fml.common.network.IGuiHandler; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.ISpeciesRoot; import forestry.core.gadgets.TileForestry; @@ -23,6 +18,9 @@ import forestry.core.gadgets.TileNaturalistChest; import forestry.core.gui.ContainerNaturalistInventory; import forestry.core.gui.GuiNaturalistInventory; import forestry.core.proxy.Proxies; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public abstract class GuiHandlerBase implements IGuiHandler { @@ -39,18 +37,13 @@ public abstract class GuiHandlerBase implements IGuiHandler { public GuiNaturalistInventory getNaturalistChestGui(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) { TileNaturalistChest tile = (TileNaturalistChest) getTileForestry(world, x, y, z); ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistInventory(speciesRoot, player.inventory, tile, page, 25), tile, page, 5); + return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistInventory(player.inventory, tile, page, 25), tile, page, 5); } public ContainerNaturalistInventory getNaturalistChestContainer(String rootUID, EntityPlayer player, World world, int x, int y, int z, int page) { ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(rootUID); speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); - return new ContainerNaturalistInventory(speciesRoot, - player.inventory, (TileNaturalistChest) getTileForestry(world, x, y, z), page, 25); - } - - public ItemStack getEquippedItem(EntityPlayer player) { - return player.getCurrentEquippedItem(); + return new ContainerNaturalistInventory(player.inventory, (TileNaturalistChest) getTileForestry(world, x, y, z), page, 25); } public static int encodeGuiData(int guiId, int data) { diff --git a/src/main/java/forestry/core/PickupHandlerCore.java b/src/main/java/forestry/core/PickupHandlerCore.java index e27f04063..83170fb46 100755 --- a/src/main/java/forestry/core/PickupHandlerCore.java +++ b/src/main/java/forestry/core/PickupHandlerCore.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.core; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.ISpeciesRoot; import forestry.core.interfaces.IPickupHandler; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; public class PickupHandlerCore implements IPickupHandler { diff --git a/src/main/java/forestry/core/SaveEventHandlerCore.java b/src/main/java/forestry/core/SaveEventHandlerCore.java index b51152825..5375d81e1 100755 --- a/src/main/java/forestry/core/SaveEventHandlerCore.java +++ b/src/main/java/forestry/core/SaveEventHandlerCore.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core; -import net.minecraft.world.World; - import forestry.core.interfaces.ISaveEventHandler; +import net.minecraft.world.World; public class SaveEventHandlerCore implements ISaveEventHandler { diff --git a/src/main/java/forestry/core/TickHandlerCoreClient.java b/src/main/java/forestry/core/TickHandlerCoreClient.java index 99ffeb4f6..ab33a8706 100755 --- a/src/main/java/forestry/core/TickHandlerCoreClient.java +++ b/src/main/java/forestry/core/TickHandlerCoreClient.java @@ -14,16 +14,17 @@ import java.util.concurrent.ConcurrentLinkedQueue; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent; +import forestry.core.utils.GeneticsUtil; import forestry.core.config.Config; import forestry.core.config.Version; import forestry.core.proxy.Proxies; -import forestry.core.utils.Utils; public class TickHandlerCoreClient { @@ -44,7 +45,7 @@ public class TickHandlerCoreClient { if (event.phase != Phase.END) return; EntityPlayer player = Proxies.common.getClientInstance().thePlayer; - boolean hasNaturalistEye = Utils.hasNaturalistEye(player); + boolean hasNaturalistEye = GeneticsUtil.hasNaturalistEye(player); if (hasNaturalistEye != hasNaturalistView) { hasNaturalistView = !hasNaturalistView; Proxies.common.getClientInstance().renderGlobal.markBlockRangeForRenderUpdate( @@ -59,21 +60,15 @@ public class TickHandlerCoreClient { } } - /* - if (!Config.disableNags) - if (Proxies.common.isModLoaded("GregTech_Addon")) - queueChatMessage("\u00A76Forestry may have been modified by GregTech. It may behave unexpectedly and some config options may not work. Do not report issues with this install! You can disable this nag in the config."); - */ - if (!naggedVersion && !Config.disableVersionCheck && Version.needsUpdateNoticeAndMarkAsSeen()) { - queueChatMessage(String.format("\u00A7cNew version of Forestry available: %s for Minecraft %s", Version.getRecommendedVersion(), + queueChatMessage(EnumChatFormatting.RED + String.format("New version of Forestry available: %s for Minecraft %s", Version.getRecommendedVersion(), Proxies.common.getMinecraftVersion())); - queueChatMessage("\u00A7cThis message only displays once. Type '/forestry version' to see the changelog."); + queueChatMessage(EnumChatFormatting.RED + "This message only displays once. Type '/forestry version' to see the changelog."); naggedVersion = true; } if (!naggedVerify && Config.invalidFingerprint) { - queueChatMessage("\u00A76Forestry's jar file was tampered with. Some machines have shut down and beekeeping has grown dangerous. Get a new jar from the official download page to fix that!"); + queueChatMessage(EnumChatFormatting.GOLD + "Forestry's jar file was tampered with. Some machines have shut down and beekeeping has grown dangerous. Get a new jar from the official download page to fix that!"); naggedVerify = true; } } diff --git a/src/main/java/forestry/core/TickHandlerCoreServer.java b/src/main/java/forestry/core/TickHandlerCoreServer.java index 3345d7214..74a091310 100755 --- a/src/main/java/forestry/core/TickHandlerCoreServer.java +++ b/src/main/java/forestry/core/TickHandlerCoreServer.java @@ -10,30 +10,91 @@ ******************************************************************************/ package forestry.core; +import com.google.common.collect.LinkedListMultimap; + +import java.util.List; +import java.util.Random; + import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.ChunkDataEvent; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent; +import forestry.core.config.Config; +import forestry.core.config.Defaults; import forestry.core.interfaces.IResupplyHandler; +import forestry.core.utils.ChunkCoords; import forestry.plugins.PluginManager; public class TickHandlerCoreServer { - public TickHandlerCoreServer() { + + private final WorldGenerator worldGenerator; + private final LinkedListMultimap chunkRegenList = LinkedListMultimap.create(); + + public TickHandlerCoreServer(WorldGenerator worldGenerator) { + this.worldGenerator = worldGenerator; FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public void onWorldTick(WorldTickEvent event) { if (event.phase != Phase.END) return; - for (Object obj : event.world.playerEntities) { - EntityPlayer player = (EntityPlayer) obj; - for (IResupplyHandler handler : PluginManager.resupplyHandlers) - handler.resupply(player); + if (Config.enableBackpackResupply) { + for (Object obj : event.world.playerEntities) { + EntityPlayer player = (EntityPlayer) obj; + for (IResupplyHandler handler : PluginManager.resupplyHandlers) + handler.resupply(player); + } } + if (Config.doRetrogen) { + World world = event.world; + int dimensionID = world.provider.dimensionId; + List chunkList = chunkRegenList.get(dimensionID); + + if (chunkList.size() > 0) { + ChunkCoords coords = chunkList.get(0); + chunkList.remove(0); + + // This bit is from FML's GameRegistry.generateWorld where the seed is constructed. + long worldSeed = world.getSeed(); + Random random = new Random(worldSeed); + long xSeed = random.nextLong() >> 2 + 1L; + long zSeed = random.nextLong() >> 2 + 1L; + random.setSeed((xSeed * coords.xCoord + zSeed * coords.zCoord) ^ worldSeed); + + worldGenerator.retroGen(random, coords.xCoord, coords.zCoord, world); + } + } + } + + @SubscribeEvent + public void chunkSaveEventHandler(ChunkDataEvent.Save event) { + NBTTagCompound tag = new NBTTagCompound(); + if (Config.doRetrogen) { + tag.setBoolean("retrogen", true); + } + + event.getData().setTag(Defaults.MOD, tag); + } + + @SubscribeEvent + public void chunkLoadEventHandler(ChunkDataEvent.Load event) { + if (Config.doRetrogen) { + NBTTagCompound tag = (NBTTagCompound)event.getData().getTag(Defaults.MOD); + if (tag == null || !tag.hasKey("retrogen") || Config.forceRetrogen) { + ChunkCoords coords = new ChunkCoords(event.getChunk()); + chunkRegenList.put(coords.dimension, coords); + } + } } } diff --git a/src/main/java/forestry/core/WorldGenerator.java b/src/main/java/forestry/core/WorldGenerator.java index ea57f2105..66b6dcc2b 100755 --- a/src/main/java/forestry/core/WorldGenerator.java +++ b/src/main/java/forestry/core/WorldGenerator.java @@ -15,13 +15,16 @@ import java.util.Random; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.terraingen.PopulateChunkEvent; + import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import forestry.core.config.Config; import forestry.core.config.ForestryBlock; import forestry.core.proxy.Proxies; import forestry.core.worldgen.WorldGenMinableMeta; -import forestry.plugins.ForestryPlugin; import forestry.plugins.PluginManager; public class WorldGenerator implements IWorldGenerator { @@ -30,11 +33,31 @@ public class WorldGenerator implements IWorldGenerator { private WorldGenMinableMeta copperGenerator; private WorldGenMinableMeta tinGenerator; + public WorldGenerator() { + MinecraftForge.EVENT_BUS.register(this); + } + @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + generateWorld(random, chunkX, chunkZ, world); + } + + @SubscribeEvent + public void populateChunk(PopulateChunkEvent.Post event) { + // / PLUGIN WORLD GENERATION + PluginManager.populateChunk(event.chunkProvider, event.world, event.rand, event.chunkX, event.chunkZ, event.hasVillageGenerated); + } + + public void retroGen(Random random, int chunkX, int chunkZ, World world) { + generateWorld(random, chunkX, chunkZ, world); + PluginManager.populateChunkRetroGen(world, random, chunkX, chunkZ); + world.getChunkFromChunkCoords(chunkX, chunkZ).setChunkModified(); + } + + private void generateWorld(Random random, int chunkX, int chunkZ, World world) { if (apatiteGenerator == null) { - apatiteGenerator = new WorldGenMinableMeta(ForestryBlock.resources.block(), 0, 36); + apatiteGenerator = new WorldGenMinableMeta(ForestryBlock.resources, 0, 36); copperGenerator = new WorldGenMinableMeta(ForestryBlock.resources, 1, 6); tinGenerator = new WorldGenMinableMeta(ForestryBlock.resources, 2, 6); } @@ -70,9 +93,6 @@ public class WorldGenerator implements IWorldGenerator { int randPosZ = chunkZ + random.nextInt(16); tinGenerator.generate(world, random, randPosX, randPosY, randPosZ); } - - // / PLUGIN WORLD GENERATION - PluginManager.generateSurface(world, random, chunkX, chunkZ); } } diff --git a/src/main/java/forestry/core/circuits/Circuit.java b/src/main/java/forestry/core/circuits/Circuit.java index ac8b4989e..be7061f2f 100755 --- a/src/main/java/forestry/core/circuits/Circuit.java +++ b/src/main/java/forestry/core/circuits/Circuit.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.core.circuits; -import java.util.List; - import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuit; import forestry.core.utils.StringUtil; +import java.util.List; public abstract class Circuit implements ICircuit { diff --git a/src/main/java/forestry/core/circuits/CircuitBoard.java b/src/main/java/forestry/core/circuits/CircuitBoard.java index 744bffaff..1fe85ff27 100755 --- a/src/main/java/forestry/core/circuits/CircuitBoard.java +++ b/src/main/java/forestry/core/circuits/CircuitBoard.java @@ -10,22 +10,26 @@ ******************************************************************************/ package forestry.core.circuits; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; + import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitLayout; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; - -import java.util.ArrayList; -import java.util.List; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StringUtil; public class CircuitBoard implements ICircuitBoard { - EnumCircuitBoardType type; - ICircuitLayout layout; - ICircuit[] circuits; + private EnumCircuitBoardType type; + private ICircuitLayout layout; + private ICircuit[] circuits; public CircuitBoard(EnumCircuitBoardType type, ICircuitLayout layout, ICircuit[] circuits) { this.type = type; @@ -50,11 +54,18 @@ public class CircuitBoard implements ICircuitBoard { @Override public void addTooltip(List list) { if (layout != null) - list.add("\u00A76" + layout.getUsage() + ":"); + list.add(EnumChatFormatting.GOLD + layout.getUsage() + ":"); + List extendedTooltip = new ArrayList(); for (ICircuit circuit : circuits) if (circuit != null) - circuit.addTooltip(list); + circuit.addTooltip(extendedTooltip); + + if(Proxies.common.isShiftDown() || extendedTooltip.size() <= 4) { + list.addAll(extendedTooltip); + } else { + list.add(EnumChatFormatting.ITALIC + "<" + StringUtil.localize("gui.tooltip.tmi") + ">"); + } } @Override diff --git a/src/main/java/forestry/core/circuits/CircuitLayout.java b/src/main/java/forestry/core/circuits/CircuitLayout.java index e649a9017..60cb2d29d 100755 --- a/src/main/java/forestry/core/circuits/CircuitLayout.java +++ b/src/main/java/forestry/core/circuits/CircuitLayout.java @@ -28,11 +28,11 @@ public class CircuitLayout implements ICircuitLayout { @Override public String getName() { - return StringUtil.localize("layout." + this.uid); + return StringUtil.localize("circuit.layout." + this.uid + ".name"); } @Override public String getUsage() { - return StringUtil.localize("usage." + this.uid); + return StringUtil.localize("circuit.layout." + this.uid + ".usage"); } } diff --git a/src/main/java/forestry/core/circuits/CircuitLibrary.java b/src/main/java/forestry/core/circuits/CircuitLibrary.java index 22d9d6d09..591d5de80 100755 --- a/src/main/java/forestry/core/circuits/CircuitLibrary.java +++ b/src/main/java/forestry/core/circuits/CircuitLibrary.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.core.circuits; +import forestry.api.circuits.ICircuitLibrary; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.WorldSavedData; -import forestry.api.circuits.ICircuitLibrary; - public class CircuitLibrary extends WorldSavedData implements ICircuitLibrary { public CircuitLibrary(String par1Str) { diff --git a/src/main/java/forestry/core/circuits/CircuitRegistry.java b/src/main/java/forestry/core/circuits/CircuitRegistry.java index bfcac9040..00f496615 100755 --- a/src/main/java/forestry/core/circuits/CircuitRegistry.java +++ b/src/main/java/forestry/core/circuits/CircuitRegistry.java @@ -10,25 +10,30 @@ ******************************************************************************/ package forestry.core.circuits; -import java.util.HashMap; -import java.util.LinkedHashMap; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitLayout; import forestry.api.circuits.ICircuitLibrary; import forestry.api.circuits.ICircuitRegistry; import forestry.core.config.ForestryItem; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; public class CircuitRegistry implements ICircuitRegistry { - private final LinkedHashMap layoutMap = new LinkedHashMap(); - private final LinkedHashMap circuitMap = new LinkedHashMap(); - private final HashMap legacyMap = new HashMap(); + public static final ICircuitLayout DUMMY_LAYOUT = new CircuitLayout("dummy"); + public static final Map DUMMY_MAP = new LinkedHashMap(); + private final Map layoutMap = new LinkedHashMap(); + private final Map circuitMap = new LinkedHashMap(); + private final Map legacyMap = new HashMap(); + + static { + DUMMY_MAP.put("dummy", DUMMY_LAYOUT); + } @Override public ICircuitLibrary getCircuitLibrary(World world, String playername) { @@ -47,12 +52,16 @@ public class CircuitRegistry implements ICircuitRegistry { public ICircuitLayout getDefaultLayout() { if (layoutMap.containsKey("forestry.engine.tin")) return layoutMap.get("forestry.engine.tin"); - else + else if (!layoutMap.isEmpty()) return layoutMap.values().iterator().next(); + else + return DUMMY_LAYOUT; } @Override - public LinkedHashMap getRegisteredLayouts() { + public Map getRegisteredLayouts() { + if (layoutMap.isEmpty()) + return DUMMY_MAP; return layoutMap; } @@ -71,7 +80,7 @@ public class CircuitRegistry implements ICircuitRegistry { /* CIRCUITS */ @Override - public HashMap getRegisteredCircuits() { + public Map getRegisteredCircuits() { return circuitMap; } @@ -100,14 +109,12 @@ public class CircuitRegistry implements ICircuitRegistry { public void initialize() { } - - - + @Override public boolean isChipset(ItemStack itemstack) { return ForestryItem.circuitboards.isItemEqual(itemstack); } - + @Override public ICircuitBoard getCircuitboard(ItemStack itemstack) { NBTTagCompound nbttagcompound = itemstack.getTagCompound(); diff --git a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java index 5c4555a28..be414af19 100755 --- a/src/main/java/forestry/core/circuits/ContainerSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ContainerSolderingIron.java @@ -12,15 +12,14 @@ package forestry.core.circuits; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.api.circuits.ICircuitLayout; import forestry.core.circuits.ItemSolderingIron.SolderingInventory; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; @@ -28,23 +27,23 @@ import forestry.core.proxy.Proxies; public class ContainerSolderingIron extends ContainerItemInventory implements IGuiSelectable { - SolderingInventory inventory; + private final SolderingInventory inventory; public ContainerSolderingIron(InventoryPlayer inventoryplayer, SolderingInventory inventory) { super(inventory, inventoryplayer.player); this.inventory = inventory; // Input - this.addSlot(new SlotCustom(inventory, 0, 152, 12, ItemCircuitBoard.class)); + this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); // Output - this.addSlot(new SlotCustom(inventory, 1, 152, 92, ItemCircuitBoard.class)); + this.addSlotToContainer(new SlotOutput(inventory, 1, 152, 92)); // Ingredients - this.addSlot(new Slot(inventory, 2, 12, 32)); - this.addSlot(new Slot(inventory, 3, 12, 52)); - this.addSlot(new Slot(inventory, 4, 12, 72)); - this.addSlot(new Slot(inventory, 5, 12, 92)); + this.addSlotToContainer(new SlotFiltered(inventory, 2, 12, 32)); + this.addSlotToContainer(new SlotFiltered(inventory, 3, 12, 52)); + this.addSlotToContainer(new SlotFiltered(inventory, 4, 12, 72)); + this.addSlotToContainer(new SlotFiltered(inventory, 5, 12, 92)); // Player inventory for (int i1 = 0; i1 < 3; i1++) @@ -56,24 +55,6 @@ public class ContainerSolderingIron extends ContainerItemInventory implements IG } - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return false; - } - - /* - * @Override public void onCraftGuiClosed(EntityPlayer entityplayer) { - * - * if (!Proxies.common.isSimulating(entityplayer.worldObj)) return; - * - * // Drop everything still in there. for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack stack = inventory.getStackInSlot(i); if (stack == - * null) { continue; } - * - * Proxies.common.dropItemPlayer(entityplayer, stack); inventory.setInventorySlotContents(i, null); } - * - * } - */ - public ICircuitLayout getLayout() { return inventory.getLayout(); } diff --git a/src/main/java/forestry/core/circuits/GuiSolderingIron.java b/src/main/java/forestry/core/circuits/GuiSolderingIron.java index 5f47254c2..68ed4d15a 100755 --- a/src/main/java/forestry/core/circuits/GuiSolderingIron.java +++ b/src/main/java/forestry/core/circuits/GuiSolderingIron.java @@ -10,10 +10,6 @@ ******************************************************************************/ package forestry.core.circuits; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; - import forestry.api.circuits.ICircuitLayout; import forestry.core.circuits.ItemSolderingIron.CircuitRecipe; import forestry.core.circuits.ItemSolderingIron.SolderingInventory; @@ -22,6 +18,9 @@ import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; public class GuiSolderingIron extends GuiForestry { diff --git a/src/main/java/forestry/core/circuits/ItemCircuitBoard.java b/src/main/java/forestry/core/circuits/ItemCircuitBoard.java index 626d549a0..22999f920 100755 --- a/src/main/java/forestry/core/circuits/ItemCircuitBoard.java +++ b/src/main/java/forestry/core/circuits/ItemCircuitBoard.java @@ -10,21 +10,19 @@ ******************************************************************************/ package forestry.core.circuits; -import java.util.List; -import java.util.Locale; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitBoard; import forestry.api.circuits.ICircuitLayout; import forestry.core.config.ForestryItem; import forestry.core.items.ItemForestryMultiPass; +import java.util.List; +import java.util.Locale; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class ItemCircuitBoard extends ItemForestryMultiPass { diff --git a/src/main/java/forestry/core/circuits/ItemSolderingIron.java b/src/main/java/forestry/core/circuits/ItemSolderingIron.java index 0a6e3413e..0034fb1d2 100755 --- a/src/main/java/forestry/core/circuits/ItemSolderingIron.java +++ b/src/main/java/forestry/core/circuits/ItemSolderingIron.java @@ -10,31 +10,33 @@ ******************************************************************************/ package forestry.core.circuits; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map.Entry; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuit; import forestry.api.circuits.ICircuitLayout; import forestry.api.circuits.ISolderManager; import forestry.api.core.ForestryAPI; -import forestry.api.core.EnumErrorCode; +import forestry.api.core.IErrorState; +import forestry.core.EnumErrorCode; import forestry.core.interfaces.IErrorSource; +import forestry.core.inventory.ItemInventory; import forestry.core.items.ItemForestry; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; +import forestry.core.utils.RevolvingList; +import forestry.plugins.PluginApiculture; + +import java.util.ArrayList; +import java.util.Collection; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; public class ItemSolderingIron extends ItemForestry implements ISolderingIron { public static class CircuitRecipe { + private final ICircuitLayout layout; private final ItemStack resource; public final ICircuit circuit; @@ -54,6 +56,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { } public static class SolderManager implements ISolderManager { + public static final ArrayList recipes = new ArrayList(); @Override @@ -71,9 +74,10 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { if (layout == null || resource == null) return null; - for (CircuitRecipe recipe : recipes) + for (CircuitRecipe recipe : recipes) { if (recipe.matches(layout, resource)) return recipe; + } return null; } @@ -82,66 +86,42 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { // / INVENTORY MANAGMENT public static class SolderingInventory extends ItemInventory implements IErrorSource { - private ICircuitLayout layout; + private final RevolvingList layouts = new RevolvingList(ChipsetManager.circuitRegistry.getRegisteredLayouts().values()); private EnumErrorCode errorState; private final short blankSlot = 0; private final short finishedSlot = 1; private final short ingredientSlot1 = 2; + private final short ingredientSlotCount = 4; - public SolderingInventory() { - super(ItemSolderingIron.class, 6); - layout = ChipsetManager.circuitRegistry.getDefaultLayout(); + public SolderingInventory(ItemStack itemStack) { + super(ItemSolderingIron.class, 6, itemStack); + init(); } - public SolderingInventory(ItemStack itemstack) { - super(ItemSolderingIron.class, 6, itemstack); - layout = ChipsetManager.circuitRegistry.getDefaultLayout(); + @Override + public int getInventoryStackLimit() { + return 1; + } + + private void init() { + layouts.setCurrent(ChipsetManager.circuitRegistry.getDefaultLayout()); } public ICircuitLayout getLayout() { - return this.layout; + return layouts.getCurrent(); } public void setLayout(String uid) { - this.layout = ChipsetManager.circuitRegistry.getLayout(uid); + layouts.setCurrent(ChipsetManager.circuitRegistry.getLayout(uid)); } public void advanceLayout() { - Iterator> it = ChipsetManager.circuitRegistry.getRegisteredLayouts().entrySet().iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getKey().equals(layout.getUID())) { - - if (it.hasNext()) - layout = it.next().getValue(); - else - layout = ChipsetManager.circuitRegistry.getRegisteredLayouts().entrySet().iterator().next().getValue(); - - break; - } - } + layouts.rotateRight(); } public void regressLayout() { - Iterator> it = ChipsetManager.circuitRegistry.getRegisteredLayouts().entrySet().iterator(); - - ICircuitLayout previous = null; - while (it.hasNext()) { - Entry entry = it.next(); - if (entry.getKey().equals(layout.getUID())) { - - if (previous != null) - layout = previous; - else - while (it.hasNext()) - layout = it.next().getValue(); - - break; - } - - previous = entry.getValue(); - } + layouts.rotateLeft(); } private Collection getCircuits(EnumCircuitBoardType type, boolean doConsume) { @@ -153,7 +133,7 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { if (ingredient == null) continue; - CircuitRecipe recipe = SolderManager.getMatchingRecipe(layout, ingredient); + CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), ingredient); if (recipe == null) continue; @@ -170,16 +150,18 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { } public void trySolder() { - - // Requires blank slot - if (inventoryStacks[blankSlot] == null) + if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) return; - if (inventoryStacks[blankSlot].stackSize > 1) + + ItemStack blank = inventoryStacks[blankSlot]; + // Requires blank slot + if (blank == null) + return; + if (blank.stackSize > 1) return; if (inventoryStacks[finishedSlot] != null) return; - ItemStack blank = inventoryStacks[blankSlot]; // Need a chipset item if (!ChipsetManager.circuitRegistry.isChipset(blank)) return; @@ -199,26 +181,19 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { } circuits = getCircuits(type, true); - inventoryStacks[finishedSlot] = ItemCircuitBoard.createCircuitboard(type, layout, circuits.toArray(new ICircuit[circuits.size()])); + inventoryStacks[finishedSlot] = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits.toArray(new ICircuit[circuits.size()])); inventoryStacks[blankSlot] = null; } public int getCount(ICircuit circuit, ArrayList circuits) { int count = 0; - for (ICircuit other : circuits) + for (ICircuit other : circuits) { if (other.getUID().equals(circuit.getUID())) count++; + } return count; } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - } - @Override public void markDirty() { errorState = EnumErrorCode.OK; @@ -231,7 +206,9 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { } @Override - public EnumErrorCode getErrorState() { + public IErrorState getErrorState() { + if (layouts.getCurrent() == CircuitRegistry.DUMMY_LAYOUT) + return EnumErrorCode.NOCIRCUITLAYOUT; if (inventoryStacks[blankSlot] == null) return EnumErrorCode.NOCIRCUITBOARD; if (inventoryStacks[blankSlot].stackSize > 1) @@ -241,6 +218,21 @@ public class ItemSolderingIron extends ItemForestry implements ISolderingIron { return EnumErrorCode.OK; } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (itemStack == null) + return false; + + Item item = itemStack.getItem(); + if (slotIndex == blankSlot) { + return item instanceof ItemCircuitBoard; + } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { + CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), itemStack); + return recipe != null; + } + return false; + } } public ItemSolderingIron() { diff --git a/src/main/java/forestry/core/commands/CommandHelpers.java b/src/main/java/forestry/core/commands/CommandHelpers.java index 71d440ca3..d1ff93265 100644 --- a/src/main/java/forestry/core/commands/CommandHelpers.java +++ b/src/main/java/forestry/core/commands/CommandHelpers.java @@ -11,6 +11,9 @@ package forestry.core.commands; import forestry.core.utils.StringUtil; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; @@ -22,10 +25,6 @@ import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - /** * * @author CovertJaguar @@ -70,14 +69,11 @@ public class CommandHelpers { } /** - Avoid using this function if at all possible. Commands are processed on the server, - which has no localization information. - - StringUtil.localize() is NOT a valid alternative for sendLocalizedChatMessage(). - Messages will not be localized properly if you use StringUtil.localize(). - - @param sender - @param message + * Avoid using this function if at all possible. Commands are processed on the server, + * which has no localization information. + * + * StringUtil.localize() is NOT a valid alternative for sendLocalizedChatMessage(). + * Messages will not be localized properly if you use StringUtil.localize(). */ public static void sendChatMessage(ICommandSender sender, String message) { sender.addChatMessage(new ChatComponentText(message)); diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingMode.java b/src/main/java/forestry/core/commands/CommandMode.java similarity index 68% rename from src/main/java/forestry/apiculture/commands/CommandBeekeepingMode.java rename to src/main/java/forestry/core/commands/CommandMode.java index 0502deb12..ee3c2cc16 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingMode.java +++ b/src/main/java/forestry/core/commands/CommandMode.java @@ -4,19 +4,17 @@ * 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.commands; +package forestry.core.commands; -import forestry.core.commands.SubCommand; +public class CommandMode extends SubCommand { -public class CommandBeekeepingMode extends SubCommand { - - public CommandBeekeepingMode() { + public CommandMode(ICommandModeHelper modeHelper) { super("mode"); - addChildCommand(new CommandBeekeepingModeInfo()); - addChildCommand(new CommandBeekeepingModeSet()); + addChildCommand(new CommandModeInfo(modeHelper)); + addChildCommand(new CommandModeSet(modeHelper)); } } diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingModeInfo.java b/src/main/java/forestry/core/commands/CommandModeInfo.java similarity index 53% rename from src/main/java/forestry/apiculture/commands/CommandBeekeepingModeInfo.java rename to src/main/java/forestry/core/commands/CommandModeInfo.java index dce83b61b..62b3ce7dc 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingModeInfo.java +++ b/src/main/java/forestry/core/commands/CommandModeInfo.java @@ -8,45 +8,26 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture.commands; +package forestry.core.commands; -import forestry.api.apiculture.IBeekeepingMode; -import forestry.core.commands.CommandHelpers; -import forestry.core.commands.SubCommand; -import forestry.plugins.PluginApiculture; +import java.util.List; import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; +import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class CommandBeekeepingModeInfo extends SubCommand { - +public class CommandModeInfo extends SubCommand { private final String[] modeStringArr; private final String helpString; + private final ICommandModeHelper modeHelper; - public CommandBeekeepingModeInfo() { + public CommandModeInfo(ICommandModeHelper modeHelper) { super("info"); - List modeStrings = new ArrayList(); - for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) - modeStrings.add(mode.getName()); - - modeStringArr = modeStrings.toArray(new String[modeStrings.size()]); - - StringBuilder help = new StringBuilder(); - String separator = ", "; - - Iterator iter = modeStrings.iterator(); - while (iter.hasNext()) { - help.append(iter.next()); - if (iter.hasNext()) - help.append(separator); - } - helpString = help.toString(); + this.modeHelper = modeHelper; + modeStringArr = modeHelper.getModeNames(); + helpString = StringUtils.join(modeStringArr, ", "); } @Override @@ -56,42 +37,33 @@ public class CommandBeekeepingModeInfo extends SubCommand { return; } - String modeName = args[0]; + String modeName = modeHelper.getModeNameMatching(args[0]); - IBeekeepingMode found = findModeWithName(modeName); - if (found == null) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.error", modeName); + if (modeName == null) { + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.error", args[0]); printHelp(sender); return; } ChatStyle green = new ChatStyle(); green.setColor(EnumChatFormatting.GREEN); - CommandHelpers.sendLocalizedChatMessage(sender, green, found.getName()); + CommandHelpers.sendLocalizedChatMessage(sender, green, modeName); - for (String desc : found.getDescription()) + for (String desc : modeHelper.getDescription(modeName)) CommandHelpers.sendLocalizedChatMessage(sender, "for." + desc); } - private IBeekeepingMode findModeWithName(String name) { - for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) { - if (mode.getName().equalsIgnoreCase(name)) - return mode; - } - return null; - } - @Override public void printHelp(ICommandSender sender) { super.printHelp(sender); World world = CommandHelpers.getWorld(sender, this); - String modeName = PluginApiculture.beeInterface.getBeekeepingMode(world).getName(); + String modeName = modeHelper.getModeName(world); String worldName = String.valueOf(world.getWorldInfo().getSaveVersion()); - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.current", modeName, worldName); - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.available", helpString); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.current", modeName, worldName); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.available", helpString); } @Override diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingModeSet.java b/src/main/java/forestry/core/commands/CommandModeSet.java similarity index 60% rename from src/main/java/forestry/apiculture/commands/CommandBeekeepingModeSet.java rename to src/main/java/forestry/core/commands/CommandModeSet.java index 13aa6bb34..c7071d405 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingModeSet.java +++ b/src/main/java/forestry/core/commands/CommandModeSet.java @@ -8,30 +8,23 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture.commands; +package forestry.core.commands; -import forestry.api.apiculture.IBeekeepingMode; -import forestry.core.commands.CommandHelpers; -import forestry.core.commands.SubCommand; -import forestry.plugins.PluginApiculture; +import java.util.List; import net.minecraft.command.ICommandSender; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.List; - -public class CommandBeekeepingModeSet extends SubCommand { +public final class CommandModeSet extends SubCommand { private final String[] modeStringArr; + private final ICommandModeHelper modeSetter; - public CommandBeekeepingModeSet() { + public CommandModeSet(ICommandModeHelper modeSetter) { super("set"); setPermLevel(PermLevel.ADMIN); - int modeStringCount = PluginApiculture.beeInterface.getBeekeepingModes().size(); - List modeStrings = new ArrayList(modeStringCount); - for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) - modeStrings.add(mode.getName()); - modeStringArr = modeStrings.toArray(new String[modeStringCount]); + this.modeSetter = modeSetter; + modeStringArr = modeSetter.getModeNames(); + } @Override @@ -49,15 +42,15 @@ public class CommandBeekeepingModeSet extends SubCommand { String desired = args[args.length - 1]; - IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(desired); - if (mode == null) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.set.error", desired); + String modeName = modeSetter.getModeNameMatching(desired); + if (modeName == null) { + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.set.error", desired); printHelp(sender); return; } - PluginApiculture.beeInterface.setBeekeepingMode(world, mode.getName()); - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.set.success", mode.getName()); + modeSetter.setMode(world, modeName); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.set.success", modeName); } @Override diff --git a/src/main/java/forestry/core/commands/CommandPlugins.java b/src/main/java/forestry/core/commands/CommandPlugins.java index 16aa894ca..90ec50349 100644 --- a/src/main/java/forestry/core/commands/CommandPlugins.java +++ b/src/main/java/forestry/core/commands/CommandPlugins.java @@ -16,6 +16,7 @@ import forestry.plugins.Plugin; import forestry.plugins.PluginManager; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; /** @@ -49,9 +50,7 @@ public class CommandPlugins extends SubCommand { } private String makeListEntry(ForestryPlugin plugin) { - String entry = "\u00A7c"; - if (plugin.isAvailable()) - entry = "\u00A7a"; + String entry = plugin.isAvailable() ? EnumChatFormatting.GREEN.toString() : EnumChatFormatting.RED.toString(); Plugin info = plugin.getClass().getAnnotation(Plugin.class); if (info != null) { @@ -95,18 +94,17 @@ public class CommandPlugins extends SubCommand { if (found == null) throw new CommandException(StringUtil.localizeAndFormat("chat.plugins.error", plugin)); - String entry = "\u00A7c"; - if (found.isAvailable()) - entry = "\u00A7a"; + EnumChatFormatting formatting = found.isAvailable() ? EnumChatFormatting.GREEN : EnumChatFormatting.RED; + Plugin info = found.getClass().getAnnotation(Plugin.class); if (info != null) { - CommandHelpers.sendChatMessage(sender, entry + "Plugin: " + info.name()); + CommandHelpers.sendChatMessage(sender, formatting + "Plugin: " + info.name()); if (!info.version().isEmpty()) - CommandHelpers.sendChatMessage(sender, "\u00A79Version: " + info.version()); + CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + "Version: " + info.version()); if (!info.author().isEmpty()) - CommandHelpers.sendChatMessage(sender, "\u00A79Author(s): " + info.author()); + CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + "Author(s): " + info.author()); if (!info.url().isEmpty()) - CommandHelpers.sendChatMessage(sender, "\u00A79URL: " + info.url()); + CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + "URL: " + info.url()); if (!info.unlocalizedDescription().isEmpty()) CommandHelpers.sendChatMessage(sender, StatCollector.translateToLocal(info.unlocalizedDescription())); } diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingSave.java b/src/main/java/forestry/core/commands/CommandSaveStats.java similarity index 61% rename from src/main/java/forestry/apiculture/commands/CommandBeekeepingSave.java rename to src/main/java/forestry/core/commands/CommandSaveStats.java index 60423d3c8..7c0d457d0 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingSave.java +++ b/src/main/java/forestry/core/commands/CommandSaveStats.java @@ -8,24 +8,15 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture.commands; +package forestry.core.commands; -import com.mojang.authlib.GameProfile; -import forestry.api.apiculture.IAlleleBeeSpecies; -import forestry.api.apiculture.IApiaristTracker; import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAllele; -import forestry.core.commands.CommandHelpers; -import forestry.core.commands.SubCommand; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; import forestry.core.config.Defaults; import forestry.core.config.Version; import forestry.core.proxy.Proxies; -import forestry.plugins.PluginApiculture; -import net.minecraft.command.ICommandSender; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - +import forestry.core.utils.StringUtil; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; @@ -37,18 +28,29 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; -public class CommandBeekeepingSave extends SubCommand { +public final class CommandSaveStats extends SubCommand { - private final String discoveredSymbol; - private final String blacklistedSymbol; - private final String notCountedSymbol; + private static final String discoveredSymbol; + private static final String blacklistedSymbol; + private static final String notCountedSymbol; + static { + discoveredSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered.symbol"); + blacklistedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.blacklisted.symbol"); + notCountedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.notCounted.symbol"); + } - public CommandBeekeepingSave() { + private final IStatsSaveHelper saveHelper; + private final ICommandModeHelper modeHelper; + + public CommandSaveStats(IStatsSaveHelper saveHelper, ICommandModeHelper modeHelper) { super("save"); - discoveredSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered.symbol"); - blacklistedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.blacklisted.symbol"); - notCountedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.notCounted.symbol"); + this.saveHelper = saveHelper; + this.modeHelper = modeHelper; } @Override @@ -58,7 +60,7 @@ public class CommandBeekeepingSave extends SubCommand { @Override public void processSubCommand(ICommandSender sender, String[] args) { - if (args.length != 1) { + if (args.length > 1) { printHelp(sender); return; } @@ -66,76 +68,66 @@ public class CommandBeekeepingSave extends SubCommand { String newLine = System.getProperty("line.separator"); World world = CommandHelpers.getWorld(sender, this); - String player = args[0]; + EntityPlayerMP player; + if (args.length > 0) + player = CommandHelpers.getPlayer(sender, args[0]); + else + player = CommandHelpers.getPlayer(sender, sender.getCommandSenderName()); + Collection statistics = new ArrayList(); String date = DateFormat.getInstance().format(new Date()); - statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.beekeeping.save.stats", player, date)); + statistics.add(StatCollector.translateToLocalFormatted(saveHelper.getUnlocalizedSaveStatsString(), player.getDisplayName(), date)); statistics.add(""); - String modeName = PluginApiculture.beeInterface.getBeekeepingMode(world).getName(); - statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.beekeeping.save.mode", modeName)); + statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.stats.save.mode", modeHelper.getModeName(world))); statistics.add(""); - GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(player); - IApiaristTracker tracker = PluginApiculture.beeInterface.getBreedingTracker(world, profile); + IBreedingTracker tracker = saveHelper.getBreedingTracker(world, player.getGameProfile()); if (tracker == null) - statistics.add(StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.error4")); + statistics.add(StatCollector.translateToLocal("for.chat.command.forestry.stats.save.error4")); else { - String discoveredLine = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered") + ":"; - statistics.add(discoveredLine); - statistics.add(line(discoveredLine.length())); + saveHelper.addExtraInfo(statistics, tracker); - String queen = StatCollector.translateToLocal("for.bees.grammar.queen.type"); - String princess = StatCollector.translateToLocal("for.bees.grammar.princess.type"); - String drone = StatCollector.translateToLocal("for.bees.grammar.drone.type"); - statistics.add(queen + ":\t\t" + tracker.getQueenCount()); - statistics.add(princess + ":\t" + tracker.getPrincessCount()); - statistics.add(drone + ":\t\t" + tracker.getDroneCount()); - statistics.add(""); - - Collection species = new ArrayList(); - for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) - if (allele instanceof IAlleleBeeSpecies) - species.add((IAlleleBeeSpecies) allele); + Collection species = saveHelper.getSpecies(); String speciesCount = StatCollector.translateToLocal("for.gui.speciescount"); String speciesCountLine = String.format("%s (%s):", speciesCount, species.size()); statistics.add(speciesCountLine); - statistics.add(line(speciesCountLine.length())); + statistics.add(StringUtil.line(speciesCountLine.length())); - statistics.add(discoveredSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered")); - statistics.add(blacklistedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.blacklisted")); - statistics.add(notCountedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.notCounted")); + statistics.add(discoveredSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered")); + statistics.add(blacklistedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.blacklisted")); + statistics.add(notCountedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.notCounted")); statistics.add(""); String header = generateSpeciesListHeader(); statistics.add(header); - statistics.add(line(header.length())); + statistics.add(StringUtil.line(header.length())); statistics.add(""); - for (IAlleleBeeSpecies allele : species) + for (IAlleleSpecies allele : species) statistics.add(generateSpeciesListEntry(allele, tracker)); } - File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player + ".log"); + File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + "-" + saveHelper.getFileSuffix() + ".log"); try { File folder = file.getParentFile(); if (folder != null && !folder.exists()) { boolean success = file.getParentFile().mkdirs(); if (!success) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error1"); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1"); return; } } if (!file.exists() && !file.createNewFile()) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error1"); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1"); return; } if (!file.canWrite()) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error2"); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error2"); return; } @@ -151,20 +143,12 @@ public class CommandBeekeepingSave extends SubCommand { } catch (IOException ex) { - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error3"); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error3"); ex.printStackTrace(); return; } - CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.saved", player); - } - - private String line(int length) { - StringBuilder line = new StringBuilder(); - for (int i = 0; i < length; i++) - line.append("-"); - - return line.toString(); + CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.saved", player.getDisplayName()); } private String generateSpeciesListHeader() { @@ -173,7 +157,7 @@ public class CommandBeekeepingSave extends SubCommand { return speciesListEntry(discoveredSymbol, blacklistedSymbol, notCountedSymbol, "UID", species, authority); } - private String generateSpeciesListEntry(IAlleleBeeSpecies species, IApiaristTracker tracker) { + private String generateSpeciesListEntry(IAlleleSpecies species, IBreedingTracker tracker) { String discovered = ""; if (tracker.isDiscovered(species)) discovered = discoveredSymbol; diff --git a/src/main/java/forestry/core/commands/CommandVersion.java b/src/main/java/forestry/core/commands/CommandVersion.java index 045aaf84d..55a18f927 100644 --- a/src/main/java/forestry/core/commands/CommandVersion.java +++ b/src/main/java/forestry/core/commands/CommandVersion.java @@ -10,9 +10,9 @@ ******************************************************************************/ package forestry.core.commands; -import net.minecraft.command.ICommandSender; import forestry.core.config.Version; import forestry.core.proxy.Proxies; +import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; @@ -37,7 +37,7 @@ public class CommandVersion extends SubCommand { CommandHelpers.sendLocalizedChatMessage(sender, style, "for.chat.version", Version.getVersion(), Proxies.common.getMinecraftVersion(), Version.getRecommendedVersion()); if (Version.isOutdated()) for (String updateLine : Version.getChangelog()) { - CommandHelpers.sendChatMessage(sender, "\u00A79" + updateLine); + CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + updateLine); } } diff --git a/src/main/java/forestry/core/commands/ICommandModeHelper.java b/src/main/java/forestry/core/commands/ICommandModeHelper.java new file mode 100644 index 000000000..f5670c7d2 --- /dev/null +++ b/src/main/java/forestry/core/commands/ICommandModeHelper.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import net.minecraft.world.World; + +public interface ICommandModeHelper { + String[] getModeNames(); + + String getModeNameMatching(String desired); + + String getModeName(World world); + void setMode(World world, String modeName); + + Iterable getDescription(String modeName); +} diff --git a/src/main/java/forestry/core/commands/IStatsSaveHelper.java b/src/main/java/forestry/core/commands/IStatsSaveHelper.java new file mode 100644 index 000000000..8a671b739 --- /dev/null +++ b/src/main/java/forestry/core/commands/IStatsSaveHelper.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import com.mojang.authlib.GameProfile; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; +import java.util.Collection; +import net.minecraft.world.World; + +public interface IStatsSaveHelper { + + String getUnlocalizedSaveStatsString(); + + void addExtraInfo(Collection statistics, IBreedingTracker breedingTracker); + + Collection getSpecies(); + + String getFileSuffix(); + + IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile); +} diff --git a/src/main/java/forestry/apiculture/SpeciesNotFoundException.java b/src/main/java/forestry/core/commands/SpeciesNotFoundException.java old mode 100755 new mode 100644 similarity index 89% rename from src/main/java/forestry/apiculture/SpeciesNotFoundException.java rename to src/main/java/forestry/core/commands/SpeciesNotFoundException.java index 9e4308a12..c84501bf5 --- a/src/main/java/forestry/apiculture/SpeciesNotFoundException.java +++ b/src/main/java/forestry/core/commands/SpeciesNotFoundException.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture; +package forestry.core.commands; import net.minecraft.command.CommandException; @@ -17,7 +17,7 @@ public class SpeciesNotFoundException extends CommandException { private static final long serialVersionUID = 1L; public SpeciesNotFoundException(String title) { - super("Could not find bee species with Name or UID %s", title); + super("Could not find species with Name or UID %s", title); } } diff --git a/src/main/java/forestry/apiculture/TemplateNotFoundException.java b/src/main/java/forestry/core/commands/TemplateNotFoundException.java old mode 100755 new mode 100644 similarity index 96% rename from src/main/java/forestry/apiculture/TemplateNotFoundException.java rename to src/main/java/forestry/core/commands/TemplateNotFoundException.java index 16a157084..a8a6cea35 --- a/src/main/java/forestry/apiculture/TemplateNotFoundException.java +++ b/src/main/java/forestry/core/commands/TemplateNotFoundException.java @@ -8,11 +8,10 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture; - -import net.minecraft.command.CommandException; +package forestry.core.commands; import forestry.api.genetics.IAlleleSpecies; +import net.minecraft.command.CommandException; public class TemplateNotFoundException extends CommandException { diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index 52b01dc0f..677aff035 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.core.config; -import forestry.core.proxy.Proxies; - import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; @@ -22,22 +20,28 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Locale; import java.util.Properties; +import java.util.Set; + +import forestry.core.fluids.Fluids; +import forestry.core.proxy.Proxies; public class Config { public static final String CATEGORY_COMMON = "common"; + public static final String CATEGORY_FLUIDS = "fluids"; public static final String CATEGORY_DEBUG = "debug"; public static Configuration config; public static String gameMode; - public static final HashSet disabledStructures = new HashSet(); + private static final Set disabledStructures = new HashSet(); + private static final Set disabledFluids = new HashSet(); + private static final Set disabledBlocks = new HashSet(); public static boolean isDebug = false; public static boolean disablePermissions = false; - public static boolean disableNags = false; public static boolean disableVersionCheck = false; public static boolean invalidFingerprint = false; @@ -56,33 +60,23 @@ public class Config { public static boolean generateCopperOre = true; public static boolean generateTinOre = true; public static boolean generateBeehives = true; - public static boolean generateBogEarth = false; public static boolean generateBeehivesDebug = false; + // Retrogen + public static boolean doRetrogen = false; + public static boolean forceRetrogen = false; + // Performance public static boolean enableBackpackResupply = true; - public static int planterThrottle; - public static int harvesterThrottle; // Customization public static boolean tooltipLiquidAmount = true; - public static boolean planterSideSensitive = true; - /** - * True if the harvester should decide output to pipes according to side. - */ - public static boolean harvesterSideSensitive = true; - /* GO AWAY GRED */ private static boolean craftingBronzeEnabled = true; - public static boolean getCraftingBronzeEnabled() { - return craftingBronzeEnabled; - } - public static boolean craftingStampsEnabled = true; public static final ArrayList collectorStamps = new ArrayList(); - public static boolean applePickup = true; public static boolean squareFarms = false; // Mail @@ -93,6 +87,22 @@ public class Config { public static final HashMap hints = new HashMap(); public static boolean disableEnergyStat = false; + public static boolean isStructureEnabled(String uid) { + return !Config.disabledStructures.contains(uid); + } + + public static boolean isFluidEnabled(Fluids fluids) { + return !Config.disabledFluids.contains(fluids.getTag()); + } + + public static boolean isBlockEnabled(String tag) { + return !Config.disabledBlocks.contains(tag); + } + + public static boolean isCraftingBronzeEnabled() { + return craftingBronzeEnabled; + } + public static void load() { setDebugMode(); @@ -107,13 +117,131 @@ public class Config { config.addPurge("buildcraft.ignore"); config.addPurge("power.framework"); + loadModes(); + loadFluids(); + + Property property; + + Property particleFX = config.get("performance.particleFX.enabled", CATEGORY_COMMON, true); + particleFX.comment = "set to false to disable particle fx on slower machines"; + enableParticleFX = Boolean.parseBoolean(particleFX.value); + + // RetroGen + + String retroGenMessage = "Forestry will attempt worldGen in chunks that were created before the mod was added."; + Property retroGen = config.get("world.retrogen.normal", CATEGORY_COMMON, false); + retroGen.comment = "Set to true, " + retroGenMessage; + doRetrogen = Boolean.parseBoolean(retroGen.value); + + String forcedRetroGenMessage = "Forestry will attempt worldGen in all chunks for this game instance. Config option will be set to false after this run."; + String forcedRetroGenKey = "world.retrogen.forced"; + Property forceRetroGen = config.get(forcedRetroGenKey, CATEGORY_COMMON, false); + forceRetroGen.comment = "Set to true, " + forcedRetroGenMessage; + forceRetrogen = Boolean.parseBoolean(forceRetroGen.value); + + if (forceRetrogen) { + Proxies.log.info(forcedRetroGenMessage); + config.set(forcedRetroGenKey, CATEGORY_COMMON, false); + doRetrogen = true; + } else if (doRetrogen) { + Proxies.log.info(retroGenMessage); + } + + Property genApatiteOre = config.get("world.generate.apatite", CATEGORY_COMMON, true); + genApatiteOre.comment = "set to false to force forestry to skip generating own apatite ore blocks in the world"; + generateApatiteOre = Boolean.parseBoolean(genApatiteOre.value); + + Property genBeehives = config.get("world.generate.beehives", CATEGORY_COMMON, true); + genBeehives.comment = "set to false to force forestry to skip generating beehives in the world"; + generateBeehives = Boolean.parseBoolean(genBeehives.value); + + Property genDebugBeehives = config.get("world.generate.beehives.debug", CATEGORY_DEBUG, false); + genDebugBeehives.comment = "Set to true to force Forestry to try to generate a beehive at every possible location."; + generateBeehivesDebug = Boolean.parseBoolean(genDebugBeehives.value); + + Property genCopperOre = config.get("world.generate.copper", CATEGORY_COMMON, true); + genCopperOre.comment = "set to false to force forestry to skip generating own copper ore blocks in the world"; + generateCopperOre = Boolean.parseBoolean(genCopperOre.value); + + Property genTinOre = config.get("world.generate.tin", CATEGORY_COMMON, true); + genTinOre.comment = "set to false to force forestry to skip generating own tin ore blocks in the world"; + generateTinOre = Boolean.parseBoolean(genTinOre.value); + + Property bronzeRecipe = config.get("crafting.bronze.enabled", CATEGORY_COMMON, true); + bronzeRecipe.comment = "set to false to disable crafting recipe for bronze"; + craftingBronzeEnabled = Boolean.parseBoolean(bronzeRecipe.value); + + property = config.get("crafting.stamps.enabled", CATEGORY_COMMON, true); + property.comment = "set to false to disable crafting recipes for all types of stamps."; + craftingStampsEnabled = Boolean.parseBoolean(property.value); + + String defaultCollectors = "20n;50n;100n;200n"; + property = config.get("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); + property.comment = "if crafting of stamps is generally allowed, these stamps are still excluded from crafting."; + try { + collectorStamps.addAll(Arrays.asList(parseStamps(property.value))); + } catch(Exception ex) { + config.set("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); + collectorStamps.addAll(Arrays.asList(parseStamps(defaultCollectors))); + } + + Property indicatorEnable = config.get("tweaks.mailalert.enabled", CATEGORY_COMMON, true); + indicatorEnable.comment = "set to false to disable the mail alert box"; + mailAlertEnabled = Boolean.parseBoolean(indicatorEnable.value); + + Property clearGenome = config.get("genetics.clear.invalid.chromosomes", CATEGORY_COMMON, clearInvalidChromosomes); + clearGenome.comment = "set to true to clear chromosomes which contain invalid alleles. might rescue your save if it is crashing after the removal of a bee addon."; + clearInvalidChromosomes = Boolean.parseBoolean(clearGenome.value); + + Property dungeonLootRarity = config.get("difficulty.dungeonloot.rare", CATEGORY_COMMON, false); + dungeonLootRarity.comment = "set to true to make dungeon loot generated by forestry rarer"; + dungeonLootRare = Boolean.parseBoolean(dungeonLootRarity.value); + + Property resupplyEnable = config.get("performance.backpacks.resupply", CATEGORY_COMMON, true); + resupplyEnable.comment = "leaving this enabled will cycle the list of active players PER INGAME TICK to check for resupply via backpack. you want to set this to false on busy servers."; + Config.enableBackpackResupply = Boolean.parseBoolean(resupplyEnable.value); + + property = config.get("tweaks.hints.disabled", CATEGORY_COMMON, false); + property.comment = "set to true to disable hints on machine and engine guis."; + Config.disableHints = Boolean.parseBoolean(property.value); + property = config.get("tweaks.energystat.disabled", CATEGORY_COMMON, true); + property.comment = "set to true to disable energy statistics on energy consumers."; + Config.disableEnergyStat = !isDebug && Boolean.parseBoolean(property.value); + property = config.get("tweaks.tooltip.liquidamount.disabled", CATEGORY_COMMON, false); + property.comment = "set to true to disable displaying liquid amounts in tank tooltips."; + Config.tooltipLiquidAmount = isDebug || !Boolean.parseBoolean(property.value); + + property = config.get("tweaks.permissions.disabled", CATEGORY_COMMON, false); + property.comment = "set to true to disable access restrictions on forestry machines."; + Config.disablePermissions = Boolean.parseBoolean(property.value); + + property = config.get("tweaks.upgradenotice.disabled", CATEGORY_COMMON, false); + property.comment = "set to true to disable update and version check notice."; + Config.disableVersionCheck = isDebug || Boolean.parseBoolean(property.value); + + property = config.get("tweaks.farms.squared", CATEGORY_COMMON, false); + property.comment = "set to true to have farms use a square layout instead of a diamond one."; + Config.squareFarms = Boolean.parseBoolean(property.value); + + property = config.get("structures.schemata.disabled", CATEGORY_COMMON, ""); + property.comment = "add schemata keys to disable them. current keys: alveary3x3;farm3x3;farm3x4;farm3x5;farm4x4;farm5x5"; + disabledStructures.addAll(Arrays.asList(parseStructureKeys(property.value))); + for (String str : disabledStructures) + Proxies.log.finer("Disabled structure '%s'.", str); + + config.save(); + + loadHints(); + } + + private static void loadModes() { Property property = config.get("difficulty.gamemode", CATEGORY_COMMON, "EASY"); - property.Comment = "set to your preferred game mode. available modes are OP, EASY, NORMAL, HARD. mismatch with the server may cause visual glitches with recipes. setting an unavailable mode will create a new mode definition file."; - gameMode = property.Value; + property.comment = "set to your preferred game mode. available modes are OP, EASY, NORMAL, HARD. mismatch with the server may cause visual glitches with recipes. setting an unavailable mode will create a new mode definition file."; + gameMode = property.value; property = config.get("difficulty.recreate.definitions", CATEGORY_COMMON, true); - property.Comment = "set to true to force recreation of the game mode definitions in config/forestry/gamemodes"; - boolean recreate = Boolean.parseBoolean(property.Value); + property.comment = "set to true to force recreation of the game mode definitions in config/forestry/gamemodes"; + boolean recreate = Boolean.parseBoolean(property.value); if (recreate) Proxies.log.info("Recreating all gamemode definitions from the defaults. This may be caused by an upgrade"); @@ -136,111 +264,21 @@ public class Config { CopyFileToFS(hardMode, "/config/forestry/gamemodes/HARD.conf"); config.set("difficulty.recreate.definitions", CATEGORY_COMMON, false); + } - Property particleFX = config.get("performance.particleFX.enabled", CATEGORY_COMMON, true); - particleFX.Comment = "set to false to disable particle fx on slower machines"; - enableParticleFX = Boolean.parseBoolean(particleFX.Value); + private static void loadFluids() { + Property property; + for (Fluids fluid : Fluids.values()) { + property = config.get("disable.fluid." + fluid.getTag(), CATEGORY_FLUIDS, false); + property.comment = "set to true to disable the fluid for " + fluid.getTag(); + if (Boolean.parseBoolean(property.value)) + Config.disabledFluids.add(fluid.getTag()); - Property genApatiteOre = config.get("world.generate.apatite", CATEGORY_COMMON, true); - genApatiteOre.Comment = "set to false to force forestry to skip generating own apatite ore blocks in the world"; - generateApatiteOre = Boolean.parseBoolean(genApatiteOre.Value); - - Property genBeehives = config.get("world.generate.beehives", CATEGORY_COMMON, true); - genBeehives.Comment = "set to false to force forestry to skip generating beehives in the world"; - generateBeehives = Boolean.parseBoolean(genBeehives.Value); - - Property genDebugBeehives = config.get("world.generate.beehives.debug", CATEGORY_DEBUG, false); - genDebugBeehives.Comment = "Set to true to force Forestry to try to generate a beehive at every possible location."; - generateBeehivesDebug = Boolean.parseBoolean(genDebugBeehives.Value); - - Property genCopperOre = config.get("world.generate.copper", CATEGORY_COMMON, true); - genCopperOre.Comment = "set to false to force forestry to skip generating own copper ore blocks in the world"; - generateCopperOre = Boolean.parseBoolean(genCopperOre.Value); - - Property genTinOre = config.get("world.generate.tin", CATEGORY_COMMON, true); - genTinOre.Comment = "set to false to force forestry to skip generating own tin ore blocks in the world"; - generateTinOre = Boolean.parseBoolean(genTinOre.Value); - - Property planterSideSense = config.get("planters.sidesensitive", CATEGORY_COMMON, true); - planterSideSense.Comment = "set to false if farms should output all harvested products regardless of side a pipe is attached to"; - planterSideSensitive = Boolean.parseBoolean(planterSideSense.Value); - Property harvesterSideSense = config.get("harvesters.sidesensitive", CATEGORY_COMMON, true); - harvesterSideSense.Comment = "set to false if harvesters should output all harvested products regardless of side a pipe is attached to"; - harvesterSideSensitive = Boolean.parseBoolean(harvesterSideSense.Value); - - Property bronzeRecipe = config.get("crafting.bronze.enabled", CATEGORY_COMMON, true); - bronzeRecipe.Comment = "set to false to disable crafting recipe for bronze"; - craftingBronzeEnabled = Boolean.parseBoolean(bronzeRecipe.Value); - - property = config.get("crafting.stamps.enabled", CATEGORY_COMMON, true); - property.Comment = "set to false to disable crafting recipes for all types of stamps."; - craftingStampsEnabled = Boolean.parseBoolean(property.Value); - - String defaultCollectors = "20n;50n;100n;200n"; - property = config.get("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); - property.Comment = "if crafting of stamps is generally allowed, these stamps are still excluded from crafting."; - try { - collectorStamps.addAll(Arrays.asList(parseStamps(property.Value))); - } catch(Exception ex) { - config.set("crafting.stamps.collector", CATEGORY_COMMON, defaultCollectors); - collectorStamps.addAll(Arrays.asList(parseStamps(defaultCollectors))); + property = config.get("disable.fluidBlock." + fluid.getTag(), CATEGORY_FLUIDS, false); + property.comment = "set to true to disable the in-world FluidBlock for " + fluid.getTag(); + if (Boolean.parseBoolean(property.value)) + Config.disabledBlocks.add(fluid.getTag()); } - - Property indicatorEnable = config.get("tweaks.mailalert.enabled", CATEGORY_COMMON, true); - indicatorEnable.Comment = "set to false to disable the mail alert box"; - mailAlertEnabled = Boolean.parseBoolean(indicatorEnable.Value); - - Property appleHarvest = config.get("tweaks.apple.pickup.enabled", CATEGORY_COMMON, true); - appleHarvest.Comment = "set to false to disable apple pickup by appropriate harvesters"; - applePickup = Boolean.parseBoolean(appleHarvest.Value); - - Property clearGenome = config.get("genetics.clear.invalid.chromosomes", CATEGORY_COMMON, clearInvalidChromosomes); - clearGenome.Comment = "set to true to clear chromosomes which contain invalid alleles. might rescue your save if it is crashing after the removal of a bee addon."; - clearInvalidChromosomes = Boolean.parseBoolean(clearGenome.Value); - - Property dungeonLootRarity = config.get("difficulty.dungeonloot.rare", CATEGORY_COMMON, false); - dungeonLootRarity.Comment = "set to true to make dungeon loot generated by forestry rarer"; - dungeonLootRare = Boolean.parseBoolean(dungeonLootRarity.Value); - - Property resupplyEnable = config.get("performance.backpacks.resupply", CATEGORY_COMMON, true); - resupplyEnable.Comment = "leaving this enabled will cycle the list of active players PER INGAME TICK to check for resupply via backpack. you want to set this to false on busy servers."; - Config.enableBackpackResupply = Boolean.parseBoolean(resupplyEnable.Value); - - property = config.get("tweaks.hints.disabled", CATEGORY_COMMON, false); - property.Comment = "set to true to disable hints on machine and engine guis."; - Config.disableHints = Boolean.parseBoolean(property.Value); - property = config.get("tweaks.energystat.disabled", CATEGORY_COMMON, true); - property.Comment = "set to true to disable energy statistics on energy consumers."; - Config.disableEnergyStat = !isDebug && Boolean.parseBoolean(property.Value); - property = config.get("tweaks.tooltip.liquidamount.disabled", CATEGORY_COMMON, false); - property.Comment = "set to true to disable displaying liquid amounts in tank tooltips."; - Config.tooltipLiquidAmount = isDebug || !Boolean.parseBoolean(property.Value); - - property = config.get("tweaks.permissions.disabled", CATEGORY_COMMON, false); - property.Comment = "set to true to disable access restrictions on forestry machines."; - Config.disablePermissions = Boolean.parseBoolean(property.Value); - - property = config.get("tweaks.nags.disabled", CATEGORY_COMMON, false); - property.Comment = "set to true to disable some nagging and warnings (e.g. GregTech)."; - Config.disableNags = Boolean.parseBoolean(property.Value); - - property = config.get("tweaks.upgradenotice.disabled", CATEGORY_COMMON, false); - property.Comment = "set to true to disable update and version check notice."; - Config.disableVersionCheck = isDebug || Boolean.parseBoolean(property.Value); - - property = config.get("tweaks.farms.squared", CATEGORY_COMMON, false); - property.Comment = "set to true to have farms use a square layout instead of a diamond one."; - Config.squareFarms = Boolean.parseBoolean(property.Value); - - property = config.get("structures.schemata.disabled", CATEGORY_COMMON, ""); - property.Comment = "add schemata keys to disable them. current keys: alveary3x3;farm3x3;farm3x4;farm3x5;farm4x4;farm5x5"; - disabledStructures.addAll(Arrays.asList(parseStructureKeys(property.Value))); - for (String str : disabledStructures) - Proxies.log.finer("Disabled structure '%s'.", str); - - config.save(); - - loadHints(); } private static void setDebugMode() { @@ -305,9 +343,4 @@ public class Config { else return list.split("[;]+"); } - - public static boolean getOrCreateBooleanProperty(String key, String kind, boolean defaults) { - return Boolean.parseBoolean(config.get(key, kind, defaults).Value); - } - } diff --git a/src/main/java/forestry/core/config/Configuration.java b/src/main/java/forestry/core/config/Configuration.java index 2f6eabbc9..40d60d5b1 100755 --- a/src/main/java/forestry/core/config/Configuration.java +++ b/src/main/java/forestry/core/config/Configuration.java @@ -11,8 +11,6 @@ package forestry.core.config; import forestry.core.proxy.Proxies; -import net.minecraftforge.common.config.Configuration.UnicodeInputStreamReader; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -20,10 +18,10 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; -import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.TreeMap; +import net.minecraftforge.common.config.Configuration.UnicodeInputStreamReader; public class Configuration { @@ -90,7 +88,7 @@ public class Configuration { public void set(String key, String category, boolean val) { Property existing = getExisting(key, category); if (existing != null) { - existing.Value = Boolean.toString(val); + existing.value = Boolean.toString(val); return; } @@ -103,7 +101,7 @@ public class Configuration { public void set(String key, String category, String val) { Property existing = getExisting(key, category); if (existing != null) { - existing.Value = val; + existing.value = val; return; } @@ -116,7 +114,7 @@ public class Configuration { public void set(String key, String category, int val) { Property existing = getExisting(key, category); if (existing != null) { - existing.Value = Integer.toString(val); + existing.value = Integer.toString(val); return; } @@ -129,7 +127,7 @@ public class Configuration { public void set(String key, String category, float val) { Property existing = getExisting(key, category); if (existing != null) { - existing.Value = Float.toString(val); + existing.value = Float.toString(val); return; } @@ -144,7 +142,7 @@ public class Configuration { loadCategory(category); for (Property property : categorized.get(category)) - if (property.Key.equals(key)) + if (property.key.equals(key)) return property; return null; @@ -201,7 +199,7 @@ public class Configuration { property = new Property(tokens[0], ""); if (lastComment != null) { - property.Comment = lastComment; + property.comment = lastComment; lastComment = null; } categorized.get(category).add(property); @@ -215,9 +213,7 @@ public class Configuration { } public void save() { - Iterator>> it = categorized.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry> entry = it.next(); + for (Map.Entry> entry : categorized.entrySet()) { saveFile(getCategoryFile(entry.getKey()), entry.getValue()); } } @@ -241,26 +237,24 @@ public class Configuration { writer.write("# " + Defaults.MOD + newLine + "# " + Version.getVersion() + newLine); writer.write("#" + newLine + "# Config files:" + newLine); - writer.write("# base.conf\t\t-\t Contains Forge configuration for block and item ids" + newLine); writer.write("# common.conf\t\t-\t Contains all options common to Forestry" + newLine); + writer.write("# fluids.conf\t\t-\t Contains all options for fluids" + newLine); writer.write("# apiculture.conf\t-\t Contains all options for bee breeding" + newLine); writer.write("# backpacks.conf\t-\t Contains custom configurations for backpacks" + newLine); writer.write("# pipes.conf\t\t-\t Configures item id for the apiarist's pipe" + newLine); writer.write("# gamemodes/\t\t-\t Configures available gamemodes"); TreeMap> subsectioned = getSubsectioned(properties); - Iterator>> it = subsectioned.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry> entry = it.next(); + for (Map.Entry> entry : subsectioned.entrySet()) { writer.write(newLine + newLine + "#####################" + newLine + "# " + entry.getKey().toUpperCase() + newLine + "#####################" + newLine); for (Property property : entry.getValue()) { - if(purge.contains(property.Key)) + if (purge.contains(property.key)) continue; - if (property.Comment != null) - writer.write("# " + property.Comment + newLine); - writer.write(property.Key + "=" + property.Value + newLine); + if (property.comment != null) + writer.write("# " + property.comment + newLine); + writer.write(property.key + "=" + property.value + newLine); } } @@ -276,7 +270,7 @@ public class Configuration { TreeMap> subsectioned = new TreeMap>(); for (Property property : properties) { - String subsection = property.Key.split("\\.")[0]; + String subsection = property.key.split("\\.")[0]; if (!subsectioned.containsKey(subsection)) subsectioned.put(subsection, new ArrayList()); subsectioned.get(subsection).add(property); diff --git a/src/main/java/forestry/core/config/Defaults.java b/src/main/java/forestry/core/config/Defaults.java index 104eff1e5..6de0dd57b 100755 --- a/src/main/java/forestry/core/config/Defaults.java +++ b/src/main/java/forestry/core/config/Defaults.java @@ -11,7 +11,6 @@ package forestry.core.config; import java.util.Locale; - import net.minecraftforge.oredict.OreDictionary; public class Defaults { @@ -29,7 +28,6 @@ public class Defaults { public static final int NET_MAX_UPDATE_DISTANCE = 50; - public static final String DEFAULT_POWER_FRAMEWORK = "forestry.energy.BioPowerFramework"; public static final int BUCKET_VOLUME = 1000; public static final int FLUID_PER_HONEY_DROP = 100; @@ -45,19 +43,7 @@ public class Defaults { public static final int[] FACING_WESTEAST = { FACING_WEST, FACING_EAST }; public static final int[] FACINGS_NONE = new int[0]; - public static final String LIQUID_WATER = "water"; - public static final String LIQUID_LAVA = "lava"; - public static final String LIQUID_MILK = "milk"; - public static final String LIQUID_BIOMASS = "biomass"; - public static final String LIQUID_ETHANOL = "bioethanol"; - public static final String LIQUID_SEEDOIL = "seedoil"; - public static final String LIQUID_HONEY = "honey"; - public static final String LIQUID_JUICE = "juice"; - public static final String LIQUID_ICE = "ice"; - public static final String LIQUID_MEAD = "short.mead"; - public static final String LIQUID_GLASS = "glass"; - public static final String LIQUID_OIL = "oil"; - public static final String LIQUID_FUEL = "fuel"; + public static final int[] SLOTS_NONE = new int[0]; // Textures public static final String TEXTURE_PATH_GUI = "textures/gui"; @@ -65,20 +51,12 @@ public class Defaults { public static final String TEXTURE_PATH_ITEMS = "textures/items"; public static final String TEXTURE_PATH_ENTITIES = "textures/entity"; - public static final String TEXTURE_BLOCKS = TEXTURE_PATH_BLOCKS + "/blocks.png"; - public static final String TEXTURE_ARBORICULTURE = TEXTURE_PATH_BLOCKS + "/arboriculture.png"; - public static final String TEXTURE_PODS = TEXTURE_PATH_BLOCKS + "/pods.png"; - public static final String TEXTURE_FARM = TEXTURE_PATH_BLOCKS + "/farm.png"; - public static final String TEXTURE_APIARIST_ARMOR_PRIMARY = TEXTURE_PATH_ITEMS + "/apiarist_armor_1.png"; public static final String TEXTURE_APIARIST_ARMOR_SECONDARY = TEXTURE_PATH_ITEMS + "/apiarist_armor_2.png"; public static final String TEXTURE_NATURALIST_ARMOR_PRIMARY = TEXTURE_PATH_ITEMS + "/naturalist_armor_1.png"; public static final String TEXTURE_SKIN_BEEKPEEPER = TEXTURE_PATH_ENTITIES + "/beekeeper.png"; public static final String TEXTURE_SKIN_LUMBERJACK = TEXTURE_PATH_ENTITIES + "/lumberjack.png"; - public static final String TEXTURE_ICONS_MINECRAFT = "/gui/items.png"; - public static final String TEXTURE_BLOCKS_MINECRAFT = "/terrain.png"; - // Villagers public static final int ID_VILLAGER_BEEKEEPER = 80; public static final int ID_VILLAGER_LUMBERJACK = 81; @@ -160,13 +138,6 @@ public class Defaults { public static final int FOOD_HONEY_HEAL = 2; public static final float FOOD_HONEY_SATURATION = 0.2f; - // IndustrialCraft 2 - public static final int ID_IC2_FUELCAN_DAMAGE = 6480; - - // BuildCraft - public static final int BUILDCRAFT_BLOCKID_ENGINE = 161; - public static final int BUILDCRAFT_BLOCKID_PIPE = 166; - public static final int APIARY_MIN_LEVEL_LIGHT = 11; public static final int APIARY_BREEDING_TIME = 100; @@ -233,32 +204,4 @@ public class Defaults { public static final int CARPENTER_CRATING_CYCLES = 5; public static final int CARPENTER_UNCRATING_CYCLES = 5; public static final int CARPENTER_CRATING_LIQUID_QUANTITY = 100; - - // SMP gui ids - public static final int ID_GUI_ARBORETUM = 90; - public static final int ID_GUI_BOTTLER = 91; - public static final int ID_GUI_ENGINE_BRONZE = 92; - public static final int ID_GUI_FARM = 93; - public static final int ID_GUI_FERMENTER = 94; - public static final int ID_GUI_FORESTER = 95; - public static final int ID_GUI_PLANTATION = 96; - public static final int ID_GUI_PUMPKIN_FARM = 97; - public static final int ID_GUI_PEAT_BOG = 98; - public static final int ID_GUI_STILL = 99; - public static final int ID_GUI_ENGINE_COPPER = 89; - public static final int ID_GUI_RAINTANK = 88; - public static final int ID_GUI_GENERATOR = 87; - public static final int ID_GUI_CARPENTER = 86; - public static final int ID_GUI_MOISTENER = 85; - public static final int ID_GUI_MUSHROOM_FARM = 84; - public static final int ID_GUI_APIARY = 83; - public static final int ID_GUI_CENTRIFUGE = 82; - public static final int ID_GUI_APIARIST_INVENTORY = 81; - public static final int ID_GUI_BACKPACK = 80; - public static final int ID_GUI_SQUEEZER = 79; - public static final int ID_GUI_NETHER_FARM = 78; - public static final int ID_GUI_BEEALYZER = 100; - public static final int ID_GUI_BACKPACK_T2 = 101; - public static final int ID_GUI_BIOME_FINDER = 102; - // ID 100 used by bucket filler. } diff --git a/src/main/java/forestry/core/config/ForestryItem.java b/src/main/java/forestry/core/config/ForestryItem.java index 6d586e14e..259792017 100755 --- a/src/main/java/forestry/core/config/ForestryItem.java +++ b/src/main/java/forestry/core/config/ForestryItem.java @@ -10,14 +10,16 @@ ******************************************************************************/ package forestry.core.config; +import java.util.EnumSet; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + import forestry.core.proxy.Proxies; import forestry.plugins.PluginManager; import forestry.plugins.PluginManager.Stage; -import java.util.EnumSet; -import net.minecraftforge.oredict.OreDictionary; /** * Allows direct access to Forestry's items. Will be populated during @@ -43,9 +45,13 @@ public enum ForestryItem { wrench, pipette, bucketBiomass, - vialEmpty, - vialCatalyst, - bucketBiofuel, + bucketEthanol, + bucketGlass, + bucketHoney, + bucketIce, + bucketJuice, + bucketSeedoil, + bucketShortMead, // Crafting impregnatedCasing, sturdyCasing, @@ -159,7 +165,7 @@ public enum ForestryItem { waxCapsule, waxCapsuleWater, waxCapsuleBiomass, - waxCapsuleBiofuel, + waxCapsuleEthanol, waxCapsuleOil, waxCapsuleFuel, waxCapsuleSeedOil, @@ -170,7 +176,7 @@ public enum ForestryItem { refractoryEmpty, refractoryWater, refractoryBiomass, - refractoryBiofuel, + refractoryEthanol, refractoryOil, refractoryFuel, refractoryLava, @@ -182,71 +188,14 @@ public enum ForestryItem { canWater, canEmpty, canBiomass, - canBiofuel, + canEthanol, canOil, canFuel, canLava, canSeedOil, canHoney, canJuice, - canIce, - // Crating - cratedWood, - cratedCobblestone, - cratedDirt, - cratedStone, - cratedBrick, - cratedCacti, - cratedSand, - cratedObsidian, - cratedNetherrack, - cratedSoulsand, - cratedSandstone, - cratedBogearth, - cratedHumus, - cratedNetherbrick, - cratedPeat, - cratedApatite, - cratedFertilizer, - cratedTin, - cratedCopper, - cratedBronze, - cratedWheat, - cratedMycelium, - cratedMulch, - cratedSilver, - cratedBrass, - cratedCookies, - cratedHoneycombs, - cratedBeeswax, - cratedPollen, - cratedPropolis, - cratedHoneydew, - cratedRoyalJelly, - cratedCocoaComb, - cratedRedstone, - cratedLapis, - cratedReeds, - cratedClay, - cratedGlowstone, - cratedApples, - cratedNetherwart, - cratedResin, - cratedRubber, - cratedScrap, - cratedUUM, - cratedSimmeringCombs, - cratedStringyCombs, - cratedFrozenCombs, - cratedDrippingCombs, - cratedRefractoryWax, - cratedPhosphor, - cratedAsh, - cratedCharcoal, - cratedGravel, - cratedCoal, - cratedSeeds, - cratedSaplings; + canIce; private Item item; public void registerItem(Item item, String name) { diff --git a/src/main/java/forestry/core/config/Property.java b/src/main/java/forestry/core/config/Property.java index 1630ffb21..01ade1cfc 100755 --- a/src/main/java/forestry/core/config/Property.java +++ b/src/main/java/forestry/core/config/Property.java @@ -11,12 +11,12 @@ package forestry.core.config; public class Property { - public String Key; - public String Value; - public String Comment; + public final String key; + public String value; + public String comment; public Property(String key, String value) { - Key = key; - Value = value; + this.key = key; + this.value = value; } } diff --git a/src/main/java/forestry/core/config/Version.java b/src/main/java/forestry/core/config/Version.java index 0d675b126..0f5c7b6df 100755 --- a/src/main/java/forestry/core/config/Version.java +++ b/src/main/java/forestry/core/config/Version.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.core.config; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.versioning.DefaultArtifactVersion; +import forestry.Forestry; +import forestry.core.proxy.Proxies; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.versioning.DefaultArtifactVersion; - -import forestry.Forestry; -import forestry.core.proxy.Proxies; - /** * With permission from pahimar. * @@ -64,13 +62,13 @@ public class Version { return false; Property property = Config.config.get("vars.version.seen", Config.CATEGORY_COMMON, VERSION); - property.Comment = "indicates the last version the user has been informed about and will suppress further notices on it."; - String seenVersion = property.Value; + property.comment = "indicates the last version the user has been informed about and will suppress further notices on it."; + String seenVersion = property.value; if (recommendedVersion == null || recommendedVersion.equals(seenVersion)) return false; - property.Value = recommendedVersion; + property.value = recommendedVersion; Config.config.save(); return true; } diff --git a/src/main/java/forestry/core/fluids/BlockForestryFluid.java b/src/main/java/forestry/core/fluids/BlockForestryFluid.java new file mode 100644 index 000000000..dde8cf45b --- /dev/null +++ b/src/main/java/forestry/core/fluids/BlockForestryFluid.java @@ -0,0 +1,248 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.fluids; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.init.Blocks; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.BlockFluidClassic; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.core.config.Defaults; +import forestry.core.render.EntityColoredDropParticleFX; +import forestry.core.render.TextureManager; + +public class BlockForestryFluid extends BlockFluidClassic { + + private final boolean flammable; + private final int flammability; + private final Color color; + + @SideOnly(Side.CLIENT) + private List icons; + + public BlockForestryFluid(Fluids forestryFluid) { + this(forestryFluid, 0, false); + } + + public BlockForestryFluid(Fluids forestryFluid, int flammability, boolean flammable) { + this(forestryFluid.getFluid(), flammability, flammable, forestryFluid.getColor()); + } + + private BlockForestryFluid(Fluid fluid, int flammability, boolean flammable, Color color) { + super(fluid, Material.water); + + setDensity(fluid.getDensity()); + + this.flammability = flammability; + this.flammable = flammable; + + this.color = color; + } + + @Override + public boolean canDrain(World world, int x, int y, int z) { + return true; + } + + @Override + public Fluid getFluid() { + return FluidRegistry.getFluid(fluidName); + } + + @Override + public IIcon getIcon(int side, int meta) { + if (side == 0 || side == 1 || this.icons.size() == 1) { + return this.icons.get(0); + } else { + return this.icons.get(1); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister iconRegister) { + + this.icons = new ArrayList(2); + + String still = "liquid/" + fluidName + "_still"; + this.icons.add(TextureManager.getInstance().registerTex(iconRegister, still)); + + if(flowTextureExists()) { + String flow = "liquid/" + fluidName + "_flow"; + this.icons.add(TextureManager.getInstance().registerTex(iconRegister, flow)); + } + } + + @SideOnly(Side.CLIENT) + public boolean flowTextureExists() { + try { + ResourceLocation resourceLocation = new ResourceLocation(Defaults.ID, "textures/blocks/liquid/" + fluidName + "_flow.png"); + IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); + return resourceManager.getResource(resourceLocation) != null; + } catch (java.lang.Exception e) { + return false; + } + } + + @Override + @SideOnly(Side.CLIENT) + public void randomDisplayTick(World world, int x, int y, int z, Random rand) { + if (rand.nextInt(10) == 0 && World.doesBlockHaveSolidTopSurface(world, x, y - 1, z) && !world.getBlock(x, y - 2, z).getMaterial().blocksMovement()) { + double px = (double) ((float) x + rand.nextFloat()); + double py = (double) y - 1.05D; + double pz = (double) ((float) z + rand.nextFloat()); + + EntityFX fx = new EntityColoredDropParticleFX(world, px, py, pz, color.getRed(), color.getGreen(), color.getBlue()); + FMLClientHandler.instance().getClient().effectRenderer.addEffect(fx); + } + } + + @Override + public boolean canDisplace(IBlockAccess world, int x, int y, int z) { + if (world.getBlock(x, y, z).getMaterial().isLiquid()) { + return false; + } + return super.canDisplace(world, x, y, z); + } + + @Override + public boolean displaceIfPossible(World world, int x, int y, int z) { + if (world.getBlock(x, y, z).getMaterial().isLiquid()) { + return false; + } + return super.displaceIfPossible(world, x, y, z); + } + + @Override + public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + return flammable ? 30 : 0; + } + + @Override + public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + return flammability; + } + + public boolean isFlammable(IBlockAccess world, int x, int y, int z) { + return flammable; + } + + @Override + public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) { + return flammable; + } + + @Override + public boolean isFireSource(World world, int x, int y, int z, ForgeDirection side) { + return flammable && flammability == 0; + } + + public Color getColor() { + return color; + } + + @Override + public Material getMaterial() { + // Fahrenheit 451 = 505.928 Kelvin + // The temperature at which book-paper catches fire, and burns. + if (temperature > 505) + return Material.lava; + else + return super.getMaterial(); + } + + @Override + public void updateTick(World world, int x, int y, int z, Random rand) { + super.updateTick(world, x, y, z, rand); + + // Start fires if the fluid is lava-like + if (getMaterial() == Material.lava) { + int rangeUp = rand.nextInt(3); + + for (int i = 0; i < rangeUp; ++i) { + x += rand.nextInt(3) - 1; + ++y; + z += rand.nextInt(3) - 1; + Block block = world.getBlock(x, y, z); + + if (block.getMaterial() == Material.air) { + if (isNeighborFlammable(world, x, y, z)) { + world.setBlock(x, y, z, Blocks.fire); + return; + } + } else if (block.getMaterial().blocksMovement()) { + return; + } + } + + if (rangeUp == 0) { + int startX = x; + int startZ = z; + + for (int i = 0; i < 3; ++i) { + x = startX + rand.nextInt(3) - 1; + z = startZ + rand.nextInt(3) - 1; + + if (world.isAirBlock(x, y + 1, z) && this.isFlammable(world, x, y, z)) { + world.setBlock(x, y + 1, z, Blocks.fire); + } + } + } + } + + // explode if very flammable and near fire + int flammability = getFlammability(world, x, y, z, ForgeDirection.UNKNOWN); + if (flammability > 0) { + // Explosion size is determined by flammability, up to size 4. + float explosionSize = 4F * flammability / 300F; + if (explosionSize > 1.0 && isNearFire(world, x, y, z)) { + world.setBlock(x, y, z, Blocks.fire); + world.newExplosion(null, x, y, z, explosionSize, true, true); + } + } + } + + private boolean isNeighborFlammable(World world, int x, int y, int z) { + return isFlammable(world, x - 1, y, z) || + isFlammable(world, x + 1, y, z) || + isFlammable(world, x, y, z - 1) || + isFlammable(world, x, y, z + 1) || + isFlammable(world, x, y - 1, z) || + isFlammable(world, x, y + 1, z); + } + + private boolean isNearFire(World world, int x, int y, int z) { + AxisAlignedBB boundingBox = AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1); + return world.func_147470_e(boundingBox); + } +} diff --git a/src/main/java/forestry/core/fluids/FluidHelper.java b/src/main/java/forestry/core/fluids/FluidHelper.java index 9d7f65071..cec862084 100644 --- a/src/main/java/forestry/core/fluids/FluidHelper.java +++ b/src/main/java/forestry/core/fluids/FluidHelper.java @@ -12,20 +12,24 @@ package forestry.core.fluids; import forestry.core.fluids.tanks.StandardTank; import forestry.core.inventory.InvTools; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; +import forestry.core.utils.StackUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import net.minecraftforge.fluids.*; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidBlock; +import net.minecraftforge.fluids.IFluidContainerItem; +import net.minecraftforge.fluids.IFluidHandler; /** * @@ -53,7 +57,15 @@ public final class FluidHelper { if (used > 0) { if (!player.capabilities.isCreativeMode) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, InvTools.depleteItem(current)); + ItemStack drainedContainer = getDrainedContainer(current, used); + if (current.stackSize > 1) { + player.inventory.decrStackSize(player.inventory.currentItem, 1); + if (drainedContainer != null && !player.inventory.addItemStackToInventory(drainedContainer)) { + player.dropPlayerItemWithRandomChoice(drainedContainer, false); + } + } else { + player.inventory.setInventorySlotContents(player.inventory.currentItem, drainedContainer); + } player.inventory.markDirty(); } return true; @@ -63,7 +75,7 @@ public final class FluidHelper { FluidStack available = tank.drain(side, Integer.MAX_VALUE, false); if (available != null) { - ItemStack filled = fillContainer(available, current); + ItemStack filled = getFilledContainer(available, current); liquid = getFluidStackInContainer(filled); if (liquid != null) { @@ -116,6 +128,10 @@ public final class FluidHelper { } public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) { + return fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill, true); + } + + public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean doFill) { ItemStack input = inv.getStackInSlot(inputSlot); ItemStack output = inv.getStackInSlot(outputSlot); ItemStack filled = getFilledContainer(fluidToFill, input); @@ -123,12 +139,14 @@ public final class FluidHelper { FluidStack fluidInContainer = getFluidStackInContainer(filled); FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false); if (drain != null && drain.amount == fluidInContainer.amount) { - fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true); - if (output == null) - inv.setInventorySlotContents(outputSlot, filled); - else - output.stackSize++; - inv.decrStackSize(inputSlot, 1); + if (doFill) { + fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true); + if (output == null) + inv.setInventorySlotContents(outputSlot, filled); + else + output.stackSize++; + inv.decrStackSize(inputSlot, 1); + } return true; } } @@ -143,30 +161,43 @@ public final class FluidHelper { ItemStack input = inv.getStackInSlot(inputSlot); ItemStack output = inv.getStackInSlot(outputSlot); - if (input != null) { - FluidStack fluidInContainer = getFluidStackInContainer(input); - ItemStack emptyItem = input.getItem().getContainerItem(input); - if (fluidInContainer != null && (emptyItem == null || output == null - || (inputSlot == outputSlot && input.stackSize == 1) - || (output.stackSize < output.getMaxStackSize() && InvTools.isItemEqual(output, emptyItem)))) { - int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false); - if (used >= fluidInContainer.amount) { - fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true); - if (emptyItem != null) - if (output == null) - inv.setInventorySlotContents(outputSlot, emptyItem); - else - output.stackSize++; - inv.decrStackSize(inputSlot, 1); - return true; - } - } - } - return false; - } + if (input == null) + return false; - public static boolean isBucket(ItemStack stack) { - return FluidContainerRegistry.isBucket(stack); + FluidStack fluidInContainer = getFluidStackInContainer(input); + if (fluidInContainer == null) + return false; + + int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false); + if (used < fluidInContainer.amount) + return false; + + ItemStack emptyItem = getEmptyContainer(input); + + if (output != null && emptyItem != null) + if (outputSlot == inputSlot) { + if (input.stackSize > 1) + return false; + } else if (!StackUtils.isIdenticalItem(output, emptyItem)) + return false; + else if (output.stackSize + emptyItem.stackSize > output.getMaxStackSize()) + return false; + + fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true); + + if (emptyItem != null) { + if (outputSlot == inputSlot) { + inv.setInventorySlotContents(outputSlot, emptyItem); + return true; + } + + if (output == null) + inv.setInventorySlotContents(outputSlot, emptyItem); + else + output.stackSize++; + } + inv.decrStackSize(inputSlot, 1); + return true; } public static boolean isContainer(ItemStack stack) { @@ -176,72 +207,130 @@ public final class FluidHelper { } public static boolean isFilledContainer(ItemStack stack) { - return FluidContainerRegistry.isFilledContainer(stack); + if (FluidContainerRegistry.isFilledContainer(stack)) + return true; + + Item item = stack.getItem(); + if (item instanceof IFluidContainerItem) { + IFluidContainerItem containerItem = (IFluidContainerItem) item; + FluidStack fluidStack = containerItem.getFluid(stack); + return fluidStack != null && fluidStack.amount > 0; + } + + return false; } - public static boolean isEmptyContainer(ItemStack stack) { - return FluidContainerRegistry.isEmptyContainer(stack); + public static boolean isFillableContainer(ItemStack stack, FluidStack liquid) { + ItemStack empty = StackUtils.createSplitStack(stack, 1); + Item item = empty.getItem(); + if (item instanceof IFluidContainerItem) { + IFluidContainerItem containerItem = (IFluidContainerItem) item; + return containerItem.fill(empty, liquid, false) > 0; + } + + for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData()) { + if (cont.fluid.isFluidEqual(liquid) && (cont.emptyContainer != null && cont.emptyContainer.isItemEqual(empty))) + return true; + } + + return false; + } + + public static boolean isEmptyContainer(ItemStack empty) { + + if (FluidContainerRegistry.isEmptyContainer(empty)) + return true; + + Item item = empty.getItem(); + if (item instanceof IFluidContainerItem) { + IFluidContainerItem containerItem = (IFluidContainerItem) item; + FluidStack fluid = containerItem.getFluid(empty); + return fluid == null || fluid.amount == 0; + } + + return false; + } + + public static ItemStack getEmptyContainer(ItemStack container) { + Item item = container.getItem(); + if (item == null) + return null; + + return item.getContainerItem(container); + } + + public static ItemStack getDrainedContainer(ItemStack container, int drainAmount) { + if (container == null) + return null; + + if (drainAmount == 0) + return container; + + Item item = container.getItem(); + if (item instanceof IFluidContainerItem) { + ItemStack drained = container.copy(); + drained.stackSize = 1; + IFluidContainerItem containerItem = (IFluidContainerItem) item; + containerItem.drain(drained, drainAmount, true); + return drained; + } + + return getEmptyContainer(container); } public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) { - if (fluid == null || empty == null) + if (fluid == null) return null; - return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty); + + FluidStack fluidToFill = new FluidStack(fluid, Integer.MAX_VALUE); + + return getFilledContainer(fluidToFill, empty); } - public static ItemStack getFilledContainer(FluidStack fluid, ItemStack empty) { - if (fluid == null || empty == null) - return null; - fluid = fluid.copy(); - fluid.amount = Integer.MAX_VALUE; - return FluidContainerRegistry.fillFluidContainer(fluid, empty); - } - - public static ItemStack fillContainer(FluidStack liquid, ItemStack empty) { + public static ItemStack getFilledContainer(FluidStack liquid, ItemStack empty) { if (liquid == null || empty == null) return null; + + Item item = empty.getItem(); + if (item instanceof IFluidContainerItem) { + ItemStack full = empty.copy(); + full.stackSize = 1; + IFluidContainerItem containerItem = (IFluidContainerItem) item; + containerItem.fill(full, liquid, true); + return full; + } + return FluidContainerRegistry.fillFluidContainer(liquid, empty); } public static FluidStack getFluidStackInContainer(ItemStack stack) { + Item item = stack.getItem(); + if (item instanceof IFluidContainerItem) { + IFluidContainerItem containerItem = (IFluidContainerItem) item; + return containerItem.getFluid(stack); + } + return FluidContainerRegistry.getFluidForFilledItem(stack); } - public static Fluid getFluidInContianer(ItemStack stack) { - FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack); + public static Fluid getFluidInContainer(ItemStack stack) { + FluidStack fluidStack = getFluidStackInContainer(stack); return fluidStack != null ? fluidStack.getFluid() : null; } public static boolean containsFluidStack(ItemStack stack, FluidStack fluidStack) { + Item item = stack.getItem(); + if (item instanceof IFluidContainerItem) { + IFluidContainerItem containerItem = (IFluidContainerItem) item; + FluidStack contained = containerItem.getFluid(stack); + return contained != null && contained.containsFluid(fluidStack); + } + return FluidContainerRegistry.containsFluid(stack, fluidStack); } public static boolean containsFluid(ItemStack stack, Fluid fluid) { - return FluidContainerRegistry.containsFluid(stack, new FluidStack(fluid, 1)); - } - - public static boolean isFluidEqual(FluidStack L1, FluidStack L2) { - if (L1 == null || L2 == null) - return false; - return L1.isFluidEqual(L2); - } - - public static Collection getContainersFilledWith(FluidStack fluidStack) { - List containers = new ArrayList(); - for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) { - FluidStack inContainer = getFluidStackInContainer(data.filledContainer); - if (inContainer != null && inContainer.containsFluid(fluidStack)) - containers.add(data.filledContainer.copy()); - } - return containers; - } - - public static void nerfWaterBottle() { - for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) - if (data.filledContainer.getItem() == Items.potionitem && data.emptyContainer.getItem() == Items.glass_bottle && Fluids.WATER.is(data.fluid)) { - data.fluid.amount = 333; - return; - } + return containsFluidStack(stack, new FluidStack(fluid, 1)); } public static FluidStack drainBlock(World world, int x, int y, int z, boolean doDrain) { @@ -290,5 +379,4 @@ public final class FluidHelper { return FluidRegistry.LAVA; return null; } - } diff --git a/src/main/java/forestry/core/fluids/Fluids.java b/src/main/java/forestry/core/fluids/Fluids.java index f148112d9..0e91266bb 100644 --- a/src/main/java/forestry/core/fluids/Fluids.java +++ b/src/main/java/forestry/core/fluids/Fluids.java @@ -1,85 +1,431 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.fluids; - -import forestry.core.config.Defaults; -import java.util.Locale; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -/** - * - * @author CovertJaguar - */ -public enum Fluids { - - WATER, LAVA, FUEL, BIOMASS, BIOFUEL, CREOSOTE, STEAM, BIOETHANOL, - COAL, PYROTHEUM, HONEY, MILK, JUICE, ICE, GLASS, OIL, SEEDOIL, SHORT_MEAD(Defaults.LIQUID_MEAD); - private final String tag; - - private Fluids() { - tag = name().toLowerCase(Locale.ENGLISH); - } - - private Fluids(String tag) { - this.tag = tag; - } - - public String getTag() { - return tag; - } - - public Fluid get() { - return FluidRegistry.getFluid(tag); - } - - /** - * Gets a FluidStack filled with qty milliBuckets worth of Fluid. - * - * @param qty - * @return - */ - public FluidStack get(int qty) { - return FluidRegistry.getFluidStack(tag, qty); - } - - /** - * Gets a FluidStack filled with n buckets worth of Fluid. - * - * @param n - * @return - */ - public FluidStack getB(int n) { - return FluidRegistry.getFluidStack(tag, n * FluidContainerRegistry.BUCKET_VOLUME); - } - - public boolean is(Fluid fluid) { - return get() == fluid; - } - - public boolean is(FluidStack fluidStack) { - return fluidStack != null && get() == fluidStack.getFluid(); - } - - public boolean isContained(ItemStack containerStack) { - return containerStack != null && FluidHelper.containsFluid(containerStack, get()); - } - - public static boolean areEqual(Fluid fluid, FluidStack fluidStack) { - if (fluidStack != null && fluid == fluidStack.getFluid()) - return true; - return fluid == null && fluidStack == null; - } - -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.fluids; + +import java.awt.Color; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; + +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import forestry.core.config.Defaults; +import forestry.core.config.ForestryItem; +import forestry.core.items.ItemLiquidContainer; + +import static forestry.core.items.ItemLiquidContainer.EnumContainerType; + +public enum Fluids { + + ETHANOL(new Color(255, 111, 0), 790, 1000) { + @Override + public String getTag() { + return "bioethanol"; + } + + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 300, true); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketEthanol; + case CAN: + return ForestryItem.canEthanol; + case CAPSULE: + return ForestryItem.waxCapsuleEthanol; + case REFRACTORY: + return ForestryItem.refractoryEthanol; + default: + return null; + } + } + }, + BIOMASS(new Color(100, 132, 41), 400, 6560) { + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 100, true); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketBiomass; + case CAN: + return ForestryItem.canBiomass; + case CAPSULE: + return ForestryItem.waxCapsuleBiomass; + case REFRACTORY: + return ForestryItem.refractoryBiomass; + default: + return null; + } + } + }, + GLASS(new Color(164, 164, 164), 2400, 10000) { + @Override + public int getTemperature() { + return 1200; + } + + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 0, true); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketGlass; + default: + return null; + } + } + }, + HONEY(new Color(255, 196, 35), 1420, 73600) { + @Override + public String getTag() { + return "for.honey"; + } + + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketHoney; + case CAN: + return ForestryItem.canHoney; + case CAPSULE: + return ForestryItem.waxCapsuleHoney; + case REFRACTORY: + return ForestryItem.refractoryHoney; + default: + return null; + } + } + + @Override + public void setProperties(ItemLiquidContainer liquidContainer) { + if (liquidContainer.getType() != EnumContainerType.BUCKET) + liquidContainer.setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION); + } + }, + LEGACY_HONEY { + @Override + public String getTag() { + return "honey"; + } + }, + ICE(new Color(175, 242, 255), 920, 1000) { + @Override + public int getTemperature() { + return 265; + } + + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketIce; + case CAN: + return ForestryItem.canIce; + case CAPSULE: + return ForestryItem.waxCapsuleIce; + case REFRACTORY: + return ForestryItem.refractoryIce; + default: + return null; + } + } + }, + JUICE(new Color(168, 201, 114)) { + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketJuice; + case CAN: + return ForestryItem.canJuice; + case CAPSULE: + return ForestryItem.waxCapsuleJuice; + case REFRACTORY: + return ForestryItem.refractoryJuice; + default: + return null; + } + } + + @Override + public void setProperties(ItemLiquidContainer liquidContainer) { + if (liquidContainer.getType() != EnumContainerType.BUCKET) + liquidContainer.setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION); + } + }, + MILK(new Color(255, 255, 255), 1030, 3000) { + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } + + @Override + public List getOtherContainers() { + return Arrays.asList( + new ItemStack(Items.milk_bucket) + ); + } + }, + SEEDOIL(new Color(255, 255, 168), 885, 5000) { + @Override + public Block makeBlock() { + return new BlockForestryFluid(this, 2, true); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketSeedoil; + case CAN: + return ForestryItem.canSeedOil; + case CAPSULE: + return ForestryItem.waxCapsuleSeedOil; + case REFRACTORY: + return ForestryItem.refractorySeedOil; + default: + return null; + } + } + }, + SHORT_MEAD(new Color(239, 154, 56), 1000, 1200) { + @Override + public String getTag() { + return "short.mead"; + } + + @Override + public Block makeBlock() { + return new BlockForestryFluid(this); + } + + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case BUCKET: + return ForestryItem.bucketShortMead; + default: + return null; + } + } + }, + // Vanilla + WATER(new Color(0x2432ec)) { + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canWater; + case CAPSULE: + return ForestryItem.waxCapsuleWater; + case REFRACTORY: + return ForestryItem.refractoryWater; + default: + return null; + } + } + }, + LAVA(new Color(0xfd461f)) { + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canLava; + case REFRACTORY: + return ForestryItem.refractoryLava; + default: + return null; + } + } + }, + // BuildCraft + FUEL(new Color(0xffff00)) { + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canFuel; + case CAPSULE: + return ForestryItem.waxCapsuleFuel; + case REFRACTORY: + return ForestryItem.refractoryFuel; + default: + return null; + } + } + }, + OIL(new Color(0x404040)) { + @Override + public ForestryItem getContainerForType(EnumContainerType type) { + switch (type) { + case CAN: + return ForestryItem.canOil; + case CAPSULE: + return ForestryItem.waxCapsuleOil; + case REFRACTORY: + return ForestryItem.refractoryOil; + default: + return null; + } + } + }, + // Railcraft + CREOSOTE, STEAM, + // Thermal Expansion + COAL, PYROTHEUM; + + public static final Fluids[] forestryFluids = {ETHANOL, BIOMASS, GLASS, HONEY, LEGACY_HONEY, ICE, JUICE, MILK, SEEDOIL, SHORT_MEAD}; + + private final String tag; + private final int density, viscosity; + private final Color color; + + private Fluids() { + this(null); + } + + private Fluids(Color color) { + this(color, 1000, 1000); + } + + private Fluids(Color color, int density, int viscosity) { + this.tag = name().toLowerCase(Locale.ENGLISH); + this.color = color; + this.density = density; + this.viscosity = viscosity; + } + + public int getTemperature() { + return 295; + } + + public String getTag() { + return tag; + } + + public final int getDensity() { + return density; + } + + public final int getViscosity() { + return viscosity; + } + + public final Fluid getFluid() { + return FluidRegistry.getFluid(getTag()); + } + + public final FluidStack getFluid(int mb) { + return FluidRegistry.getFluidStack(getTag(), mb); + } + + public final Block getBlock() { + Fluid fluid = getFluid(); + if (fluid == null) + return null; + return fluid.getBlock(); + } + + public final Color getColor() { + return color; + } + + public final boolean is(Fluid fluid) { + return getFluid() == fluid; + } + + public final boolean is(FluidStack fluidStack) { + return fluidStack != null && getFluid() == fluidStack.getFluid(); + } + + public final boolean isContained(ItemStack containerStack) { + return containerStack != null && FluidHelper.containsFluid(containerStack, getFluid()); + } + + public static boolean areEqual(Fluid fluid, FluidStack fluidStack) { + if (fluidStack != null && fluid == fluidStack.getFluid()) + return true; + return fluid == null && fluidStack == null; + } + + public static boolean areEqual(FluidStack a, FluidStack b) { + if (a == b) + return true; + if (a == null || b == null) + return false; + return a.isFluidEqual(b); + } + + /** FluidBlock and Container registration */ + /** + * Add the filled containers for this fluid. + * They will be automatically created and registered. + */ + public ForestryItem getContainerForType(EnumContainerType type) { + return null; + } + + /** + * Add non-forestry containers for this fluid. + */ + public List getOtherContainers() { + return Collections.emptyList(); + } + + /** + * Create a FluidBlock for this fluid. + */ + public Block makeBlock() { + return null; + } + + /** + * Set the properties for an ItemLiquidContainer before it gets registered. + */ + public void setProperties(ItemLiquidContainer liquidContainer) { + + } +} diff --git a/src/main/java/forestry/core/fluids/TankManager.java b/src/main/java/forestry/core/fluids/TankManager.java index dbef0aeab..b035dff35 100644 --- a/src/main/java/forestry/core/fluids/TankManager.java +++ b/src/main/java/forestry/core/fluids/TankManager.java @@ -25,20 +25,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import net.minecraftforge.fluids.IFluidTank; /** * @@ -71,12 +68,8 @@ public class TankManager extends ForwardingList implements IFluidH } @Override - public boolean addAll(Collection collection) { - boolean changed = false; - for (StandardTank tank : collection) - changed |= add(tank); - - return changed; + public final boolean addAll(Collection collection) { + return standardAddAll(collection); } @Override @@ -117,8 +110,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void writePacketData(DataOutputStream data) throws IOException { - for (int i = 0; i < tanks.size(); i++) + for (int i = 0; i < tanks.size(); i++) { writePacketData(data, i); + } } public void writePacketData(DataOutputStream data, int tankIndex) throws IOException { @@ -135,8 +129,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void readPacketData(DataInputStream data) throws IOException { - for (int i = 0; i < tanks.size(); i++) + for (int i = 0; i < tanks.size(); i++) { readPacketData(data, i); + } } public void readPacketData(DataInputStream data, int tankIndex) throws IOException { @@ -152,8 +147,9 @@ public class TankManager extends ForwardingList implements IFluidH } public void initGuiData(Container container, ICrafting player) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { initGuiData(container, player, tank.getTankIndex()); + } } public void initGuiData(Container container, ICrafting player, int tankIndex) { @@ -169,12 +165,13 @@ public class TankManager extends ForwardingList implements IFluidH player.sendProgressBarUpdate(container, tankIndex * NETWORK_DATA, fluidId); PacketGuiInteger packet = new PacketGuiInteger(container.windowId, tankIndex * NETWORK_DATA + 1, fluidAmount); - Proxies.net.sendToPlayer(packet, (EntityPlayerMP)player); + Proxies.net.sendToPlayer(packet, (EntityPlayerMP) player); } public void updateGuiData(Container container, List crafters) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { updateGuiData(container, crafters, tank.getTankIndex()); + } } public void updateGuiData(Container container, List crafters, int tankIndex) { @@ -229,16 +226,16 @@ public class TankManager extends ForwardingList implements IFluidH int color = tank.colorCache; boolean newLiquid = false; switch (messageId % NETWORK_DATA) { - case 0: - fluidId = data; - newLiquid = true; - break; - case 1: - amount = data; - break; - case 2: - color = data; - break; + case 0: + fluidId = data; + newLiquid = true; + break; + case 1: + amount = data; + break; + case 2: + color = data; + break; } if (newLiquid) { fluidStack = new FluidStack(fluidId, 0); @@ -250,9 +247,10 @@ public class TankManager extends ForwardingList implements IFluidH @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tankAcceptsFluid(tank, resource)) return fill(tank.getTankIndex(), resource, doFill); + } return FakeTank.INSTANCE.fill(resource, doFill); } @@ -270,9 +268,10 @@ public class TankManager extends ForwardingList implements IFluidH @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - for (StandardTank tank : tanks) + for (StandardTank tank : tanks) { if (tankCanDrain(tank)) return drain(tank.getTankIndex(), maxDrain, doDrain); + } return FakeTank.INSTANCE.drain(maxDrain, doDrain); } @@ -287,14 +286,19 @@ public class TankManager extends ForwardingList implements IFluidH return tank.drain(maxDrain, doDrain); } - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - for (StandardTank tank : tanks) + public FluidStack drain(FluidStack resource, boolean doDrain) { + for (StandardTank tank : tanks) { if (tankCanDrainFluid(tank, resource)) return tank.drain(resource.amount, doDrain); + } return null; } + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return drain(resource, doDrain); + } + @Override public boolean canFill(ForgeDirection from, Fluid fluid) { return true; @@ -308,8 +312,9 @@ public class TankManager extends ForwardingList implements IFluidH @Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { FluidTankInfo[] info = new FluidTankInfo[size()]; - for (int i = 0; i < size(); i++) + for (int i = 0; i < size(); i++) { info[i] = get(i).getInfo(); + } return info; } @@ -345,27 +350,38 @@ public class TankManager extends ForwardingList implements IFluidH return tank; } + public boolean accepts(Fluid fluid) { + if (fluid == null) + return false; + + for (StandardTank tank : tanks) { + if (tank.accepts(fluid)) + return true; + } + + return false; + } + private boolean tankAcceptsFluid(StandardTank tank, FluidStack fluidStack) { if (fluidStack == null) return false; if (!tank.canBeFilledExternally()) return false; - if (tank.fill(fluidStack, false) > 0) - return true; - return false; + return tank.fill(fluidStack, false) > 0; } private boolean tankCanDrain(StandardTank tank) { if (!tank.canBeDrainedExternally()) return false; FluidStack drained = tank.drain(1, false); - if (drained != null && drained.amount > 0) - return true; - return false; + return drained != null && drained.amount > 0; } private boolean tankCanDrainFluid(StandardTank tank, FluidStack fluidStack) { - return fluidStack != null && tankCanDrain(tank); + if (fluidStack == null) + return false; + if (!Fluids.areEqual(tank.getFluidType(), fluidStack)) + return false; + return tankCanDrain(tank); } - } diff --git a/src/main/java/forestry/core/fluids/tanks/FilteredTank.java b/src/main/java/forestry/core/fluids/tanks/FilteredTank.java index 18c67dbce..ae2cd8b3d 100644 --- a/src/main/java/forestry/core/fluids/tanks/FilteredTank.java +++ b/src/main/java/forestry/core/fluids/tanks/FilteredTank.java @@ -10,23 +10,29 @@ ******************************************************************************/ package forestry.core.fluids.tanks; -import forestry.core.gui.tooltips.ToolTipLine; -import net.minecraft.item.EnumRarity; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import net.minecraft.item.EnumRarity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import forestry.core.gui.tooltips.ToolTipLine; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StringUtil; + /** * * @author CovertJaguar */ public class FilteredTank extends StandardTank { - private HashSet filters; + private final HashSet filters; public FilteredTank(int capacity, Fluid... filters) { this(capacity, Arrays.asList(filters), null); @@ -72,19 +78,20 @@ public class FilteredTank extends StandardTank { } toolTip.clear(); - int amount = 0; - for (Fluid filter : filters) { - EnumRarity rarity = filter.getRarity(); - if (rarity == null) - rarity = EnumRarity.common; - FluidStack filterFluidStack = FluidRegistry.getFluidStack(filter.getName(), 0); - ToolTipLine name = new ToolTipLine(filter.getLocalizedName(filterFluidStack), rarity.rarityColor, 2); - toolTip.add(name); - if (getFluid() != null) - amount = getFluid().amount; + if(Proxies.common.isShiftDown() || filters.size() < 5) { + for (Fluid filter : filters) { + EnumRarity rarity = filter.getRarity(); + if (rarity == null) + rarity = EnumRarity.common; + FluidStack filterFluidStack = FluidRegistry.getFluidStack(filter.getName(), 0); + ToolTipLine name = new ToolTipLine(filter.getLocalizedName(filterFluidStack), rarity.rarityColor, 2); + toolTip.add(name); + } + } else { + toolTip.add(EnumChatFormatting.ITALIC + "<" + StringUtil.localize("gui.tooltip.tmi") + ">"); } - toolTip.add(new ToolTipLine(String.format("%,d", amount) + " / " + String.format("%,d", getCapacity()))); + toolTip.add(String.format("%,d", getFluidAmount()) + " / " + String.format("%,d", getCapacity())); } } diff --git a/src/main/java/forestry/core/fluids/tanks/StandardTank.java b/src/main/java/forestry/core/fluids/tanks/StandardTank.java index d2dae22b1..bfcbc5675 100644 --- a/src/main/java/forestry/core/fluids/tanks/StandardTank.java +++ b/src/main/java/forestry/core/fluids/tanks/StandardTank.java @@ -104,7 +104,7 @@ public class StandardTank extends FluidTank { } public boolean accepts(Fluid fluid) { - return true; + return fluid != null; } public boolean canBeFilledExternally() { diff --git a/src/main/java/forestry/core/gadgets/BlockBase.java b/src/main/java/forestry/core/gadgets/BlockBase.java index 404db46d6..562d88585 100755 --- a/src/main/java/forestry/core/gadgets/BlockBase.java +++ b/src/main/java/forestry/core/gadgets/BlockBase.java @@ -22,21 +22,24 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.IFluidHandler; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.core.fluids.FluidHelper; import forestry.core.interfaces.IOwnable; import forestry.core.items.ItemNBTTile; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StringUtil; +import forestry.core.utils.PlayerUtil; +import forestry.core.utils.Utils; public class BlockBase extends BlockForestry { @@ -161,36 +164,23 @@ public class BlockBase extends BlockForestry { return false; TileBase tile = (TileBase) world.getTileEntity(x, y, z); - if (!tile.isUseableByPlayer(player)) + if (!Utils.isUseableByPlayer(player, tile)) return false; ItemStack current = player.getCurrentEquippedItem(); - if (current != null && current.getItem() != Items.bucket && tile instanceof IFluidHandler) { - if (Proxies.common.isSimulating(world)) { - if (LiquidHelper.handleRightClick((IFluidHandler) tile, ForgeDirection.getOrientation(side), player, true, tile.canDrainWithBucket())) { - return true; - } - } else { - if (FluidContainerRegistry.isContainer(current)) { - return true; - } + if (current != null && current.getItem() != Items.bucket && tile instanceof IFluidHandler && tile.allowsAlteration(player)) { + if (FluidHelper.handleRightClick((IFluidHandler) tile, ForgeDirection.getOrientation(side), player, true, tile.canDrainWithBucket())) { + return true; } } if (!Proxies.common.isSimulating(world)) return true; - if (tile.allowsInteraction(player)) { + if (tile.allowsViewing(player)) { tile.openGui(player, tile); - } - else { - String ownerName = StringUtil.localize("gui.derelict"); - - if (tile.getOwnerProfile() != null) - ownerName = tile.getOwnerProfile().getName(); - - - player.addChatMessage(new ChatComponentTranslation("for.chat.accesslocked",ownerName)); + } else { + player.addChatMessage(new ChatComponentTranslation("for.chat.accesslocked", PlayerUtil.getOwnerName(tile))); } return true; } diff --git a/src/main/java/forestry/core/gadgets/BlockForestry.java b/src/main/java/forestry/core/gadgets/BlockForestry.java index ba26d000a..6ffd6e735 100755 --- a/src/main/java/forestry/core/gadgets/BlockForestry.java +++ b/src/main/java/forestry/core/gadgets/BlockForestry.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.core.gadgets; -import java.util.Random; - +import forestry.core.CreativeTabForestry; +import forestry.core.interfaces.IOwnable; +import forestry.core.proxy.Proxies; +import forestry.core.utils.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; @@ -20,11 +22,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; - -import forestry.core.CreativeTabForestry; -import forestry.core.interfaces.IOwnable; -import forestry.core.proxy.Proxies; -import forestry.core.utils.Utils; +import org.apache.logging.log4j.Level; public abstract class BlockForestry extends BlockContainer { @@ -66,6 +64,19 @@ public abstract class BlockForestry extends BlockContainer { TileForestry tile = (TileForestry) world.getTileEntity(i, j, k); if (entityliving instanceof EntityPlayer) - tile.owner = ((EntityPlayer) entityliving).getGameProfile(); + tile.setOwner(((EntityPlayer) entityliving)); } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { + try { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TileForestry) + ((TileForestry) tile).onNeighborBlockChange(block); + } catch (StackOverflowError error) { + Proxies.log.logThrowable(Level.ERROR, "Stack Overflow Error in BlockMachine.onNeighborBlockChange()", 10, error); + throw error; + } + } + } diff --git a/src/main/java/forestry/core/gadgets/BlockResource.java b/src/main/java/forestry/core/gadgets/BlockResource.java index 66fd7b3ff..cf9ef65e3 100755 --- a/src/main/java/forestry/core/gadgets/BlockResource.java +++ b/src/main/java/forestry/core/gadgets/BlockResource.java @@ -10,9 +10,13 @@ ******************************************************************************/ package forestry.core.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; +import forestry.core.config.ForestryItem; +import forestry.core.render.TextureManager; import java.util.ArrayList; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -23,13 +27,6 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.CreativeTabForestry; -import forestry.core.config.ForestryItem; -import forestry.core.render.TextureManager; - public class BlockResource extends Block { public BlockResource() { super(Material.rock); diff --git a/src/main/java/forestry/core/gadgets/BlockResourceStorageBlock.java b/src/main/java/forestry/core/gadgets/BlockResourceStorageBlock.java index bd0a97c4d..cd38198de 100644 --- a/src/main/java/forestry/core/gadgets/BlockResourceStorageBlock.java +++ b/src/main/java/forestry/core/gadgets/BlockResourceStorageBlock.java @@ -1,7 +1,10 @@ package forestry.core.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; +import forestry.core.render.TextureManager; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -9,10 +12,6 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.core.CreativeTabForestry; -import forestry.core.render.TextureManager; public class BlockResourceStorageBlock extends Block { @@ -40,6 +39,11 @@ public class BlockResourceStorageBlock extends Block { itemList.add(new ItemStack(this, 1, 2)); itemList.add(new ItemStack(this, 1, 3)); } + + @Override + public int damageDropped(int damage) { + return damage; + } @Override @SideOnly(Side.CLIENT) @@ -53,7 +57,7 @@ public class BlockResourceStorageBlock extends Block { @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int i, int meta) { - IIcon icon = null; + IIcon icon; if (meta == 0) { icon = iconApatite; } else if (meta == 1) { diff --git a/src/main/java/forestry/core/gadgets/BlockSoil.java b/src/main/java/forestry/core/gadgets/BlockSoil.java index 08d67af41..b3fbcd797 100755 --- a/src/main/java/forestry/core/gadgets/BlockSoil.java +++ b/src/main/java/forestry/core/gadgets/BlockSoil.java @@ -10,11 +10,18 @@ ******************************************************************************/ package forestry.core.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; +import forestry.core.IItemTyped; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.config.ForestryItem; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; import java.util.ArrayList; import java.util.List; import java.util.Random; - -import forestry.core.IItemTyped; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -25,21 +32,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.ForgeDirection; -import forestry.core.CreativeTabForestry; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.config.ForestryItem; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; - /** * Humus, bog earth, peat */ @@ -111,14 +107,6 @@ public class BlockSoil extends Block implements IItemTyped { matureBog(world, i, j, k); } - /** - * - * @param world - * @param x - * @param y - * @param z - * @return - */ private boolean isEnrooted(World world, int x, int y, int z) { for (int i = -1; i < 2; i++) @@ -127,10 +115,7 @@ public class BlockSoil extends Block implements IItemTyped { if (block == Blocks.log || block == Blocks.sapling || block == ForestryBlock.saplingGE.block()) // We are not returning true if we are the base of a // sapling. - if (i == 0 && j == 0) - return false; - else - return true; + return !(i == 0 && j == 0); } return false; @@ -138,18 +123,13 @@ public class BlockSoil extends Block implements IItemTyped { /** * If a tree or sapling is in the vicinity, there is a chance, that the soil will degrade. - * - * @param world - * @param i - * @param j - * @param k */ - private void degradeSoil(World world, int i, int j, int k) { + private void degradeSoil(World world, int x, int y, int z) { if (world.rand.nextInt(140) != 0) return; - int meta = world.getBlockMetadata(i, j, k); + int meta = world.getBlockMetadata(x, y, z); // Unpack first int type = meta & 0x03; @@ -162,10 +142,10 @@ public class BlockSoil extends Block implements IItemTyped { meta = (grade << 2 | type); if (grade >= degradeDelimiter) - world.setBlock(i, j, k, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); + world.setBlock(x, y, z, Blocks.sand, 0, Defaults.FLAG_BLOCK_SYNCH); else - world.setBlockMetadataWithNotify(i, j, k, meta, Defaults.FLAG_BLOCK_SYNCH); - world.markBlockForUpdate(i, j, k); + world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH); + world.markBlockForUpdate(x, y, z); } public static boolean isMoistened(World world, int x, int y, int z) { @@ -192,7 +172,7 @@ public class BlockSoil extends Block implements IItemTyped { int type = meta & 0x03; int maturity = meta >> 2; - if (maturity >= this.degradeDelimiter) + if (maturity >= degradeDelimiter) return; // Increment (de)gradation diff --git a/src/main/java/forestry/core/gadgets/BlockStainedGlass.java b/src/main/java/forestry/core/gadgets/BlockStainedGlass.java index ff4e31e05..2cd12a511 100755 --- a/src/main/java/forestry/core/gadgets/BlockStainedGlass.java +++ b/src/main/java/forestry/core/gadgets/BlockStainedGlass.java @@ -10,9 +10,12 @@ ******************************************************************************/ package forestry.core.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; +import forestry.core.render.TextureManager; import java.util.List; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.block.BlockBreakable; import net.minecraft.block.material.Material; @@ -23,12 +26,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.CreativeTabForestry; -import forestry.core.render.TextureManager; - public class BlockStainedGlass extends BlockBreakable { public BlockStainedGlass() { diff --git a/src/main/java/forestry/core/gadgets/BlockStructure.java b/src/main/java/forestry/core/gadgets/BlockStructure.java index 4f1a8ed17..e87e8e969 100755 --- a/src/main/java/forestry/core/gadgets/BlockStructure.java +++ b/src/main/java/forestry/core/gadgets/BlockStructure.java @@ -14,12 +14,13 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; + import forestry.api.core.ITileStructure; import forestry.core.proxy.Proxies; -import forestry.core.utils.StringUtil; +import forestry.core.utils.PlayerUtil; +import forestry.core.utils.Utils; public abstract class BlockStructure extends BlockForestry { @@ -60,34 +61,27 @@ public abstract class BlockStructure extends BlockForestry { return false; TileForestry tile = (TileForestry) world.getTileEntity(x, y, z); - if (!tile.isUseableByPlayer(player)) + if (!Utils.isUseableByPlayer(player, tile)) return false; - if (!Proxies.common.isSimulating(world)) - return player.getCurrentEquippedItem() == null || !(player.getCurrentEquippedItem().getItem() instanceof IStructureBlockItem); - // GUIs can only be opened on integrated structure blocks. if (tile instanceof ITileStructure) if (!((ITileStructure) tile).isIntegratedIntoStructure()) return false; - if (tile.allowsInteraction(player)) { - tile.openGui(player); - } - else { - String ownerName = StringUtil.localize("gui.derelict"); - - if (tile.getOwnerProfile() != null) - ownerName = tile.getOwnerProfile().getName(); - - player.addChatMessage(new ChatComponentTranslation("for.chat.accesslocked",ownerName)); + if (Proxies.common.isSimulating(world)) { + if (tile.allowsViewing(player)) { + tile.openGui(player); + } else { + player.addChatMessage(new ChatComponentTranslation("for.chat.accesslocked", PlayerUtil.getOwnerName(tile))); + } } return true; } @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) { - + super.onNeighborBlockChange(world, x, y, z, neighbor); if (!Proxies.common.isSimulating(world)) return; diff --git a/src/main/java/forestry/core/gadgets/Engine.java b/src/main/java/forestry/core/gadgets/Engine.java index b64929df5..7ef6a7d84 100755 --- a/src/main/java/forestry/core/gadgets/Engine.java +++ b/src/main/java/forestry/core/gadgets/Engine.java @@ -11,6 +11,11 @@ package forestry.core.gadgets; import cofh.api.energy.IEnergyConnection; +import forestry.core.TemperatureState; +import forestry.core.config.Defaults; +import forestry.core.network.PacketPayload; +import forestry.core.utils.BlockUtil; +import forestry.energy.EnergyManager; import net.minecraft.entity.EntityLivingBase; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -19,11 +24,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import forestry.core.TemperatureState; -import forestry.core.config.Defaults; -import forestry.core.network.PacketPayload; -import forestry.core.utils.BlockUtil; -import forestry.energy.EnergyManager; public abstract class Engine extends TileBase implements IEnergyConnection { @@ -68,7 +68,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection { protected final int maxHeat; protected boolean forceCooldown = false; public float progress; - protected EnergyManager energyManager; + protected final EnergyManager energyManager; public Engine(int maxHeat, int maxEnergy, int maxEnergyExtracted) { this.maxHeat = maxHeat; @@ -85,11 +85,6 @@ public abstract class Engine extends TileBase implements IEnergyConnection { rotateEngine(); } - /** - * Adds heat - * - * @param i - */ protected void addHeat(int i) { heat += i; @@ -227,8 +222,6 @@ public abstract class Engine extends TileBase implements IEnergyConnection { /** * Returns the current energy state of the engine - * - * @return */ public TemperatureState getTemperatureState() { // double scaledStorage = (double)storedEnergy / (double)maxEnergy; @@ -248,11 +241,6 @@ public abstract class Engine extends TileBase implements IEnergyConnection { return TemperatureState.MELTING; } - /** - * Piston speed - * - * @return - */ public float getPistonSpeed() { switch (getTemperatureState()) { case COOL: diff --git a/src/main/java/forestry/core/gadgets/MachineDefinition.java b/src/main/java/forestry/core/gadgets/MachineDefinition.java index 99a644b1f..1461c10a4 100755 --- a/src/main/java/forestry/core/gadgets/MachineDefinition.java +++ b/src/main/java/forestry/core/gadgets/MachineDefinition.java @@ -16,6 +16,9 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.core.interfaces.IBlockRenderer; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -30,13 +33,6 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * This will replace the whole {@link Gadget}-nonsense at some point, using the proper Forge hook. Will hopefully sort out any issues with interfaces. - */ public class MachineDefinition { public final Class teClass; diff --git a/src/main/java/forestry/core/gadgets/MachineNBTDefinition.java b/src/main/java/forestry/core/gadgets/MachineNBTDefinition.java index a0dbf916b..338a8a3e9 100755 --- a/src/main/java/forestry/core/gadgets/MachineNBTDefinition.java +++ b/src/main/java/forestry/core/gadgets/MachineNBTDefinition.java @@ -10,6 +10,10 @@ ******************************************************************************/ package forestry.core.gadgets; +import forestry.core.interfaces.IBlockRenderer; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -17,11 +21,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import forestry.core.interfaces.IBlockRenderer; -import forestry.core.proxy.Proxies; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; - public class MachineNBTDefinition extends MachineDefinition { public MachineNBTDefinition(int meta, String teIdent, Class teClass, IRecipe... recipes) { diff --git a/src/main/java/forestry/core/gadgets/Mill.java b/src/main/java/forestry/core/gadgets/Mill.java index 67f1291a1..a6f15aa7f 100755 --- a/src/main/java/forestry/core/gadgets/Mill.java +++ b/src/main/java/forestry/core/gadgets/Mill.java @@ -10,15 +10,12 @@ ******************************************************************************/ package forestry.core.gadgets; -import forestry.core.network.EntityNetData; +import forestry.core.network.PacketPayload; public abstract class Mill extends TileBase { - @EntityNetData public int charge = 0; - @EntityNetData public float speed; - @EntityNetData public int stage = 0; public float progress; @@ -36,6 +33,24 @@ public abstract class Mill extends TileBase { update(true); } + @Override + public PacketPayload getPacketPayload() { + PacketPayload payload = new PacketPayload(2, 1, 0); + payload.intPayload[0] = charge; + payload.intPayload[1] = stage; + + payload.floatPayload[0] = speed; + return payload; + } + + @Override + public void fromPacketPayload(PacketPayload payload) { + charge = payload.intPayload[0]; + stage = payload.intPayload[1]; + + speed = payload.floatPayload[0]; + } + private void update(boolean isSimulating) { // Stop gracefully if discharged. diff --git a/src/main/java/forestry/core/gadgets/NaturalistGame.java b/src/main/java/forestry/core/gadgets/NaturalistGame.java index e55f3d5b0..399c041d5 100755 --- a/src/main/java/forestry/core/gadgets/NaturalistGame.java +++ b/src/main/java/forestry/core/gadgets/NaturalistGame.java @@ -10,21 +10,19 @@ ******************************************************************************/ package forestry.core.gadgets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Random; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - import forestry.api.core.INBTTagable; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.api.genetics.ISpeciesRoot; import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Random; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; public class NaturalistGame implements INBTTagable { diff --git a/src/main/java/forestry/core/gadgets/StructureLogic.java b/src/main/java/forestry/core/gadgets/StructureLogic.java index 2dcc57c02..96632ace4 100755 --- a/src/main/java/forestry/core/gadgets/StructureLogic.java +++ b/src/main/java/forestry/core/gadgets/StructureLogic.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.core.gadgets; -import java.util.HashMap; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - import forestry.api.core.IStructureLogic; import forestry.api.core.ITileStructure; import forestry.core.config.Defaults; import forestry.core.gadgets.BlockStructure.EnumStructureState; import forestry.core.utils.Schemata; import forestry.core.utils.Schemata.EnumStructureBlock; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.HashMap; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; public abstract class StructureLogic implements IStructureLogic { @@ -70,7 +68,7 @@ public abstract class StructureLogic implements IStructureLogic { EnumStructureState state = EnumStructureState.INDETERMINATE; - boolean rotate = false; + boolean rotate; for (int i = 0; i < schematas.length; i++) { if (!schematas[i].isEnabled()) continue; @@ -87,7 +85,6 @@ public abstract class StructureLogic implements IStructureLogic { isRotated = rotate; break; } - } // Structure state is indeterminate, possibly caused by chunkloading. Remain calm, do nothing. diff --git a/src/main/java/forestry/core/gadgets/TileAnalyzer.java b/src/main/java/forestry/core/gadgets/TileAnalyzer.java index 22a1c007b..cfe7ca335 100755 --- a/src/main/java/forestry/core/gadgets/TileAnalyzer.java +++ b/src/main/java/forestry/core/gadgets/TileAnalyzer.java @@ -15,6 +15,7 @@ import java.util.Stack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -28,22 +29,21 @@ import net.minecraftforge.fluids.FluidTankInfo; import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; -import forestry.api.core.EnumErrorCode; -import forestry.core.fluids.TankManager; +import forestry.core.EnumErrorCode; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.Fluids; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; +import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.inventory.wrappers.InventoryMapper; -import forestry.core.utils.InventoryAdapter; -import net.minecraft.inventory.IInventory; +import forestry.core.network.GuiId; +import forestry.core.utils.GuiUtil; public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiquidTankContainer { @@ -54,32 +54,45 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui public static final short SLOT_ANALYZE = 0; public static final short SLOT_CAN = 1; public static final short SLOT_INPUT_1 = 2; + public static final short SLOT_INPUT_COUNT = 6; public static final short SLOT_OUTPUT_1 = 8; + public static final short SLOT_OUTPUT_COUNT = 4; /* MEMBER */ - private final InventoryAdapter inventory = new InventoryAdapter(12, "Items"); - private int analyzeTime; - @EntityNetData public final FilteredTank resourceTank; private final TankManager tankManager; private final Stack pendingProducts = new Stack(); - private final IInventory invInput = new InventoryMapper(inventory, SLOT_INPUT_1, 6); + private final IInventory invInput; /* CONSTRUCTOR */ public TileAnalyzer() { super(800, 40, Defaults.MACHINE_MAX_ENERGY); - resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.get()); - tankManager = new TankManager(resourceTank); - } + setInternalInventory(new TileInventoryAdapter(this, 12, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (GuiUtil.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOT_INPUT_COUNT)) { + return AlleleManager.alleleRegistry.isIndividual(itemStack); + } else if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return resourceTank.accepts(fluid); + } - @Override - public String getInventoryName() { - return getUnlocalizedName(); + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT); + } + }); + resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.getFluid()); + tankManager = new TankManager(resourceTank); + invInput = new InventoryMapper(getInternalInventory(), SLOT_INPUT_1, 6); } /* GUI */ @@ -100,17 +113,15 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui // / Pending Products NBTTagList nbttaglist = new NBTTagList(); ItemStack[] pending = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); - for (int i = 0; i < pending.length; i++) + for (int i = 0; i < pending.length; i++) { if (pending[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); pending[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingProducts", nbttaglist); - - // / Inventory - inventory.writeToNBT(nbttagcompound); } @Override @@ -127,9 +138,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); pendingProducts.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); } - - // / Inventory - inventory.readFromNBT(nbttagcompound); } @Override @@ -137,9 +145,9 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui // Check if we have suitable items waiting in the can slot FluidHelper.drainContainers(tankManager, this, SLOT_CAN); ItemStack can = getStackInSlot(SLOT_CAN); - if (ForestryItem.honeyDrop.isItemEqual(can) && resourceTank.fill(Fluids.HONEY.get(Defaults.FLUID_PER_HONEY_DROP), false) == Defaults.FLUID_PER_HONEY_DROP) { + if (ForestryItem.honeyDrop.isItemEqual(can) && resourceTank.fill(Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP), false) == Defaults.FLUID_PER_HONEY_DROP) { setInventorySlotContents(SLOT_CAN, InvTools.depleteItem(can)); - resourceTank.fill(Fluids.HONEY.get(Defaults.FLUID_PER_HONEY_DROP), true); + resourceTank.fill(Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP), true); } for (int i = 0; i < invInput.getSizeInventory(); i++) { @@ -249,7 +257,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui return false; ItemStack next = pendingProducts.peek(); - if (inventory.tryAddStack(next, SLOT_OUTPUT_1, inventory.getSizeInventory() - SLOT_OUTPUT_1, true)) { + if (InvTools.tryAddStack(getInternalInventory(), next, SLOT_OUTPUT_1, getInternalInventory().getSizeInventory() - SLOT_OUTPUT_1, true)) { pendingProducts.pop(); return true; } @@ -270,7 +278,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui if (analyzeTime > 0) return true; - return getErrorState() == EnumErrorCode.OK ||getErrorState() == EnumErrorCode.NOPOWER; + return getErrorState() == EnumErrorCode.OK || getErrorState() == EnumErrorCode.NOPOWER; } public int getProgressScaled(int i) { @@ -303,121 +311,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui } - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex >= SLOT_OUTPUT_1 && slotIndex < SLOT_OUTPUT_1 + 4; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack stack, int side) { - - if (!super.canPutStackFromSide(slotIndex, stack, side)) - return false; - - if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + 6) - return AlleleManager.alleleRegistry.isIndividual(stack); - - if (slotIndex == SLOT_CAN) - return Fluids.HONEY.isContained(stack); - - return false; - } - - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - /* ILIQUIDCONTAINER */ @Override public TankManager getTankManager() { @@ -453,5 +346,4 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } - } diff --git a/src/main/java/forestry/core/gadgets/TileBase.java b/src/main/java/forestry/core/gadgets/TileBase.java index a88799bae..33f9e9e8e 100755 --- a/src/main/java/forestry/core/gadgets/TileBase.java +++ b/src/main/java/forestry/core/gadgets/TileBase.java @@ -11,13 +11,8 @@ package forestry.core.gadgets; import forestry.core.interfaces.IHintSource; -import forestry.core.network.ClassMap; -import forestry.core.network.IndexInPayload; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumAccess; -import forestry.core.utils.PlayerUtil; -import forestry.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; public abstract class TileBase extends TileForestry implements IHintSource { @@ -52,53 +47,17 @@ public abstract class TileBase extends TileForestry implements IHintSource { /* NETWORK */ @Override public PacketPayload getPacketPayload() { - if (!ClassMap.classMappers.containsKey(this.getClass())) - ClassMap.classMappers.put(this.getClass(), new ClassMap(this.getClass())); - - ClassMap classmap = ClassMap.classMappers.get(this.getClass()); - PacketPayload payload = new PacketPayload(classmap.intSize, classmap.floatSize, classmap.stringSize); - - try { - classmap.setData(this, payload.intPayload, payload.floatPayload, payload.stringPayload, new IndexInPayload(0, 0, 0)); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - return payload; + return null; } @Override public void fromPacketPayload(PacketPayload payload) { - - if (payload.isEmpty()) - return; - - if (!ClassMap.classMappers.containsKey(this.getClass())) - ClassMap.classMappers.put(this.getClass(), new ClassMap(this.getClass())); - - ClassMap classmap = ClassMap.classMappers.get(this.getClass()); - - try { - classmap.fromData(this, payload.intPayload, payload.floatPayload, payload.stringPayload, new IndexInPayload(0, 0, 0)); - } catch (Exception ex) { - ex.printStackTrace(); - } } /* INTERACTION */ public void openGui(EntityPlayer player, TileBase tile) { } - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - if (!Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord)) - return false; - if (getAccess() == EnumAccess.PRIVATE) - return PlayerUtil.isSameGameProfile(owner, player.getGameProfile()); - - return true; - } - public boolean canDrainWithBucket() { return false; } diff --git a/src/main/java/forestry/core/gadgets/TileEscritoire.java b/src/main/java/forestry/core/gadgets/TileEscritoire.java index 6fdde0480..b98990bf7 100755 --- a/src/main/java/forestry/core/gadgets/TileEscritoire.java +++ b/src/main/java/forestry/core/gadgets/TileEscritoire.java @@ -22,6 +22,8 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; import forestry.core.interfaces.ICrafter; import forestry.core.interfaces.IRenderableMachine; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.ForestryPacket; import forestry.core.network.GuiId; import forestry.core.network.PacketIds; @@ -29,10 +31,8 @@ import forestry.core.network.PacketTileNBT; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.StringUtil; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; +import forestry.core.utils.GeneticsUtil; +import forestry.core.utils.GuiUtil; public class TileEscritoire extends TileBase implements ISidedInventory, IRenderableMachine, ICrafter { @@ -44,14 +44,60 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender /* MEMBER */ private final NaturalistGame game = new NaturalistGame(); - private final InventoryAdapter inventory; - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } public TileEscritoire() { - inventory = new TileInventoryAdapter(this, 12, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 12, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + Math.min(game.getSampleSize(), SLOTS_INPUT_COUNT)) { + ItemStack specimen = getStackInSlot(SLOT_ANALYZE); + if (specimen == null) + return false; + IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen); + return individual != null && individual.getGenome().getPrimary().getResearchSuitability(itemStack) > 0; + } + + if (slotIndex == SLOT_ANALYZE) { + return AlleleManager.alleleRegistry.isIndividual(itemStack); + } + + return false; + } + + @Override + public boolean isLocked(int slotIndex) { + if (slotIndex == SLOT_ANALYZE) + return false; + + if (getStackInSlot(SLOT_ANALYZE) == null) + return true; + + if (GuiUtil.isIndexInRange(slotIndex, SLOT_INPUT_1, SLOTS_INPUT_COUNT)) { + if (slotIndex >= SLOT_INPUT_1 + game.getSampleSize()) + return true; + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT); + } + + @Override + public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { + super.setInventorySlotContents(slotIndex, itemstack); + if (slotIndex == SLOT_ANALYZE && Proxies.common.isSimulating(worldObj)) { + if (!AlleleManager.alleleRegistry.isIndividual(getStackInSlot(SLOT_ANALYZE)) && getStackInSlot(SLOT_ANALYZE) != null) { + ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_ANALYZE)); + if (ersatz != null) + setInventorySlotContents(SLOT_ANALYZE, ersatz); + } + game.initialize(getStackInSlot(SLOT_ANALYZE)); + } + } + }); } /* GUI */ @@ -66,7 +112,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender super.writeToNBT(nbttagcompound); game.writeToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); } @Override @@ -74,7 +119,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender super.readFromNBT(nbttagcompound); game.readFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); } /* GAME */ @@ -83,42 +127,43 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender } public void processTurnResult(GameProfile gameProfile) { - if(!game.isWon()) + if (!game.isWon()) return; - IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inventory.getStackInSlot(SLOT_ANALYZE)); - if(individual == null) + IIndividual individual = AlleleManager.alleleRegistry.getIndividual(getInternalInventory().getStackInSlot(SLOT_ANALYZE)); + if (individual == null) return; - for(ItemStack itemstack : individual.getGenome().getPrimary().getResearchBounty(worldObj, gameProfile, individual, game.getBountyLevel())) - inventory.addStack(itemstack, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT, false, true); + for (ItemStack itemstack : individual.getGenome().getPrimary().getResearchBounty(worldObj, gameProfile, individual, game.getBountyLevel())) { + InvTools.addStack(getInternalInventory(), itemstack, SLOT_RESULTS_1, SLOTS_RESULTS_COUNT, false, true); + } } private boolean areProbeSlotsFilled() { int filledSlots = 0; int required = game.getSampleSize() < SLOTS_INPUT_COUNT ? game.getSampleSize() : SLOTS_INPUT_COUNT; - for(int i = SLOT_INPUT_1; i < SLOT_INPUT_1 + required; i++) - if(inventory.getStackInSlot(i) != null) + for (int i = SLOT_INPUT_1; i < SLOT_INPUT_1 + required; i++) { + if (getInternalInventory().getStackInSlot(i) != null) filledSlots++; + } return filledSlots >= required; } public void probe() { - if (!worldObj.isRemote && inventory.getStackInSlot(SLOT_ANALYZE) != null && areProbeSlotsFilled()) { - game.probe(inventory.getStackInSlot(SLOT_ANALYZE), this, SLOT_INPUT_1, SLOTS_INPUT_COUNT); - } + if (!worldObj.isRemote && getInternalInventory().getStackInSlot(SLOT_ANALYZE) != null && areProbeSlotsFilled()) + game.probe(getInternalInventory().getStackInSlot(SLOT_ANALYZE), this, SLOT_INPUT_1, SLOTS_INPUT_COUNT); } /* NETWORK */ @Override public void fromPacket(ForestryPacket packetRaw) { - if(packetRaw instanceof PacketTileUpdate) { + if (packetRaw instanceof PacketTileUpdate) { super.fromPacket(packetRaw); return; } - PacketTileNBT packet = (PacketTileNBT)packetRaw; + PacketTileNBT packet = (PacketTileNBT) packetRaw; readFromNBT(packet.getTagCompound()); } @@ -126,100 +171,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player); } - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - if(slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + SLOTS_INPUT_COUNT) - return slotIndex < SLOT_INPUT_1 + game.getSampleSize(); - - return true; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex >= SLOT_RESULTS_1 && slotIndex < SLOT_RESULTS_1 + SLOTS_RESULTS_COUNT; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - int samples = game.getSampleSize(); - return slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + (samples < SLOTS_INPUT_COUNT ? samples : SLOTS_INPUT_COUNT); - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - inventory.setInventorySlotContents(slotIndex, itemstack); - if(slotIndex == SLOT_ANALYZE && Proxies.common.isSimulating(worldObj)) { - if(!AlleleManager.alleleRegistry.isIndividual(inventory.getStackInSlot(SLOT_ANALYZE)) - && inventory.getStackInSlot(SLOT_ANALYZE) != null) { - ItemStack ersatz = Utils.convertSaplingToGeneticEquivalent(inventory.getStackInSlot(SLOT_ANALYZE)); - if(ersatz != null) - inventory.setInventorySlotContents(SLOT_ANALYZE, ersatz); - } - game.initialize(inventory.getStackInSlot(SLOT_ANALYZE)); - } - } - - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - @Override public EnumTankLevel getPrimaryLevel() { return EnumTankLevel.EMPTY; @@ -232,7 +183,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender @Override public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { - if(slotIndex == SLOT_ANALYZE) + if (slotIndex == SLOT_ANALYZE) game.reset(); return null; } @@ -246,6 +197,4 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender public boolean canTakeStack(int slotIndex) { return true; } - - } diff --git a/src/main/java/forestry/core/gadgets/TileForestry.java b/src/main/java/forestry/core/gadgets/TileForestry.java index a6e1aedcd..918eba51c 100755 --- a/src/main/java/forestry/core/gadgets/TileForestry.java +++ b/src/main/java/forestry/core/gadgets/TileForestry.java @@ -10,27 +10,12 @@ ******************************************************************************/ package forestry.core.gadgets; -import buildcraft.api.statements.IStatementContainer; -import buildcraft.api.statements.ITriggerExternal; -import buildcraft.api.statements.ITriggerInternal; -import buildcraft.api.statements.ITriggerProvider; -import com.mojang.authlib.GameProfile; -import cpw.mods.fml.common.Optional; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.interfaces.IErrorSource; -import forestry.core.interfaces.IOwnable; -import forestry.core.network.ForestryPacket; -import forestry.core.network.INetworkedEntity; -import forestry.core.network.PacketPayload; -import forestry.core.network.PacketTileUpdate; -import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumAccess; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.Vect; +import java.util.Collection; + +import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; @@ -38,23 +23,69 @@ import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; + +import com.mojang.authlib.GameProfile; + import net.minecraftforge.common.util.ForgeDirection; -import java.util.Collection; +import cpw.mods.fml.common.Optional; + +import forestry.api.core.IErrorState; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.interfaces.IErrorSource; +import forestry.core.interfaces.IFilterSlotDelegate; +import forestry.core.interfaces.IRestrictedAccess; +import forestry.core.inventory.FakeInventoryAdapter; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.network.ForestryPacket; +import forestry.core.network.INetworkedEntity; +import forestry.core.network.PacketPayload; +import forestry.core.network.PacketTileUpdate; +import forestry.core.proxy.Proxies; +import forestry.core.utils.AdjacentTileCache; +import forestry.core.utils.EnumAccess; +import forestry.core.utils.PlayerUtil; +import forestry.core.utils.Utils; +import forestry.core.vect.Vect; + +import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.ITriggerExternal; +import buildcraft.api.statements.ITriggerInternal; +import buildcraft.api.statements.ITriggerProvider; @Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") -public abstract class TileForestry extends TileEntity implements INetworkedEntity, IOwnable, IErrorSource, ITriggerProvider { +public abstract class TileForestry extends TileEntity implements INetworkedEntity, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate { + protected final AdjacentTileCache tileCache = new AdjacentTileCache(this); protected boolean isInited = false; + private IInventoryAdapter inventory = FakeInventoryAdapter.instance(); + + public AdjacentTileCache getTileCache() { + return tileCache; + } + + public void onNeighborBlockChange(Block id) { + tileCache.onNeighborChange(); + } + + @Override + public void invalidate() { + tileCache.purge(); + super.invalidate(); + } + + @Override + public void validate() { + tileCache.purge(); + super.validate(); + } public Vect Coords() { return new Vect(xCoord, yCoord, zCoord); } - public World getWorld() { - return this.getWorldObj(); - } - public void openGui(EntityPlayer player) { } @@ -79,44 +110,43 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit initialize(); isInited = true; } - - if (!Proxies.common.isSimulating(worldObj)) - return; } public abstract void initialize(); // / SAVING & LOADING @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); - if (nbttagcompound.hasKey("Access")) - access = EnumAccess.values()[nbttagcompound.getInteger("Access")]; + inventory.readFromNBT(data); + + if (data.hasKey("Access")) + access = EnumAccess.values()[data.getInteger("Access")]; else access = EnumAccess.SHARED; - if (nbttagcompound.hasKey("owner")) { - owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner")); - } + if (data.hasKey("owner")) + owner = NBTUtil.func_152459_a(data.getCompoundTag("owner")); - if (nbttagcompound.hasKey("Orientation")) - orientation = ForgeDirection.values()[nbttagcompound.getInteger("Orientation")]; + if (data.hasKey("Orientation")) + orientation = ForgeDirection.values()[data.getInteger("Orientation")]; else orientation = ForgeDirection.WEST; } @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - nbttagcompound.setInteger("Access", access.ordinal()); + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + inventory.writeToNBT(data); + data.setInteger("Access", access.ordinal()); if (this.owner != null) { NBTTagCompound nbt = new NBTTagCompound(); NBTUtil.func_152460_a(nbt, owner); - nbttagcompound.setTag("owner", nbt); + data.setTag("owner", nbt); } if (orientation != null) - nbttagcompound.setInteger("Orientation", orientation.ordinal()); + data.setInteger("Orientation", orientation.ordinal()); } // / SMP @@ -186,9 +216,9 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit this.sendNetworkUpdate(); } // / ERROR HANDLING - public EnumErrorCode errorState = EnumErrorCode.OK; + public IErrorState errorState = EnumErrorCode.OK; - public void setErrorState(EnumErrorCode state) { + public void setErrorState(IErrorState state) { if (this.errorState == state) return; this.errorState = state; @@ -201,41 +231,30 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit } @Override - public EnumErrorCode getErrorState() { + public IErrorState getErrorState() { return errorState; } // / OWNERSHIP - public GameProfile owner = null; + private GameProfile owner = null; private EnumAccess access = EnumAccess.SHARED; @Override - public boolean allowsRemoval(EntityPlayer player) { - if (!isOwnable()) - return true; - if (!isOwned()) - return true; - if (isOwner(player)) - return true; - if (Proxies.common.isOp(player)) - return true; - - return getAccess() == EnumAccess.SHARED; + public final boolean allowsRemoval(EntityPlayer player) { + return Config.disablePermissions || !isOwnable() || !isOwned() || isOwner(player) || Proxies.common.isOp(player); } @Override - public boolean allowsInteraction(EntityPlayer player) { - if (Config.disablePermissions) - return true; - if (!isOwnable()) - return true; - if (!isOwned()) - return true; - if (isOwner(player)) - return true; - if (Proxies.common.isOp(player)) - return true; + public final boolean allowsAlteration(EntityPlayer player) { + return allowsRemoval(player) || getAccess() == EnumAccess.SHARED; + } - return getAccess() == EnumAccess.SHARED || getAccess() == EnumAccess.VIEWABLE; + @Override + public final boolean allowsViewing(EntityPlayer player) { + return allowsAlteration(player) || getAccess() == EnumAccess.VIEWABLE; + } + + private boolean allowsPipeConnections() { + return access == EnumAccess.SHARED; } @Override @@ -265,10 +284,9 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit @Override public boolean isOwner(EntityPlayer player) { - if (owner != null) - return owner.getId().compareTo(player.getPersistentID()) == 0; - else - return false; + if (owner != null && player != null) + return PlayerUtil.isSameGameProfile(owner, player.getGameProfile()); + return false; } @Override @@ -276,61 +294,141 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit if (!isOwner(player)) return false; - if (access.ordinal() < EnumAccess.values().length - 1) - access = EnumAccess.values()[access.ordinal() + 1]; - else - access = EnumAccess.values()[0]; + boolean couldPipesConnect = allowsPipeConnections(); + + int ordinal = (access.ordinal() + 1) % EnumAccess.values().length; + access = EnumAccess.values()[ordinal]; + if (!this.worldObj.isRemote) + sendNetworkUpdate(); + + boolean canPipesConnect = allowsPipeConnections(); + if (couldPipesConnect != canPipesConnect) { + // pipes connected to this need to update + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType); + markDirty(); + } return true; } /* NAME */ - /** * Gets the tile's unlocalized name, based on the block at the location of this entity (client-only). */ public String getUnlocalizedName() { - String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.",""); + String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.", ""); return blockUnlocalizedName + "." + getBlockMetadata() + ".name"; } - public boolean hasCustomInventoryName() { - return true; - } - - /* ACCESS */ - public abstract boolean isUseableByPlayer(EntityPlayer player); - /* INVENTORY BASICS */ - public InventoryAdapter getInternalInventory() { - return null; + public IInventoryAdapter getInternalInventory() { + return inventory; } - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return true; + public final void setInternalInventory(IInventoryAdapter inv) { + if (inv == null) { + throw new NullPointerException("Inventory cannot be null"); + } + this.inventory = inv; } - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return canPutStackFromSide(i, itemstack, j); + /* ISidedInventory */ + @Override + public final int getSizeInventory() { + return getInternalInventory().getSizeInventory(); } - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return getAccess() == EnumAccess.SHARED; + @Override + public final ItemStack getStackInSlot(int slotIndex) { + return getInternalInventory().getStackInSlot(slotIndex); } - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return canTakeStackFromSide(i, itemstack, j); + @Override + public final ItemStack decrStackSize(int slotIndex, int amount) { + return getInternalInventory().decrStackSize(slotIndex, amount); } - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return getAccess() == EnumAccess.SHARED; + @Override + public final ItemStack getStackInSlotOnClosing(int slotIndex) { + return getInternalInventory().getStackInSlotOnClosing(slotIndex); } - public int[] getAccessibleSlotsFromSide(int side) { - if (getInternalInventory() == null) - return Defaults.FACINGS_NONE; - else - return getInternalInventory().getSizeInventorySide(side); + @Override + public final void setInventorySlotContents(int slotIndex, ItemStack itemstack) { + getInternalInventory().setInventorySlotContents(slotIndex, itemstack); + } + @Override + public final int getInventoryStackLimit() { + return getInternalInventory().getInventoryStackLimit(); + } + + @Override + public final void openInventory() { + getInternalInventory().openInventory(); + } + + @Override + public final void closeInventory() { + getInternalInventory().closeInventory(); + } + + @Override + public final String getInventoryName() { + return getUnlocalizedName(); + } + + @Override + public final boolean isUseableByPlayer(EntityPlayer player) { + if (!Utils.isUseableByPlayer(player, this) || !allowsViewing(player)) + return false; + return getInternalInventory().isUseableByPlayer(player); + } + + @Override + public final boolean hasCustomInventoryName() { + return getInternalInventory().hasCustomInventoryName(); + } + + @Override + public final boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { + if (itemStack == null || !allowsPipeConnections()) + return false; + + if (!canSlotAccept(slotIndex, itemStack)) + return false; + + return getInternalInventory().isItemValidForSlot(slotIndex, itemStack); + } + + @Override + public final boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return getInternalInventory().canSlotAccept(slotIndex, itemStack); + } + + @Override + public boolean isLocked(int slotIndex) { + return getInternalInventory().isLocked(slotIndex); + } + + @Override + public final int[] getAccessibleSlotsFromSide(int side) { + if (!allowsPipeConnections()) + return Defaults.SLOTS_NONE; + return getInternalInventory().getAccessibleSlotsFromSide(side); + } + + @Override + public final boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) { + if (itemStack == null || !allowsPipeConnections()) + return false; + return isItemValidForSlot(slotIndex, itemStack); + } + + @Override + public final boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) { + if (itemStack == null || !allowsPipeConnections()) + return false; + return getInternalInventory().canExtractItem(slotIndex, itemStack, side); } } diff --git a/src/main/java/forestry/core/gadgets/TileMachine.java b/src/main/java/forestry/core/gadgets/TileMachine.java index 54d250006..55d6f212a 100755 --- a/src/main/java/forestry/core/gadgets/TileMachine.java +++ b/src/main/java/forestry/core/gadgets/TileMachine.java @@ -12,32 +12,25 @@ package forestry.core.gadgets; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; -import forestry.api.core.ISpecialInventory; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IHintSource; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumAccess; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.Utils; import forestry.plugins.PluginApiculture; import forestry.plugins.PluginEnergy; import forestry.plugins.PluginFactory; import forestry.plugins.PluginIC2; import forestry.plugins.PluginMail; +import java.util.HashMap; import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; -import net.minecraftforge.common.util.ForgeDirection; -import java.util.HashMap; - -public abstract class TileMachine extends TileForestry implements ISpecialInventory, IClimatised, IHintSource { +public abstract class TileMachine extends TileForestry implements IClimatised, IHintSource { public TileMachine() { } @@ -275,86 +268,6 @@ public abstract class TileMachine extends TileForestry implements ISpecialInvent return false; } - // IINVENTORY IMPLEMENTATION - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(int i) { - return null; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return null; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - // IPARTICULARINVENTORY IMPLEMENTATION - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (getAccess() == EnumAccess.PRIVATE) - return 0; - - return 0; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - if (getAccess() == EnumAccess.PRIVATE) - return new ItemStack[0]; - - return new ItemStack[0]; - } // INETWORKEDTILE IMPLEMENTATION @Override diff --git a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java index 152f0fa8c..2450070b8 100755 --- a/src/main/java/forestry/core/gadgets/TileNaturalistChest.java +++ b/src/main/java/forestry/core/gadgets/TileNaturalistChest.java @@ -11,35 +11,38 @@ package forestry.core.gadgets; 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 forestry.api.core.ForestryAPI; import forestry.api.genetics.ISpeciesRoot; import forestry.core.GuiHandler; import forestry.core.config.Config; import forestry.core.gui.IPagedInventory; -import forestry.core.utils.StringUtil; +import forestry.core.inventory.TileInventoryAdapter; -public abstract class TileNaturalistChest extends TileBase implements IInventory, IPagedInventory { +public abstract class TileNaturalistChest extends TileBase implements IPagedInventory { + + private static class NaturalistInventoryAdapter extends TileInventoryAdapter { + private final ISpeciesRoot speciesRoot; + public NaturalistInventoryAdapter(TileNaturalistChest tile, int size, String name, ISpeciesRoot speciesRoot) { + super(tile, size, name); + this.speciesRoot = speciesRoot; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemstack) { + return speciesRoot.isMember(itemstack); + } + } - private ItemStack[] inventoryStacks = new ItemStack[125]; - private final ISpeciesRoot speciesRoot; private final int guiID; public TileNaturalistChest(ISpeciesRoot speciesRoot, int guiId) { + setInternalInventory(new NaturalistInventoryAdapter(this, 125, "Items", speciesRoot)); setHints(Config.hints.get("apiarist.chest")); - this.speciesRoot = speciesRoot; this.guiID = guiId; } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, guiID, player.worldObj, xCoord, yCoord, zCoord); @@ -50,38 +53,6 @@ public abstract class TileNaturalistChest extends TileBase implements IInventory player.openGui(ForestryAPI.instance, GuiHandler.encodeGuiData(guiID, page), player.worldObj, xCoord, yCoord, zCoord); } - /* SAVING & LOADING */ - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < inventoryStacks.length; i++) { - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } - nbttagcompound.setTag("Items", nbttaglist); - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - - NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10); - inventoryStacks = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) { - - NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); - byte byte0 = nbttagcompound1.getByte("Slot"); - if (byte0 >= 0 && byte0 < inventoryStacks.length) - inventoryStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); - } - } - /* UPDATING */ @Override public void updateServerSide() { @@ -92,84 +63,4 @@ public abstract class TileNaturalistChest extends TileBase implements IInventory public boolean throwsErrors() { return false; } - - /* IINVENTORY */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return itemstack == null || speciesRoot.isMember(itemstack); - } - - @Override - public int getSizeInventory() { - return inventoryStacks.length; - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventoryStacks[i]; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - if (inventoryStacks[i] == null) - return null; - - ItemStack product; - if (inventoryStacks[i].stackSize <= j) { - product = inventoryStacks[i]; - inventoryStacks[i] = null; - return product; - } else { - product = inventoryStacks[i].splitStack(j); - if (inventoryStacks[i].stackSize == 0) - inventoryStacks[i] = null; - - return product; - } - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventoryStacks[i] = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) - itemstack.stackSize = getInventoryStackLimit(); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - if (inventoryStacks[slot] == null) - return null; - ItemStack toReturn = inventoryStacks[slot]; - inventoryStacks[slot] = null; - return toReturn; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } } diff --git a/src/main/java/forestry/core/gadgets/TilePowered.java b/src/main/java/forestry/core/gadgets/TilePowered.java index 41fea59e5..587725271 100644 --- a/src/main/java/forestry/core/gadgets/TilePowered.java +++ b/src/main/java/forestry/core/gadgets/TilePowered.java @@ -12,60 +12,19 @@ package forestry.core.gadgets; import buildcraft.api.tiles.IHasWork; import cpw.mods.fml.common.Optional; -import forestry.core.fluids.tanks.StandardTank; import forestry.core.interfaces.IPowerHandler; import forestry.core.interfaces.IRenderableMachine; -import forestry.core.network.ClassMap; -import forestry.core.network.IndexInPayload; -import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; import forestry.energy.EnergyManager; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; @Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles") public abstract class TilePowered extends TileBase implements IRenderableMachine, IPowerHandler, IHasWork { public static final int WORK_CYCLES = 4; - @Override - public PacketPayload getPacketPayload() { - if (!ClassMap.classMappers.containsKey(this.getClass())) - ClassMap.classMappers.put(this.getClass(), new ClassMap(this.getClass())); - - ClassMap classmap = ClassMap.classMappers.get(this.getClass()); - PacketPayload payload = new PacketPayload(classmap.intSize, classmap.floatSize, classmap.stringSize); - - try { - classmap.setData(this, payload.intPayload, payload.floatPayload, payload.stringPayload, new IndexInPayload(0, 0, 0)); - } catch (Exception ex) { - ex.printStackTrace(); - } - - return payload; - } - - @Override - public void fromPacketPayload(PacketPayload payload) { - - if (payload.isEmpty()) - return; - - if (!ClassMap.classMappers.containsKey(this.getClass())) - ClassMap.classMappers.put(this.getClass(), new ClassMap(this.getClass())); - - ClassMap classmap = ClassMap.classMappers.get(this.getClass()); - - try { - classmap.fromData(this, payload.intPayload, payload.floatPayload, payload.stringPayload, new IndexInPayload(0, 0, 0)); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - protected final EnergyManager energyManager; public TilePowered(int maxTransfer, int energyPerWork, int capacity) { @@ -118,32 +77,6 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine energyManager.readFromNBT(nbt); } - /* LIQUID CONTAINER HANDLING */ - /** - @deprecated Use FluidHelper - */ - @Deprecated - protected ItemStack bottleIntoContainer(ItemStack canStack, ItemStack outputStack, FluidContainerData container, StandardTank tank) { - if (tank.getFluidAmount() < container.fluid.amount) - return outputStack; - if (canStack.stackSize <= 0) - return outputStack; - if (outputStack != null && !outputStack.isItemEqual(container.filledContainer)) - return outputStack; - if (outputStack != null && outputStack.stackSize >= outputStack.getMaxStackSize()) - return outputStack; - - tank.drain(container.fluid.amount, true); - canStack.stackSize--; - - if (outputStack == null) - outputStack = container.filledContainer.copy(); - else - outputStack.stackSize++; - - return outputStack; - } - // / ADDITIONAL LIQUID HANDLING @Override public EnumTankLevel getPrimaryLevel() { diff --git a/src/main/java/forestry/core/genetics/Allele.java b/src/main/java/forestry/core/genetics/Allele.java index e5e3b8d9a..660a59dc2 100755 --- a/src/main/java/forestry/core/genetics/Allele.java +++ b/src/main/java/forestry/core/genetics/Allele.java @@ -10,16 +10,14 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IAllele; import forestry.api.genetics.ILegacyHandler; import forestry.core.config.Defaults; import forestry.core.utils.StringUtil; +import java.util.EnumSet; +import net.minecraftforge.common.EnumPlantType; public class Allele implements IAllele { @@ -118,13 +116,13 @@ public class Allele implements IAllele { // Agrarian branch public static AlleleSpecies speciesRural; - // 41 Farmerly - // 42 Agrarian + public static AlleleSpecies speciesFarmerly; + public static AlleleSpecies speciesArgrarian; // Boggy branch public static AlleleSpecies speciesMarshy; - // 44 speciesMiry - // 45 speciesBoggy + public static AlleleSpecies speciesMiry; + public static AlleleSpecies speciesBoggy; // Monastic branch public static AlleleSpecies speciesMonastic; @@ -170,6 +168,11 @@ public class Allele implements IAllele { public static AlleleSpecies treeMaple; + public static AlleleSpecies treeIpe; + public static AlleleSpecies treePadauk; + public static AlleleSpecies treeCocobolo; + public static AlleleSpecies treeZebrawood; + /// BUTTERFLIES // SPECIES // Moths public static AlleleSpecies mothBrimstone; @@ -391,6 +394,8 @@ public class Allele implements IAllele { public static Allele effectReanimation; public static Allele effectResurrection; public static Allele effectRepulsion; + public static Allele effectFertile; + public static Allele effectMycophilic; // / TREES // EFFECTS public static Allele leavesNone; @@ -707,4 +712,9 @@ public class Allele implements IAllele { name = string; return this; } + + @Override + public String toString() { + return uid; + } } diff --git a/src/main/java/forestry/core/genetics/AlleleArea.java b/src/main/java/forestry/core/genetics/AlleleArea.java index 88d7b57f5..dfec2771f 100755 --- a/src/main/java/forestry/core/genetics/AlleleArea.java +++ b/src/main/java/forestry/core/genetics/AlleleArea.java @@ -12,7 +12,7 @@ package forestry.core.genetics; import forestry.api.genetics.IAlleleArea; import forestry.core.utils.StringUtil; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; public class AlleleArea extends Allele implements IAlleleArea { diff --git a/src/main/java/forestry/core/genetics/AllelePlantType.java b/src/main/java/forestry/core/genetics/AllelePlantType.java index 756f9737c..25c1be1cf 100755 --- a/src/main/java/forestry/core/genetics/AllelePlantType.java +++ b/src/main/java/forestry/core/genetics/AllelePlantType.java @@ -10,11 +10,9 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IAllelePlantType; +import java.util.EnumSet; +import net.minecraftforge.common.EnumPlantType; public class AllelePlantType extends Allele implements IAllelePlantType { diff --git a/src/main/java/forestry/core/genetics/AlleleRegistry.java b/src/main/java/forestry/core/genetics/AlleleRegistry.java index 3b3f8588c..fa390ba02 100755 --- a/src/main/java/forestry/core/genetics/AlleleRegistry.java +++ b/src/main/java/forestry/core/genetics/AlleleRegistry.java @@ -10,18 +10,7 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; - -import net.minecraft.item.ItemStack; - import com.mojang.authlib.GameProfile; - import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleHandler; import forestry.api.genetics.IAlleleRegistry; @@ -35,6 +24,14 @@ import forestry.api.genetics.IMutation; import forestry.api.genetics.ISpeciesRoot; import forestry.core.config.ForestryItem; import forestry.core.genetics.ItemResearchNote.EnumNoteType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import net.minecraft.item.ItemStack; public class AlleleRegistry implements IAlleleRegistry, ILegacyHandler { diff --git a/src/main/java/forestry/core/genetics/AlleleSpecies.java b/src/main/java/forestry/core/genetics/AlleleSpecies.java index a387ecc31..b8d64869c 100755 --- a/src/main/java/forestry/core/genetics/AlleleSpecies.java +++ b/src/main/java/forestry/core/genetics/AlleleSpecies.java @@ -24,11 +24,10 @@ import forestry.api.genetics.IMutation; import forestry.core.config.ForestryItem; import forestry.core.utils.StackUtils; import forestry.core.utils.StringUtil; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import java.util.Collection; import java.util.Map; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public abstract class AlleleSpecies extends Allele implements IAlleleSpecies { @@ -74,7 +73,7 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpecies { return 0.7f; else if (ForestryItem.beeComb.isItemEqual(itemstack)) return 0.4f; - else if (AlleleManager.alleleRegistry.isIndividual(itemstack)) + else if (getRoot().isMember(itemstack)) return 1.0f; for (Map.Entry entry : getRoot().getResearchCatalysts().entrySet()) { diff --git a/src/main/java/forestry/core/genetics/AlleleTolerance.java b/src/main/java/forestry/core/genetics/AlleleTolerance.java index e046cc4d6..0a13075d9 100755 --- a/src/main/java/forestry/core/genetics/AlleleTolerance.java +++ b/src/main/java/forestry/core/genetics/AlleleTolerance.java @@ -12,7 +12,6 @@ package forestry.core.genetics; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IAlleleTolerance; -import forestry.core.utils.StringUtil; public class AlleleTolerance extends Allele implements IAlleleTolerance { diff --git a/src/main/java/forestry/core/genetics/BreedingTracker.java b/src/main/java/forestry/core/genetics/BreedingTracker.java index b3b1d8c1d..90b3f71a9 100755 --- a/src/main/java/forestry/core/genetics/BreedingTracker.java +++ b/src/main/java/forestry/core/genetics/BreedingTracker.java @@ -10,16 +10,7 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.ArrayList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.WorldSavedData; - -import net.minecraftforge.common.MinecraftForge; - import com.mojang.authlib.GameProfile; - import forestry.api.core.ForestryEvent; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; @@ -29,6 +20,11 @@ import forestry.api.genetics.IMutation; import forestry.core.network.PacketIds; import forestry.core.network.PacketNBT; import forestry.core.proxy.Proxies; +import java.util.ArrayList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.WorldSavedData; +import net.minecraftforge.common.MinecraftForge; public abstract class BreedingTracker extends WorldSavedData implements IBreedingTracker { diff --git a/src/main/java/forestry/core/genetics/Chromosome.java b/src/main/java/forestry/core/genetics/Chromosome.java index 36e9253ec..1ce9719c4 100755 --- a/src/main/java/forestry/core/genetics/Chromosome.java +++ b/src/main/java/forestry/core/genetics/Chromosome.java @@ -10,14 +10,16 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.Random; - -import net.minecraft.nbt.NBTTagCompound; +import com.google.common.base.Objects; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IChromosome; import forestry.api.genetics.ILegacyHandler; +import forestry.core.proxy.Proxies; + +import java.util.Random; +import net.minecraft.nbt.NBTTagCompound; public class Chromosome implements IChromosome { @@ -103,20 +105,59 @@ public class Chromosome implements IChromosome { return secondary; } - public void overrideInvalidAlleles(IAllele template, Class chromosomeClass) { - if (primary == null || !chromosomeClass.isInstance(primary)) + public boolean overrideInvalidAlleles(IAllele template, Class chromosomeClass) { + boolean foundInvalidAlleles = false; + + // use the other chromosome instead of the template if it's valid + if (primary != null && chromosomeClass.isInstance(primary)) { + template = primary; + } else if (secondary != null && chromosomeClass.isInstance(secondary)) { + template = secondary; + } + + if (primary == null) { + Proxies.log.warning("Missing primary allele: {0}. Setting to: {1}", this, template); primary = template; + foundInvalidAlleles = true; + } else if (!chromosomeClass.isInstance(primary)) { + Proxies.log.warning("Wrong primary allele: {0}. Setting to: {1}", this, template); + primary = template; + foundInvalidAlleles = true; + } - if (secondary == null || !chromosomeClass.isInstance(secondary)) + if (secondary == null) { + Proxies.log.warning("Missing secondary allele: {0}. Setting to: {1}", this, template); secondary = template; + foundInvalidAlleles = true; + } else if (!chromosomeClass.isInstance(secondary)) { + Proxies.log.warning("Wrong secondary allele: {0}. Setting to: {1}", this, template); + secondary = template; + foundInvalidAlleles = true; + } + + return foundInvalidAlleles; } public boolean hasInvalidAlleles(Class chromosomeClass) { - if (primary == null || !chromosomeClass.isInstance(primary)) + if (primary == null) { + Proxies.log.severe("Missing primary allele: {0}", this); return true; + } + + if (!chromosomeClass.isInstance(primary)) { + Proxies.log.severe("Wrong primary allele for: {0}. Should be: {1}", this, chromosomeClass.getSimpleName()); + return true; + } - if (secondary == null || !chromosomeClass.isInstance(secondary)) + if (secondary == null) { + Proxies.log.severe("Missing secondary allele: {0}", this); return true; + } + + if (!chromosomeClass.isInstance(secondary)) { + Proxies.log.severe("Wrong secondary allele for: {0}. Should be: {1}", this, chromosomeClass.getSimpleName()); + return true; + } return false; } @@ -148,4 +189,9 @@ public class Chromosome implements IChromosome { return new Chromosome(choice2, choice1); } + @Override + public String toString() { + return Objects.toStringHelper(this).add("Primary", primary).add("Secondary", secondary).toString(); + } + } diff --git a/src/main/java/forestry/core/genetics/Classification.java b/src/main/java/forestry/core/genetics/Classification.java index 1641cbe72..9120725f9 100755 --- a/src/main/java/forestry/core/genetics/Classification.java +++ b/src/main/java/forestry/core/genetics/Classification.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.ArrayList; -import java.util.Locale; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IClassification; import forestry.core.utils.StringUtil; +import java.util.ArrayList; +import java.util.Locale; public class Classification implements IClassification { diff --git a/src/main/java/forestry/core/genetics/ClimateHelper.java b/src/main/java/forestry/core/genetics/ClimateHelper.java index b0cc7384d..27e0f425c 100755 --- a/src/main/java/forestry/core/genetics/ClimateHelper.java +++ b/src/main/java/forestry/core/genetics/ClimateHelper.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.ArrayList; -import java.util.Locale; - import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IClimateHelper; import forestry.core.utils.StringUtil; +import java.util.ArrayList; +import java.util.Locale; public class ClimateHelper implements IClimateHelper { diff --git a/src/main/java/forestry/core/genetics/EffectData.java b/src/main/java/forestry/core/genetics/EffectData.java index 075199735..70d7feda2 100755 --- a/src/main/java/forestry/core/genetics/EffectData.java +++ b/src/main/java/forestry/core/genetics/EffectData.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core.genetics; -import net.minecraft.nbt.NBTTagCompound; - import forestry.api.genetics.IEffectData; +import net.minecraft.nbt.NBTTagCompound; public class EffectData implements IEffectData { diff --git a/src/main/java/forestry/core/genetics/Genome.java b/src/main/java/forestry/core/genetics/Genome.java index af3ca541e..275eb6ee6 100755 --- a/src/main/java/forestry/core/genetics/Genome.java +++ b/src/main/java/forestry/core/genetics/Genome.java @@ -10,17 +10,20 @@ ******************************************************************************/ package forestry.core.genetics; +import com.google.common.base.Objects; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IGenome; -import forestry.apiculture.items.ItemBeeGE; import forestry.core.config.Config; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import forestry.core.proxy.Proxies; public abstract class Genome implements IGenome { @@ -69,11 +72,11 @@ public abstract class Genome implements IGenome { return null; } - public static IAllele getPrimaryAllele(ItemStack itemStack, IChromosomeType chromosomeType) { + public static IAllele getActiveAllele(ItemStack itemStack, IChromosomeType chromosomeType) { Chromosome chromosome = getChromosome(itemStack, chromosomeType); if (chromosome == null) return null; - return chromosome.getPrimaryAllele(); + return chromosome.getActiveAllele(); } // / SAVING & LOADING @@ -82,6 +85,9 @@ public abstract class Genome implements IGenome { NBTTagList nbttaglist = nbttagcompound.getTagList("Chromosomes", 10); chromosomes = new Chromosome[chromosomes.length]; + + Boolean invalidGenome = false; + for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte byte0 = nbttagcompound1.getByte(SLOT_TAG); @@ -89,15 +95,22 @@ public abstract class Genome implements IGenome { if (byte0 >= 0 && byte0 < chromosomes.length) { Chromosome chromosome = Chromosome.loadChromosomeFromNBT(nbttagcompound1); chromosomes[byte0] = chromosome; - - if (Config.clearInvalidChromosomes) - chromosome.overrideInvalidAlleles(getDefaultTemplate()[byte0], getSpeciesRoot().getKaryotype()[byte0].getAlleleClass()); + + if (Config.clearInvalidChromosomes) { + if (chromosome.overrideInvalidAlleles(getDefaultTemplate()[byte0], getSpeciesRoot().getKaryotype()[byte0].getAlleleClass())) { + invalidGenome = true; + } + } if (chromosome.hasInvalidAlleles(getSpeciesRoot().getKaryotype()[byte0].getAlleleClass())) - throw new RuntimeException("Found Chromosome with invalid Alleles. See config option \"genetics.clear.invalid.chromosomes\"."); + throw new RuntimeException("Found Chromosome with invalid Alleles.\nNBTTagCompound: " + nbttaglist + "\nSee config option \"genetics.clear.invalid.chromosomes\"."); } } + if (invalidGenome) { + Proxies.log.warning("Overrode alleles for genome:\n{0}\nOriginal NBTTagCompound: {1}", this, nbttaglist); + } + // handle old saves that have missing chromosomes IChromosome speciesChromosome = chromosomes[EnumTreeChromosome.SPECIES.ordinal()]; if (speciesChromosome != null) { @@ -136,11 +149,21 @@ public abstract class Genome implements IGenome { return chromosomes[chromosome].getActiveAllele(); } + @Override + public IAllele getActiveAllele(IChromosomeType chromosomeType) { + return chromosomes[chromosomeType.ordinal()].getActiveAllele(); + } + @Override public IAllele getInactiveAllele(int chromosome) { return chromosomes[chromosome].getInactiveAllele(); } + @Override + public IAllele getInactiveAllele(IChromosomeType chromosomeType) { + return chromosomes[chromosomeType.ordinal()].getInactiveAllele(); + } + @Override public boolean isGeneticEqual(IGenome other) { IChromosome[] genetics = other.getChromosomes(); @@ -163,4 +186,14 @@ public abstract class Genome implements IGenome { return true; } + + @Override + public String toString() { + Objects.ToStringHelper toStringHelper = Objects.toStringHelper(this); + int i = 0; + for (IChromosome chromosome : chromosomes) { + toStringHelper.add(String.valueOf(i++), chromosome); + } + return toStringHelper.toString(); + } } diff --git a/src/main/java/forestry/core/genetics/Individual.java b/src/main/java/forestry/core/genetics/Individual.java index 9931f3473..70c86e9f7 100755 --- a/src/main/java/forestry/core/genetics/Individual.java +++ b/src/main/java/forestry/core/genetics/Individual.java @@ -10,9 +10,9 @@ ******************************************************************************/ package forestry.core.genetics; -import net.minecraft.nbt.NBTTagCompound; - +import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IIndividual; +import net.minecraft.nbt.NBTTagCompound; public abstract class Individual implements IIndividual { @@ -74,8 +74,13 @@ public abstract class Individual implements IIndividual { } @Override + @SuppressWarnings("deprecated") public boolean isPureBred(int chromosomeOrdinal) { return getGenome().getActiveAllele(chromosomeOrdinal).getUID().equals(getGenome().getInactiveAllele(chromosomeOrdinal).getUID()); } + @Override + public boolean isPureBred(IChromosomeType chromosomeType) { + return getGenome().getActiveAllele(chromosomeType).getUID().equals(getGenome().getInactiveAllele(chromosomeType).getUID()); + } } diff --git a/src/main/java/forestry/core/genetics/IndividualLiving.java b/src/main/java/forestry/core/genetics/IndividualLiving.java index b48058f9d..bd62257a8 100755 --- a/src/main/java/forestry/core/genetics/IndividualLiving.java +++ b/src/main/java/forestry/core/genetics/IndividualLiving.java @@ -10,27 +10,20 @@ ******************************************************************************/ package forestry.core.genetics; +import forestry.api.genetics.IGenome; +import forestry.api.genetics.IIndividualLiving; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.api.genetics.IGenome; -import forestry.api.genetics.IIndividualLiving; - public abstract class IndividualLiving extends Individual implements IIndividualLiving { - protected int generation; - protected boolean isNatural; - protected boolean isIrregularMating; - protected int health; protected int maxHealth; public IndividualLiving() {} - public IndividualLiving(int newHealth, boolean isNatural, int generation) { + public IndividualLiving(int newHealth) { health = maxHealth = newHealth; - this.isNatural = isNatural; - this.generation = generation; } /* SAVING & LOADING */ @@ -39,13 +32,6 @@ public abstract class IndividualLiving extends Individual implements IIndividual super.readFromNBT(nbttagcompound); - if (nbttagcompound.hasKey("NA")) - isNatural = nbttagcompound.getBoolean("NA"); - else - isNatural = true; - isIrregularMating = nbttagcompound.getBoolean("IM"); - generation = nbttagcompound.getInteger("GEN"); - health = nbttagcompound.getInteger("Health"); maxHealth = nbttagcompound.getInteger("MaxH"); @@ -56,10 +42,6 @@ public abstract class IndividualLiving extends Individual implements IIndividual super.writeToNBT(nbttagcompound); - nbttagcompound.setBoolean("NA", isNatural); - nbttagcompound.setBoolean("IM", isIrregularMating); - nbttagcompound.setInteger("GEN", generation); - nbttagcompound.setInteger("Health", health); nbttagcompound.setInteger("MaxH", maxHealth); @@ -78,22 +60,6 @@ public abstract class IndividualLiving extends Individual implements IIndividual /* GENERATION */ public abstract IGenome getMate(); - - public void setIsNatural(boolean flag) { - this.isNatural = flag; - } - - public boolean isIrregularMating() { - return this.isIrregularMating; - } - - public boolean isNatural() { - return this.isNatural; - } - - public int getGeneration() { - return generation; - } @Override public boolean isAlive() { diff --git a/src/main/java/forestry/core/genetics/ItemGE.java b/src/main/java/forestry/core/genetics/ItemGE.java index 0d3395dc0..a71dec25e 100755 --- a/src/main/java/forestry/core/genetics/ItemGE.java +++ b/src/main/java/forestry/core/genetics/ItemGE.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.List; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IIndividual; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; public abstract class ItemGE extends Item { @@ -37,7 +35,7 @@ public abstract class ItemGE extends Item { protected abstract int getDefaultSecondaryColour(); - protected abstract IIndividual getIndividual(ItemStack itemstack); + public abstract IIndividual getIndividual(ItemStack itemstack); protected abstract IAlleleSpecies getSpecies(ItemStack itemStack); @@ -74,7 +72,7 @@ public abstract class ItemGE extends Item { if(Proxies.common.isShiftDown()) individual.addTooltip(list); else - list.add("\u00A7o<" + StringUtil.localize("gui.tooltip.tmi") + ">"); + list.add(EnumChatFormatting.ITALIC + "<" + StringUtil.localize("gui.tooltip.tmi") + ">"); } else list.add("<" + StringUtil.localize("gui.unknown") + ">"); } diff --git a/src/main/java/forestry/core/genetics/ItemResearchNote.java b/src/main/java/forestry/core/genetics/ItemResearchNote.java index 0025a41ef..0eadd47b9 100755 --- a/src/main/java/forestry/core/genetics/ItemResearchNote.java +++ b/src/main/java/forestry/core/genetics/ItemResearchNote.java @@ -10,29 +10,9 @@ ******************************************************************************/ package forestry.core.genetics; -import java.util.ArrayList; -import java.util.IllegalFormatException; -import java.util.List; -import java.util.Locale; - -import forestry.core.utils.StringUtil; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.IIcon; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; - +import com.mojang.authlib.GameProfile; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import com.mojang.authlib.GameProfile; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; @@ -41,6 +21,21 @@ import forestry.api.genetics.IMutation; import forestry.api.genetics.ISpeciesRoot; import forestry.core.items.ItemForestry; import forestry.core.proxy.Proxies; +import forestry.core.utils.StringUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; public class ItemResearchNote extends ItemForestry { @@ -94,7 +89,7 @@ public class ItemResearchNote extends ItemForestry { if(encoded.getSpecialConditions() != null && encoded.getSpecialConditions().size() > 0) { for(String line : encoded.getSpecialConditions()) - tooltips.add("\u00A76" + line); + tooltips.add(EnumChatFormatting.GOLD + line); } } else if(this == SPECIES) { IAlleleSpecies allele0 = (IAlleleSpecies)AlleleManager.alleleRegistry.getAllele(compound.getString("AL0")); @@ -219,7 +214,7 @@ public class ItemResearchNote extends ItemForestry { public void addTooltip(List list) { ArrayList tooltips = type.getTooltip(inner); if(tooltips.size() <= 0) { - list.add("\u00A7o\u00A7c" + StringUtil.localize("researchNote.error.0")); + list.add(EnumChatFormatting.ITALIC + EnumChatFormatting.RED.toString() + StringUtil.localize("researchNote.error.0")); list.add(StringUtil.localize("researchNote.error.1")); return; } diff --git a/src/main/java/forestry/core/genetics/Mutation.java b/src/main/java/forestry/core/genetics/Mutation.java index 41cfc1ffa..031e8aabf 100755 --- a/src/main/java/forestry/core/genetics/Mutation.java +++ b/src/main/java/forestry/core/genetics/Mutation.java @@ -11,13 +11,12 @@ package forestry.core.genetics; -import java.util.ArrayList; -import java.util.Collection; - import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.IAllele; import forestry.api.genetics.IMutation; +import java.util.ArrayList; +import java.util.Collection; public abstract class Mutation implements IMutation { diff --git a/src/main/java/forestry/core/genetics/SpeciesRoot.java b/src/main/java/forestry/core/genetics/SpeciesRoot.java index 20556ffa1..1db63e276 100755 --- a/src/main/java/forestry/core/genetics/SpeciesRoot.java +++ b/src/main/java/forestry/core/genetics/SpeciesRoot.java @@ -10,6 +10,11 @@ ******************************************************************************/ package forestry.core.genetics; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IChromosome; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -17,14 +22,8 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Random; - import net.minecraft.item.ItemStack; -import forestry.api.genetics.IAllele; -import forestry.api.genetics.IChromosome; -import forestry.api.genetics.IMutation; -import forestry.api.genetics.ISpeciesRoot; - public abstract class SpeciesRoot implements ISpeciesRoot { /* RESEARCH */ @@ -74,6 +73,7 @@ public abstract class SpeciesRoot implements ISpeciesRoot { return combinations; } + @Deprecated @Override public Collection getPaths(IAllele result, int chromosomeOrdinal) { ArrayList paths = new ArrayList(); @@ -84,6 +84,16 @@ public abstract class SpeciesRoot implements ISpeciesRoot { return paths; } + @Override + public Collection getPaths(IAllele result, IChromosomeType chromosomeType) { + ArrayList paths = new ArrayList(); + for (IMutation mutation : getMutations(false)) + if(mutation.getTemplate()[chromosomeType.ordinal()] == result) + paths.add(mutation); + + return paths; + } + /* GENOME CONVERSIONS */ @Override public IChromosome[] templateAsChromosomes(IAllele[] template) { diff --git a/src/main/java/forestry/core/gui/ContainerAlyzer.java b/src/main/java/forestry/core/gui/ContainerAlyzer.java index 91f95b2a0..403423d62 100644 --- a/src/main/java/forestry/core/gui/ContainerAlyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAlyzer.java @@ -1,9 +1,8 @@ package forestry.core.gui; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.inventory.AlyzerInventory; import forestry.core.proxy.Proxies; -import forestry.core.utils.AlyzerInventory; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -12,25 +11,26 @@ public class ContainerAlyzer extends ContainerItemInventory { private final AlyzerInventory inventory; - protected ContainerAlyzer(InventoryPlayer inventoryplayer, AlyzerInventory inventory, Object[] acceptedEnergy, Object... acceptedSpecimens) { - super(inventory, inventoryplayer.player); + public ContainerAlyzer(AlyzerInventory inventory, EntityPlayer player) { + super(inventory, player); + InventoryPlayer inventoryplayer = player.inventory; this.inventory = inventory; final int xPosLeftSlots = 223; // Energy - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ENERGY, xPosLeftSlots, 8, acceptedEnergy)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ENERGY, xPosLeftSlots, 8)); // Bee to analyze - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_SPECIMEN, xPosLeftSlots, 26, acceptedSpecimens)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_SPECIMEN, xPosLeftSlots, 26)); // Analyzed bee - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_1, xPosLeftSlots, 57, acceptedSpecimens)); - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_2, xPosLeftSlots, 75, acceptedSpecimens)); - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_3, xPosLeftSlots, 93, acceptedSpecimens)); - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_4, xPosLeftSlots, 111, acceptedSpecimens)); - this.addSlot(new SlotCustom(inventory, AlyzerInventory.SLOT_ANALYZE_5, xPosLeftSlots, 129, acceptedSpecimens)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_1, xPosLeftSlots, 57)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_2, xPosLeftSlots, 75)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_3, xPosLeftSlots, 93)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_4, xPosLeftSlots, 111)); + this.addSlotToContainer(new SlotFiltered(inventory, AlyzerInventory.SLOT_ANALYZE_5, xPosLeftSlots, 129)); final int xPosPlayerInv = 43; final int xSpacePlayerInv = 18; @@ -75,9 +75,4 @@ public class ContainerAlyzer extends ContainerItemInventory { inventory.onGuiSaved(entityplayer); } - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return true; - } - } diff --git a/src/main/java/forestry/core/gui/ContainerAnalyzer.java b/src/main/java/forestry/core/gui/ContainerAnalyzer.java index b6cfbd5f2..f53f955dd 100755 --- a/src/main/java/forestry/core/gui/ContainerAnalyzer.java +++ b/src/main/java/forestry/core/gui/ContainerAnalyzer.java @@ -10,59 +10,41 @@ ******************************************************************************/ package forestry.core.gui; -import forestry.core.config.ForestryItem; -import forestry.core.fluids.Fluids; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import forestry.core.gadgets.TileAnalyzer; -import forestry.core.genetics.ItemGE; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -import net.minecraft.item.ItemStack; public class ContainerAnalyzer extends ContainerLiquidTanks { - private final TileAnalyzer tile; - public ContainerAnalyzer(InventoryPlayer player, TileAnalyzer tile) { - super(tile, tile); - - this.tile = tile; + super(tile); // Input buffer for (int i = 0; i < 3; i++) for (int k = 0; k < 2; k++) - addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18, ItemGE.class)); + addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_INPUT_1 + i * 2 + k, 8 + k * 18, 28 + i * 18)); // Analyze slot - addSlot(new SlotCustom(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59)); + addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_ANALYZE, 73, 59)); // Can slot - addSlot(new SlotLiquidContainer(tile, TileAnalyzer.SLOT_CAN, 143, 24, false, Fluids.HONEY.get()) { - - @Override - public boolean isItemValid(ItemStack stack) { - if (ForestryItem.honeyDrop.isItemEqual(stack)) - return true; - return super.isItemValid(stack); - } - - }); + addSlotToContainer(new SlotFiltered(tile, TileAnalyzer.SLOT_CAN, 143, 24)); // Output buffer for (int i = 0; i < 2; i++) for (int k = 0; k < 2; k++) - addSlot(new SlotOutput(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18)); + addSlotToContainer(new SlotOutput(tile, TileAnalyzer.SLOT_OUTPUT_1 + i * 2 + k, 134 + k * 18, 48 + i * 18)); // Player inventory for (int i1 = 0; i1 < 3; i1++) for (int l1 = 0; l1 < 9; l1++) - addSlot(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 94 + i1 * 18)); + addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 94 + i1 * 18)); // Player hotbar for (int j1 = 0; j1 < 9; j1++) - addSlot(new Slot(player, j1, 8 + j1 * 18, 152)); + addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 152)); } diff --git a/src/main/java/forestry/core/gui/ContainerEscritoire.java b/src/main/java/forestry/core/gui/ContainerEscritoire.java index cb279ddc9..a1e7d9db4 100755 --- a/src/main/java/forestry/core/gui/ContainerEscritoire.java +++ b/src/main/java/forestry/core/gui/ContainerEscritoire.java @@ -10,17 +10,12 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.ArrayList; -import java.util.Collection; - import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.inventory.Slot; -import forestry.api.genetics.AlleleManager; import forestry.core.gadgets.TileEscritoire; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; @@ -39,28 +34,26 @@ public class ContainerEscritoire extends ContainerForestry implements IGuiSelect this.player = player; this.tile = t; - Collection filters = new ArrayList(); - filters.add(Blocks.sapling); - filters.addAll(AlleleManager.alleleRegistry.getSpeciesRoot().values()); // Analyze slot - addSlot(new SlotCustom(tile, TileEscritoire.SLOT_ANALYZE, 97, 67, filters.toArray()).setCrafter(tile)); + addSlotToContainer(new SlotFiltered(tile, TileEscritoire.SLOT_ANALYZE, 97, 67).setCrafter(tile)); for (int i = 0; i < TileEscritoire.SLOTS_INPUT_COUNT; i++) { - addSlot(new SlotCustom(tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setExclusion(true).setBlockedTexture("slots/blocked_2")); + addSlotToContainer(new SlotFiltered(tile, TileEscritoire.SLOT_INPUT_1 + i, 17, 49 + i * 18).setBlockedTexture("slots/blocked_2")); } - for(int i = 0; i < 3; i++) - for(int j = 0; j < 2; j++) { - addSlot(new SlotClosed(tile, TileEscritoire.SLOT_RESULTS_1 + (i*2) + j, 177 + j*18, 85 + i*18)); + for(int i = 0; i < 3; i++) { + for (int j = 0; j < 2; j++) { + addSlotToContainer(new SlotOutput(tile, TileEscritoire.SLOT_RESULTS_1 + (i * 2) + j, 177 + j * 18, 85 + i * 18)); } + } // Player inventory for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new Slot(player.inventory, j + i * 9 + 9, 34 + j * 18, 153 + i * 18)); + addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 34 + j * 18, 153 + i * 18)); // Player hotbar for (int k = 0; k < 9; k++) - addSlot(new Slot(player.inventory, k, 34 + k * 18, 211)); + addSlotToContainer(new Slot(player.inventory, k, 34 + k * 18, 211)); } @Override diff --git a/src/main/java/forestry/core/gui/ContainerForestry.java b/src/main/java/forestry/core/gui/ContainerForestry.java index 8ce2131b9..7f63c8eb3 100755 --- a/src/main/java/forestry/core/gui/ContainerForestry.java +++ b/src/main/java/forestry/core/gui/ContainerForestry.java @@ -10,11 +10,6 @@ ******************************************************************************/ package forestry.core.gui; -import forestry.core.gadgets.TileForestry; -import forestry.core.gui.slots.SlotForestry; -import forestry.core.utils.EnumAccess; -import forestry.core.utils.PlayerUtil; -import forestry.core.utils.StackUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -22,26 +17,25 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import forestry.core.gadgets.TileForestry; +import forestry.core.gui.slots.SlotForestry; +import forestry.core.interfaces.IRestrictedAccess; +import forestry.core.inventory.ItemInventory; +import forestry.core.utils.StackUtils; + public class ContainerForestry extends Container { - protected final IInventory inventory; - protected final TileForestry inventoryForestry; + protected final IInventory inventoryAccess; + protected final IRestrictedAccess restrictedAccess; - public ContainerForestry(IInventory inventory) { - this.inventory = inventory; - if (inventory instanceof TileForestry) - this.inventoryForestry = (TileForestry)inventory; - else - this.inventoryForestry = null; + public ContainerForestry(TileForestry tileForestry) { + this.inventoryAccess = tileForestry; + this.restrictedAccess = tileForestry; } - /** - * Adds a slot to the container, shortcut for addSlotToContainer(slot). - * - * @param slot - */ - protected Slot addSlot(Slot slot) { - return addSlotToContainer(slot); + public ContainerForestry(ItemInventory itemInventory) { + this.inventoryAccess = itemInventory; + this.restrictedAccess = null; } @Override @@ -49,16 +43,13 @@ public class ContainerForestry extends Container { if (player == null) return null; - if ((inventoryForestry != null) && (inventoryForestry.getAccess() != EnumAccess.SHARED)) - if ((inventoryForestry.owner != null) && !PlayerUtil.isSameGameProfile(inventoryForestry.owner, player.getGameProfile())) - return null; + if (restrictedAccess != null && !restrictedAccess.allowsAlteration(player)) + return null; Slot slot = slotIndex < 0 ? null : (Slot) this.inventorySlots.get(slotIndex); - if (slot instanceof SlotForestry) { - if (((SlotForestry) slot).isPhantom()) { + if (slot instanceof SlotForestry) + if (((SlotForestry) slot).isPhantom()) return slotClickPhantom(slot, button, modifier, player); - } - } return super.slotClick(slotIndex, button, modifier, player); } @@ -69,9 +60,9 @@ public class ContainerForestry extends Container { if (stackSlot != null) stack = stackSlot.copy(); - if (mouseButton == 2) { + if (mouseButton == 2) fillPhantomSlot(slot, null, mouseButton, modifier); - } else if (mouseButton == 0 || mouseButton == 1) { + else if (mouseButton == 0 || mouseButton == 1) { InventoryPlayer playerInv = player.inventory; ItemStack stackHeld = playerInv.getItemStack(); @@ -79,9 +70,9 @@ public class ContainerForestry extends Container { if (stackSlot == null) { if (stackHeld != null && slot.isItemValid(stackHeld)) fillPhantomSlot(slot, stackHeld, mouseButton, modifier); - } else if (stackHeld == null) { - fillPhantomSlot(slot, null, mouseButton, modifier); - } else if (slot.isItemValid(stackHeld)) + } else if (stackHeld == null) + adjustPhantomSlot(slot, mouseButton, modifier); + else if (slot.isItemValid(stackHeld)) if (StackUtils.isIdenticalItem(stackSlot, stackHeld)) adjustPhantomSlot(slot, mouseButton, modifier); else @@ -111,7 +102,9 @@ public class ContainerForestry extends Container { stackSlot.stackSize = stackSize; if (stackSlot.stackSize <= 0) - slot.putStack(null); + stackSlot = null; + + slot.putStack(stackSlot); } protected void fillPhantomSlot(Slot slot, ItemStack stackHeld, int mouseButton, int modifier) { @@ -191,6 +184,12 @@ public class ContainerForestry extends Container { @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { + if (player == null) + return null; + + if (restrictedAccess != null && !restrictedAccess.allowsAlteration(player)) + return null; + ItemStack originalStack = null; Slot slot = (Slot) inventorySlots.get(slotIndex); int numSlots = inventorySlots.size(); @@ -220,7 +219,9 @@ public class ContainerForestry extends Container { } @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return inventory.isUseableByPlayer(entityplayer); + public final boolean canInteractWith(EntityPlayer entityplayer) { + if (inventoryAccess == null) + return true; + return inventoryAccess.isUseableByPlayer(entityplayer); } } diff --git a/src/main/java/forestry/core/gui/ContainerItemInventory.java b/src/main/java/forestry/core/gui/ContainerItemInventory.java index eb7a26704..cc2734931 100755 --- a/src/main/java/forestry/core/gui/ContainerItemInventory.java +++ b/src/main/java/forestry/core/gui/ContainerItemInventory.java @@ -12,12 +12,13 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gui.slots.SlotItemInventory; import forestry.core.gui.slots.SlotLocked; +import forestry.core.inventory.ItemInventory; import forestry.core.proxy.Proxies; -import forestry.core.utils.ItemInventory; +import forestry.core.utils.StackUtils; public abstract class ContainerItemInventory extends ContainerForestry { @@ -30,31 +31,12 @@ public abstract class ContainerItemInventory extends ContainerForestry { this.player = player; } - public ItemInventory getItemInventory() { - return inventory; - } - protected void addSecuredSlot(IInventory other, int slot, int x, int y) { - if (other.getStackInSlot(slot) != null && inventory.itemClass.isAssignableFrom(other.getStackInSlot(slot).getItem().getClass())) - addSlot(new SlotLocked(other, slot, x, y)); + ItemStack stackInSlot = other.getStackInSlot(slot); + if (StackUtils.isIdenticalItem(inventory.parent, stackInSlot)) + addSlotToContainer(new SlotLocked(other, slot, x, y)); else - addSlot(new SlotItemInventory(this, other, player, slot, x, y)); - } - - protected abstract boolean isAcceptedItem(EntityPlayer player, ItemStack stack); - - public void purgeBag(EntityPlayer player) { - for (int i = 0; i < inventory.getSizeInventory(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - if (isAcceptedItem(player, stack)) - continue; - - Proxies.common.dropItemPlayer(player, stack); - inventory.setInventorySlotContents(i, null); - } + addSlotToContainer(new Slot(other, slot, x, y)); } public void saveInventory(EntityPlayer entityplayer) { @@ -68,7 +50,6 @@ public abstract class ContainerItemInventory extends ContainerForestry { if (!Proxies.common.isSimulating(player.worldObj)) return; - purgeBag(player); saveInventory(player); } } diff --git a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java index 1def8b1f0..a92e744af 100755 --- a/src/main/java/forestry/core/gui/ContainerLiquidTanks.java +++ b/src/main/java/forestry/core/gui/ContainerLiquidTanks.java @@ -11,15 +11,19 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + import forestry.api.core.IToolPipette; import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.TileForestry; import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; @@ -30,12 +34,23 @@ public class ContainerLiquidTanks extends ContainerForestry { private final ILiquidTankContainer tile; - public ContainerLiquidTanks(IInventory inventory, ILiquidTankContainer tile) { - super(inventory); + public ContainerLiquidTanks(T tile) { + super(tile); this.tile = tile; } - public void handlePipetteClick(int slot, EntityPlayer player) { + @SideOnly(Side.CLIENT) + public void handlePipetteClickClient(int slot, EntityPlayer player) { + ItemStack itemstack = player.inventory.getItemStack(); + if (itemstack == null || !(itemstack.getItem() instanceof IToolPipette)) + return; + + PacketPayload payload = new PacketPayload(1, 0, 0); + payload.intPayload[0] = slot; + Proxies.net.sendToServer(new PacketUpdate(PacketIds.PIPETTE_CLICK, payload)); + } + + public void handlePipetteClick(int slot, EntityPlayerMP player) { ItemStack itemstack = player.inventory.getItemStack(); if (itemstack == null) @@ -45,13 +60,6 @@ public class ContainerLiquidTanks extends ContainerForestry { if (!(held instanceof IToolPipette)) return; - if (!Proxies.common.isSimulating(player.worldObj)) { - PacketPayload payload = new PacketPayload(1, 0, 0); - payload.intPayload[0] = slot; - Proxies.net.sendToServer(new PacketUpdate(PacketIds.PIPETTE_CLICK, payload)); - return; - } - IToolPipette pipette = (IToolPipette) held; StandardTank tank = tile.getTankManager().get(slot); int liquidAmount = tank.getFluidAmount(); @@ -61,11 +69,14 @@ public class ContainerLiquidTanks extends ContainerForestry { FluidStack fillAmount = tank.drain(1000, false); int filled = pipette.fill(itemstack, fillAmount, true); tank.drain(filled, true); + player.updateHeldItem(); } } else { FluidStack potential = pipette.drain(itemstack, pipette.getCapacity(itemstack), false); - if (potential != null) + if (potential != null) { pipette.drain(itemstack, tank.fill(potential, true), true); + player.updateHeldItem(); + } } } diff --git a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java index 156ba3b65..0bbf2f84d 100755 --- a/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/ContainerNaturalistInventory.java @@ -13,53 +13,35 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import forestry.api.genetics.ISpeciesRoot; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gadgets.TileNaturalistChest; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketUpdate; -import forestry.core.proxy.Proxies; public class ContainerNaturalistInventory extends ContainerForestry implements IGuiSelectable { private final IPagedInventory inv; - private ISpeciesRoot speciesRoot; - public ContainerNaturalistInventory(ISpeciesRoot speciesRoot, InventoryPlayer player, IPagedInventory inventory, int page, int pageSize) { - super(inventory); - this.inv = inventory; - this.speciesRoot = speciesRoot; + public ContainerNaturalistInventory(InventoryPlayer player, TileNaturalistChest tile, int page, int pageSize) { + super(tile); + this.inv = tile; // Inventory for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { - addSlot(new SlotCustom(inventory, y + page * pageSize + x * 5, 100 + y * 18, 21 + x * 18, speciesRoot)); + addSlotToContainer(new SlotFiltered(tile, y + page * pageSize + x * 5, 100 + y * 18, 21 + x * 18)); } } // Player inventory for (int i1 = 0; i1 < 3; i1++) { for (int l1 = 0; l1 < 9; l1++) { - addSlot(new Slot(player, l1 + i1 * 9 + 9, 18 + l1 * 18, 120 + i1 * 18)); + addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 18 + l1 * 18, 120 + i1 * 18)); } } // Player hotbar for (int j1 = 0; j1 < 9; j1++) { - addSlot(new Slot(player, j1, 18 + j1 * 18, 178)); - } - } - - public void purgeBag(EntityPlayer player) { - for (int i = 0; i < inventory.getSizeInventory(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - if (speciesRoot.isMember(stack)) - continue; - - Proxies.common.dropItemPlayer(player, stack); - inventory.setInventorySlotContents(i, null); + addSlotToContainer(new Slot(player, j1, 18 + j1 * 18, 178)); } } diff --git a/src/main/java/forestry/core/gui/ContainerSocketed.java b/src/main/java/forestry/core/gui/ContainerSocketed.java index 9489911a7..15735eb16 100755 --- a/src/main/java/forestry/core/gui/ContainerSocketed.java +++ b/src/main/java/forestry/core/gui/ContainerSocketed.java @@ -11,10 +11,10 @@ package forestry.core.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import forestry.core.gadgets.TileForestry; import forestry.core.interfaces.ISocketable; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; @@ -25,9 +25,9 @@ import forestry.core.utils.StackUtils; public class ContainerSocketed extends ContainerForestry { - ISocketable tile; + private final ISocketable tile; - public ContainerSocketed(IInventory inventory, ISocketable tile) { + public ContainerSocketed(TileForestry inventory, ISocketable tile) { super(inventory); this.tile = tile; } diff --git a/src/main/java/forestry/core/gui/ErrorLedger.java b/src/main/java/forestry/core/gui/ErrorLedger.java index 7c1ffc88e..035a233e1 100755 --- a/src/main/java/forestry/core/gui/ErrorLedger.java +++ b/src/main/java/forestry/core/gui/ErrorLedger.java @@ -10,7 +10,8 @@ ******************************************************************************/ package forestry.core.gui; -import forestry.api.core.EnumErrorCode; +import forestry.api.core.IErrorState; +import forestry.core.EnumErrorCode; import forestry.core.interfaces.IErrorSource; import forestry.core.utils.StringUtil; @@ -19,7 +20,7 @@ import forestry.core.utils.StringUtil; */ public class ErrorLedger extends Ledger { - IErrorSource tile; + private final IErrorSource tile; public ErrorLedger(LedgerManager manager, IErrorSource tile) { super(manager); @@ -30,7 +31,7 @@ public class ErrorLedger extends Ledger { @Override public void draw(int x, int y) { - EnumErrorCode state = tile.getErrorState(); + IErrorState state = tile.getErrorState(); if (state == EnumErrorCode.OK) return; @@ -52,11 +53,8 @@ public class ErrorLedger extends Ledger { @Override public boolean isVisible() { - EnumErrorCode state = tile.getErrorState(); - if (state == EnumErrorCode.OK) - return false; - else - return true; + IErrorState state = tile.getErrorState(); + return state != EnumErrorCode.OK; } @Override diff --git a/src/main/java/forestry/core/gui/GuiAlyzer.java b/src/main/java/forestry/core/gui/GuiAlyzer.java index ee3b0b258..a3e250c55 100755 --- a/src/main/java/forestry/core/gui/GuiAlyzer.java +++ b/src/main/java/forestry/core/gui/GuiAlyzer.java @@ -10,6 +10,19 @@ ******************************************************************************/ package forestry.core.gui; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Stack; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import org.apache.commons.lang3.StringUtils; +import org.lwjgl.opengl.GL11; + import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; @@ -17,6 +30,7 @@ import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IAlleleTolerance; import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IClassification; import forestry.api.genetics.IClassification.EnumClassLevel; import forestry.api.genetics.IIndividual; @@ -27,17 +41,6 @@ import forestry.core.gadgets.TileForestry; import forestry.core.genetics.EnumMutateChance; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.opengl.GL11; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Stack; public abstract class GuiAlyzer extends GuiForestry { @@ -45,23 +48,25 @@ public abstract class GuiAlyzer extends GuiForestry { protected static final int COLUMN_1 = 85; protected static final int COLUMN_2 = 150; - protected IInventory inventory; - protected ISpeciesRoot speciesRoot; - protected IBreedingTracker breedingTracker; + protected final IInventory inventory; + protected final ISpeciesRoot speciesRoot; + protected final IBreedingTracker breedingTracker; - protected String guiName; + protected final String guiName; protected HashMap iconStacks = new HashMap(); - public GuiAlyzer(ISpeciesRoot speciesRoot, EntityPlayer player, ContainerForestry container, IInventory inventory, int pageMax, int pageSize) { + public GuiAlyzer(String speciesRoot, EntityPlayer player, ContainerForestry container, IInventory inventory, String guiName) { super(Defaults.TEXTURE_PATH_GUI + "/beealyzer2.png", container); - xSize = 246; - ySize = 238; + this.xSize = 246; + this.ySize = 238; + + this.guiName = guiName; this.inventory = inventory; - this.speciesRoot = speciesRoot; - this.breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile()); + this.speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(speciesRoot); + this.breedingTracker = this.speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile()); } protected final int getColorCoding(boolean dominant) { @@ -71,26 +76,34 @@ public abstract class GuiAlyzer extends GuiForestry { return fontColor.get("gui.beealyzer.recessive"); } - protected final void drawLine(String text, int x, IIndividual individual, Enum chromosome, boolean inactive) { + protected final void drawLine(String text, int x, IIndividual individual, IChromosomeType chromosome, boolean inactive) { if (!inactive) - drawLine(text, x, getColorCoding(individual.getGenome().getActiveAllele(chromosome.ordinal()).isDominant())); + drawLine(text, x, getColorCoding(individual.getGenome().getActiveAllele(chromosome).isDominant())); else - drawLine(text, x, getColorCoding(individual.getGenome().getInactiveAllele(chromosome.ordinal()).isDominant())); + drawLine(text, x, getColorCoding(individual.getGenome().getInactiveAllele(chromosome).isDominant())); } - protected final void drawSplitLine(String text, int x, int maxWidth, IIndividual individual, Enum chromosome, boolean inactive) { + protected final void drawSplitLine(String text, int x, int maxWidth, IIndividual individual, IChromosomeType chromosome, boolean inactive) { if (!inactive) - drawSplitLine(text, x, maxWidth, getColorCoding(individual.getGenome().getActiveAllele(chromosome.ordinal()).isDominant())); + drawSplitLine(text, x, maxWidth, getColorCoding(individual.getGenome().getActiveAllele(chromosome).isDominant())); else - drawSplitLine(text, x, maxWidth, getColorCoding(individual.getGenome().getInactiveAllele(chromosome.ordinal()).isDominant())); + drawSplitLine(text, x, maxWidth, getColorCoding(individual.getGenome().getInactiveAllele(chromosome).isDominant())); } - protected final void drawRow(String text0, String text1, String text2, IIndividual individual, Enum chromosome) { - drawRow(text0, text1, text2, fontColor.get("gui.screen"), getColorCoding(individual.getGenome().getActiveAllele(chromosome.ordinal()).isDominant()), - getColorCoding(individual.getGenome().getInactiveAllele(chromosome.ordinal()).isDominant())); + protected final void drawRow(String text0, String text1, String text2, IIndividual individual, IChromosomeType chromosome) { + drawRow(text0, text1, text2, fontColor.get("gui.screen"), getColorCoding(individual.getGenome().getActiveAllele(chromosome).isDominant()), + getColorCoding(individual.getGenome().getInactiveAllele(chromosome).isDominant())); } - protected final void drawSpeciesRow(String text0, IIndividual individual, Enum chromosome, String customPrimaryName, String customSecondaryName) { + protected final void drawChromosomeRow(String chromosomeName, IIndividual individual, IChromosomeType chromosome) { + IAllele active = individual.getGenome().getActiveAllele(chromosome); + IAllele inactive = individual.getGenome().getInactiveAllele(chromosome); + drawRow(chromosomeName, active.getName(), inactive.getName(), + fontColor.get("gui.screen"), getColorCoding(active.isDominant()), + getColorCoding(inactive.isDominant())); + } + + protected final void drawSpeciesRow(String text0, IIndividual individual, IChromosomeType chromosome, String customPrimaryName, String customSecondaryName) { IAlleleSpecies primary = individual.getGenome().getPrimary(); IAlleleSpecies secondary = individual.getGenome().getSecondary(); @@ -116,7 +129,7 @@ public abstract class GuiAlyzer extends GuiForestry { } - protected final void drawSpeciesRow(String text0, IIndividual individual, Enum chromosome){ + protected final void drawSpeciesRow(String text0, IIndividual individual, IChromosomeType chromosome){ drawSpeciesRow(text0, individual, chromosome, null, null); } diff --git a/src/main/java/forestry/core/gui/GuiAnalyzer.java b/src/main/java/forestry/core/gui/GuiAnalyzer.java index f03f2b9d4..6211b4639 100755 --- a/src/main/java/forestry/core/gui/GuiAnalyzer.java +++ b/src/main/java/forestry/core/gui/GuiAnalyzer.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.core.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gadgets.TileAnalyzer; import forestry.core.gui.widgets.TankWidget; import forestry.core.utils.EnumTankLevel; import forestry.core.utils.Utils; +import net.minecraft.entity.player.InventoryPlayer; public class GuiAnalyzer extends GuiForestryTitled { diff --git a/src/main/java/forestry/core/gui/GuiEscritoire.java b/src/main/java/forestry/core/gui/GuiEscritoire.java index 515e56643..a029591a0 100755 --- a/src/main/java/forestry/core/gui/GuiEscritoire.java +++ b/src/main/java/forestry/core/gui/GuiEscritoire.java @@ -10,10 +10,16 @@ ******************************************************************************/ package forestry.core.gui; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; + +import java.util.List; + import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; @@ -29,14 +35,20 @@ import forestry.core.utils.StringUtil; public class GuiEscritoire extends GuiForestry { - private static String[][] researchNotes = new String[][] { - new String[] { "I have found a curious specimen on my travels.", "This strange fellow needs further investigation.", "Elated, I wanted to start at once with my research." }, - new String[] { "I was amazed at the wondrous nature of it.", "The specimen twitched, while I inspected it more closely.", "Strange markings on the underside made me curious.", "This will be the talk of the society when I am done investigating." }, - new String[] { "After some prodding I discovered an interesting new lead.", "I scratched my head at this discovery and questioned everything.", "I thought my eyes deceived me, but there it was.", "A previously unseen dot led me to question the specimen's classification." }, - new String[] { "My screams of frustration had the housekeeper look into my study in worry.", "In a frenzy and on the verge of despair, I ripped up all the notes!", "This... just doesn't make any sense!", "It just cannot be. It didn't do that before!", "The sledgehammer barely made a dent, so I sent for the chainsaw.", "I swear it was looking at me, with its beady, cruel, little eyes.", "Is that laughter? Do I hear laughter? Who is laughing here?" }, - new String[] { "EUREKA!", "Wondrous! My name will go down in history!", "My colleagues will be impressed!", "I will be the envy of everyone at the society!", "Woot!" }, - new String[] { "All is lost.", "I consign my notes to the fire.", "Why? I had made such great strides at first...", "Failed. Again.", "Oh my..." } - }; + private static enum Notes { + level1, level2, level3, level4, success, failure + } + private static final ListMultimap researchNotes; + static { + researchNotes = ArrayListMultimap.create(); + for (Notes notesLevel : Notes.values()) { + int levelCount = Integer.valueOf(StringUtil.localize("gui.escritoire.notes." + notesLevel + ".count")); + for (int i = 1; i <= levelCount; i++) { + String note = StringUtil.localize("gui.escritoire.notes." + notesLevel + "." + i); + researchNotes.put(notesLevel, note); + } + } + } private class TokenSlot extends Widget { @@ -216,7 +228,8 @@ public class GuiEscritoire extends GuiForestry { newLine(); newLine(); - drawLine("\u00A7n\u00A7oAttempt No. " + (NaturalistGame.BOUNTY_MAX - tile.getGame().getBountyLevel()), 171, fontColor.get("gui.mail.lettertext")); + String format = EnumChatFormatting.UNDERLINE + EnumChatFormatting.ITALIC.toString(); + drawLine(format + "Attempt No. " + (NaturalistGame.BOUNTY_MAX - tile.getGame().getBountyLevel()), 171, fontColor.get("gui.mail.lettertext")); newLine(); drawSplitLine(getResearchNote(), 171, 46, fontColor.get("gui.mail.lettertext")); @@ -228,22 +241,22 @@ public class GuiEscritoire extends GuiForestry { return researchNote; if (!tile.getGame().isInited()) - researchNote = ""; + researchNote = StringUtil.localize("gui.escritoire.instructions"); else { if (tile.getGame().isWon()) { - researchNote = getRandomNote(researchNotes[4]); + researchNote = getRandomNote(researchNotes.get(Notes.success)); } else if (tile.getGame().isEnded()) { - researchNote = getRandomNote(researchNotes[5]); + researchNote = getRandomNote(researchNotes.get(Notes.failure)); } else { int bounty = tile.getGame().getBountyLevel(); if (bounty >= NaturalistGame.BOUNTY_MAX) { - researchNote = getRandomNote(researchNotes[0]); + researchNote = getRandomNote(researchNotes.get(Notes.level1)); } else if (bounty > NaturalistGame.BOUNTY_MAX / 2) { - researchNote = getRandomNote(researchNotes[1]); + researchNote = getRandomNote(researchNotes.get(Notes.level2)); } else if (bounty > NaturalistGame.BOUNTY_MAX / 4) { - researchNote = getRandomNote(researchNotes[2]); + researchNote = getRandomNote(researchNotes.get(Notes.level3)); } else - researchNote = getRandomNote(researchNotes[3]); + researchNote = getRandomNote(researchNotes.get(Notes.level4)); } } @@ -251,7 +264,8 @@ public class GuiEscritoire extends GuiForestry { return researchNote; } - private String getRandomNote(String[] candidates) { - return candidates[mc.theWorld.rand.nextInt(candidates.length)]; + private String getRandomNote(List candidates) { + int index = mc.theWorld.rand.nextInt(candidates.size()); + return candidates.get(index); } } diff --git a/src/main/java/forestry/core/gui/GuiForestry.java b/src/main/java/forestry/core/gui/GuiForestry.java index dd55ed8ac..b46e84d4b 100755 --- a/src/main/java/forestry/core/gui/GuiForestry.java +++ b/src/main/java/forestry/core/gui/GuiForestry.java @@ -10,13 +10,31 @@ ******************************************************************************/ package forestry.core.gui; -import codechicken.nei.VisiblityData; -import codechicken.nei.api.INEIGuiHandler; -import codechicken.nei.api.TaggedInventoryArea; +import java.awt.Color; +import java.util.Collection; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; + import cpw.mods.fml.common.Optional; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + import forestry.core.config.Config; import forestry.core.gadgets.TileForestry; -import forestry.core.gui.slots.SlotForestry; import forestry.core.gui.tooltips.IToolTipProvider; import forestry.core.gui.tooltips.ToolTip; import forestry.core.gui.tooltips.ToolTipLine; @@ -28,22 +46,10 @@ import forestry.core.interfaces.IOwnable; import forestry.core.interfaces.IPowerHandler; import forestry.core.proxy.Proxies; import forestry.core.utils.FontColour; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import java.awt.Color; -import java.util.Collection; -import java.util.List; +import codechicken.nei.VisiblityData; +import codechicken.nei.api.INEIGuiHandler; +import codechicken.nei.api.TaggedInventoryArea; @Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems") public abstract class GuiForestry extends GuiContainer implements INEIGuiHandler { @@ -56,20 +62,20 @@ public abstract class GuiForestry extends GuiContainer i protected final FontColour fontColor; public final ResourceLocation textureFile; - public GuiForestry(String texture, ContainerForestry container) { + public GuiForestry(String texture, Container container) { this(new ResourceLocation("forestry", texture), container, null); } - public GuiForestry(String texture, ContainerForestry container, Object inventory) { + public GuiForestry(String texture, Container container, Object inventory) { this(new ResourceLocation("forestry", texture), container, inventory); } - public GuiForestry(ResourceLocation texture, ContainerForestry container) { + public GuiForestry(ResourceLocation texture, Container container) { this(texture, container, null); } @SuppressWarnings("unchecked") - public GuiForestry(ResourceLocation texture, ContainerForestry container, Object inventory) { + public GuiForestry(ResourceLocation texture, Container container, Object inventory) { super(container); this.widgetManager = new WidgetManager(this); this.ledgerManager = new LedgerManager(this); @@ -247,7 +253,7 @@ public abstract class GuiForestry extends GuiContainer i int y; for (ToolTipLine tip : toolTips) { - y = this.fontRendererObj.getStringWidth(tip.getText()); + y = this.fontRendererObj.getStringWidth(tip.toString()); height += 10 + tip.getSpacing(); if (y > length) @@ -276,17 +282,19 @@ public abstract class GuiForestry extends GuiContainer i this.drawGradientRect(x - 3, y - 3, x + length + 2, y - 3 + 1, borderColorTopInt, borderColorTopInt); this.drawGradientRect(x - 3, y + height, x + length + 2, y + height + 1, borderColorBottomInt, borderColorBottomInt); + boolean firstLine = true; for (ToolTipLine tip : toolTips) { - String line = tip.getText(); + String line = tip.toString(); - if (tip.getColor() == null) - line = "\u00a77" + line; - else - line = "\u00a7" + tip.getColor().getFormattingCode() + line; + if (!firstLine) { + line = EnumChatFormatting.GRAY + line; + } this.fontRendererObj.drawStringWithShadow(line, x, y, -1); y += 10 + tip.getSpacing(); + + firstLine = false; } this.zLevel = 0.0F; @@ -408,54 +416,14 @@ public abstract class GuiForestry extends GuiContainer i public void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6) { super.drawGradientRect(par1, par2, par3, par4, par5, par6); } - // - // protected void drawGuiContainerForegroundLayer() { - // } - /** - * Draws the basic background texture centered on the screen. - */ - // protected void drawBackground() { - // drawBackground((this.width - this.xSize) / 2, (this.height - this.ySize) / 2, this.xSize, this.ySize); - // } - // protected void drawBackground(int x, int y, int w, int h) { - // bindTexture(); - // this.drawTexturedModalRect(x, y, 0, 0, w, h); - // } - // protected void bindTexture() { - // bindTexture(textureFile); - // } - // - // protected void drawSlotInventory(Slot slot) { - // - // int xPos = slot.xDisplayPosition; - // int yPos = slot.yDisplayPosition; - // ItemStack slotStack = slot.getStack(); - // boolean backgroundDrawn = false; - // - // this.zLevel = 100.0F; - // itemRenderer.zLevel = 100.0F; - // - // if (slotStack == null) { - // IIcon icon = slot.getBackgroundIconIndex(); - // - // if (icon != null) { - // GL11.glDisable(GL11.GL_LIGHTING); - // GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); - // Proxies.common.bindTexture(SpriteSheet.ITEMS); - // this.drawTexturedModelRectFromIcon(xPos, yPos, icon, 16, 16); - // GL11.glEnable(GL11.GL_LIGHTING); - // backgroundDrawn = true; - // } - // } - // - // if (!backgroundDrawn && slotStack != null) - // drawItemStack(slotStack, xPos, yPos); - // - // this.zLevel = 0.0F; - // itemRenderer.zLevel = 0.0F; - // } public void drawItemStack(ItemStack stack, int xPos, int yPos) { + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glTranslatef(0.0F, 0.0F, 32.0F); this.zLevel = 100.0F; itemRender.zLevel = 100.0F; @@ -468,31 +436,29 @@ public abstract class GuiForestry extends GuiContainer i itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), stack, xPos, yPos); this.zLevel = 0.0F; itemRender.zLevel = 0.0F; + + RenderHelper.disableStandardItemLighting(); + GL11.glPopAttrib(); } protected class ItemStackWidget extends Widget { - ItemStack itemStack; + private final ItemStack itemStack; public ItemStackWidget(int xPos, int yPos, ItemStack itemStack) { super(widgetManager, xPos, yPos); - - IIcon icon = itemStack.getItem().getIcon(itemStack, 0); - - this.width = icon.getIconWidth(); - this.height = icon.getIconHeight(); this.itemStack = itemStack; } @Override public void draw(int startX, int startY) { - itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, itemStack, xPos + startX, yPos + startY); - itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, itemStack, xPos + startX, yPos + startY); + drawItemStack(itemStack, xPos + startX, yPos + startY); } @Override public ToolTip getToolTip() { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; ToolTip tip = new ToolTip(); - tip.add(itemStack.getDisplayName()); + tip.add(itemStack.getTooltip(player, false)); return tip; } } diff --git a/src/main/java/forestry/core/gui/GuiForestryTitled.java b/src/main/java/forestry/core/gui/GuiForestryTitled.java index d09b4ec30..f4550559b 100644 --- a/src/main/java/forestry/core/gui/GuiForestryTitled.java +++ b/src/main/java/forestry/core/gui/GuiForestryTitled.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.core.gui; -import net.minecraft.util.ResourceLocation; - import forestry.core.gadgets.TileForestry; import forestry.core.utils.StringUtil; +import net.minecraft.util.ResourceLocation; public abstract class GuiForestryTitled extends GuiForestry { diff --git a/src/main/java/forestry/core/gui/GuiNaturalistInventory.java b/src/main/java/forestry/core/gui/GuiNaturalistInventory.java index e2b8e0f16..bbdf0184c 100755 --- a/src/main/java/forestry/core/gui/GuiNaturalistInventory.java +++ b/src/main/java/forestry/core/gui/GuiNaturalistInventory.java @@ -10,15 +10,8 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.HashMap; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - import forestry.api.apiculture.IApiaristTracker; +import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.IIndividual; @@ -34,6 +27,12 @@ import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; +import java.util.HashMap; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; public class GuiNaturalistInventory extends GuiForestry { private final ISpeciesRoot speciesRoot; @@ -74,9 +73,8 @@ public class GuiNaturalistInventory extends GuiForestry { startPage(); displaySpeciesInformation(true, individual.getGenome().getPrimary(), iconStacks.get(individual.getIdent()), 10); - if (!individual.isPureBred(0)) - displaySpeciesInformation(individual.isAnalyzed(), individual.getGenome().getSecondary(), iconStacks.get(individual.getGenome().getSecondary().getUID()), - 10); + if (!individual.isPureBred(EnumTreeChromosome.SPECIES)) + displaySpeciesInformation(individual.isAnalyzed(), individual.getGenome().getSecondary(), iconStacks.get(individual.getGenome().getSecondary().getUID()), 10); endPage(); } @@ -194,7 +192,7 @@ public class GuiNaturalistInventory extends GuiForestry { RenderHelper.disableStandardItemLighting(); int line = 48; - int column = 0; + int column; EnumMutateChance chance = EnumMutateChance.rateChance(combination.getBaseChance()); if (chance == EnumMutateChance.HIGHEST) { line += 16; @@ -225,8 +223,8 @@ public class GuiNaturalistInventory extends GuiForestry { float chance = mutation.getBaseChance(); - int line = 0; - int column = 0; + int line; + int column; if (chance >= 20) { line = 16; column = 228; diff --git a/src/main/java/forestry/core/gui/GuiTextBox.java b/src/main/java/forestry/core/gui/GuiTextBox.java index 48a92b981..afc00161d 100755 --- a/src/main/java/forestry/core/gui/GuiTextBox.java +++ b/src/main/java/forestry/core/gui/GuiTextBox.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.Iterator; import java.util.List; - import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiTextField; public class GuiTextBox extends GuiTextField { + private static final int enabledColor = 14737632; + private static final int disabledColor = 7368816; private final FontRenderer fontRendererObj; - private final int startX, startY, width, height; - private final int enabledColor = 14737632; - private final int disabledColor = 7368816; private int lineScroll = 0; private int maxLines = 0; @@ -100,7 +97,7 @@ public class GuiTextBox extends GuiTextField { drawRect(startX, startY, startX + this.width, startY + this.height, -16777216); } - int textColour = isFocused() ? this.enabledColor : this.disabledColor; + int textColour = isFocused() ? enabledColor : disabledColor; drawScrolledSplitString(getCursoredText(), startX + 2, startY + 2, width - 4, textColour); } diff --git a/src/main/java/forestry/core/gui/HintLedger.java b/src/main/java/forestry/core/gui/HintLedger.java index 61a2f4141..710ebde32 100755 --- a/src/main/java/forestry/core/gui/HintLedger.java +++ b/src/main/java/forestry/core/gui/HintLedger.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.Random; - import forestry.core.interfaces.IHintSource; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; +import java.util.Random; public class HintLedger extends Ledger { diff --git a/src/main/java/forestry/core/gui/IGuiSelectable.java b/src/main/java/forestry/core/gui/IGuiSelectable.java index f1e6349c2..d231aba5d 100755 --- a/src/main/java/forestry/core/gui/IGuiSelectable.java +++ b/src/main/java/forestry/core/gui/IGuiSelectable.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core.gui; -import net.minecraft.entity.player.EntityPlayer; - import forestry.core.network.PacketUpdate; +import net.minecraft.entity.player.EntityPlayer; public interface IGuiSelectable { void handleSelectionChange(EntityPlayer player, PacketUpdate packet); diff --git a/src/main/java/forestry/core/gui/Ledger.java b/src/main/java/forestry/core/gui/Ledger.java index c011ee618..b2ac970b6 100755 --- a/src/main/java/forestry/core/gui/Ledger.java +++ b/src/main/java/forestry/core/gui/Ledger.java @@ -10,16 +10,14 @@ ******************************************************************************/ package forestry.core.gui; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - import forestry.core.config.Defaults; import forestry.core.config.SessionVars; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.utils.ForestryResource; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; /** * Side ledger for guis @@ -81,11 +79,7 @@ public abstract class Ledger { } public boolean intersectsWith(int mouseX, int mouseY, int shiftX, int shiftY) { - - if (mouseX >= shiftX && mouseX <= shiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + getHeight()) - return true; - - return false; + return mouseX >= shiftX && mouseX <= shiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + getHeight(); } public void setFullyOpen() { diff --git a/src/main/java/forestry/core/gui/LedgerManager.java b/src/main/java/forestry/core/gui/LedgerManager.java index 69aa3353c..1e5e742fe 100755 --- a/src/main/java/forestry/core/gui/LedgerManager.java +++ b/src/main/java/forestry/core/gui/LedgerManager.java @@ -10,15 +10,12 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.ArrayList; - -import net.minecraft.client.Minecraft; - -import org.lwjgl.opengl.GL11; - import forestry.core.config.SessionVars; import forestry.core.gadgets.TileForestry; import forestry.core.proxy.Proxies; +import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import org.lwjgl.opengl.GL11; public class LedgerManager { @@ -40,8 +37,6 @@ public class LedgerManager { /** * Inserts a ledger into the next-to-last position. - * - * @param ledger */ public void insert(Ledger ledger) { this.ledgers.add(ledgers.size() - 1, ledger); diff --git a/src/main/java/forestry/core/gui/OwnerLedger.java b/src/main/java/forestry/core/gui/OwnerLedger.java index 0fa6803b4..4fe3e979d 100755 --- a/src/main/java/forestry/core/gui/OwnerLedger.java +++ b/src/main/java/forestry/core/gui/OwnerLedger.java @@ -10,17 +10,18 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.Locale; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; import forestry.core.interfaces.IOwnable; +import forestry.core.interfaces.IRestrictedAccess; import forestry.core.network.PacketCoordinates; import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; import forestry.core.utils.EnumAccess; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.StringUtil; +import java.util.Locale; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; /** * Ledger displaying ownership information @@ -39,9 +40,7 @@ public class OwnerLedger extends Ledger { int shiftX = currentShiftX; int shiftY = currentShiftY + 44; - if (mouseX >= shiftX && mouseX <= currentShiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + 12) - return true; - return false; + return mouseX >= shiftX && mouseX <= currentShiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + 12; } public boolean isOwnerChangeButton(int mouseX, int mouseY) { @@ -53,7 +52,6 @@ public class OwnerLedger extends Ledger { // Update state boolean playerIsOwner = tile.isOwner(manager.minecraft.thePlayer); - EnumAccess access = tile.getAccess(); if (playerIsOwner) maxHeight = 60; @@ -64,6 +62,12 @@ public class OwnerLedger extends Ledger { drawBackground(x, y); // Draw icon + EnumAccess access; + if (tile instanceof IRestrictedAccess) { + access = ((IRestrictedAccess)tile).getAccess(); + } else { + access = EnumAccess.SHARED; + } IIcon accessIcon = TextureManager.getInstance().getDefault("misc/access." + access.toString().toLowerCase(Locale.ENGLISH)); drawIcon(accessIcon, x + 3, y + 4); @@ -73,42 +77,32 @@ public class OwnerLedger extends Ledger { manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.owner"), x + 22, y + 8, manager.gui.fontColor.get("ledger.owner.header")); - String ownerName = StringUtil.localize("gui.derelict"); - - if (tile.getOwnerProfile() != null) - ownerName = tile.getOwnerProfile().getName(); - - manager.minecraft.fontRenderer.drawString(ownerName, x + 22, y + 20, manager.gui.fontColor.get("ledger.owner.text")); - - if (!playerIsOwner) - return; - - manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.access") + ":", x + 22, y + 32, - manager.gui.fontColor.get("ledger.owner.subheader")); - // Access rules - drawIcon(accessIcon, x + 20, y + 40); - manager.minecraft.fontRenderer.drawString(StringUtil.localize(access.getName()), x + 38, y + 44, manager.gui.fontColor.get("ledger.owner.text")); + manager.minecraft.fontRenderer.drawString(PlayerUtil.getOwnerName(tile), x + 22, y + 20, manager.gui.fontColor.get("ledger.owner.text")); + if (playerIsOwner && tile instanceof IRestrictedAccess) { + manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.access") + ":", x + 22, y + 32, + manager.gui.fontColor.get("ledger.owner.subheader")); + // Access rules + drawIcon(accessIcon, x + 20, y + 40); + manager.minecraft.fontRenderer.drawString(StringUtil.localize(access.getName()), x + 38, y + 44, manager.gui.fontColor.get("ledger.owner.text")); + } } @Override public String getTooltip() { - if (tile.getOwnerProfile() != null) - return StringUtil.localize("gui.owner") + ": " + tile.getOwnerProfile().getName(); - else - return StringUtil.localize("gui.derelict"); + return StringUtil.localize("gui.owner") + ": " + PlayerUtil.getOwnerName(tile); } @Override public boolean handleMouseClicked(int x, int y, int mouseButton) { - if (isAccessButton(x, y)) { + if (isAccessButton(x, y) && tile instanceof IRestrictedAccess) { if (!Proxies.common.isSimulating(((TileEntity) tile).getWorldObj())) { TileEntity te = (TileEntity) tile; Proxies.net.sendToServer(new PacketCoordinates(PacketIds.ACCESS_SWITCH, te.xCoord, te.yCoord, te.zCoord)); } - tile.switchAccessRule(manager.minecraft.thePlayer); + ((IRestrictedAccess) tile).switchAccessRule(manager.minecraft.thePlayer); return true; } diff --git a/src/main/java/forestry/core/gui/WidgetManager.java b/src/main/java/forestry/core/gui/WidgetManager.java index f96f66a4b..38cc516be 100755 --- a/src/main/java/forestry/core/gui/WidgetManager.java +++ b/src/main/java/forestry/core/gui/WidgetManager.java @@ -10,15 +10,12 @@ ******************************************************************************/ package forestry.core.gui; -import java.util.ArrayList; - -import net.minecraft.client.Minecraft; - -import org.lwjgl.opengl.GL11; - import forestry.core.gadgets.TileForestry; import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; +import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import org.lwjgl.opengl.GL11; public class WidgetManager { diff --git a/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java b/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java index 4a3fa0782..a21c8887a 100755 --- a/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java +++ b/src/main/java/forestry/core/gui/buttons/GuiBetterButton.java @@ -10,20 +10,17 @@ ******************************************************************************/ package forestry.core.gui.buttons; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.config.Defaults; +import forestry.core.gui.tooltips.IToolTipProvider; +import forestry.core.gui.tooltips.ToolTip; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import org.lwjgl.opengl.GL11; -import forestry.core.config.Defaults; -import forestry.core.gui.tooltips.IToolTipProvider; -import forestry.core.gui.tooltips.ToolTip; - @SideOnly(Side.CLIENT) public class GuiBetterButton extends GuiButton implements IToolTipProvider{ diff --git a/src/main/java/forestry/core/gui/buttons/GuiMultiButton.java b/src/main/java/forestry/core/gui/buttons/GuiMultiButton.java index dcadc2621..85873f60f 100755 --- a/src/main/java/forestry/core/gui/buttons/GuiMultiButton.java +++ b/src/main/java/forestry/core/gui/buttons/GuiMultiButton.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.core.gui.buttons; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - +import forestry.core.gui.tooltips.ToolTip; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import forestry.core.gui.tooltips.ToolTip; - /** * * @author CovertJaguar diff --git a/src/main/java/forestry/core/gui/slots/SlotCraftAuto.java b/src/main/java/forestry/core/gui/slots/SlotCraftAuto.java index 51687ae8c..44f1c9074 100755 --- a/src/main/java/forestry/core/gui/slots/SlotCraftAuto.java +++ b/src/main/java/forestry/core/gui/slots/SlotCraftAuto.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.core.gui.slots; +import forestry.core.interfaces.IContainerCrafting; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import forestry.core.interfaces.IContainerCrafting; - /** * Informs the passed container of slot changes. */ diff --git a/src/main/java/forestry/core/gui/slots/SlotCustom.java b/src/main/java/forestry/core/gui/slots/SlotCustom.java deleted file mode 100755 index 50ce36767..000000000 --- a/src/main/java/forestry/core/gui/slots/SlotCustom.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui.slots; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.genetics.ISpeciesRoot; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.config.ForestryItem; -import forestry.core.interfaces.ICrafter; -import forestry.core.render.TextureManager; -import forestry.core.utils.StackUtils; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - -/** - * Slot which only specific items. (With permission by RichardG.) - * - * @author Richard - */ -public class SlotCustom extends SlotForestry { - - protected final Object[] items; - private boolean exclusion; - private ICrafter crafter; - private String blockedTexture = "slots/blocked"; - - public SlotCustom(IInventory iinventory, int slotIndex, int xPos, int yPos, Object... items) { - super(iinventory, slotIndex, xPos, yPos); - this.items = items; - } - - public SlotCustom setCrafter(ICrafter crafter) { - this.crafter = crafter; - return this; - } - - public SlotCustom setExclusion(boolean exclusion) { - this.exclusion = exclusion; - return this; - } - - @Override - public boolean isItemValid(ItemStack itemstack) { - if (itemstack == null) - return false; - if (!inventory.isItemValidForSlot(getSlotIndex(), itemstack)) - return false; - - if (exclusion) - return !determineValidity(itemstack); - else - return determineValidity(itemstack); - } - - @Override - public boolean getHasStack() { - if (crafter != null && !crafter.canTakeStack(getSlotIndex())) - return false; - else - return super.getHasStack(); - } - - @Override - public ItemStack decrStackSize(int i) { - if (crafter != null && !crafter.canTakeStack(getSlotIndex())) - return null; - else - return super.decrStackSize(i); - } - - @Override - public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) { - if (crafter != null) - crafter.takenFromSlot(getSlotIndex(), true, player); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private boolean determineValidity(ItemStack itemstack) { - for (Object filter : items) { - if (filter == null) - continue; - if (filter instanceof Class) { - Block block = StackUtils.getBlock(itemstack); - - if (block != null && ((Class) filter).isAssignableFrom(block.getClass())) return true; - if (((Class) filter).isAssignableFrom(itemstack.getItem().getClass())) return true; - } else if (filter instanceof ItemStack) { - if (((ItemStack) filter).getItemDamage() == Defaults.WILDCARD && itemstack.getItem() == ((ItemStack) filter).getItem()) - return true; - else if (itemstack.isItemEqual((ItemStack) filter)) - return true; - } else if (filter instanceof Block) { - if (StackUtils.equals((Block) filter, itemstack)) return true; - } else if (filter instanceof Item) { - if (itemstack.getItem() == filter) return true; - } else if (filter instanceof ForestryItem) { - if (((ForestryItem) filter).isItemEqual(itemstack)) return true; - } else if (filter instanceof ForestryBlock) { - if (((ForestryBlock) filter).isItemEqual(itemstack)) return true; - } else if (filter instanceof ISpeciesRoot) { - if (((ISpeciesRoot) filter).isMember(itemstack)) return true; - } else { - throw new RuntimeException("invalid filter item specified: "+filter+" ("+filter.getClass()+")"); - } - } - - return false; - } - - public SlotCustom setBlockedTexture(String ident) { - blockedTexture = ident; - return this; - } - - @SideOnly(Side.CLIENT) - @Override - public IIcon getBackgroundIconIndex() { - if (!inventory.isItemValidForSlot(getSlotIndex(), null)) - return TextureManager.getInstance().getDefault(blockedTexture); - else - return null; - } -} diff --git a/src/main/java/forestry/core/gui/slots/SlotFiltered.java b/src/main/java/forestry/core/gui/slots/SlotFiltered.java new file mode 100644 index 000000000..515b53de3 --- /dev/null +++ b/src/main/java/forestry/core/gui/slots/SlotFiltered.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.gui.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import forestry.core.interfaces.IFilterSlotDelegate; + +/** + * Slot which only takes specific items, specified by the ICustomSlotInventory. + */ +public class SlotFiltered extends SlotWatched { + + protected final IFilterSlotDelegate filterSlotDelegate; + + public SlotFiltered(T filterSlotDelegateInventory, int slotIndex, int xPos, int yPos) { + this(filterSlotDelegateInventory, filterSlotDelegateInventory, slotIndex, xPos, yPos); + } + + public SlotFiltered(IFilterSlotDelegate filterSlotDelegate, IInventory inventory, int slotIndex, int xPos, int yPos) { + super(inventory, slotIndex, xPos, yPos); + this.filterSlotDelegate = filterSlotDelegate; + } + + @Override + public boolean isItemValid(ItemStack itemstack) { + int slotIndex = getSlotIndex(); + if (filterSlotDelegate.isLocked(slotIndex)) + return false; + if (itemstack != null) + return filterSlotDelegate.canSlotAccept(slotIndex, itemstack); + return true; + } +} diff --git a/src/main/java/forestry/core/gui/slots/SlotForestry.java b/src/main/java/forestry/core/gui/slots/SlotForestry.java index 1171bda30..306c731c2 100755 --- a/src/main/java/forestry/core/gui/slots/SlotForestry.java +++ b/src/main/java/forestry/core/gui/slots/SlotForestry.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.core.gui.slots; +import forestry.core.gui.tooltips.IToolTipProvider; +import forestry.core.gui.tooltips.ToolTip; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gui.tooltips.IToolTipProvider; -import forestry.core.gui.tooltips.ToolTip; - public class SlotForestry extends Slot implements IToolTipProvider{ protected boolean isPhantom; @@ -28,12 +27,10 @@ public class SlotForestry extends Slot implements IToolTipProvider{ private ToolTip toolTips; public SlotForestry(IInventory inventory, int slotIndex, int xPos, int yPos) { - this(inventory, slotIndex, xPos, yPos, -1); - } - - public SlotForestry(IInventory inventory, int slotIndex, int xPos, int yPos, int stackLimit) { super(inventory, slotIndex, xPos, yPos); - this.stackLimit = stackLimit; + if (inventory == null) + throw new IllegalArgumentException("Inventory must not be null"); + this.stackLimit = -1; } public SlotForestry setInfinite() { diff --git a/src/main/java/forestry/core/gui/slots/SlotItemInventory.java b/src/main/java/forestry/core/gui/slots/SlotItemInventory.java deleted file mode 100755 index d2f99fb1b..000000000 --- a/src/main/java/forestry/core/gui/slots/SlotItemInventory.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui.slots; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -import forestry.core.gui.ContainerItemInventory; - -public class SlotItemInventory extends Slot { - - private final EntityPlayer player; - private final ContainerItemInventory container; - - public SlotItemInventory(ContainerItemInventory container, IInventory inventory, EntityPlayer player, int par2, int par3, int par4) { - super(inventory, par2, par3, par4); - this.container = container; - this.player = player; - } - - @Override - public void onSlotChange(ItemStack par1ItemStack, ItemStack par2ItemStack) { - super.onSlotChange(par1ItemStack, par2ItemStack); - container.saveInventory(player); - } - -} diff --git a/src/main/java/forestry/core/gui/slots/SlotLiquidContainer.java b/src/main/java/forestry/core/gui/slots/SlotLiquidContainer.java deleted file mode 100755 index 2a73c551d..000000000 --- a/src/main/java/forestry/core/gui/slots/SlotLiquidContainer.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui.slots; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.core.fluids.FluidHelper; - -import forestry.core.render.TextureManager; -import net.minecraftforge.fluids.Fluid; - -public class SlotLiquidContainer extends SlotForestry { - - private final boolean allowEmpty; - private final Fluid[] fluids; - - public SlotLiquidContainer(IInventory iinventory, int slotIndex, int xPos, int yPos) { - this(iinventory, slotIndex, xPos, yPos, false); - } - - public SlotLiquidContainer(IInventory iinventory, int slotIndex, int xPos, int yPos, boolean allowEmpty, Fluid... fluids) { - super(iinventory, slotIndex, xPos, yPos); - - this.allowEmpty = allowEmpty; - this.fluids = fluids; - } - - @Override - public boolean isItemValid(ItemStack stack) { - if (allowEmpty) - return FluidHelper.isEmptyContainer(stack); - if (fluids.length > 0) { - for (Fluid fluid : fluids) - if (FluidHelper.containsFluid(stack, fluid)) - return true; - return false; - } - return FluidHelper.isFilledContainer(stack); - } - - @SideOnly(Side.CLIENT) - @Override - public IIcon getBackgroundIconIndex() { - if (allowEmpty) - return TextureManager.getInstance().getDefault("slots/container"); - else - return TextureManager.getInstance().getDefault("slots/liquid"); - } - -} diff --git a/src/main/java/forestry/core/gui/slots/SlotOutput.java b/src/main/java/forestry/core/gui/slots/SlotOutput.java index 3f7760d1a..cfe07db6a 100755 --- a/src/main/java/forestry/core/gui/slots/SlotOutput.java +++ b/src/main/java/forestry/core/gui/slots/SlotOutput.java @@ -1,30 +1,40 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui.slots; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -/** - * - * @author CovertJaguar - */ -public class SlotOutput extends SlotForestry { - - public SlotOutput(IInventory iinventory, int slotIndex, int posX, int posY) { - super(iinventory, slotIndex, posX, posY); - } - - @Override - public boolean isItemValid(ItemStack itemstack) { - return false; - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.gui.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * + * @author CovertJaguar + */ +public class SlotOutput extends SlotWatched { + + public SlotOutput(IInventory iinventory, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + } + + @Override + public boolean isItemValid(ItemStack itemstack) { + return false; + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getBackgroundIconIndex() { + return null; + } +} diff --git a/src/main/java/forestry/core/gui/slots/SlotWatched.java b/src/main/java/forestry/core/gui/slots/SlotWatched.java new file mode 100644 index 000000000..014b33090 --- /dev/null +++ b/src/main/java/forestry/core/gui/slots/SlotWatched.java @@ -0,0 +1,66 @@ +package forestry.core.gui.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.core.interfaces.ICrafter; +import forestry.core.render.TextureManager; + +/** + * Slot with an ICrafter callback. + */ +public abstract class SlotWatched extends SlotForestry { + private ICrafter crafter; + private String blockedTexture = "slots/blocked"; + + public SlotWatched(IInventory inventory, int slotIndex, int xPos, int yPos) { + super(inventory, slotIndex, xPos, yPos); + } + + public SlotWatched setCrafter(ICrafter crafter) { + this.crafter = crafter; + return this; + } + + @Override + public boolean getHasStack() { + if (crafter != null && !crafter.canTakeStack(getSlotIndex())) + return false; + else + return super.getHasStack(); + } + + @Override + public ItemStack decrStackSize(int i) { + if (crafter != null && !crafter.canTakeStack(getSlotIndex())) + return null; + else + return super.decrStackSize(i); + } + + @Override + public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) { + if (crafter != null) + crafter.takenFromSlot(getSlotIndex(), true, player); + } + + public SlotWatched setBlockedTexture(String ident) { + blockedTexture = ident; + return this; + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getBackgroundIconIndex() { + ItemStack stack = getStack(); + if (!isItemValid(stack)) + return TextureManager.getInstance().getDefault(blockedTexture); + else + return null; + } +} diff --git a/src/main/java/forestry/core/gui/tooltips/ToolTip.java b/src/main/java/forestry/core/gui/tooltips/ToolTip.java index d254a0ff8..701684388 100755 --- a/src/main/java/forestry/core/gui/tooltips/ToolTip.java +++ b/src/main/java/forestry/core/gui/tooltips/ToolTip.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.core.gui.tooltips; +import com.google.common.collect.ForwardingList; +import forestry.core.utils.StringUtil; import java.util.ArrayList; import java.util.List; -import com.google.common.collect.ForwardingList; - -import forestry.core.utils.StringUtil; - /** * @author CovertJaguar */ @@ -43,6 +41,15 @@ public class ToolTip extends ForwardingList { return add(new ToolTipLine(line)); } + public boolean add(List lines) { + boolean changed = false; + for (Object line : lines) { + if (line instanceof String) + changed |= add((String) line); + } + return changed; + } + public void onTick(boolean mouseOver) { if (delay == 0) return; @@ -67,7 +74,7 @@ public class ToolTip extends ForwardingList { public List convertToStrings() { List tips = new ArrayList(size()); for (ToolTipLine line : this) { - tips.add(line.getText()); + tips.add(line.toString()); } return tips; } diff --git a/src/main/java/forestry/core/gui/tooltips/ToolTipLine.java b/src/main/java/forestry/core/gui/tooltips/ToolTipLine.java index a8fe70cc2..3fcfd02e9 100755 --- a/src/main/java/forestry/core/gui/tooltips/ToolTipLine.java +++ b/src/main/java/forestry/core/gui/tooltips/ToolTipLine.java @@ -40,12 +40,10 @@ public class ToolTipLine { return spacing; } - public String getText() { - return text; - } - - public EnumChatFormatting getColor() { - return color; + public String toString() { + if (color == null) + return text; + return color + text; } } diff --git a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java index e10165d82..fba887aea 100755 --- a/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java +++ b/src/main/java/forestry/core/gui/widgets/ReservoirWidget.java @@ -10,15 +10,12 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import net.minecraft.util.IIcon; - -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - import forestry.core.gui.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.FluidStack; +import org.lwjgl.opengl.GL11; public class ReservoirWidget extends TankWidget { @@ -46,7 +43,7 @@ public class ReservoirWidget extends TankWidget { GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); while (true) { - int x = 0; + int x; if (squaled > 16) { x = 16; diff --git a/src/main/java/forestry/core/gui/widgets/SocketWidget.java b/src/main/java/forestry/core/gui/widgets/SocketWidget.java index 68d10ad25..f2a98eb9d 100755 --- a/src/main/java/forestry/core/gui/widgets/SocketWidget.java +++ b/src/main/java/forestry/core/gui/widgets/SocketWidget.java @@ -10,11 +10,6 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import java.util.List; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - import forestry.core.circuits.ISolderingIron; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.gui.ContainerSocketed; @@ -24,6 +19,9 @@ import forestry.core.gui.tooltips.ToolTip; import forestry.core.interfaces.ISocketable; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; +import java.util.List; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; public class SocketWidget extends Widget { diff --git a/src/main/java/forestry/core/gui/widgets/TankWidget.java b/src/main/java/forestry/core/gui/widgets/TankWidget.java index a4fe7d66e..8a0d817c4 100755 --- a/src/main/java/forestry/core/gui/widgets/TankWidget.java +++ b/src/main/java/forestry/core/gui/widgets/TankWidget.java @@ -10,24 +10,20 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import forestry.farming.gui.ContainerFarm; -import net.minecraft.inventory.Container; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - import forestry.api.core.IToolPipette; import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gui.ContainerForestry; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.WidgetManager; import forestry.core.gui.tooltips.ToolTip; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; +import forestry.farming.gui.ContainerFarm; +import net.minecraft.inventory.Container; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.FluidStack; +import org.lwjgl.opengl.GL11; /** * Slot for liquid tanks @@ -61,10 +57,11 @@ public class TankWidget extends Widget { @Override public void draw(int startX, int startY) { - if (getTank() == null) + StandardTank tank = getTank(); + if (tank == null) return; - FluidStack contents = getTank().getFluid(); + FluidStack contents = tank.getFluid(); if (contents == null || contents.amount <= 0 || contents.getFluid() == null) return; IIcon liquidIcon = contents.getFluid().getIcon(contents); @@ -79,7 +76,7 @@ public class TankWidget extends Widget { GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); while (true) { - int x = 0; + int x; if (squaled > 16) { x = 16; @@ -117,7 +114,7 @@ public class TankWidget extends Widget { Item held = itemstack.getItem(); if (held instanceof IToolPipette && manager.gui.inventorySlots instanceof ContainerLiquidTanks) - ((ContainerLiquidTanks) manager.gui.inventorySlots).handlePipetteClick(slot, manager.minecraft.thePlayer); + ((ContainerLiquidTanks) manager.gui.inventorySlots).handlePipetteClickClient(slot, manager.minecraft.thePlayer); } } diff --git a/src/main/java/forestry/core/gui/widgets/Widget.java b/src/main/java/forestry/core/gui/widgets/Widget.java index e0e2e45d6..d9a57c6ab 100755 --- a/src/main/java/forestry/core/gui/widgets/Widget.java +++ b/src/main/java/forestry/core/gui/widgets/Widget.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.core.gui.widgets; -import net.minecraft.entity.player.EntityPlayer; - import forestry.core.gui.WidgetManager; import forestry.core.gui.tooltips.IToolTipProvider; import forestry.core.gui.tooltips.ToolTip; import forestry.core.proxy.Proxies; +import net.minecraft.entity.player.EntityPlayer; /** * Basic non-ItemStack slot diff --git a/src/main/java/forestry/core/interfaces/IErrorSource.java b/src/main/java/forestry/core/interfaces/IErrorSource.java index 342a2ad35..019c03f78 100755 --- a/src/main/java/forestry/core/interfaces/IErrorSource.java +++ b/src/main/java/forestry/core/interfaces/IErrorSource.java @@ -10,12 +10,12 @@ ******************************************************************************/ package forestry.core.interfaces; -import forestry.api.core.EnumErrorCode; +import forestry.api.core.IErrorState; public interface IErrorSource { boolean throwsErrors(); - EnumErrorCode getErrorState(); + IErrorState getErrorState(); } diff --git a/src/main/java/forestry/core/interfaces/IFilterSlotDelegate.java b/src/main/java/forestry/core/interfaces/IFilterSlotDelegate.java new file mode 100644 index 000000000..ccacaf29b --- /dev/null +++ b/src/main/java/forestry/core/interfaces/IFilterSlotDelegate.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.interfaces; + +import net.minecraft.item.ItemStack; + +public interface IFilterSlotDelegate { + + /** + * Non-automation version of IInventory's isItemValidForSlot. + * Used to determine if a player can place a stack in a slot. + * + * Combine this with Forestry's access permissions to implement isItemValidForSlot. + */ + boolean canSlotAccept(int slotIndex, ItemStack itemStack); + + /** + * Used to lock slots under special conditions. + * Locked slots will have an X over them. + */ + boolean isLocked(int slotIndex); + +} diff --git a/src/main/java/forestry/core/interfaces/ILiquidTankContainer.java b/src/main/java/forestry/core/interfaces/ILiquidTankContainer.java index f3b410ba7..5dbf7fff5 100755 --- a/src/main/java/forestry/core/interfaces/ILiquidTankContainer.java +++ b/src/main/java/forestry/core/interfaces/ILiquidTankContainer.java @@ -11,7 +11,6 @@ package forestry.core.interfaces; import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.StandardTank; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraftforge.fluids.IFluidHandler; diff --git a/src/main/java/forestry/core/interfaces/IOwnable.java b/src/main/java/forestry/core/interfaces/IOwnable.java index ef87cd4f8..290e977f8 100755 --- a/src/main/java/forestry/core/interfaces/IOwnable.java +++ b/src/main/java/forestry/core/interfaces/IOwnable.java @@ -14,8 +14,6 @@ import net.minecraft.entity.player.EntityPlayer; import com.mojang.authlib.GameProfile; -import forestry.core.utils.EnumAccess; - public interface IOwnable { boolean isOwnable(); @@ -28,11 +26,6 @@ public interface IOwnable { boolean isOwner(EntityPlayer player); - boolean switchAccessRule(EntityPlayer player); - - EnumAccess getAccess(); - boolean allowsRemoval(EntityPlayer player); - boolean allowsInteraction(EntityPlayer player); } diff --git a/src/main/java/forestry/core/interfaces/IPacketHandler.java b/src/main/java/forestry/core/interfaces/IPacketHandler.java index ab17f5b0a..70e7f6efa 100755 --- a/src/main/java/forestry/core/interfaces/IPacketHandler.java +++ b/src/main/java/forestry/core/interfaces/IPacketHandler.java @@ -11,7 +11,6 @@ package forestry.core.interfaces; import java.io.DataInputStream; - import net.minecraft.entity.player.EntityPlayer; public interface IPacketHandler { diff --git a/src/main/java/forestry/core/interfaces/IRenderableMachine.java b/src/main/java/forestry/core/interfaces/IRenderableMachine.java index 6a36d9135..8a9741878 100755 --- a/src/main/java/forestry/core/interfaces/IRenderableMachine.java +++ b/src/main/java/forestry/core/interfaces/IRenderableMachine.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core.interfaces; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.core.utils.EnumTankLevel; +import net.minecraftforge.common.util.ForgeDirection; public interface IRenderableMachine { diff --git a/src/main/java/forestry/core/gui/slots/SlotClosed.java b/src/main/java/forestry/core/interfaces/IRestrictedAccess.java old mode 100755 new mode 100644 similarity index 60% rename from src/main/java/forestry/core/gui/slots/SlotClosed.java rename to src/main/java/forestry/core/interfaces/IRestrictedAccess.java index 98b907272..3a941b7ee --- a/src/main/java/forestry/core/gui/slots/SlotClosed.java +++ b/src/main/java/forestry/core/interfaces/IRestrictedAccess.java @@ -1,27 +1,27 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.gui.slots; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class SlotClosed extends SlotForestry { - - public SlotClosed(IInventory par1iInventory, int par2, int par3, int par4) { - super(par1iInventory, par2, par3, par4); - } - - @Override - public boolean isItemValid(ItemStack par1ItemStack) { - return false; - } - -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.interfaces; + +import net.minecraft.entity.player.EntityPlayer; + +import forestry.core.utils.EnumAccess; + +public interface IRestrictedAccess extends IOwnable { + + boolean switchAccessRule(EntityPlayer player); + + EnumAccess getAccess(); + + boolean allowsAlteration(EntityPlayer player); + + boolean allowsViewing(EntityPlayer player); + +} diff --git a/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java b/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java new file mode 100644 index 000000000..da1a14afb --- /dev/null +++ b/src/main/java/forestry/core/inventory/AdjacentInventoryCache.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.inventory; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +import forestry.core.utils.AdjacentTileCache; + +/** + * + * @author CovertJaguar + */ +public final class AdjacentInventoryCache implements AdjacentTileCache.ICacheListener { + + private final AdjacentTileCache cache; + private boolean changed = true; + private final List invs = new LinkedList(); + private final IInventory[] sides = new IInventory[6]; + private final Comparator sorter; + private final ITileFilter filter; + + public AdjacentInventoryCache(TileEntity tile, AdjacentTileCache cache) { + this(tile, cache, null, null); + } + + public AdjacentInventoryCache(TileEntity tile, AdjacentTileCache cache, ITileFilter filter, Comparator sorter) { + this.cache = cache; + this.filter = filter; + this.sorter = sorter; + cache.addListener(this); + } + + public IInventory getAdjacentInventory(ForgeDirection side) { + checkChanged(); + return sides[side.ordinal()]; + } + + public Collection getAdjacentInventories() { + checkChanged(); + return invs; + } + + @Override + public void changed() { + changed = true; + } + + @Override + public void purge() { + invs.clear(); + Arrays.fill(sides, null); + } + + private void checkChanged() { + cache.refresh(); + if (changed) { + changed = false; + purge(); + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tile = cache.getTileOnSide(side); + if (tile != null && (filter == null || filter.matches(tile))) { + IInventory inv = InvTools.getInventoryFromTile(tile, side.getOpposite()); + if (inv != null) { + sides[side.ordinal()] = inv; + invs.add(inv); + } + } + } + if (sorter != null) + Collections.sort(invs, sorter); + } + } + +} diff --git a/src/main/java/forestry/core/inventory/AlyzerInventory.java b/src/main/java/forestry/core/inventory/AlyzerInventory.java new file mode 100644 index 000000000..20a9ffe51 --- /dev/null +++ b/src/main/java/forestry/core/inventory/AlyzerInventory.java @@ -0,0 +1,55 @@ +package forestry.core.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.core.config.ForestryItem; + +public abstract class AlyzerInventory extends ItemInventory { + + public static final int SLOT_SPECIMEN = 0; + public static final int SLOT_ANALYZE_1 = 1; + public static final int SLOT_ANALYZE_2 = 2; + public static final int SLOT_ANALYZE_3 = 3; + public static final int SLOT_ANALYZE_4 = 4; + public static final int SLOT_ANALYZE_5 = 6; + public static final int SLOT_ENERGY = 5; + + protected EntityPlayer player; + + public AlyzerInventory(Class itemClass, int size, ItemStack itemstack) { + super(itemClass, size, itemstack); + } + + protected boolean isEnergy(ItemStack itemstack) { + if (itemstack == null || itemstack.stackSize <= 0) + return false; + + return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + } + + protected boolean hasSpecimen() { + for (int i = SLOT_SPECIMEN; i <= SLOT_ANALYZE_5; i++) { + if (i == SLOT_ENERGY) + continue; + + ItemStack itemStack = getStackInSlot(i); + if (itemStack != null) + return true; + } + return false; + } + + protected abstract boolean isSpecimen(ItemStack itemStack); + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_ENERGY) { + return isEnergy(itemStack); + } else { + return !hasSpecimen() && isSpecimen(itemStack); + } + } + +} diff --git a/src/main/java/forestry/core/inventory/FakeInventoryAdapter.java b/src/main/java/forestry/core/inventory/FakeInventoryAdapter.java new file mode 100644 index 000000000..0aac42ff7 --- /dev/null +++ b/src/main/java/forestry/core/inventory/FakeInventoryAdapter.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import forestry.core.config.Defaults; + +public class FakeInventoryAdapter implements IInventoryAdapter { + + private static FakeInventoryAdapter instance; + + public static FakeInventoryAdapter instance() { + if (instance == null) { + instance = new FakeInventoryAdapter(); + } + return instance; + } + + private FakeInventoryAdapter() { + + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return false; + } + + @Override + public boolean isLocked(int slotIndex) { + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int p_94128_1_) { + return Defaults.SLOTS_NONE; + } + + @Override + public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) { + + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public void markDirty() { + + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() { + + } + + @Override + public void closeInventory() { + + } + + @Override + public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { + return false; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + + } + + @Override + public IInventoryAdapter configureSided(int[] sides, int[] slots) { + return this; + } +} diff --git a/src/main/java/forestry/core/inventory/IInventoryAdapter.java b/src/main/java/forestry/core/inventory/IInventoryAdapter.java new file mode 100644 index 000000000..218257b03 --- /dev/null +++ b/src/main/java/forestry/core/inventory/IInventoryAdapter.java @@ -0,0 +1,12 @@ +package forestry.core.inventory; + +import net.minecraft.inventory.ISidedInventory; + +import forestry.api.core.INBTTagable; +import forestry.core.interfaces.IFilterSlotDelegate; + +public interface IInventoryAdapter extends ISidedInventory, IFilterSlotDelegate, INBTTagable { + + /* Sided */ + public IInventoryAdapter configureSided(int[] sides, int[] slots); +} diff --git a/src/main/java/forestry/core/inventory/InvTools.java b/src/main/java/forestry/core/inventory/InvTools.java index b4b973c1c..0b24e07df 100755 --- a/src/main/java/forestry/core/inventory/InvTools.java +++ b/src/main/java/forestry/core/inventory/InvTools.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core.inventory; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; @@ -19,6 +20,7 @@ import java.util.TreeMap; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -32,9 +34,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; -import buildcraft.api.transport.PipeManager; +import cpw.mods.fml.common.Optional; -import forestry.api.core.ISpecialInventory; +import forestry.core.config.Defaults; import forestry.core.inventory.filters.ArrayStackFilter; import forestry.core.inventory.filters.IStackFilter; import forestry.core.inventory.filters.InvertedStackFilter; @@ -42,18 +44,23 @@ import forestry.core.inventory.filters.StackFilter; import forestry.core.inventory.manipulators.InventoryManipulator; import forestry.core.inventory.wrappers.ChestWrapper; import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryCopy; import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.inventory.wrappers.SidedInventoryMapper; -import forestry.core.inventory.wrappers.SpecialInventoryMapper; +import forestry.core.utils.AdjacentTileCache; import forestry.core.utils.PlainInventory; +import forestry.core.utils.StackUtils; +import forestry.plugins.PluginManager; + +import buildcraft.api.transport.IPipeTile; public abstract class InvTools { /*private static final String TAG_ID = "id"; - private static final String TAG_SIZE = "stackSize"; - private static final String TAG_DAMAGE = "Damage"; - private static final String TAG_COUNT = "Count";*/ + private static final String TAG_SIZE = "stackSize"; + private static final String TAG_DAMAGE = "Damage"; + private static final String TAG_COUNT = "Count";*/ private static final String TAG_SLOT = "Slot"; public static int getXOnSide(int x, ForgeDirection side) { @@ -130,9 +137,7 @@ public abstract class InvTools { public boolean matches(TileEntity tile) { if (type != null && !type.isAssignableFrom(tile.getClass())) return false; - if (exclude != null && exclude.isAssignableFrom(tile.getClass())) - return false; - return true; + return !(exclude != null && exclude.isAssignableFrom(tile.getClass())); } }); } @@ -148,9 +153,6 @@ public abstract class InvTools { if (tile == null || !(tile instanceof IInventory)) return null; - if (!PipeManager.canExtractItems(null, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) - return null; - if (tile instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) tile; return new ChestWrapper(chest); @@ -161,10 +163,7 @@ public abstract class InvTools { public static IInventory getInventory(IInventory inv, ForgeDirection side) { if (inv == null) return null; - - if (inv instanceof ISpecialInventory) - inv = new SpecialInventoryMapper((ISpecialInventory) inv, side); - else if (inv instanceof ISidedInventory) + if (inv instanceof ISidedInventory) inv = new SidedInventoryMapper((ISidedInventory) inv, side); return inv; } @@ -178,15 +177,14 @@ public abstract class InvTools { } /*public static void addItemToolTip(ItemStack stack, String tag, String msg) { - NBTTagCompound nbt = getItemData(stack); - NBTTagCompound display = nbt.getCompoundTag("display"); - nbt.setTag("display", display); - NBTTagList lore = display.getTagList("Lore", 8); // 8 = String - display.setTag("Lore", lore); - //lore.appendTag(new NBTTagString(tag, msg)); - lore.appendTag(new NBTTagString(msg)); - }*/ - + NBTTagCompound nbt = getItemData(stack); + NBTTagCompound display = nbt.getCompoundTag("display"); + nbt.setTag("display", display); + NBTTagList lore = display.getTagList("Lore", 8); // 8 = String + display.setTag("Lore", lore); + //lore.appendTag(new NBTTagString(tag, msg)); + lore.appendTag(new NBTTagString(msg)); + }*/ public static NBTTagCompound getItemData(ItemStack stack) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { @@ -258,9 +256,6 @@ public abstract class InvTools { /** * Counts the number of items. - * - * @param inv - * @return */ public static int countItems(IInventory inv) { int count = 0; @@ -298,10 +293,6 @@ public abstract class InvTools { * Counts the number of items that match the filter. Ignores * ISpecialInventory and ISidedInventory, and bypasses InventoryMapper to * count from the base IInventory. - * - * @param inv - * @param filters - * @return */ public static int countItems(IInventory inv, ItemStack... filters) { if (inv instanceof InventoryMapper) @@ -318,9 +309,8 @@ public abstract class InvTools { return countItems(inv); int count = 0; - ItemStack stack = null; - for (int slot = 0; slot < inv.getSizeInventory(); slot++) { - stack = inv.getStackInSlot(slot); + for (IInvSlot slot : InventoryIterator.getIterable(inv)) { + ItemStack stack = slot.getStackInSlot(); if (stack != null) for (ItemStack filter : filters) { if (filter != null && isItemEqual(stack, filter)) { @@ -332,7 +322,7 @@ public abstract class InvTools { return count; } - public static int countItems(Collection inventories, ItemStack... filter) { + public static int countItems(Iterable inventories, ItemStack... filter) { int count = 0; for (IInventory inv : inventories) { count += InvTools.countItems(inv, filter); @@ -378,9 +368,6 @@ public abstract class InvTools { /** * Attempts to move a single item from one inventory to another. - * - * @param source - * @param dest * @return null if nothing was moved, the stack moved otherwise */ public static ItemStack moveOneItem(IInventory source, IInventory dest) { @@ -389,10 +376,7 @@ public abstract class InvTools { /** * Attempts to move a single item from one inventory to another. - * - * @param source - * @param dest - * @param filer an ItemStack[] to match against + * @param filters an ItemStack[] to match against * @return null if nothing was moved, the stack moved otherwise */ public static ItemStack moveOneItem(IInventory source, IInventory dest, ItemStack... filters) { @@ -401,10 +385,7 @@ public abstract class InvTools { /** * Attempts to move a single item from one inventory to another. - * - * @param source - * @param dest - * @param filer an IItemType to match against + * @param filter an IItemType to match against * @return null if nothing was moved, the stack moved otherwise */ public static ItemStack moveOneItem(IInventory source, IInventory dest, IStackFilter filter) { @@ -414,13 +395,8 @@ public abstract class InvTools { /** * Attempts to move one item from a collection of inventories. - * - * @param sources - * @param dest - * @param filters - * @return */ - public static ItemStack moveOneItem(Collection sources, IInventory dest, ItemStack... filters) { + public static ItemStack moveOneItem(Iterable sources, IInventory dest, ItemStack... filters) { for (IInventory inv : sources) { ItemStack moved = InvTools.moveOneItem(inv, dest, filters); if (moved != null) @@ -431,13 +407,8 @@ public abstract class InvTools { /** * Attempts to move one item from a collection of inventories. - * - * @param sources - * @param dest - * @param filters - * @return */ - public static ItemStack moveOneItem(Collection sources, IInventory dest, IStackFilter filter) { + public static ItemStack moveOneItem(Iterable sources, IInventory dest, IStackFilter filter) { for (IInventory inv : sources) { ItemStack moved = InvTools.moveOneItem(inv, dest, filter); if (moved != null) @@ -448,13 +419,8 @@ public abstract class InvTools { /** * Attempts to move one item to a collection of inventories. - * - * @param sources - * @param dest - * @param filters - * @return */ - public static ItemStack moveOneItem(IInventory source, Collection destinations, ItemStack... filters) { + public static ItemStack moveOneItem(IInventory source, Iterable destinations, ItemStack... filters) { for (IInventory dest : destinations) { ItemStack moved = InvTools.moveOneItem(source, dest, filters); if (moved != null) @@ -468,9 +434,7 @@ public abstract class InvTools { * * Will not move any items in the filter. * - * @param source - * @param dest - * @param filer an ItemStack[] to exclude + * @param filters an ItemStack[] to exclude * @return null if nothing was moved, the stack moved otherwise */ public static ItemStack moveOneItemExcept(IInventory source, IInventory dest, ItemStack... filters) { @@ -479,13 +443,8 @@ public abstract class InvTools { /** * Attempts to move one item from a collection of inventories. - * - * @param sources - * @param dest - * @param filters - * @return */ - public static ItemStack moveOneItemExcept(Collection sources, IInventory dest, ItemStack... filters) { + public static ItemStack moveOneItemExcept(Iterable sources, IInventory dest, ItemStack... filters) { for (IInventory inv : sources) { ItemStack moved = InvTools.moveOneItemExcept(inv, dest, filters); if (moved != null) @@ -496,13 +455,8 @@ public abstract class InvTools { /** * Attempts to move one item to a collection of inventories. - * - * @param sources - * @param dest - * @param filters - * @return */ - public static ItemStack moveOneItemExcept(IInventory source, Collection destinations, ItemStack... filters) { + public static ItemStack moveOneItemExcept(IInventory source, Iterable destinations, ItemStack... filters) { for (IInventory dest : destinations) { ItemStack moved = InvTools.moveOneItemExcept(source, dest, filters); if (moved != null) @@ -619,10 +573,6 @@ public abstract class InvTools { /** * Returns true if the item is equal to any one of several possible matches. - * - * @param stack - * @param matches - * @return */ public static boolean isItemEqual(ItemStack stack, ItemStack... matches) { for (ItemStack match : matches) { @@ -634,10 +584,6 @@ public abstract class InvTools { /** * Returns true if the item is equal to any one of several possible matches. - * - * @param stack - * @param matches - * @return */ public static boolean isItemEqual(ItemStack stack, Collection matches) { for (ItemStack match : matches) { @@ -661,6 +607,41 @@ public abstract class InvTools { return im.addStack(stack); } + /** + * Attempts to move an ItemStack from one inventory to another. + * + * @param source The source IInventory. + * @param dest The destination IInventory. + * @return true if any items were moved + */ + public static boolean moveItemStack(IInventory source, IInventory dest) { + InventoryManipulator im = InventoryManipulator.get(dest); + for (IInvSlot slot : InventoryIterator.getIterable(source)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null) { + ItemStack remainder = im.addStack(stack); + slot.setStackInSlot(remainder); + return !isItemEqualStrict(stack, remainder); + } + } + return false; + } + + /** + * Attempts to move an ItemStack from one inventory to another. + * + * @param source The source IInventory. + * @param destinations The destination IInventory. + * @return true if any items were moved + */ + public static boolean moveItemStack(IInventory source, Iterable destinations) { + for (IInventory dest : destinations) { + if (moveItemStack(source, dest)) + return true; + } + return false; + } + /** * Checks if there is room for the ItemStack in the inventory. * @@ -678,14 +659,8 @@ public abstract class InvTools { /** * Removes a up to numItems worth of items from the inventory, not caring * about what the items are. - * - * @param inv - * @param numItems - * @return */ public static ItemStack[] removeItems(IInventory inv, int numItems) { - if (inv instanceof ISpecialInventory) - return ((ISpecialInventory) inv).extractItem(true, ForgeDirection.UNKNOWN, numItems); PlainInventory output = new PlainInventory(27, "temp"); for (int i = 0; i < inv.getSizeInventory(); i++) { if (numItems <= 0) @@ -750,11 +725,11 @@ public abstract class InvTools { * Removes and returns a single item from the inventory that matches the * filter. * - * @param inv The inventory + * @param invs The inventory * @param filter EnumItemType to match against * @return An ItemStack */ - public static ItemStack removeOneItem(Collection invs, IStackFilter filter) { + public static ItemStack removeOneItem(Iterable invs, IStackFilter filter) { for (IInventory inv : invs) { ItemStack stack = removeOneItem(inv, filter); if (stack != null) @@ -763,6 +738,61 @@ public abstract class InvTools { return null; } + /** + * Attempts to move a single item from the source inventory into a adjacent Buildcraft pipe. + * If the attempt fails, the source Inventory will not be modified. + * + * @param source The source inventory + * @param tileCache The tile cache of the source block. + * @return true if an item was inserted, otherwise false. + */ + public static boolean moveOneItemToPipe(IInventory source, AdjacentTileCache tileCache) { + return moveOneItemToPipe(source, tileCache, ForgeDirection.VALID_DIRECTIONS); + } + + public static boolean moveOneItemToPipe(IInventory source, AdjacentTileCache tileCache, ForgeDirection[] directions) { + if (PluginManager.Module.BUILDCRAFT_TRANSPORT.isEnabled()) { + return internal_moveOneItemToPipe(source, tileCache, directions); + } + + return false; + } + + @Optional.Method(modid = "BuildCraftAPI|transport") + private static boolean internal_moveOneItemToPipe(IInventory source, AdjacentTileCache tileCache, ForgeDirection[] directions) { + IInventory invClone = new InventoryCopy(source); + ItemStack stackToMove = removeOneItem(invClone); + if (stackToMove == null) + return false; + if (stackToMove.stackSize <= 0) + return false; + + List> pipes = new ArrayList>(); + boolean foundPipe = false; + for (ForgeDirection side : directions) { + TileEntity tile = tileCache.getTileOnSide(side); + if (tile instanceof IPipeTile) { + IPipeTile pipe = (IPipeTile) tile; + if (pipe.getPipeType() == IPipeTile.PipeType.ITEM && pipe.isPipeConnected(side.getOpposite())) { + pipes.add(new AbstractMap.SimpleEntry(side, pipe)); + foundPipe = true; + } + } + } + + if (!foundPipe) + return false; + + int choice = tileCache.getSource().getWorldObj().rand.nextInt(pipes.size()); + Map.Entry pipe = pipes.get(choice); + if (pipe.getValue().injectItem(stackToMove, false, pipe.getKey().getOpposite(), null) > 0) + if (removeOneItem(source, stackToMove) != null) { + pipe.getValue().injectItem(stackToMove, true, pipe.getKey().getOpposite(), null); + return true; + } + return false; + } + public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) { NBTTagList list = new NBTTagList(); for (byte slot = 0; slot < inv.getSizeInventory(); slot++) { @@ -796,4 +826,252 @@ public abstract class InvTools { stack.stackSize = 127; stack.writeToNBT(data); } + + public static IInventoryAdapter configureSidedUp(IInventoryAdapter inventory, int startSlot, int count) { + return configureSided(inventory, Defaults.FACING_UP, startSlot, count); + } + + public static IInventoryAdapter configureSidedDown(IInventoryAdapter inventory, int startSlot, int count) { + return configureSided(inventory, Defaults.FACING_DOWN, startSlot, count); + } + + public static IInventoryAdapter configureSidedNorthSouth(IInventoryAdapter inventory, int startSlot, int count) { + return configureSided(inventory, Defaults.FACING_NORTHSOUTH, startSlot, count); + } + + public static IInventoryAdapter configureSidedWestEast(IInventoryAdapter inventory, int startSlot, int count) { + return configureSided(inventory, Defaults.FACING_WESTEAST, startSlot, count); + } + + public static IInventoryAdapter configureSidedSides(IInventoryAdapter inventory, int startSlot, int count) { + return configureSided(inventory, Defaults.FACING_SIDES, startSlot, count); + } + + public static IInventoryAdapter configureSided(IInventoryAdapter inventory, int side, int startSlot, int count) { + return configureSided(inventory, new int[]{side}, startSlot, count); + } + + public static IInventoryAdapter configureSided(IInventoryAdapter inventory, int[] sides, int startSlot, int count) { + int[] slots = new int[count]; + for (int i = 0; i < count; i++) { + slots[i] = startSlot + i; + } + + return inventory.configureSided(sides, slots); + } + + /* REMOVAL */ + /** + * Removes a set of items from an inventory. + * Removes the exact items first if they exist, and then removes crafting equivalents. + * If the inventory doesn't have all the required items, returns false without removing anything. + * If stowContainer is true, items with containers will have their container stowed. + */ + public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) { + + ItemStack[] condensedSet = StackUtils.condenseStacks(set, -1, false); + + ItemStack[] stock = getStacks(inventory, firstSlotIndex, slotCount); + if (StackUtils.containsSets(condensedSet, stock, oreDictionary, craftingTools) < count) + return false; + + for (ItemStack stackToRemove : condensedSet) { + stackToRemove.stackSize *= count; + + // try to remove the exact stack first + removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, false, false); + + // remove crafting equivalents next + if (stackToRemove.stackSize > 0) + removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, craftingTools); + } + return true; + } + + /** + * Private Helper for removeSetsFromInventory. Assumes removal is possible. + */ + private static void removeStack(IInventory inventory, ItemStack stackToRemove, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) { + for (int j = firstSlotIndex; j < firstSlotIndex + slotCount; j++) { + ItemStack stackInSlot = inventory.getStackInSlot(j); + if (stackInSlot == null) + continue; + + if (!StackUtils.isCraftingEquivalent(stackToRemove, stackInSlot, oreDictionary, craftingTools)) + continue; + + ItemStack removed = inventory.decrStackSize(j, stackToRemove.stackSize); + stackToRemove.stackSize -= removed.stackSize; + + if (stowContainer && stackToRemove.getItem().hasContainerItem(stackToRemove)) + StackUtils.stowContainerItem(removed, inventory, j, player); + + if (stackToRemove.stackSize == 0) + return; + } + } + + /* CONTAINS */ + public static boolean contains(IInventory inventory, ItemStack query, int startSlot, int slots) { + ItemStack[] queryArray = new ItemStack[]{query}; + return contains(inventory, queryArray, startSlot, slots); + } + + public static boolean contains(IInventory inventory, ItemStack[] query, int startSlot, int slots) { + ItemStack[] stock = getStacks(inventory, startSlot, slots); + return StackUtils.containsSets(query, stock) > 0; + } + + public static boolean containsPercent(IInventory inventory, float percent, int slot1, int length) { + int amount = 0; + int stackMax = 0; + for (ItemStack itemStack : getStacks(inventory, slot1, length)) { + if (itemStack == null) { + stackMax += 64; + continue; + } + + amount += itemStack.stackSize; + stackMax += itemStack.getMaxStackSize(); + } + if (stackMax == 0) + return false; + return ((float) amount / (float) stackMax) >= percent; + } + + public static boolean containsAmount(IInventory inventory, int amount, int slot1, int length) { + int total = 0; + for (ItemStack itemStack : getStacks(inventory, slot1, length)) { + if (itemStack == null) + continue; + + total += itemStack.stackSize; + if (total >= amount) + return true; + } + return false; + } + + public static ItemStack[] getStacks(IInventory inventory) { + ItemStack[] stacks = new ItemStack[inventory.getSizeInventory()]; + for (int i = 0; i < inventory.getSizeInventory(); i++) { + stacks[i] = inventory.getStackInSlot(i); + } + return stacks; + } + + public static ItemStack[] getStacks(IInventory inventory, int slot1, int length) { + ItemStack[] result = new ItemStack[length]; + for (int i = slot1; i < slot1 + length; i++) { + result[i - slot1] = inventory.getStackInSlot(i); + } + return result; + } + + public static boolean tryAddStacksCopy(IInventory inventory, ItemStack[] stacks, boolean all) { + return tryAddStacksCopy(inventory, stacks, 0, inventory.getSizeInventory(), all); + } + + public static boolean tryAddStacksCopy(IInventory inventory, ItemStack[] stacks, int startSlot, int slots, boolean all) { + + for (ItemStack stack : stacks) { + if (stack == null) + continue; + + if (!tryAddStack(inventory, stack.copy(), startSlot, slots, all)) + return false; + } + + return true; + } + + public static boolean tryAddStacks(IInventory inventory, ItemStack[] stacks, boolean all) { + + boolean addedAll = true; + for (ItemStack stack : stacks) { + if (stack == null) + continue; + + if (!tryAddStack(inventory, stack, all)) + addedAll = false; + } + + return addedAll; + } + + public static boolean tryAddStack(IInventory inventory, ItemStack stack, boolean all) { + return tryAddStack(inventory, stack, 0, inventory.getSizeInventory(), all); + } + + /** + * Tries to add a stack to the specified slot range. + */ + public static boolean tryAddStack(IInventory inventory, ItemStack stack, int startSlot, int slots, boolean all) { + return tryAddStack(inventory, stack, startSlot, slots, all, true); + } + + public static boolean tryAddStack(IInventory inventory, ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) { + int added = addStack(inventory, stack, startSlot, slots, all, doAdd); + if (all) + return added == stack.stackSize; + else + return added > 0; + } + + public static int addStack(IInventory inventory, ItemStack stack, boolean all, boolean doAdd) { + return addStack(inventory, stack, 0, inventory.getSizeInventory(), all, doAdd); + } + + public static int addStack(IInventory inventory, ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) { + + int added = 0; + // Add to existing stacks first + for (int i = startSlot; i < startSlot + slots; i++) { + + // Empty slot. Add + if (inventory.getStackInSlot(i) == null) + continue; + + // Already occupied by different item, skip this slot. + if (!inventory.getStackInSlot(i).isItemEqual(stack)) + continue; + if (!ItemStack.areItemStackTagsEqual(inventory.getStackInSlot(i), stack)) + continue; + + int remain = stack.stackSize - added; + int space = inventory.getStackInSlot(i).getMaxStackSize() - inventory.getStackInSlot(i).stackSize; + // No space left, skip this slot. + if (space <= 0) + continue; + // Enough space + if (space >= remain) { + if (doAdd) + inventory.getStackInSlot(i).stackSize += remain; + return stack.stackSize; + } + + // Not enough space + if (doAdd) + inventory.getStackInSlot(i).stackSize = inventory.getStackInSlot(i).getMaxStackSize(); + + added += space; + } + + if (added >= stack.stackSize) + return added; + + for (int i = startSlot; i < startSlot + slots; i++) { + if (inventory.getStackInSlot(i) != null) + continue; + + if (doAdd) { + inventory.setInventorySlotContents(i, stack.copy()); + inventory.getStackInSlot(i).stackSize = stack.stackSize - added; + } + return stack.stackSize; + + } + + return added; + } } diff --git a/src/main/java/forestry/core/inventory/InventoryAdapter.java b/src/main/java/forestry/core/inventory/InventoryAdapter.java new file mode 100755 index 000000000..15c77c78b --- /dev/null +++ b/src/main/java/forestry/core/inventory/InventoryAdapter.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.inventory; + +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 forestry.core.config.Defaults; +import forestry.core.utils.PlainInventory; + +/** + * With permission from Krapht. + */ +public class InventoryAdapter implements IInventoryAdapter { + + protected final IInventory inventory; + private boolean allowAutomation = true; + + //private boolean debug = false; + + public InventoryAdapter(int size, String name) { + this(size, name, 64); + } + + public InventoryAdapter(int size, String name, int stackLimit) { + this(new PlainInventory(size, name, stackLimit)); + } + + public InventoryAdapter(IInventory inventory) { + this.inventory = inventory; + configureSided(); + } + + public InventoryAdapter disableAutomation() { + this.allowAutomation = false; + return this; + } + +// public InventoryAdapter enableDebug() { +// this.debug = true; +// return this; +// } + /** + * @return Copy of this inventory. Stacks are copies. + */ + public InventoryAdapter copy() { + InventoryAdapter copy = new InventoryAdapter(inventory.getSizeInventory(), inventory.getInventoryName(), inventory.getInventoryStackLimit()); + + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (inventory.getStackInSlot(i) != null) + copy.setInventorySlotContents(i, inventory.getStackInSlot(i).copy()); + } + + return copy; + } + + + + /* IINVENTORY */ + @Override + public int getSizeInventory() { + return inventory.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int slotId) { + return inventory.getStackInSlot(slotId); + } + + @Override + public ItemStack decrStackSize(int slotId, int count) { + return inventory.decrStackSize(slotId, count); + } + + @Override + public void setInventorySlotContents(int slotId, ItemStack itemstack) { + inventory.setInventorySlotContents(slotId, itemstack); + } + + @Override + public String getInventoryName() { + return inventory.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + return inventory.getInventoryStackLimit(); + } + + @Override + public void markDirty() { + inventory.markDirty(); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slotIndex) { + return inventory.getStackInSlotOnClosing(slotIndex); + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return true; + } + + @Override + public boolean hasCustomInventoryName() { + return true; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return true; + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return true; + } + + @Override + public boolean isLocked(int slotIndex) { + return false; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + /* ISIDEDINVENTORY */ + private int[][] slotMap; + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + if (allowAutomation) + return slotMap[side]; + return Defaults.SLOTS_NONE; + } + + private void configureSided() { + slotMap = new int[6][0]; + InvTools.configureSided(this, Defaults.FACINGS, 0, getSizeInventory()); + } + + @Override + public InventoryAdapter configureSided(int[] sides, int[] slots) { + for (int side : sides) { + slotMap[side] = slots; + } + + return this; + } + + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side) { + return isItemValidForSlot(slot, stack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) { + return false; + } + + /* SAVING & LOADING */ + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + if (!nbttagcompound.hasKey(inventory.getInventoryName())) + return; + + NBTTagList nbttaglist = nbttagcompound.getTagList(inventory.getInventoryName(), 10); + + for (int j = 0; j < nbttaglist.tagCount(); ++j) { + NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); + int index = nbttagcompound2.getByte("Slot"); + inventory.setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(nbttagcompound2)); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < inventory.getSizeInventory(); i++) { + if (inventory.getStackInSlot(i) != null) { + NBTTagCompound nbttagcompound2 = new NBTTagCompound(); + nbttagcompound2.setByte("Slot", (byte) i); + inventory.getStackInSlot(i).writeToNBT(nbttagcompound2); + nbttaglist.appendTag(nbttagcompound2); + } + } + nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist); + } +} diff --git a/src/main/java/forestry/core/inventory/InventoryConcatenator.java b/src/main/java/forestry/core/inventory/InventoryConcatenator.java index 55c0d31bb..0bdaa174c 100755 --- a/src/main/java/forestry/core/inventory/InventoryConcatenator.java +++ b/src/main/java/forestry/core/inventory/InventoryConcatenator.java @@ -12,7 +12,6 @@ package forestry.core.inventory; import java.util.ArrayList; import java.util.List; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; diff --git a/src/main/java/forestry/core/inventory/InventorySorter.java b/src/main/java/forestry/core/inventory/InventorySorter.java index b20aabb8c..f40398ba4 100755 --- a/src/main/java/forestry/core/inventory/InventorySorter.java +++ b/src/main/java/forestry/core/inventory/InventorySorter.java @@ -11,7 +11,6 @@ package forestry.core.inventory; import java.util.Comparator; - import net.minecraft.inventory.IInventory; /** diff --git a/src/main/java/forestry/core/utils/ItemInventory.java b/src/main/java/forestry/core/inventory/ItemInventory.java similarity index 80% rename from src/main/java/forestry/core/utils/ItemInventory.java rename to src/main/java/forestry/core/inventory/ItemInventory.java index 5b122489a..89eda851f 100755 --- a/src/main/java/forestry/core/utils/ItemInventory.java +++ b/src/main/java/forestry/core/inventory/ItemInventory.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.utils; +package forestry.core.inventory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -18,25 +18,21 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import forestry.api.core.INBTTagable; +import forestry.core.interfaces.IFilterSlotDelegate; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; -public class ItemInventory implements IInventory, INBTTagable { +public class ItemInventory implements IInventory, IFilterSlotDelegate, INBTTagable { public final Class itemClass; - public boolean isItemInventory = false; + public final boolean isItemInventory; public ItemStack parent; protected ItemStack[] inventoryStacks; - protected ItemInventory(Class itemClass) { - this.itemClass = itemClass; - } - - public ItemInventory(Class itemClass, int slots) { - this(itemClass); - inventoryStacks = new ItemStack[slots]; - } - public ItemInventory(Class itemClass, int size, ItemStack itemstack) { - this(itemClass, size); + this.itemClass = itemClass; + + inventoryStacks = new ItemStack[size]; parent = itemstack; isItemInventory = true; @@ -77,46 +73,18 @@ public class ItemInventory implements IInventory, INBTTagable { } public void onGuiSaved(EntityPlayer player) { - parent = findParent(player); + parent = findParentInInventory(player); if (parent != null) save(); } - public ItemStack findParent(EntityPlayer player) { - if (parent == null) - return null; - - NBTTagCompound parentNBT = parent.getTagCompound(); - if (parentNBT == null) - return null; - - int uid = parentNBT.getInteger("UID"); - + public ItemStack findParentInInventory(EntityPlayer player) { for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack stack = player.inventory.getStackInSlot(i); - if (stack == null) - continue; - if(stack.getItem() != parent.getItem()) - continue; - NBTTagCompound slotNBT = stack.getTagCompound(); - if (slotNBT == null) - continue; - if (uid == slotNBT.getInteger("UID")) - return player.inventory.getStackInSlot(i); + if (StackUtils.isIdenticalItem(stack, parent)) + return stack; } - return null; - } - - public boolean matchesUID(int otherId) { - if (parent == null) - return false; - - NBTTagCompound nbt = parent.getTagCompound(); - if (nbt == null) - return false; - - int uid = nbt.getInteger("UID"); - return uid == otherId; + return parent; } public void save() { @@ -220,10 +188,20 @@ public class ItemInventory implements IInventory, INBTTagable { } @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { + public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { + return canSlotAccept(slotIndex, itemStack); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { return true; } + @Override + public boolean isLocked(int slotIndex) { + return false; + } + @Override public void openInventory() { } diff --git a/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java b/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java new file mode 100644 index 000000000..fc38a1149 --- /dev/null +++ b/src/main/java/forestry/core/inventory/ItemInventoryBackpack.java @@ -0,0 +1,33 @@ +package forestry.core.inventory; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.api.storage.IBackpackDefinition; +import forestry.storage.items.ItemBackpack; + +public class ItemInventoryBackpack extends ItemInventory { + + private final IBackpackDefinition backpackDefinition; + + public ItemInventoryBackpack(Class itemClass, int size, ItemStack itemstack) { + super(itemClass, size, itemstack); + + if (parent == null) + throw new IllegalArgumentException("Parent cannot be null."); + + Item item = parent.getItem(); + if (!(item instanceof ItemBackpack)) + throw new IllegalArgumentException("Parent must be a backpack."); + + this.backpackDefinition = ((ItemBackpack) item).getDefinition(); + + if (this.backpackDefinition == null) + throw new IllegalArgumentException("Backpack must have a backpack definition."); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return backpackDefinition.isValidItem(null, itemStack); + } +} diff --git a/src/main/java/forestry/core/inventory/ItemStackMap.java b/src/main/java/forestry/core/inventory/ItemStackMap.java index 85e18cab6..8fee3212d 100755 --- a/src/main/java/forestry/core/inventory/ItemStackMap.java +++ b/src/main/java/forestry/core/inventory/ItemStackMap.java @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; - import net.minecraft.item.ItemStack; /** diff --git a/src/main/java/forestry/core/inventory/ItemStackSet.java b/src/main/java/forestry/core/inventory/ItemStackSet.java index af3d35be0..73ea63f82 100755 --- a/src/main/java/forestry/core/inventory/ItemStackSet.java +++ b/src/main/java/forestry/core/inventory/ItemStackSet.java @@ -15,7 +15,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Set; - import net.minecraft.item.ItemStack; /** diff --git a/src/main/java/forestry/core/utils/TileInventoryAdapter.java b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java similarity index 82% rename from src/main/java/forestry/core/utils/TileInventoryAdapter.java rename to src/main/java/forestry/core/inventory/TileInventoryAdapter.java index d88b17f40..6708a738f 100755 --- a/src/main/java/forestry/core/utils/TileInventoryAdapter.java +++ b/src/main/java/forestry/core/inventory/TileInventoryAdapter.java @@ -8,9 +8,9 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.core.utils; +package forestry.core.inventory; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import forestry.core.gadgets.TileForestry; @@ -19,8 +19,7 @@ public class TileInventoryAdapter extends InventoryAdapter { private final TileForestry tile; public TileInventoryAdapter(TileForestry tile, int size, String name) { - super(size, name); - this.tile = tile; + this(tile, size, name, 64); } public TileInventoryAdapter(TileForestry tile, int size, String name, int stackLimit) { @@ -28,14 +27,14 @@ public class TileInventoryAdapter extends InventoryAdapter { this.tile = tile; } - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } - @Override public void markDirty() { super.markDirty(); tile.markDirty(); } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return false; + } } diff --git a/src/main/java/forestry/core/inventory/filters/ArrayStackFilter.java b/src/main/java/forestry/core/inventory/filters/ArrayStackFilter.java index 9e9a7fb3a..3b8f166f4 100755 --- a/src/main/java/forestry/core/inventory/filters/ArrayStackFilter.java +++ b/src/main/java/forestry/core/inventory/filters/ArrayStackFilter.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core.inventory.filters; -import net.minecraft.item.ItemStack; - import forestry.core.inventory.InvTools; +import net.minecraft.item.ItemStack; /** * @author CovertJaguar diff --git a/src/main/java/forestry/core/inventory/manipulators/InventoryManipulator.java b/src/main/java/forestry/core/inventory/manipulators/InventoryManipulator.java index 8d1a6fcfd..f0d611b80 100755 --- a/src/main/java/forestry/core/inventory/manipulators/InventoryManipulator.java +++ b/src/main/java/forestry/core/inventory/manipulators/InventoryManipulator.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.core.inventory.manipulators; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import forestry.api.core.ISpecialInventory; import forestry.core.inventory.InvTools; import forestry.core.inventory.filters.IStackFilter; import forestry.core.inventory.wrappers.IInvSlot; import forestry.core.inventory.wrappers.InventoryIterator; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; /** * @author CovertJaguar @@ -30,9 +27,6 @@ public class InventoryManipulator { private final IInventory inv; public static InventoryManipulator get(IInventory inv) { - if (inv instanceof ISpecialInventory) { - return new SpecialManipulator((ISpecialInventory) inv); - } return new InventoryManipulator(inv); } @@ -54,8 +48,6 @@ public class InventoryManipulator { /** * Attempt to add the stack to the inventory. - * - * @param stack * @return The remainder */ public ItemStack addStack(ItemStack stack) { @@ -109,10 +101,7 @@ public class InventoryManipulator { } /** - * @param slot - * @param stack * @param available Amount we can move - * @param doAdd * @return Return the number of items moved. */ private int addToSlot(IInvSlot slot, ItemStack stack, int available, boolean doAdd) { diff --git a/src/main/java/forestry/core/inventory/manipulators/SpecialManipulator.java b/src/main/java/forestry/core/inventory/manipulators/SpecialManipulator.java deleted file mode 100755 index e9547b537..000000000 --- a/src/main/java/forestry/core/inventory/manipulators/SpecialManipulator.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.inventory.manipulators; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import net.minecraftforge.common.util.ForgeDirection; - -import forestry.api.core.ISpecialInventory; -import forestry.core.inventory.filters.IStackFilter; - -/** - * - * @author CovertJaguar - */ -public class SpecialManipulator extends InventoryManipulator { - - private final ISpecialInventory inv; - protected ForgeDirection side = ForgeDirection.UNKNOWN; - - protected SpecialManipulator(ISpecialInventory inv) { - super(inv); - this.inv = inv; - } - - public void setSide(ForgeDirection side) { - this.side = side; - } - - @Override - public ItemStack tryAddStack(ItemStack stack) { - return addStackInternal(stack, false); - } - - @Override - public ItemStack addStack(ItemStack stack) { - return addStackInternal(stack, true); - } - - private ItemStack addStackInternal(ItemStack stack, boolean doAdd) { - if (stack == null) { - return null; - } - stack = stack.copy(); - int used = inv.addItem(stack.copy(), doAdd, side); - if (used >= stack.stackSize) { - return null; - } - stack.stackSize -= used; - return stack; - } - - @Override - public boolean canRemoveItem(IStackFilter filter) { - return tryRemoveItem(filter) == null; - } - - @Override - public ItemStack tryRemoveItem(IStackFilter filter) { - return removeStackInternal(filter, false); - } - - @Override - public ItemStack removeItem(IStackFilter filter) { - return removeStackInternal(filter, true); - } - - protected ItemStack removeStackInternal(IStackFilter filter, boolean doRemove) { - ItemStack[] extracted = inv.extractItem(false, side, 1); - if (extracted != null && extracted.length > 0 && filter.matches(extracted[0])) { - if (doRemove) { - inv.extractItem(true, side, 1); - } - return extracted[0]; - } - return null; - } - - @Override - public ItemStack moveItem(IInventory dest, IStackFilter filter) { - InventoryManipulator imDest = InventoryManipulator.get(dest); - ItemStack stack = tryRemoveItem(filter); - if (stack != null) { - ItemStack result = imDest.addStack(stack); - if (result == null) { - return removeItem(filter); - } - } - return null; - } - -} diff --git a/src/main/java/forestry/core/inventory/wrappers/InventoryIterator.java b/src/main/java/forestry/core/inventory/wrappers/InventoryIterator.java index 654e0e243..f9f4c3a7d 100755 --- a/src/main/java/forestry/core/inventory/wrappers/InventoryIterator.java +++ b/src/main/java/forestry/core/inventory/wrappers/InventoryIterator.java @@ -11,7 +11,6 @@ package forestry.core.inventory.wrappers; import java.util.Iterator; - import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -32,7 +31,7 @@ public class InventoryIterator implements Iterable { private InventoryIterator(IInventory inv) { this.inv = inv; - this.invSize = inv.getSizeInventory(); + this.invSize = inv != null ? inv.getSizeInventory() : 0; } @Override diff --git a/src/main/java/forestry/core/inventory/wrappers/InventoryMapper.java b/src/main/java/forestry/core/inventory/wrappers/InventoryMapper.java index a13246998..a5b83e189 100755 --- a/src/main/java/forestry/core/inventory/wrappers/InventoryMapper.java +++ b/src/main/java/forestry/core/inventory/wrappers/InventoryMapper.java @@ -13,7 +13,6 @@ package forestry.core.inventory.wrappers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; - import net.minecraftforge.common.util.ForgeDirection; /** diff --git a/src/main/java/forestry/core/inventory/wrappers/SidedInventoryIterator.java b/src/main/java/forestry/core/inventory/wrappers/SidedInventoryIterator.java index 71ca7007a..aa823fd2d 100755 --- a/src/main/java/forestry/core/inventory/wrappers/SidedInventoryIterator.java +++ b/src/main/java/forestry/core/inventory/wrappers/SidedInventoryIterator.java @@ -11,7 +11,6 @@ package forestry.core.inventory.wrappers; import java.util.Iterator; - import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; diff --git a/src/main/java/forestry/core/inventory/wrappers/SidedInventoryMapper.java b/src/main/java/forestry/core/inventory/wrappers/SidedInventoryMapper.java index 4b3afe28e..dcb013c9e 100755 --- a/src/main/java/forestry/core/inventory/wrappers/SidedInventoryMapper.java +++ b/src/main/java/forestry/core/inventory/wrappers/SidedInventoryMapper.java @@ -14,7 +14,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; - import net.minecraftforge.common.util.ForgeDirection; /** diff --git a/src/main/java/forestry/core/inventory/wrappers/SpecialInventoryMapper.java b/src/main/java/forestry/core/inventory/wrappers/SpecialInventoryMapper.java deleted file mode 100755 index e84c74e98..000000000 --- a/src/main/java/forestry/core/inventory/wrappers/SpecialInventoryMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.inventory.wrappers; - -import net.minecraft.item.ItemStack; - -import net.minecraftforge.common.util.ForgeDirection; - -import forestry.api.core.ISpecialInventory; - -/** - * - * @author CovertJaguar - */ -public class SpecialInventoryMapper extends InventoryMapper implements ISpecialInventory -{ - - private final ISpecialInventory inv; - protected final ForgeDirection side; - - public SpecialInventoryMapper(ISpecialInventory inv, ForgeDirection side) - { - super(inv, side); - this.inv = inv; - this.side = side; - } - - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) - { - return inv.addItem(stack, doAdd, side); - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) - { - return inv.extractItem(doRemove, side, maxItemCount); - } -} diff --git a/src/main/java/forestry/core/items/ItemArmorNaturalist.java b/src/main/java/forestry/core/items/ItemArmorNaturalist.java index b61620889..d533b9e0e 100755 --- a/src/main/java/forestry/core/items/ItemArmorNaturalist.java +++ b/src/main/java/forestry/core/items/ItemArmorNaturalist.java @@ -10,6 +10,13 @@ ******************************************************************************/ package forestry.core.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.IArmorNaturalist; +import forestry.core.CreativeTabForestry; +import forestry.core.config.Defaults; +import forestry.core.render.TextureManager; +import forestry.core.utils.StringUtil; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -17,15 +24,6 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.core.IArmorNaturalist; -import forestry.core.CreativeTabForestry; -import forestry.core.config.Defaults; -import forestry.core.render.TextureManager; -import forestry.core.utils.StringUtil; - public class ItemArmorNaturalist extends ItemArmor implements IArmorNaturalist { public ItemArmorNaturalist(int slot) { diff --git a/src/main/java/forestry/core/items/ItemAssemblyKit.java b/src/main/java/forestry/core/items/ItemAssemblyKit.java index 803e53ec0..27a74f9b8 100755 --- a/src/main/java/forestry/core/items/ItemAssemblyKit.java +++ b/src/main/java/forestry/core/items/ItemAssemblyKit.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.core.items; +import forestry.core.proxy.Proxies; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import forestry.core.proxy.Proxies; - public class ItemAssemblyKit extends ItemForestry { private final ItemStack assembled; private final boolean motionOnOpen; diff --git a/src/main/java/forestry/core/items/ItemCrated.java b/src/main/java/forestry/core/items/ItemCrated.java index 1a20d8510..013301a27 100755 --- a/src/main/java/forestry/core/items/ItemCrated.java +++ b/src/main/java/forestry/core/items/ItemCrated.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.core.items; -import java.util.Locale; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; @@ -30,20 +29,20 @@ import forestry.core.utils.StringUtil; public class ItemCrated extends Item implements IGenericCrate { - private ItemStack contained; + private final ItemStack contained; + private final boolean usesOreDict; - public ItemCrated() { - this(null); + public ItemCrated(ItemStack contained, boolean usesOreDict) { + this.contained = contained; + this.usesOreDict = usesOreDict; } - public ItemCrated(ItemStack contained) { - super(); - this.contained = contained; + public boolean usesOreDict() { + return usesOreDict; } @Override public void setContained(ItemStack crated, ItemStack contained) { - this.contained = contained; } @Override @@ -83,16 +82,18 @@ public class ItemCrated extends Item implements IGenericCrate { @Override public String getItemStackDisplayName(ItemStack itemstack) { - if (contained != null) + if (contained == null) { + return StatCollector.translateToLocal("item.for.crate.name"); + } else { return StringUtil.localize("item.crated.adj") + " " + Proxies.common.getDisplayName(contained); - else - return StringUtil.localize("item.crated.unknown"); + } } @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister register) { - itemIcon = TextureManager.getInstance().registerTex(register, "crates/" + getUnlocalizedName().replace("item.for.crated", "").toLowerCase(Locale.ENGLISH)); + String textureName = (contained == null) ? "crate" : "crate-filled"; + itemIcon = TextureManager.getInstance().registerTex(register, textureName); } } diff --git a/src/main/java/forestry/core/items/ItemForestry.java b/src/main/java/forestry/core/items/ItemForestry.java index 86720698b..a97d79330 100755 --- a/src/main/java/forestry/core/items/ItemForestry.java +++ b/src/main/java/forestry/core/items/ItemForestry.java @@ -10,6 +10,12 @@ ******************************************************************************/ package forestry.core.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import forestry.core.utils.StringUtil; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -17,14 +23,6 @@ import net.minecraft.item.ItemDye; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.CreativeTabForestry; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.StringUtil; - public class ItemForestry extends Item { private boolean isBonemeal = false; diff --git a/src/main/java/forestry/core/items/ItemForestryFood.java b/src/main/java/forestry/core/items/ItemForestryFood.java index d490402ac..7acaf4fba 100755 --- a/src/main/java/forestry/core/items/ItemForestryFood.java +++ b/src/main/java/forestry/core/items/ItemForestryFood.java @@ -12,6 +12,7 @@ package forestry.core.items; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.CreativeTabForestry; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; import net.minecraft.client.renderer.texture.IIconRegister; @@ -19,9 +20,6 @@ import net.minecraft.item.EnumAction; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; - -import forestry.core.CreativeTabForestry; - public class ItemForestryFood extends ItemFood { private boolean isDrink = false; diff --git a/src/main/java/forestry/core/items/ItemForestryMultiPass.java b/src/main/java/forestry/core/items/ItemForestryMultiPass.java index 5b8d28cae..2dd577742 100644 --- a/src/main/java/forestry/core/items/ItemForestryMultiPass.java +++ b/src/main/java/forestry/core/items/ItemForestryMultiPass.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.core.items; -import net.minecraft.client.renderer.texture.IIconRegister; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; +import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; public class ItemForestryMultiPass extends ItemForestry { diff --git a/src/main/java/forestry/core/items/ItemForestryPickaxe.java b/src/main/java/forestry/core/items/ItemForestryPickaxe.java index 992bb7ca9..f4f996028 100755 --- a/src/main/java/forestry/core/items/ItemForestryPickaxe.java +++ b/src/main/java/forestry/core/items/ItemForestryPickaxe.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.core.items; +import forestry.core.config.ForestryBlock; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import forestry.core.config.ForestryBlock; - public class ItemForestryPickaxe extends ItemForestryTool { private static final Block blocksEffectiveAgainst[]; diff --git a/src/main/java/forestry/core/items/ItemForestryShovel.java b/src/main/java/forestry/core/items/ItemForestryShovel.java index e0076734f..ee82a3987 100755 --- a/src/main/java/forestry/core/items/ItemForestryShovel.java +++ b/src/main/java/forestry/core/items/ItemForestryShovel.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.core.items; +import forestry.core.config.ForestryBlock; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import forestry.core.config.ForestryBlock; - public class ItemForestryShovel extends ItemForestryTool { private static final Block blocksEffectiveAgainst[]; diff --git a/src/main/java/forestry/core/items/ItemForestryTool.java b/src/main/java/forestry/core/items/ItemForestryTool.java index 866bcc48e..16a5f4f6e 100755 --- a/src/main/java/forestry/core/items/ItemForestryTool.java +++ b/src/main/java/forestry/core/items/ItemForestryTool.java @@ -12,6 +12,8 @@ package forestry.core.items; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import forestry.core.proxy.Proxies; +import java.util.Arrays; +import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; @@ -20,9 +22,6 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; -import java.util.Arrays; -import java.util.List; - public class ItemForestryTool extends ItemForestry { private final ItemStack remnants; diff --git a/src/main/java/forestry/core/items/ItemFruit.java b/src/main/java/forestry/core/items/ItemFruit.java index 6948c9c1f..66b6f0bc9 100755 --- a/src/main/java/forestry/core/items/ItemFruit.java +++ b/src/main/java/forestry/core/items/ItemFruit.java @@ -10,22 +10,19 @@ ******************************************************************************/ package forestry.core.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.config.ForestryItem; +import forestry.core.render.TextureManager; import java.util.List; import java.util.Locale; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.oredict.OreDictionary; -import forestry.core.render.TextureManager; - public class ItemFruit extends ItemForestryFood { public static enum EnumFruit { @@ -49,6 +46,14 @@ public class ItemFruit extends ItemForestryFood { public IIcon getIcon() { return icons[ordinal()]; } + + public ItemStack getStack() { + return getStack(1); + } + + public ItemStack getStack(int qty) { + return ForestryItem.fruits.getItemStack(qty, ordinal()); + } } public ItemFruit() { diff --git a/src/main/java/forestry/core/items/ItemInventoried.java b/src/main/java/forestry/core/items/ItemInventoried.java index 936027863..8c31da6d6 100755 --- a/src/main/java/forestry/core/items/ItemInventoried.java +++ b/src/main/java/forestry/core/items/ItemInventoried.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.core.items; +import forestry.core.gui.ContainerItemInventory; +import forestry.core.interfaces.IInventoriedItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; -import forestry.core.gui.ContainerItemInventory; -import forestry.core.interfaces.IInventoriedItem; - public abstract class ItemInventoried extends ItemForestry implements IInventoriedItem { public ItemInventoried() { diff --git a/src/main/java/forestry/core/items/ItemLiquidContainer.java b/src/main/java/forestry/core/items/ItemLiquidContainer.java index 96c71883e..0df5416b5 100755 --- a/src/main/java/forestry/core/items/ItemLiquidContainer.java +++ b/src/main/java/forestry/core/items/ItemLiquidContainer.java @@ -10,12 +10,18 @@ ******************************************************************************/ package forestry.core.items; +import java.awt.Color; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; +import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -24,26 +30,28 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition.MovingObjectType; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; +import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + import forestry.core.CreativeTabForestry; +import forestry.core.fluids.BlockForestryFluid; +import forestry.core.fluids.FluidHelper; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.utils.LiquidHelper; public class ItemLiquidContainer extends Item { public static enum EnumContainerType { - - GLASS, JAR, CAN, CAPSULE, REFRACTORY + GLASS, JAR, CAN, CAPSULE, REFRACTORY, BUCKET } + private static final Map buckets = new HashMap(); + private boolean isDrink = false; private boolean isAlwaysEdible = false; @@ -51,19 +59,28 @@ public class ItemLiquidContainer extends Item { private float saturationModifier = 0.0f; private final EnumContainerType type; - private final int colour; + private final Block contents; + private final Color color; - public ItemLiquidContainer(EnumContainerType type, int colour) { - super(); + public ItemLiquidContainer(EnumContainerType type, Block contents, Color color) { this.type = type; - this.colour = colour; + this.contents = contents; + this.color = color; setCreativeTab(CreativeTabForestry.tabForestry); - setMaxStackSize(16); + if (type == EnumContainerType.BUCKET) { + setContainerItem(Items.bucket); + this.maxStackSize = 1; + buckets.put(contents, this); + } + } + + public static ItemLiquidContainer getExistingBucket(Block contents) { + return buckets.get(contents); } private int getMatchingSlot(EntityPlayer player, ItemStack stack) { - for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) { + for (int slot = 0; slot < player.inventory.mainInventory.length; slot++) { ItemStack slotStack = player.inventory.getStackInSlot(slot); if (slotStack == null) @@ -146,22 +163,21 @@ public class ItemLiquidContainer extends Item { } } - if (fluid == null || fluid.amount <= 0) - return itemstack; + if (fluid == null || fluid.amount <= 0 && this.type == EnumContainerType.BUCKET) + return tryPlaceLiquid(itemstack, world, entityplayer, movingobjectposition); - // Check whether there is valid container for the liquid. - FluidContainerData container = LiquidHelper.getEmptyContainer(itemstack, fluid); - if (container == null) + ItemStack filledContainer = FluidHelper.getFilledContainer(fluid.getFluid(), itemstack); + if (filledContainer == null) return itemstack; // Search for a slot to stow a filled container in player's // inventory - int slot = getMatchingSlot(entityplayer, container.filledContainer); + int slot = getMatchingSlot(entityplayer, filledContainer); if (slot < 0) return itemstack; if (entityplayer.inventory.getStackInSlot(slot) == null) - entityplayer.inventory.setInventorySlotContents(slot, container.filledContainer.copy()); + entityplayer.inventory.setInventorySlotContents(slot, filledContainer.copy()); else entityplayer.inventory.getStackInSlot(slot).stackSize++; @@ -185,6 +201,81 @@ public class ItemLiquidContainer extends Item { } + private ItemStack tryPlaceLiquid(ItemStack itemstack, World world, EntityPlayer player, MovingObjectPosition movingobjectposition) { + + if (this.type != EnumContainerType.BUCKET) { + return itemstack; + } + + if (this.contents == Blocks.air) { + return new ItemStack(Items.bucket); + } + + int x = movingobjectposition.blockX; + int y = movingobjectposition.blockY; + int z = movingobjectposition.blockZ; + + switch (movingobjectposition.sideHit) { + case 0: --y; break; + case 1: ++y; break; + case 2: --z; break; + case 3: ++z; break; + case 4: --x; break; + case 5: ++x; break; + } + + if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, itemstack)) { + return itemstack; + } + + if (this.tryPlaceLiquidAtPosition(world, x, y, z) && !player.capabilities.isCreativeMode) { + return new ItemStack(Items.bucket); + } + + return itemstack; + } + + private boolean tryPlaceLiquidAtPosition(World world, int x, int y, int z) { + if (this.contents == Blocks.air) { + return false; + } else { + Material material = world.getBlock(x, y, z).getMaterial(); + boolean isLiquid = !material.isSolid(); + + if (!world.isAirBlock(x, y, z) && !isLiquid) { + return false; + } else { + // Can't put down liquids in the nether. + // Explode if it's flammable, evaporate otherwise. + if (world.provider.isHellWorld && this.contents != Blocks.flowing_lava) { + int flammability = contents.getFlammability(world, x, y, z, ForgeDirection.UNKNOWN); + if (contents instanceof BlockForestryFluid && flammability > 0) { + // Explosion size is determined by flammability, up to size 4. + float explosionSize = 4F * flammability / 300F; + world.newExplosion(null, x, y, z, explosionSize, true, true); + return true; + } else { + Random random = world.rand; + world.playSoundEffect(x + 0.5, y + 0.5F, z + 0.5F, "random.fizz", 0.5F, 2.6F + (random.nextFloat() - random.nextFloat()) * 0.8F); + + for (int l = 0; l < 8; ++l) { + world.spawnParticle("largesmoke", x + random.nextDouble(), y + random.nextDouble(), z + random.nextDouble(), 0.0, 0.0, 0.0); + } + } + } else { + if (!world.isRemote && isLiquid && !material.isLiquid()) { + world.func_147480_a(x, y, z, true); + } + + world.setBlock(x, y, z, this.contents, 0, 3); + } + + return true; + } + } + } + + public int getHealAmount() { return healAmount; } @@ -224,7 +315,7 @@ public class ItemLiquidContainer extends Item { @SideOnly(Side.CLIENT) @Override public IIcon getIconFromDamageForRenderPass(int i, int j) { - if (j > 0 && colour >= 0) + if (j > 0 && color != null) return icons[1]; else return icons[0]; @@ -238,9 +329,13 @@ public class ItemLiquidContainer extends Item { @Override public int getColorFromItemStack(ItemStack itemstack, int j) { - if (j > 0 && colour >= 0) - return colour; + if (j > 0 && color != null) + return color.getRGB() & 0xffffff; // remove alpha else return 0xffffff; } + + public EnumContainerType getType() { + return type; + } } diff --git a/src/main/java/forestry/core/items/ItemMisc.java b/src/main/java/forestry/core/items/ItemMisc.java index f166f60b8..ff6b34593 100755 --- a/src/main/java/forestry/core/items/ItemMisc.java +++ b/src/main/java/forestry/core/items/ItemMisc.java @@ -13,14 +13,13 @@ package forestry.core.items; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.core.render.TextureManager; +import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import java.util.List; - public class ItemMisc extends ItemForestry { private final String[] definition = new String[]{"pulsatingDust", "pulsatingMesh", "silkWisp", "wovenSilk", "dissipationCharge", "iceShard", "scentedPaneling"}; diff --git a/src/main/java/forestry/core/items/ItemNBTTile.java b/src/main/java/forestry/core/items/ItemNBTTile.java index b3e6f1e66..902e34732 100755 --- a/src/main/java/forestry/core/items/ItemNBTTile.java +++ b/src/main/java/forestry/core/items/ItemNBTTile.java @@ -11,7 +11,6 @@ package forestry.core.items; import java.util.List; - import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; diff --git a/src/main/java/forestry/core/items/ItemOverlay.java b/src/main/java/forestry/core/items/ItemOverlay.java index 910835fdc..4c3df94ed 100755 --- a/src/main/java/forestry/core/items/ItemOverlay.java +++ b/src/main/java/forestry/core/items/ItemOverlay.java @@ -10,21 +10,18 @@ ******************************************************************************/ package forestry.core.items; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.config.Config; +import forestry.core.render.TextureManager; +import forestry.core.utils.StringUtil; import java.util.List; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.config.Config; -import forestry.core.render.TextureManager; -import forestry.core.utils.StringUtil; - public class ItemOverlay extends ItemForestry { public static class OverlayInfo { diff --git a/src/main/java/forestry/core/items/ItemPipette.java b/src/main/java/forestry/core/items/ItemPipette.java index 473b0bacc..e459ee0b5 100755 --- a/src/main/java/forestry/core/items/ItemPipette.java +++ b/src/main/java/forestry/core/items/ItemPipette.java @@ -10,25 +10,21 @@ ******************************************************************************/ package forestry.core.items; -import java.util.List; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraftforge.fluids.FluidStack; - import forestry.api.core.INBTTagable; import forestry.api.core.IToolPipette; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.FluidStack; public class ItemPipette extends ItemForestry implements IToolPipette { @@ -64,8 +60,7 @@ public class ItemPipette extends ItemForestry implements IToolPipette { return; String descr = contents.getFluid().getLocalizedName(contents); - if (Config.isDebug) - descr += " (" + contents.amount + ")"; + descr += " (" + contents.amount + " mb)"; list.add(descr); } @@ -96,7 +91,7 @@ public class ItemPipette extends ItemForestry implements IToolPipette { PipetteContents contained = new PipetteContents(itemstack.getTagCompound()); int limit = getCapacity(itemstack); - int filled = 0; + int filled; if (contained.contents == null) { diff --git a/src/main/java/forestry/core/items/ItemWrench.java b/src/main/java/forestry/core/items/ItemWrench.java index efb993dc2..a863758dd 100755 --- a/src/main/java/forestry/core/items/ItemWrench.java +++ b/src/main/java/forestry/core/items/ItemWrench.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.core.items; +import buildcraft.api.tools.IToolWrench; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.tools.IToolWrench; - public class ItemWrench extends ItemForestry implements IToolWrench { public ItemWrench() { diff --git a/src/main/java/forestry/core/network/ClassMap.java b/src/main/java/forestry/core/network/ClassMap.java deleted file mode 100755 index 02fb6b930..000000000 --- a/src/main/java/forestry/core/network/ClassMap.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.network; - -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.UUID; - -import com.mojang.authlib.GameProfile; - -import forestry.core.gadgets.TileForestry; - -public class ClassMap { - - @SuppressWarnings("rawtypes") - public static final HashMap classMappers = new HashMap(); - - private final LinkedList intMember = new LinkedList(); - private final LinkedList floatMember = new LinkedList(); - private final LinkedList booleanMember = new LinkedList(); - private final LinkedList stringMember = new LinkedList(); - private final LinkedList enumMember = new LinkedList(); - private final LinkedList gameProfileMember = new LinkedList(); - private final LinkedList objectMember = new LinkedList(); - - public int intSize; - public int floatSize; - public int stringSize; - - private Field field; - - /** - * Writes the actual data to the packet payload - * - * @param obj - * {@link TileForestry} to write to packet - * @param intPayload - * @param floatPayload - * @param stringPayload - * @param index - */ - @SuppressWarnings("rawtypes") - public void setData(Object obj, int[] intPayload, float[] floatPayload, String[] stringPayload, IndexInPayload index) throws IllegalAccessException { - for (Field member : intMember) { - intPayload[index.intIndex] = member.getInt(obj); - index.intIndex++; - } - for (Field member : floatMember) { - floatPayload[index.floatIndex] = member.getFloat(obj); - index.floatIndex++; - } - for (Field member : booleanMember) { - if (member.getBoolean(obj)) - floatPayload[index.intIndex] = 1; - else - floatPayload[index.intIndex] = 0; - index.intIndex++; - } - for (Field member : stringMember) { - stringPayload[index.stringIndex] = (String) member.get(obj); - index.stringIndex++; - } - for (Field member : enumMember) { - intPayload[index.intIndex] = ((Enum) member.get(obj)).ordinal(); - index.intIndex++; - } - for (Field member : gameProfileMember) { - GameProfile profile = (GameProfile) member.get(obj); - UUID profileID = profile.getId(); - if (profileID == null) - profileID = new UUID(0,0); - intPayload[index.intIndex] = (int) (profileID.getMostSignificantBits() >>> 32); - intPayload[index.intIndex + 1] = (int) profileID.getMostSignificantBits(); - intPayload[index.intIndex + 2] = (int) (profileID.getLeastSignificantBits() >>> 32); - intPayload[index.intIndex + 3] = (int) profileID.getLeastSignificantBits(); - index.intIndex += 4; - stringPayload[index.stringIndex] = profile.getName(); - index.stringIndex++; - } - - // Handle subobjects - for (ClassMap submap : objectMember) { - Object source = submap.field.get(obj); - - if (source == null) { - intPayload[index.intIndex] = 0; - index.intIndex++; - - index.intIndex += submap.intSize; - index.floatIndex += submap.floatSize; - index.stringIndex += submap.stringSize; - } else { - intPayload[index.intIndex] = 1; - index.intIndex++; - submap.setData(source, intPayload, floatPayload, stringPayload, index); - } - } - } - - /** - * Updates the given object with the data from the passed payload arrays - * - * @param obj - * @param intPayload - * @param floatPayload - * @param stringPayload - * @param index - * @throws IllegalAccessException - */ - @SuppressWarnings("rawtypes") - public void fromData(Object obj, int[] intPayload, float[] floatPayload, String[] stringPayload, IndexInPayload index) throws IllegalAccessException { - - for (Field member : intMember) { - member.setInt(obj, intPayload[index.intIndex]); - index.intIndex++; - } - - for (Field member : booleanMember) { - member.setBoolean(obj, intPayload[index.intIndex] == 1); - index.intIndex++; - } - - for (Field member : enumMember) { - member.set(obj, ((Class) member.getGenericType()).getEnumConstants()[intPayload[index.intIndex]]); - index.intIndex++; - } - - for (Field member : floatMember) { - member.setFloat(obj, floatPayload[index.floatIndex]); - index.floatIndex++; - } - for (Field member : stringMember) { - member.set(obj, stringPayload[index.stringIndex]); - index.stringIndex++; - } - for (Field member : gameProfileMember) { - GameProfile profile = new GameProfile(new UUID((long) intPayload[index.intIndex] << 32 | intPayload[index.intIndex + 1], - (long) intPayload[index.intIndex + 2] << 32 | intPayload[index.intIndex + 3]), - stringPayload[index.stringIndex]); - index.intIndex += 4; - index.stringIndex++; - - member.set(obj, profile); - } - - for (ClassMap map : objectMember) { - boolean isNull = intPayload[index.intIndex] == 0; - index.intIndex++; - - if (isNull) { - index.intIndex += map.intSize; - index.floatIndex += map.floatSize; - index.stringIndex += map.stringSize; - } else { - map.field.get(obj); - map.fromData(map.field.get(obj), intPayload, floatPayload, stringPayload, index); - } - } - } - - @SuppressWarnings("rawtypes") - public ClassMap(final Class targetClass) { - Field[] fields = targetClass.getDeclaredFields(); - - try { - for (Field field : fields) { - // We only handle fields marked with EntityNetData - if (!isNetworkedMember(field)) - continue; - - field.setAccessible(true); - Type type = field.getGenericType(); - - if (type instanceof Class && !((Class) type).isArray()) { - Class memberClass = (Class) type; - if (memberClass.equals(int.class)) { - intSize++; - intMember.add(field); - } else if (memberClass.equals(float.class)) { - floatSize++; - floatMember.add(field); - } else if (memberClass.equals(boolean.class)) { - intSize++; - booleanMember.add(field); - } else if (memberClass.equals(String.class)) { - stringSize++; - stringMember.add(field); - } else if (Enum.class.isAssignableFrom(memberClass)) { - intSize++; - enumMember.add(field); - } else if (GameProfile.class.isAssignableFrom(memberClass)) { - intSize += 4; - stringSize++; - gameProfileMember.add(field); - } else { - // If we are none of the above we assume to be another - // mapable object - // Might not be true and fail! - ClassMap mapper = new ClassMap(memberClass); - mapper.field = field; - - objectMember.add(mapper); - intSize++; - - intSize += mapper.intSize; - floatSize += mapper.floatSize; - stringSize += mapper.stringSize; - } - } else if (type instanceof Class && ((Class) type).isArray()) - // We don't handle arrays currently. Throw exception - throw new RuntimeException("Tried to map class " + targetClass.toString() + " but it requested mapping of an array. Not handled!"); - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } - } - - private boolean isNetworkedMember(Field member) { - return member.getAnnotation(EntityNetData.class) != null; - } - -} diff --git a/src/main/java/forestry/core/network/ForestryPacket.java b/src/main/java/forestry/core/network/ForestryPacket.java index 2e527f2f5..907ee744d 100755 --- a/src/main/java/forestry/core/network/ForestryPacket.java +++ b/src/main/java/forestry/core/network/ForestryPacket.java @@ -10,28 +10,24 @@ ******************************************************************************/ package forestry.core.network; +import cpw.mods.fml.common.network.internal.FMLProxyPacket; +import cpw.mods.fml.common.registry.GameData; +import forestry.core.proxy.Proxies; +import io.netty.buffer.Unpooled; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import cpw.mods.fml.common.network.internal.FMLProxyPacket; -import cpw.mods.fml.common.registry.GameData; - -import io.netty.buffer.Unpooled; - -import forestry.core.proxy.Proxies; - public class ForestryPacket { + protected static final String channel = "FOR"; protected int id; - protected static String channel = "FOR"; public ForestryPacket() { } diff --git a/src/main/java/forestry/core/network/PacketCoordinates.java b/src/main/java/forestry/core/network/PacketCoordinates.java index 16cd80d0e..daca65865 100755 --- a/src/main/java/forestry/core/network/PacketCoordinates.java +++ b/src/main/java/forestry/core/network/PacketCoordinates.java @@ -13,7 +13,6 @@ package forestry.core.network; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; diff --git a/src/main/java/forestry/core/network/PacketFXSignal.java b/src/main/java/forestry/core/network/PacketFXSignal.java index a41f76e5b..02d9d2187 100755 --- a/src/main/java/forestry/core/network/PacketFXSignal.java +++ b/src/main/java/forestry/core/network/PacketFXSignal.java @@ -10,16 +10,13 @@ ******************************************************************************/ package forestry.core.network; +import cpw.mods.fml.common.registry.GameData; +import forestry.core.proxy.Proxies; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.block.Block; -import cpw.mods.fml.common.registry.GameData; - -import forestry.core.proxy.Proxies; - public class PacketFXSignal extends ForestryPacket { public static enum VisualFXType { diff --git a/src/main/java/forestry/core/network/PacketGuiInteger.java b/src/main/java/forestry/core/network/PacketGuiInteger.java index 7b7ff9eb7..673e3d36d 100644 --- a/src/main/java/forestry/core/network/PacketGuiInteger.java +++ b/src/main/java/forestry/core/network/PacketGuiInteger.java @@ -14,7 +14,6 @@ import cpw.mods.fml.client.FMLClientHandler; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.client.entity.EntityClientPlayerMP; /** diff --git a/src/main/java/forestry/core/network/PacketHandler.java b/src/main/java/forestry/core/network/PacketHandler.java index 0a796444e..fac5dbda4 100755 --- a/src/main/java/forestry/core/network/PacketHandler.java +++ b/src/main/java/forestry/core/network/PacketHandler.java @@ -10,17 +10,6 @@ ******************************************************************************/ package forestry.core.network; -import java.io.DataInputStream; -import java.io.InputStream; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.network.NetHandlerPlayServer; -import net.minecraft.tileentity.TileEntity; - import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.FMLEventChannel; @@ -28,24 +17,29 @@ import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.internal.FMLProxyPacket; - -import net.minecraftforge.common.MinecraftForge; - -import io.netty.buffer.ByteBufInputStream; - import forestry.api.core.ForestryEvent; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.ISpeciesRoot; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.gadgets.TileForestry; -import forestry.core.gui.ContainerForestry; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.ContainerSocketed; import forestry.core.gui.IGuiSelectable; import forestry.core.interfaces.ISocketable; import forestry.core.proxy.Proxies; import forestry.plugins.PluginManager; +import io.netty.buffer.ByteBufInputStream; +import java.io.DataInputStream; +import java.io.InputStream; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.MinecraftForge; public class PacketHandler { public PacketHandler() { @@ -65,7 +59,7 @@ public class PacketHandler { null); } - public void onPacketData(InputStream is, EntityPlayer player) { + public void onPacketData(InputStream is, EntityPlayerMP player) { DataInputStream data = new DataInputStream(is); PacketUpdate packetU; @@ -233,10 +227,6 @@ public class PacketHandler { if (tile instanceof IInventory) { ((IInventory) tile).setInventorySlotContents(packet.slotIndex, packet.itemstack); - } else if (tile instanceof TileForestry) { - IInventory inventory = ((TileForestry) tile).getInternalInventory(); - - if (inventory != null) inventory.setInventorySlotContents(packet.slotIndex, packet.itemstack); } } @@ -273,7 +263,7 @@ public class PacketHandler { tile.switchAccessRule(playerEntity); } - private void onPipetteClick(PacketUpdate packet, EntityPlayer player) { + private void onPipetteClick(PacketUpdate packet, EntityPlayerMP player) { assert FMLCommonHandler.instance().getEffectiveSide().isServer(); if (!(player.openContainer instanceof ContainerLiquidTanks)) diff --git a/src/main/java/forestry/core/network/PacketIds.java b/src/main/java/forestry/core/network/PacketIds.java index b35aa1d58..32664f47e 100755 --- a/src/main/java/forestry/core/network/PacketIds.java +++ b/src/main/java/forestry/core/network/PacketIds.java @@ -1,62 +1,63 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.network; - -/** - * Valid ids: 0 - 127 - */ -public class PacketIds { - - public static final int TILE_FORESTRY_UPDATE = 0; - public static final int TILE_UPDATE = 1; - public static final int TILE_DESCRIPTION = 2; - public static final int IINVENTORY_STACK = 3; - public static final int FX_SIGNAL = 4; - public static final int TILE_NBT = 5; - - public static final int HABITAT_BIOME_POINTER = 20; - - public static final int GUI_SELECTION_CHANGE = 30; - public static final int IMPRINT_SELECTION_GET = 31; - public static final int GUI_SELECTION = 32; - - public static final int PIPETTE_CLICK = 40; - - public static final int ACCESS_SWITCH = 50; - - public static final int GENOME_TRACKER_UPDATE = 60; - public static final int GAME_TOKEN_SET = 61; - - public static final int CHIPSET_CLICK = 70; - public static final int SOLDERING_IRON_CLICK = 71; - public static final int SOCKET_UPDATE = 72; - - public static final int LETTER_RECIPIENT = 80; - public static final int LETTER_TEXT = 81; - public static final int TRADING_ADDRESS_SET = 82; - public static final int LETTER_INFO = 83; - public static final int POBOX_INFO = 85; - public static final int POBOX_INFO_REQUEST = 86; - - public static final int LEAF_UPDATE = 90; - - public static final int GUI_INTEGER = 92; - - // Propolis pipe - public static final int PROP_SEND_FILTER_SET = 100; - public static final int PROP_REQUEST_FILTER_SET = 101; - public static final int PROP_SEND_FILTER_CHANGE_GENOME = 102; - public static final int PROP_SEND_FILTER_CHANGE_TYPE = 103; - - - - -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.network; + +/** + * Valid ids: 0 - 127 + */ +public class PacketIds { + + public static final int TILE_FORESTRY_UPDATE = 0; + public static final int TILE_UPDATE = 1; + public static final int TILE_DESCRIPTION = 2; + public static final int IINVENTORY_STACK = 3; + public static final int FX_SIGNAL = 4; + public static final int TILE_NBT = 5; + + public static final int HABITAT_BIOME_POINTER = 20; + + public static final int GUI_SELECTION_CHANGE = 30; + public static final int IMPRINT_SELECTION_GET = 31; + public static final int GUI_SELECTION = 32; + + public static final int PIPETTE_CLICK = 40; + + public static final int ACCESS_SWITCH = 50; + + public static final int GENOME_TRACKER_UPDATE = 60; + public static final int GAME_TOKEN_SET = 61; + + public static final int CHIPSET_CLICK = 70; + public static final int SOLDERING_IRON_CLICK = 71; + public static final int SOCKET_UPDATE = 72; + + public static final int LETTER_RECIPIENT = 80; + public static final int LETTER_TEXT = 81; + public static final int TRADING_ADDRESS_SET = 82; + public static final int LETTER_INFO = 83; + public static final int POBOX_INFO = 85; + public static final int POBOX_INFO_REQUEST = 86; + + public static final int LEAF_UPDATE = 90; + public static final int RIPENING_UPDATE = 91; + + public static final int GUI_INTEGER = 92; + + // Propolis pipe + public static final int PROP_SEND_FILTER_SET = 100; + public static final int PROP_REQUEST_FILTER_SET = 101; + public static final int PROP_SEND_FILTER_CHANGE_GENOME = 102; + public static final int PROP_SEND_FILTER_CHANGE_TYPE = 103; + + + + +} diff --git a/src/main/java/forestry/core/network/PacketInventoryStack.java b/src/main/java/forestry/core/network/PacketInventoryStack.java index 6a4ee5358..721ea9150 100755 --- a/src/main/java/forestry/core/network/PacketInventoryStack.java +++ b/src/main/java/forestry/core/network/PacketInventoryStack.java @@ -13,7 +13,6 @@ package forestry.core.network; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.item.ItemStack; public class PacketInventoryStack extends PacketCoordinates { diff --git a/src/main/java/forestry/core/network/PacketNBT.java b/src/main/java/forestry/core/network/PacketNBT.java index 5e6851d6b..f0da32597 100755 --- a/src/main/java/forestry/core/network/PacketNBT.java +++ b/src/main/java/forestry/core/network/PacketNBT.java @@ -14,7 +14,6 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/forestry/core/network/PacketSocketUpdate.java b/src/main/java/forestry/core/network/PacketSocketUpdate.java index 0a8991727..ddb095c86 100755 --- a/src/main/java/forestry/core/network/PacketSocketUpdate.java +++ b/src/main/java/forestry/core/network/PacketSocketUpdate.java @@ -10,14 +10,12 @@ ******************************************************************************/ package forestry.core.network; +import forestry.core.interfaces.ISocketable; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.item.ItemStack; -import forestry.core.interfaces.ISocketable; - public class PacketSocketUpdate extends PacketCoordinates { public ItemStack[] itemstacks; diff --git a/src/main/java/forestry/core/network/PacketTileNBT.java b/src/main/java/forestry/core/network/PacketTileNBT.java index a502f5afe..7805e8daf 100755 --- a/src/main/java/forestry/core/network/PacketTileNBT.java +++ b/src/main/java/forestry/core/network/PacketTileNBT.java @@ -13,7 +13,6 @@ package forestry.core.network; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; - import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; diff --git a/src/main/java/forestry/core/network/PacketTileUpdate.java b/src/main/java/forestry/core/network/PacketTileUpdate.java index e9443ca13..81eb0a7fb 100755 --- a/src/main/java/forestry/core/network/PacketTileUpdate.java +++ b/src/main/java/forestry/core/network/PacketTileUpdate.java @@ -10,23 +10,22 @@ ******************************************************************************/ package forestry.core.network; +import com.mojang.authlib.GameProfile; +import forestry.api.core.ErrorStateRegistry; +import forestry.api.core.IErrorState; +import forestry.core.EnumErrorCode; +import forestry.core.gadgets.TileForestry; +import forestry.core.utils.EnumAccess; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.UUID; - import net.minecraftforge.common.util.ForgeDirection; -import com.mojang.authlib.GameProfile; - -import forestry.api.core.EnumErrorCode; -import forestry.core.gadgets.TileForestry; -import forestry.core.utils.EnumAccess; - public class PacketTileUpdate extends PacketUpdate { private ForgeDirection orientation = ForgeDirection.WEST; - private EnumErrorCode errorState = EnumErrorCode.OK; + private IErrorState errorState = EnumErrorCode.OK; private boolean isOwnable = false; private EnumAccess access = EnumAccess.SHARED; @@ -47,21 +46,21 @@ public class PacketTileUpdate extends PacketUpdate { isOwnable = tile.isOwnable(); access = tile.getAccess(); - owner = tile.owner; + owner = tile.getOwnerProfile(); } @Override public void writeData(DataOutputStream data) throws IOException { + super.writeData(data); - data.writeInt(posX); - data.writeInt(posY); - data.writeInt(posZ); - - data.writeInt(this.orientation.ordinal()); - data.writeInt(this.errorState.ordinal()); + data.writeByte(this.orientation.ordinal()); + data.writeShort(this.errorState.getID()); + // TODO: Should this really be sent to the client? Huge network cost. + // As far as I know, only GUIs need it, and there are better ways to get the information to a GUI. + // -CovertJaguar if (isOwnable) { - data.writeInt(access.ordinal()); + data.writeByte(access.ordinal()); if (owner == null) { data.writeBoolean(false); } else { @@ -72,21 +71,16 @@ public class PacketTileUpdate extends PacketUpdate { } } else data.writeInt(-1); - - super.writeData(data); } @Override public void readData(DataInputStream data) throws IOException { + super.readData(data); - posX = data.readInt(); - posY = data.readInt(); - posZ = data.readInt(); + orientation = ForgeDirection.getOrientation(data.readByte()); + errorState = ErrorStateRegistry.getErrorState(data.readShort()); - orientation = ForgeDirection.values()[data.readInt()]; - errorState = EnumErrorCode.values()[data.readInt()]; - - int ordinal = data.readInt(); + int ordinal = data.readByte(); isOwnable = ordinal >= 0; if (isOwnable) { access = EnumAccess.values()[ordinal]; @@ -97,15 +91,13 @@ public class PacketTileUpdate extends PacketUpdate { owner = null; } } - - super.readData(data); } public ForgeDirection getOrientation() { return this.orientation; } - public EnumErrorCode getErrorState() { + public IErrorState getErrorState() { return this.errorState; } diff --git a/src/main/java/forestry/core/proxy/ClientProxyCommon.java b/src/main/java/forestry/core/proxy/ClientProxyCommon.java index fe48e0ded..45aec45bb 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ClientProxyCommon.java @@ -10,10 +10,14 @@ ******************************************************************************/ package forestry.core.proxy; -import java.io.File; - import com.mojang.authlib.GameProfile; - +import forestry.apiculture.render.TextureBiomefinder; +import forestry.core.ForestryClient; +import forestry.core.TickHandlerCoreClient; +import forestry.core.WorldGenerator; +import forestry.core.config.Config; +import forestry.core.render.SpriteSheet; +import java.io.File; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -25,18 +29,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; - -import net.minecraftforge.common.util.FakePlayerFactory; - import org.lwjgl.input.Keyboard; -import forestry.apiculture.render.TextureBiomefinder; -import forestry.core.ForestryClient; -import forestry.core.TickHandlerCoreClient; -import forestry.core.config.Config; -import forestry.core.render.SpriteSheet; - public class ClientProxyCommon extends ProxyCommon { @Override @@ -50,8 +44,8 @@ public class ClientProxyCommon extends ProxyCommon { } @Override - public void registerTickHandlers() { - super.registerTickHandlers(); + public void registerTickHandlers(WorldGenerator worldGenerator) { + super.registerTickHandlers(worldGenerator); new TickHandlerCoreClient(); } @@ -164,14 +158,6 @@ public class ClientProxyCommon extends ProxyCommon { /** * Renders a EntityBiodustFX on client. - * - * @param world - * @param d1 - * @param d2 - * @param d3 - * @param f1 - * @param f2 - * @param f3 */ // FIXME: This is causing crashes. @Override diff --git a/src/main/java/forestry/core/proxy/ClientProxyNetwork.java b/src/main/java/forestry/core/proxy/ClientProxyNetwork.java index b8c649194..196163796 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyNetwork.java +++ b/src/main/java/forestry/core/proxy/ClientProxyNetwork.java @@ -11,11 +11,14 @@ package forestry.core.proxy; import forestry.core.network.ForestryPacket; +import net.minecraft.client.network.NetHandlerPlayClient; public class ClientProxyNetwork extends ProxyNetwork { @Override public void sendToServer(ForestryPacket packet) { - Proxies.common.getClientInstance().getNetHandler().addToSendQueue(packet.getPacket()); + NetHandlerPlayClient netHandler = Proxies.common.getClientInstance().getNetHandler(); + if (netHandler != null) + netHandler.addToSendQueue(packet.getPacket()); } } diff --git a/src/main/java/forestry/core/proxy/ClientProxyRender.java b/src/main/java/forestry/core/proxy/ClientProxyRender.java index ee78420e9..8674cb7b2 100755 --- a/src/main/java/forestry/core/proxy/ClientProxyRender.java +++ b/src/main/java/forestry/core/proxy/ClientProxyRender.java @@ -10,16 +10,10 @@ ******************************************************************************/ package forestry.core.proxy; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.world.World; - import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; - import forestry.core.config.Config; import forestry.core.gadgets.MachineDefinition; import forestry.core.interfaces.IBlockRenderer; @@ -31,6 +25,10 @@ import forestry.core.render.RenderMill; import forestry.core.render.TextureManager; import forestry.core.render.TileRendererIndex; import forestry.core.utils.ForestryResource; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.world.World; public class ClientProxyRender extends ProxyRender { diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 9e34c3563..40eff4ed2 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -23,6 +23,7 @@ import cpw.mods.fml.common.versioning.VersionParser; import cpw.mods.fml.common.versioning.VersionRange; import forestry.Forestry; import forestry.core.TickHandlerCoreServer; +import forestry.core.WorldGenerator; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; @@ -31,6 +32,11 @@ import forestry.core.network.PacketFXSignal; import forestry.core.network.PacketIds; import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; +import forestry.plugins.PluginManager; + +import java.io.File; +import java.util.EnumSet; + import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IResourceManager; @@ -50,19 +56,19 @@ import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; -import java.io.File; - public class ProxyCommon { public String getMinecraftVersion() { return Loader.instance().getMinecraftModContainer().getVersion(); } - public void registerTickHandlers() { - new TickHandlerCoreServer(); + public void registerTickHandlers(WorldGenerator worldGenerator) { + new TickHandlerCoreServer(worldGenerator); } public void registerBlock(Block block, Class itemClass) { + if (!EnumSet.of(PluginManager.Stage.PRE_INIT).contains(PluginManager.getStage())) + throw new RuntimeException("Tried to register Block outside of Pre-Init"); GameRegistry.registerBlock(block, itemClass, StringUtil.cleanBlockName(block)); } diff --git a/src/main/java/forestry/core/proxy/ProxyLog.java b/src/main/java/forestry/core/proxy/ProxyLog.java index 4d6d21c1f..1669a8e7f 100755 --- a/src/main/java/forestry/core/proxy/ProxyLog.java +++ b/src/main/java/forestry/core/proxy/ProxyLog.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.core.proxy; +import forestry.core.config.Defaults; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; - -import forestry.core.config.Defaults; import org.apache.logging.log4j.message.MessageFormatMessage; public class ProxyLog { @@ -101,4 +100,35 @@ public class ProxyLog { LogManager.getLogger(Defaults.MOD).log(logLevel, new MessageFormatMessage(String.format(message, params), params)); } + /* EXCEPTIONS */ + public void logThrowable(String msg, Throwable error, Object... args) { + logThrowable(Level.ERROR, msg, 3, error, args); + } + + public void logThrowable(String msg, int lines, Throwable error, Object... args) { + logThrowable(Level.ERROR, msg, lines, error, args); + } + + public void logThrowable(Level level, String msg, int lines, Throwable error, Object... args) { + StackTraceElement[] oldtrace = error.getStackTrace(); + if (lines < oldtrace.length) { + StackTraceElement[] newtrace = new StackTraceElement[lines]; + System.arraycopy(oldtrace, 0, newtrace, 0, newtrace.length); + error.setStackTrace(newtrace); + } + LogManager.getLogger(Defaults.MOD).log(level, new MessageFormatMessage(msg, args), error); + } + + public void logErrorAPI(String mod, Throwable error, Class classFile) { + StringBuilder msg = new StringBuilder(mod); + msg.append(" API error, please update your mods. Error: ").append(error); + logThrowable(Level.ERROR, msg.toString(), 2, error); + + if (classFile != null) { + msg = new StringBuilder(mod); + msg.append(" API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain().getCodeSource().getLocation()); + log(Level.ERROR, msg.toString()); + } + } + } diff --git a/src/main/java/forestry/core/proxy/ProxyNetwork.java b/src/main/java/forestry/core/proxy/ProxyNetwork.java index 29264c722..4d64755bc 100755 --- a/src/main/java/forestry/core/proxy/ProxyNetwork.java +++ b/src/main/java/forestry/core/proxy/ProxyNetwork.java @@ -10,16 +10,14 @@ ******************************************************************************/ package forestry.core.proxy; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.world.World; - -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.common.util.FakePlayer; - import forestry.Forestry; import forestry.core.config.Defaults; import forestry.core.network.ForestryPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.common.util.FakePlayer; public class ProxyNetwork { diff --git a/src/main/java/forestry/core/proxy/ProxyRender.java b/src/main/java/forestry/core/proxy/ProxyRender.java index 3a439e812..9eb5d5560 100755 --- a/src/main/java/forestry/core/proxy/ProxyRender.java +++ b/src/main/java/forestry/core/proxy/ProxyRender.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.core.proxy; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.world.World; - import forestry.core.gadgets.MachineDefinition; import forestry.core.interfaces.IBlockRenderer; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.world.World; public class ProxyRender { diff --git a/src/main/java/forestry/core/render/BlockRenderingHandler.java b/src/main/java/forestry/core/render/BlockRenderingHandler.java index 1993f8e65..1a26c2b12 100755 --- a/src/main/java/forestry/core/render/BlockRenderingHandler.java +++ b/src/main/java/forestry/core/render/BlockRenderingHandler.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.core.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import forestry.core.ForestryClient; +import forestry.core.interfaces.IBlockRenderer; import java.util.HashMap; - import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - -import forestry.core.ForestryClient; -import forestry.core.interfaces.IBlockRenderer; - public class BlockRenderingHandler implements ISimpleBlockRenderingHandler { public static final HashMap byBlockRenderer = new HashMap(); diff --git a/src/main/java/forestry/core/render/CrateRenderingHandler.java b/src/main/java/forestry/core/render/CrateRenderingHandler.java new file mode 100644 index 000000000..b1937bc5d --- /dev/null +++ b/src/main/java/forestry/core/render/CrateRenderingHandler.java @@ -0,0 +1,322 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.render; + +import java.util.Random; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.client.IItemRenderer; + +import org.lwjgl.opengl.GL11; + +import forestry.api.recipes.IGenericCrate; + +/** + * Adapted from RenderTankCartItem by CovertJaguar + */ +public class CrateRenderingHandler implements IItemRenderer { + + private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture; + private static final ResourceLocation ITEM_TEXTURE = TextureMap.locationItemsTexture; + private static final ResourceLocation GLINT_TEXTURE = new ResourceLocation("textures/misc/enchanted_item_glint.png"); + + public static final float PIXEL = 1.0f / 16.0f; + + private final RenderItem renderItem = new RenderItem(); + + @Override + public boolean handleRenderType(ItemStack stack, ItemRenderType type) { + switch(type){ + case INVENTORY: + case ENTITY: + case EQUIPPED: + case EQUIPPED_FIRST_PERSON: + return true; + default: + return false; + } + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack stack, ItemRendererHelper helper) { + return helper == ItemRendererHelper.ENTITY_BOBBING; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack stack, Object... data) { + if (type == ItemRenderType.INVENTORY) + render(ItemRenderType.INVENTORY, stack); + else if (type == ItemRenderType.ENTITY) + if (RenderManager.instance.options.fancyGraphics) + renderAsEntity(stack, (EntityItem) data[1]); + else + renderAsEntityFlat(stack); + else if (type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON) { + GL11.glPushMatrix(); + renderEquipped(stack); + + ItemStack contained = getContainedFromCrate(stack); + + if (contained != null) { + float scale = 0.5f; + GL11.glScalef(scale, scale, 1.1f); + GL11.glTranslatef(10f * PIXEL, 8f * PIXEL, 0.001f); + if (contained.getItem() instanceof ItemBlock) { + renderIn3D(contained); + } else { + renderEquipped(contained); + } + } + GL11.glPopMatrix(); + } + } + + private void renderEquipped(ItemStack stack) { + GL11.glPushMatrix(); + Tessellator tessellator = Tessellator.instance; + + int meta = stack.getItemDamage(); + for (int pass = 0; pass < stack.getItem().getRenderPasses(meta); ++pass) { + IIcon icon = stack.getItem().getIconFromDamageForRenderPass(meta, pass); + if(icon == null) + continue; + + if (renderItem.renderWithColor) { + int color = stack.getItem().getColorFromItemStack(stack, pass); + float c1 = (float) (color >> 16 & 255) / 255.0F; + float c2 = (float) (color >> 8 & 255) / 255.0F; + float c3 = (float) (color & 255) / 255.0F; + + GL11.glColor4f(c1, c2, c3, 1.0F); + } + + float uv1 = icon.getMinU(); + float uv2 = icon.getMaxU(); + float uv3 = icon.getMinV(); + float uv4 = icon.getMaxV(); + + ItemRenderer.renderItemIn2D(tessellator, uv2, uv3, uv1, uv4, icon.getIconWidth(), icon.getIconHeight(), PIXEL); + } + + GL11.glPopMatrix(); + } + + private void renderAsEntity(ItemStack stack, EntityItem entity) { + GL11.glPushMatrix(); + byte iterations = 1; + if (stack.stackSize > 1) iterations = 2; + if (stack.stackSize > 15) iterations = 3; + if (stack.stackSize > 31) iterations = 4; + + Random rand = new Random(187L); + + float offsetZ = PIXEL + 0.021875F; + + GL11.glRotatef((((float) entity.age + 1.0F) / 20.0F + entity.hoverStart) * (180F / (float) Math.PI), 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.25F, -(offsetZ * (float) iterations / 2.0F)); + + for (int count = 0; count < iterations; ++count) { + if (count > 0) { + float offsetX = (rand.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + float offsetY = (rand.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F; + GL11.glTranslatef(offsetX, offsetY, offsetZ); + } else + GL11.glTranslatef(0f, 0f, offsetZ); + + renderIn3D(stack); + + ItemStack contained = getContainedFromCrate(stack); + + if (contained != null) { + GL11.glPushMatrix(); + float scale = 0.5f; + GL11.glScalef(scale, scale, 1.1F); + GL11.glTranslatef(10.0f * PIXEL, 8.0f * PIXEL, 0.003F); + renderIn3D(contained); + GL11.glPopMatrix(); + } + } + GL11.glPopMatrix(); + } + + private void renderIn3D(ItemStack stack) { + GL11.glPushMatrix(); + Tessellator tessellator = Tessellator.instance; + if (RenderManager.instance.renderEngine == null) + return; + + int meta = stack.getItemDamage(); + for (int pass = 0; pass < stack.getItem().getRenderPasses(meta); ++pass) { + IIcon icon = stack.getItem().getIconFromDamageForRenderPass(meta, pass); + if(icon == null) + continue; + + if (renderItem.renderWithColor) { + int color = stack.getItem().getColorFromItemStack(stack, pass); + float c1 = (float) (color >> 16 & 255) / 255.0F; + float c2 = (float) (color >> 8 & 255) / 255.0F; + float c3 = (float) (color & 255) / 255.0F; + + GL11.glColor4f(c1, c2, c3, 1.0F); + } + + float minU = icon.getMinU(); + float maxU = icon.getMaxU(); + float minV = icon.getMinV(); + float maxV = icon.getMaxV(); + + if (stack.getItemSpriteNumber() == 0) + RenderManager.instance.renderEngine.bindTexture(BLOCK_TEXTURE); + else + RenderManager.instance.renderEngine.bindTexture(ITEM_TEXTURE); + + ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, icon.getIconWidth(), icon.getIconHeight(), PIXEL); + + if (stack.hasEffect(pass)) { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + RenderManager.instance.renderEngine.bindTexture(GLINT_TEXTURE); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + float f13 = 0.76F; + GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + float f14 = 0.125F; + GL11.glScalef(f14, f14, f14); + float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; + GL11.glTranslatef(f15, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(f14, f14, f14); + f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; + GL11.glTranslatef(-f15, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, PIXEL); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + } + + GL11.glPopMatrix(); + } + + private void renderAsEntityFlat(ItemStack stack) { + GL11.glPushMatrix(); + byte iterations = 1; + if (stack.stackSize > 1) iterations = 2; + if (stack.stackSize > 15) iterations = 3; + if (stack.stackSize > 31) iterations = 4; + + Random rand = new Random(187L); + + for (int ii = 0; ii < iterations; ++ii) { + GL11.glPushMatrix(); + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(180 - RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F); + + if (ii > 0) { + float var12 = (rand.nextFloat() * 2.0F - 1.0F) * 0.3F; + float var13 = (rand.nextFloat() * 2.0F - 1.0F) * 0.3F; + float var14 = (rand.nextFloat() * 2.0F - 1.0F) * 0.3F; + GL11.glTranslatef(var12, var13, var14); + } + + GL11.glTranslatef(0.5f, 0.8f, 0); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + GL11.glScalef(1f / 16f, 1f / 16f, 1); + + render(ItemRenderType.ENTITY, stack); + GL11.glPopMatrix(); + } + GL11.glPopMatrix(); + } + + private void render(ItemRenderType type, ItemStack stack) { + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + IIcon crateTexture = stack.getIconIndex(); + renderItem.renderIcon(0, 0, crateTexture, 16, 16); + + ItemStack contained = getContainedFromCrate(stack); + + if (contained != null) { + + int meta = contained.getItemDamage(); + + float scale = 0.5f; + GL11.glScalef(scale, scale, 1); + GL11.glTranslatef(6f, 8f, 0); + if (type == ItemRenderType.ENTITY) + GL11.glTranslatef(0, 0, -0.1f); + + if (contained.getItem() instanceof ItemBlock) { + GL11.glScalef(16f, 16f, 1f); + GL11.glTranslatef(1f, 1f, 0.1f); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + renderIn3D(contained); + } else { + for (int pass = 0; pass < contained.getItem().getRenderPasses(meta); ++pass) { + IIcon containedTexture = contained.getItem().getIconFromDamageForRenderPass(meta, pass); + if (containedTexture == null) + continue; + + if (renderItem.renderWithColor) { + int color = contained.getItem().getColorFromItemStack(contained, pass); + float c1 = (float) (color >> 16 & 255) / 255.0F; + float c2 = (float) (color >> 8 & 255) / 255.0F; + float c3 = (float) (color & 255) / 255.0F; + + GL11.glColor4f(c1, c2, c3, 1.0F); + } + + renderItem.renderIcon(0, 0, containedTexture, 16, 16); + } + } + } + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + + private static ItemStack getContainedFromCrate(ItemStack crate) { + if (crate == null) + return null; + + Item crateItem = crate.getItem(); + if (crateItem instanceof IGenericCrate) { + return ((IGenericCrate) crateItem).getContained(crate); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/forestry/core/render/EntityColoredDropParticleFX.java b/src/main/java/forestry/core/render/EntityColoredDropParticleFX.java new file mode 100644 index 000000000..bccc400b6 --- /dev/null +++ b/src/main/java/forestry/core/render/EntityColoredDropParticleFX.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.render; + +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.material.Material; +import net.minecraft.client.particle.EntityFX; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class EntityColoredDropParticleFX extends EntityFX { + + /** + * The height of the current bob + */ + private int bobTimer; + + public EntityColoredDropParticleFX(World world, double x, double y, double z, float red, float green, float blue) { + super(world, x, y, z); + this.particleRed = red; + this.particleGreen = green; + this.particleBlue = blue; + + this.setParticleTextureIndex(113); + this.setSize(0.01F, 0.01F); + this.particleGravity = 0.06F; + this.bobTimer = 40; + this.particleMaxAge = (int) (64.0D / (Math.random() * 0.8D + 0.2D)); + } + + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; + + this.motionY -= (double) this.particleGravity; + + if (this.bobTimer-- > 0) { + this.motionX *= 0.02D; + this.motionY *= 0.02D; + this.motionZ *= 0.02D; + this.setParticleTextureIndex(113); + } else { + this.setParticleTextureIndex(112); + } + + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9800000190734863D; + this.motionY *= 0.9800000190734863D; + this.motionZ *= 0.9800000190734863D; + + if (this.particleMaxAge-- <= 0) { + this.setDead(); + } + + if (this.onGround) { + this.setParticleTextureIndex(114); + + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } + + Material material = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)).getMaterial(); + + if (material.isLiquid() || material.isSolid()) { + double d0 = (double) ((float) (MathHelper.floor_double(this.posY) + 1) - BlockLiquid.getLiquidHeightPercent(this.worldObj.getBlockMetadata(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)))); + + if (this.posY < d0) { + this.setDead(); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/forestry/core/render/EntitySnowFX.java b/src/main/java/forestry/core/render/EntitySnowFX.java index 92ad917cb..71446379c 100755 --- a/src/main/java/forestry/core/render/EntitySnowFX.java +++ b/src/main/java/forestry/core/render/EntitySnowFX.java @@ -11,7 +11,6 @@ package forestry.core.render; import java.util.Random; - import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; @@ -20,7 +19,7 @@ import net.minecraft.world.World; public class EntitySnowFX extends EntityFX { public static IIcon icons[]; - private Random spreadRand = new Random(); + private static final Random spreadRand = new Random(); public EntitySnowFX(World world, double x, double y, double z, float motionScaleX, float motionScaleY, float motionScaleZ) { super(world, x, y, z, 0.0D, 0.0D, 0.0D); diff --git a/src/main/java/forestry/core/render/OverlayRenderingHandler.java b/src/main/java/forestry/core/render/OverlayRenderingHandler.java index 5558c7d5d..066c0b7b0 100755 --- a/src/main/java/forestry/core/render/OverlayRenderingHandler.java +++ b/src/main/java/forestry/core/render/OverlayRenderingHandler.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.core.render; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; -import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; - public abstract class OverlayRenderingHandler implements ISimpleBlockRenderingHandler { protected static final double OVERLAY_SHIFT = 0.001; diff --git a/src/main/java/forestry/core/render/RenderAnalyzer.java b/src/main/java/forestry/core/render/RenderAnalyzer.java index bd41cdc8d..a44b3eefa 100755 --- a/src/main/java/forestry/core/render/RenderAnalyzer.java +++ b/src/main/java/forestry/core/render/RenderAnalyzer.java @@ -10,6 +10,9 @@ ******************************************************************************/ package forestry.core.render; +import forestry.apiculture.render.ModelAnalyzer; +import forestry.core.gadgets.TileAnalyzer; +import forestry.core.interfaces.IBlockRenderer; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -17,15 +20,9 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; - import org.lwjgl.opengl.GL11; -import forestry.apiculture.render.ModelAnalyzer; -import forestry.core.gadgets.TileAnalyzer; -import forestry.core.interfaces.IBlockRenderer; - public class RenderAnalyzer extends TileEntitySpecialRenderer implements IBlockRenderer { private ModelAnalyzer model; diff --git a/src/main/java/forestry/core/render/RenderEscritoire.java b/src/main/java/forestry/core/render/RenderEscritoire.java index 64b8441fd..5d9123a9e 100755 --- a/src/main/java/forestry/core/render/RenderEscritoire.java +++ b/src/main/java/forestry/core/render/RenderEscritoire.java @@ -29,15 +29,13 @@ import forestry.core.utils.ForestryResource; public class RenderEscritoire extends TileEntitySpecialRenderer implements IBlockRenderer { + private static final ResourceLocation texture = new ForestryResource(Defaults.TEXTURE_PATH_BLOCKS + "/escritoire.png"); private final ModelEscritoire modelEscritoire; - private final ResourceLocation texture = new ForestryResource(Defaults.TEXTURE_PATH_BLOCKS + "/escritoire.png"); - //private final EntityItem dummyEntityItem = new EntityItem(null); - private final RenderItem customRenderItem; public RenderEscritoire() { modelEscritoire = new ModelEscritoire(); - customRenderItem = new RenderItem() { + RenderItem customRenderItem = new RenderItem() { @Override public boolean shouldBob() { return false; diff --git a/src/main/java/forestry/core/render/RenderMachine.java b/src/main/java/forestry/core/render/RenderMachine.java index 04f78a275..e4cad8d1d 100755 --- a/src/main/java/forestry/core/render/RenderMachine.java +++ b/src/main/java/forestry/core/render/RenderMachine.java @@ -10,21 +10,18 @@ ******************************************************************************/ package forestry.core.render; -import net.minecraft.client.model.ModelBase; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - import forestry.core.interfaces.IBlockRenderer; import forestry.core.interfaces.IRenderableMachine; import forestry.core.proxy.Proxies; import forestry.core.utils.EnumTankLevel; import forestry.core.utils.ForestryResource; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.opengl.GL11; public class RenderMachine extends TileEntitySpecialRenderer implements IBlockRenderer { diff --git a/src/main/java/forestry/core/render/RenderMill.java b/src/main/java/forestry/core/render/RenderMill.java index d4ce46d9d..710d3f6ef 100755 --- a/src/main/java/forestry/core/render/RenderMill.java +++ b/src/main/java/forestry/core/render/RenderMill.java @@ -10,21 +10,18 @@ ******************************************************************************/ package forestry.core.render; +import forestry.core.gadgets.Mill; +import forestry.core.interfaces.IBlockRenderer; +import forestry.core.proxy.Proxies; +import forestry.core.utils.ForestryResource; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; - import net.minecraftforge.common.util.ForgeDirection; - import org.lwjgl.opengl.GL11; -import forestry.core.gadgets.Mill; -import forestry.core.interfaces.IBlockRenderer; -import forestry.core.proxy.Proxies; -import forestry.core.utils.ForestryResource; - public class RenderMill extends TileEntitySpecialRenderer implements IBlockRenderer { private final ModelBase model = new ModelBase() { diff --git a/src/main/java/forestry/core/utils/AdjacentTileCache.java b/src/main/java/forestry/core/utils/AdjacentTileCache.java new file mode 100644 index 000000000..9b58edddf --- /dev/null +++ b/src/main/java/forestry/core/utils/AdjacentTileCache.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * + * @author CovertJaguar + */ +public final class AdjacentTileCache { + + private static final int DELAY_MIN = 20; + private static final int DELAY_MAX = 2400; + private static final int DELAY_STEP = 2; + private final Timer[] timer = new Timer[6]; + private final TileEntity[] cache = new TileEntity[6]; + private final int[] delay = new int[6]; + private final TileEntity source; + private final Set listeners = new LinkedHashSet(); + + public static interface ICacheListener { + + void changed(); + + void purge(); + + } + + public AdjacentTileCache(TileEntity tile) { + this.source = tile; + Arrays.fill(delay, DELAY_MIN); + for (int i = 0; i < timer.length; i++) { + timer[i] = new Timer(); + } + } + + public void addListener(ICacheListener listener) { + listeners.add(listener); + } + + private TileEntity searchSide(ForgeDirection side) { + World world = source.getWorldObj(); + int sx = source.xCoord + side.offsetX; + int sy = source.yCoord + side.offsetY; + int sz = source.zCoord + side.offsetZ; + if (world.blockExists(sx, sy, sz) && world.getBlock(sx, sy, sz) != Blocks.air) + return world.getTileEntity(sx, sy, sz); + return null; + } + + public void refresh() { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + getTileOnSide(side); + } + } + + public void purge() { + Arrays.fill(cache, null); + Arrays.fill(delay, DELAY_MIN); + for (Timer t : timer) { + t.reset(); + } + changed(); + for (ICacheListener listener : listeners) { + listener.purge(); + } + } + + public void onNeighborChange() { + Arrays.fill(delay, DELAY_MIN); + } + + protected void setTile(int side, TileEntity tile) { + if (cache[side] != tile) { + cache[side] = tile; + changed(); + } + } + + private void changed() { + for (ICacheListener listener : listeners) { + listener.changed(); + } + } + + private boolean areCoordinatesOnSide(ForgeDirection side, TileEntity target) { + return source.xCoord + side.offsetX == target.xCoord && source.yCoord + side.offsetY == target.yCoord && source.zCoord + side.offsetZ == target.zCoord; + } + + public TileEntity getTileOnSide(ForgeDirection side) { + int s = side.ordinal(); + if (cache[s] != null) + if (cache[s].isInvalid() || !areCoordinatesOnSide(side, cache[s])) + setTile(s, null); + else + return cache[s]; + + if (timer[s].hasTriggered(source.getWorldObj(), delay[s])) { + setTile(s, searchSide(side)); + if (cache[s] == null) + incrementDelay(s); + else + delay[s] = DELAY_MIN; + } + + return cache[s]; + } + + private void incrementDelay(int side) { + delay[side] += DELAY_STEP; + if (delay[side] > DELAY_MAX) + delay[side] = DELAY_MAX; + } + + public TileEntity getSource() { + return source; + } + +} diff --git a/src/main/java/forestry/core/utils/AlyzerInventory.java b/src/main/java/forestry/core/utils/AlyzerInventory.java deleted file mode 100644 index 398ab4764..000000000 --- a/src/main/java/forestry/core/utils/AlyzerInventory.java +++ /dev/null @@ -1,45 +0,0 @@ -package forestry.core.utils; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -public class AlyzerInventory extends ItemInventory { - - public static final int SLOT_SPECIMEN = 0; - public static final int SLOT_ANALYZE_1 = 1; - public static final int SLOT_ANALYZE_2 = 2; - public static final int SLOT_ANALYZE_3 = 3; - public static final int SLOT_ANALYZE_4 = 4; - public static final int SLOT_ANALYZE_5 = 6; - public static final int SLOT_ENERGY = 5; - - protected EntityPlayer player; - - public AlyzerInventory(Class itemClass, int slots) { - super(itemClass, slots); - } - - public AlyzerInventory(Class itemClass, int size, ItemStack itemstack) { - super(itemClass, size, itemstack); - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - - NBTTagList nbttaglist = new NBTTagList(); - for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++) { - if (inventoryStacks[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - inventoryStacks[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } - nbttagcompound.setTag("Items", nbttaglist); - - } - -} diff --git a/src/main/java/forestry/core/utils/BlockUtil.java b/src/main/java/forestry/core/utils/BlockUtil.java index f015c1b07..a4971a0e5 100644 --- a/src/main/java/forestry/core/utils/BlockUtil.java +++ b/src/main/java/forestry/core/utils/BlockUtil.java @@ -10,28 +10,23 @@ ******************************************************************************/ package forestry.core.utils; -import buildcraft.api.core.Position; -import buildcraft.api.transport.IPipeConnection; -import buildcraft.api.transport.IPipeConnection.ConnectOverride; -import buildcraft.api.transport.IPipeTile; -import buildcraft.api.transport.IPipeTile.PipeType; -import cofh.api.energy.IEnergyHandler; -import forestry.core.config.Defaults; +import java.util.ArrayList; + import net.minecraft.block.Block; import net.minecraft.block.BlockCocoa; import net.minecraft.block.BlockLog; import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityHopper; import net.minecraft.util.Direction; import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; +import forestry.core.config.Defaults; +import forestry.core.vect.Vect; + +import cofh.api.energy.IEnergyHandler; public class BlockUtil { @@ -43,109 +38,6 @@ public class BlockUtil { } - /** - * Searches for inventories adjacent to block, excludes IPowerReceptor - * - * @param world - * @param blockPos - * @param from - * @return - */ - public static IInventory[] getAdjacentInventories(World world, Vect blockPos, ForgeDirection from) { - ArrayList inventories = new ArrayList(); - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if (from != ForgeDirection.UNKNOWN && from != dir.getOpposite()) - continue; - - TileEntity entity = world.getTileEntity(blockPos.x + dir.offsetX, blockPos.y + dir.offsetY, blockPos.z + dir.offsetZ); - if (entity != null) - if (entity instanceof IInventory) - if (!(entity instanceof TileEntityHopper)) - inventories.add((IInventory) entity); - } - - return inventories.toArray(new IInventory[inventories.size()]); - } - - /** - * Returns a list of adjacent pipes. - * - * @param world - * @param blockPos - * @param from - * @return - */ - public static ForgeDirection[] getPipeDirections(World world, Vect blockPos, ForgeDirection from) { - LinkedList possiblePipes = new LinkedList(); - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if (from != ForgeDirection.UNKNOWN && from != dir.getOpposite()) - continue; - - Position posPipe = new Position(blockPos.x, blockPos.y, blockPos.z, dir); - posPipe.moveForwards(1.0); - - TileEntity pipeEntry = world.getTileEntity((int) posPipe.x, (int) posPipe.y, (int) posPipe.z); - - if (pipeEntry instanceof IPipeTile) { - IPipeTile pipe = (IPipeTile)pipeEntry; - - if (from != ForgeDirection.UNKNOWN && pipeEntry instanceof IPipeConnection) { - if (((IPipeConnection) pipeEntry).overridePipeConnection(PipeType.ITEM, from) != ConnectOverride.DISCONNECT) - possiblePipes.add(dir); - } else if(pipe.getPipeType() == PipeType.ITEM && pipe.isPipeConnected(dir.getOpposite())) - possiblePipes.add(dir); - } - } - - return possiblePipes.toArray(new ForgeDirection[possiblePipes.size()]); - - } - - public static ArrayList filterPipeDirections(ForgeDirection[] allDirections, ForgeDirection[] exclude) { - ArrayList filtered = new ArrayList(); - ArrayList excludeList = new ArrayList(Arrays.asList(exclude)); - - for (ForgeDirection direction : allDirections) - if (!excludeList.contains(direction)) - filtered.add(direction); - - return filtered; - - } - - public static boolean putFromStackIntoPipe(TileEntity tile, ArrayList pipes, ItemStack stack) { - - if (stack == null) - return false; - if (stack.stackSize <= 0) - return false; - if (pipes.size() <= 0) - return false; - - int choice = tile.getWorldObj().rand.nextInt(pipes.size()); - Position itemPos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, pipes.get(choice)); - - itemPos.x += 0.5; - itemPos.y += 0.25; - itemPos.z += 0.5; - itemPos.moveForwards(0.5); - - Position pipePos = new Position(tile.xCoord, tile.yCoord, tile.zCoord, pipes.get(choice)); - pipePos.moveForwards(1.0); - - IPipeTile pipe = (IPipeTile) tile.getWorldObj().getTileEntity((int) pipePos.x, (int) pipePos.y, (int) pipePos.z); - - ItemStack payload = stack.splitStack(1); - if(pipe.injectItem(payload, true, itemPos.orientation.getOpposite()) > 0) - return true; - else - pipes.remove(choice); - - return false; - } - public static boolean isRFTile(ForgeDirection side, TileEntity tile) { if (tile == null) return false; diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java b/src/main/java/forestry/core/utils/ChunkCoords.java similarity index 62% rename from src/main/java/forestry/apiculture/commands/CommandBeekeeping.java rename to src/main/java/forestry/core/utils/ChunkCoords.java index f39dccc23..d214b0dd5 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java +++ b/src/main/java/forestry/core/utils/ChunkCoords.java @@ -1,24 +1,27 @@ -/******************************************************************************* - * 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.commands; - -import forestry.core.commands.SubCommand; - -public class CommandBeekeeping extends SubCommand { - - public CommandBeekeeping() { - super("beekeeping"); - addAlias("bee"); - addChildCommand(new CommandBeekeepingMode()); - addChildCommand(new CommandBeekeepingSave()); - addChildCommand(new CommandBeekeepingGiveBee()); - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +import net.minecraft.world.chunk.Chunk; + +public class ChunkCoords +{ + public int dimension; + public int xCoord; + public int zCoord; + + public ChunkCoords(Chunk chunk) + { + this.dimension = chunk.worldObj.provider.dimensionId; + this.xCoord = chunk.xPosition; + this.zCoord = chunk.zPosition; + } +} diff --git a/src/main/java/forestry/core/utils/CommandMC.java b/src/main/java/forestry/core/utils/CommandMC.java deleted file mode 100755 index 138fb83c0..000000000 --- a/src/main/java/forestry/core/utils/CommandMC.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.utils; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ChatComponentText; -import net.minecraft.world.World; - -@Deprecated -public abstract class CommandMC extends CommandBase { - - protected World getWorld(ICommandSender sender, String[] arguments) { - - // Handle passed in world argument - if (arguments.length > 2) { - int dim = 0; - try { - dim = Integer.parseInt(arguments[1]); - } catch (Exception ex) { - throw new WrongUsageException("/" + getCommandName() + " set [] "); - } - - return MinecraftServer.getServer().worldServerForDimension(dim); - } - - if (sender instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer) sender; - return player.worldObj; - } else - return MinecraftServer.getServer().worldServerForDimension(0); - - } - - protected String[] getPlayers() { - return MinecraftServer.getServer().getAllUsernames(); - } - - protected void sendChatMessage(ICommandSender sender, String message) { - sender.addChatMessage(new ChatComponentText(message)); - } -} diff --git a/src/main/java/forestry/core/utils/EnumAccess.java b/src/main/java/forestry/core/utils/EnumAccess.java index 30f983b7b..dde751fda 100755 --- a/src/main/java/forestry/core/utils/EnumAccess.java +++ b/src/main/java/forestry/core/utils/EnumAccess.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.core.utils; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.util.IIcon; public enum EnumAccess { SHARED("gui.rule.shared"), VIEWABLE("gui.rule.restricted"), PRIVATE("gui.rule.private"); diff --git a/src/main/java/forestry/core/utils/FluidStackMap.java b/src/main/java/forestry/core/utils/FluidStackMap.java index 757c2b466..a4a46e677 100755 --- a/src/main/java/forestry/core/utils/FluidStackMap.java +++ b/src/main/java/forestry/core/utils/FluidStackMap.java @@ -11,6 +11,7 @@ package forestry.core.utils; import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; public class FluidStackMap extends StackMap { @@ -38,9 +39,9 @@ public class FluidStackMap extends StackMap { if (key instanceof FluidStack) return (FluidStack) key; if (key instanceof Fluid) - return LiquidHelper.getLiquid(((Fluid) key).getName(), 1); + return FluidRegistry.getFluidStack(((Fluid) key).getName(), 1); if (key instanceof String) - return LiquidHelper.getLiquid((String) key, 1); + return FluidRegistry.getFluidStack((String) key, 1); return null; } diff --git a/src/main/java/forestry/core/utils/Fluids.java b/src/main/java/forestry/core/utils/Fluids.java deleted file mode 100755 index 681b8632f..000000000 --- a/src/main/java/forestry/core/utils/Fluids.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.utils; - -import java.util.Locale; - -import net.minecraft.item.ItemStack; - -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -/** - * @author CovertJaguar - */ -public enum Fluids { - - WATER, LAVA, FUEL, BIOFUEL, CREOSOTE, STEAM; - - public String getTag() { - return name().toLowerCase(Locale.ENGLISH); - } - - public Fluid get() { - return FluidRegistry.getFluid(getTag()); - } - - public FluidStack get(int qty) { - return FluidRegistry.getFluidStack(getTag(), qty); - } - - public boolean is(Fluid fluid) { - return get() == fluid; - } - - public boolean is(FluidStack fluidStack) { - return fluidStack != null && get() == fluidStack.getFluid(); - } - - public boolean isContained(ItemStack containerStack) { - return containerStack != null && LiquidHelper.containsFluid(containerStack, Fluids.WATER.get()); - } - - public static boolean areEqual(Fluid fluid, FluidStack fluidStack) { - if (fluidStack != null && fluid == fluidStack.getFluid()) - return true; - return fluid == null && fluidStack == null; - } -} diff --git a/src/main/java/forestry/core/utils/FontColour.java b/src/main/java/forestry/core/utils/FontColour.java index ded493d51..9d5e50ffe 100755 --- a/src/main/java/forestry/core/utils/FontColour.java +++ b/src/main/java/forestry/core/utils/FontColour.java @@ -12,7 +12,6 @@ package forestry.core.utils; import java.io.InputStream; import java.util.Properties; - import net.minecraft.client.resources.IResourceManager; public class FontColour { diff --git a/src/main/java/forestry/core/utils/ForestryModEnvWarningCallable.java b/src/main/java/forestry/core/utils/ForestryModEnvWarningCallable.java index 10aeaffaf..0d499da9c 100755 --- a/src/main/java/forestry/core/utils/ForestryModEnvWarningCallable.java +++ b/src/main/java/forestry/core/utils/ForestryModEnvWarningCallable.java @@ -10,20 +10,21 @@ ******************************************************************************/ package forestry.core.utils; -import java.util.ArrayList; -import java.util.List; - import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.ICrashCallable; import cpw.mods.fml.common.Loader; import cpw.mods.fml.relauncher.Side; - import forestry.core.config.Defaults; +import forestry.plugins.PluginManager; + +import java.util.ArrayList; +import java.util.List; public class ForestryModEnvWarningCallable implements ICrashCallable { private final List modIDs; + private final List disabledModules; public ForestryModEnvWarningCallable() { this.modIDs = new ArrayList(); @@ -41,24 +42,42 @@ public class ForestryModEnvWarningCallable implements ICrashCallable { Class c = Class.forName("org.bukkit.Bukkit"); modIDs.add("Bukkit, Cauldron, or other Bukkit replacement"); } - catch (Throwable t) {} // No need to do anything. + catch (Throwable ignored) {} // No need to do anything. - // Add other bad mods here. - if (modIDs.size() > 0) { + this.disabledModules = new ArrayList(); + for (PluginManager.Module module : PluginManager.configDisabledModules) { + disabledModules.add(module.configName()); + } + + if (modIDs.size() > 0 || disabledModules.size() > 0) { FMLCommonHandler.instance().registerCrashCallable(this); } } @Override public String call() throws Exception { - String message = "[" + Defaults.MOD + "] Warning: You have mods that change the behavior of Minecraft, ForgeModLoader, and/or Minecraft Forge to your client: \r\n"; - message = message + modIDs.get(0); - for (int i = 1; i < modIDs.size(); ++i) { - message = message + ", " + modIDs.get(i); + StringBuilder message = new StringBuilder(); + if (modIDs.size() > 0) { + message.append("Warning: You have mods that change the behavior of Minecraft, ForgeModLoader, and/or Minecraft Forge to your client: \r\n"); + message.append(modIDs.get(0)); + for (int i = 1; i < modIDs.size(); ++i) { + message.append(", ").append(modIDs.get(i)); + } + message.append("\r\nThese may have caused this error, and may not be supported. Try reproducing the crash WITHOUT these mods, and report it then."); } - message = message + "\r\nThese may have caused this error, and may not be supported. Try reproducing the crash WITHOUT these mods, and report it then."; - return message; + + if (disabledModules.size() > 0) { + if (message.length() > 0) + message.append("\r\n"); + message.append("Info: The following plugins have been disabled in the config: "); + message.append(disabledModules.get(0)); + for (int i = 1; i < disabledModules.size(); ++i) { + message.append(", ").append(disabledModules.get(i)); + } + } + + return message.toString(); } @Override diff --git a/src/main/java/forestry/core/utils/ForestryResource.java b/src/main/java/forestry/core/utils/ForestryResource.java index 00e301d25..a6947e7cb 100755 --- a/src/main/java/forestry/core/utils/ForestryResource.java +++ b/src/main/java/forestry/core/utils/ForestryResource.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.core.utils; -import net.minecraft.util.ResourceLocation; - import forestry.core.config.Defaults; +import net.minecraft.util.ResourceLocation; public class ForestryResource extends ResourceLocation { diff --git a/src/main/java/forestry/core/utils/GeneticsUtil.java b/src/main/java/forestry/core/utils/GeneticsUtil.java new file mode 100644 index 000000000..3b626a160 --- /dev/null +++ b/src/main/java/forestry/core/utils/GeneticsUtil.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import com.mojang.authlib.GameProfile; + +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.ITree; +import forestry.api.core.IArmorNaturalist; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.IPollinatable; +import forestry.core.genetics.ItemGE; +import forestry.plugins.PluginArboriculture; + +public class GeneticsUtil { + + private static Set ersatzSpecimenMaterials; + + private static Set getErsatzSpecimenMaterials() { + if (ersatzSpecimenMaterials == null) { + ersatzSpecimenMaterials = new HashSet(); + for (ItemStack ersatzSpecimen : AlleleManager.ersatzSpecimen.keySet()) { + Block ersatzBlock = StackUtils.getBlock(ersatzSpecimen); + if (ersatzBlock != null) + ersatzSpecimenMaterials.add(ersatzBlock.getMaterial()); + } + } + return ersatzSpecimenMaterials; + } + + private static boolean isErsatzMaterial(Block block) { + return block != null && getErsatzSpecimenMaterials().contains(block.getMaterial()); + } + + public static boolean hasNaturalistEye(EntityPlayer player) { + ItemStack armorItem = player.inventory.armorInventory[3]; + return armorItem != null && armorItem.getItem() instanceof IArmorNaturalist + && ((IArmorNaturalist) armorItem.getItem()).canSeePollination(player, armorItem, true); + } + + public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final int x, final int y, final int z) { + TileEntity tile = world.getTileEntity(x, y, z); + + if (tile instanceof IPollinatable) { + return (IPollinatable) tile; + } + + ITree pollen = getErsatzPollen(world, x, y, z); + if (pollen != null) { + PluginArboriculture.treeInterface.setLeaves(world, pollen, owner, x, y, z); + return (IPollinatable) world.getTileEntity(x, y, z); + } + + return null; + } + + public static ITree getErsatzPollen(World world, final int x, final int y, final int z) { + Block block = world.getBlock(x, y, z); + if (!isErsatzMaterial(block)) + return null; + + int meta = world.getBlockMetadata(x, y, z); + + if (Blocks.leaves == block || Blocks.leaves2 == block) { + if ((meta & 4) != 0) { + // no-decay vanilla leaves. http://minecraft.gamepedia.com/Data_values#Leaves + // Treat them as decorative and don't pollinate. + return null; + } + meta %= 3; + } + ItemStack itemStack = new ItemStack(block, meta); + IIndividual tree = getGeneticEquivalent(itemStack); + if (tree instanceof ITree) + return (ITree) tree; + + return null; + } + + public static IIndividual getGeneticEquivalent(ItemStack itemStack) { + Item item = itemStack.getItem(); + if (item instanceof ItemGE) + return ((ItemGE) item).getIndividual(itemStack); + + for (Map.Entry entry : AlleleManager.ersatzSaplings.entrySet()) { + if (StackUtils.isIdenticalItem(itemStack, entry.getKey())) + return entry.getValue().copy(); + } + return null; + } + + public static ItemStack convertSaplingToGeneticEquivalent(ItemStack foreign) { + IIndividual tree = getGeneticEquivalent(foreign); + if (!(tree instanceof ITree)) + return null; + + ItemStack ersatz = PluginArboriculture.treeInterface.getMemberStack(tree, EnumGermlingType.SAPLING.ordinal()); + ersatz.stackSize = foreign.stackSize; + return ersatz; + } +} diff --git a/src/main/java/forestry/core/utils/GuiUtil.java b/src/main/java/forestry/core/utils/GuiUtil.java new file mode 100644 index 000000000..e5234b8a1 --- /dev/null +++ b/src/main/java/forestry/core/utils/GuiUtil.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +public class GuiUtil { + + public static boolean isIndexInRange(int index, int start, int count) { + return (index >= start) && (index < start + count); + } + +} diff --git a/src/main/java/forestry/core/utils/InventoryAdapter.java b/src/main/java/forestry/core/utils/InventoryAdapter.java deleted file mode 100755 index ea2b606cd..000000000 --- a/src/main/java/forestry/core/utils/InventoryAdapter.java +++ /dev/null @@ -1,439 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.utils; - -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 forestry.api.core.INBTTagable; -import forestry.core.config.Defaults; - -/** - * With permission from Krapht. - */ -public class InventoryAdapter implements IInventory, INBTTagable { - - private IInventory inventory = null; - //private boolean debug = false; - - public InventoryAdapter(int size, String name) { - this(size, name, 64); - } - - public InventoryAdapter(int size, String name, int stackLimit) { - this(new PlainInventory(size, name, stackLimit)); - } - - public InventoryAdapter(IInventory inventory) { - this.inventory = inventory; - configureSided(); - } - -// public InventoryAdapter enableDebug() { -// this.debug = true; -// return this; -// } - - /** - * @return Copy of this inventory. Stacks are copies. - */ - public InventoryAdapter copy() { - InventoryAdapter copy = new InventoryAdapter(inventory.getSizeInventory(), inventory.getInventoryName(), inventory.getInventoryStackLimit()); - - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (inventory.getStackInSlot(i) != null) - copy.setInventorySlotContents(i, inventory.getStackInSlot(i).copy()); - } - - return copy; - } - - public ItemStack[] getStacks() { - ItemStack[] stacks = new ItemStack[inventory.getSizeInventory()]; - for (int i = 0; i < inventory.getSizeInventory(); i++) { - stacks[i] = inventory.getStackInSlot(i); - } - return stacks; - } - - public ItemStack[] getStacks(int slot1, int length) { - ItemStack[] result = new ItemStack[length]; - for (int i = slot1; i < slot1 + length; i++) { - result[i - slot1] = inventory.getStackInSlot(i); - } - return result; - } - - public boolean tryAddStacksCopy(ItemStack[] stacks, boolean all) { - return tryAddStacksCopy(stacks, 0, this.getSizeInventory(), all); - } - - public boolean tryAddStacksCopy(ItemStack[] stacks, int startSlot, int slots, boolean all) { - - for (ItemStack stack : stacks) { - if (stack == null) - continue; - - if (!tryAddStack(stack.copy(), startSlot, slots, all)) - return false; - } - - return true; - } - - public boolean tryAddStacks(ItemStack[] stacks, boolean all) { - - boolean addedAll = true; - for (ItemStack stack : stacks) { - if (stack == null) - continue; - - if (!tryAddStack(stack, all)) - addedAll = false; - } - - return addedAll; - } - - public boolean tryAddStack(ItemStack stack, boolean all) { - return tryAddStack(stack, 0, this.getSizeInventory(), all); - } - - /** - * Tries to add a stack to the specified slot range. - * - * @param stack - * @param startSlot - * @param slots - * @param all - * @return - */ - public boolean tryAddStack(ItemStack stack, int startSlot, int slots, boolean all) { - return tryAddStack(stack, startSlot, slots, all, true); - } - - public boolean tryAddStack(ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) { - int added = addStack(stack, startSlot, slots, all, doAdd); - if (all) - return added == stack.stackSize; - else - return added > 0; - } - - public int addStack(ItemStack stack, boolean all, boolean doAdd) { - return addStack(stack, 0, this.getSizeInventory(), all, doAdd); - } - - public int addStack(ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) { - - int added = 0; - // Add to existing stacks first - for (int i = startSlot; i < startSlot + slots; i++) { - - // Empty slot. Add - if (inventory.getStackInSlot(i) == null) - continue; - - // Already occupied by different item, skip this slot. - if (!inventory.getStackInSlot(i).isItemEqual(stack)) - continue; - if (!ItemStack.areItemStackTagsEqual(inventory.getStackInSlot(i), stack)) - continue; - - int remain = stack.stackSize - added; - int space = inventory.getStackInSlot(i).getMaxStackSize() - inventory.getStackInSlot(i).stackSize; - // No space left, skip this slot. - if (space <= 0) - continue; - // Enough space - if (space >= remain) { - if (doAdd) - inventory.getStackInSlot(i).stackSize += remain; - return stack.stackSize; - } - - // Not enough space - if (doAdd) - inventory.getStackInSlot(i).stackSize = inventory.getStackInSlot(i).getMaxStackSize(); - - added += space; - } - - if (added >= stack.stackSize) - return added; - - for (int i = startSlot; i < startSlot + slots; i++) { - if (inventory.getStackInSlot(i) != null) - continue; - - if (doAdd) { - setInventorySlotContents(i, stack.copy()); - inventory.getStackInSlot(i).stackSize = stack.stackSize - added; - } - return stack.stackSize; - - } - - return added; - - } - - /* CONTAINS */ - public boolean contains(ItemStack query, int startSlot, int slots) { - ItemStack[] queryArray = new ItemStack[]{query}; - return contains(queryArray, startSlot, slots); - } - - public boolean contains(ItemStack[] query, int startSlot, int slots) { - ItemStack[] stock = getStacks(startSlot, slots); - return StackUtils.containsSets(query, stock) > 0; - } - - public boolean containsPercent(float percent, int slot1, int length) { - int amount = 0; - int stackMax = 0; - for (ItemStack itemStack : getStacks(slot1, length)) { - if (itemStack == null) { - stackMax += 64; - continue; - } - - amount += itemStack.stackSize; - stackMax += itemStack.getMaxStackSize(); - } - if (stackMax == 0) - return false; - return ((float) amount / (float) stackMax) >= percent; - } - - public boolean containsAmount(int amount, int slot1, int length) { - int total = 0; - for (ItemStack itemStack : getStacks(slot1, length)) { - if (itemStack == null) - continue; - - total += itemStack.stackSize; - if (total >= amount) - return true; - } - return false; - } - - /* REMOVAL */ - /** - * Removes a set of items from an inventory. - * Removes the exact items first if they exist, and then removes crafting equivalents. - * If the inventory doesn't have all the required items, returns false without removing anything. - * If stowContainer is true, items with containers will have their container stowed. - * @param count - * @param set - * @param firstSlotIndex - * @param slotCount - * @param player - * @param stowContainer - * @param oreDictionary - * @param craftingTools - * @return - */ - public boolean removeSets(int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) { - - ItemStack[] condensedSet = StackUtils.condenseStacks(set, -1, false); - - ItemStack[] stock = getStacks(firstSlotIndex, slotCount); - if (StackUtils.containsSets(condensedSet, stock, oreDictionary, craftingTools) < count) - return false; - - for (ItemStack stackToRemove : condensedSet) { - stackToRemove.stackSize *= count; - - // try to remove the exact stack first - removeStack(stackToRemove, firstSlotIndex, slotCount, player, stowContainer, false, false); - - // remove crafting equivalents next - if (stackToRemove.stackSize > 0) - removeStack(stackToRemove, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, craftingTools); - } - return true; - } - - /** - * Private Helper for removeSetsFromInventory. Assumes removal is possible. - */ - private void removeStack(ItemStack stackToRemove, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) { - for (int j = firstSlotIndex; j < firstSlotIndex + slotCount; j++) { - ItemStack stackInSlot = getStackInSlot(j); - if (stackInSlot == null) - continue; - - if (!StackUtils.isCraftingEquivalent(stackToRemove, stackInSlot, oreDictionary, craftingTools)) - continue; - - ItemStack removed = decrStackSize(j, stackToRemove.stackSize); - stackToRemove.stackSize -= removed.stackSize; - - if (stowContainer && stackToRemove.getItem().hasContainerItem(stackToRemove)) - StackUtils.stowContainerItem(removed, this, j, player); - - if (stackToRemove.stackSize == 0) - return; - } - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int slotId) { - return inventory.getStackInSlot(slotId); - } - - @Override - public ItemStack decrStackSize(int slotId, int count) { - return inventory.decrStackSize(slotId, count); - } - - @Override - public void setInventorySlotContents(int slotId, ItemStack itemstack) { - inventory.setInventorySlotContents(slotId, itemstack); - } - - @Override - public String getInventoryName() { - return inventory.getInventoryName(); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void markDirty() { - inventory.markDirty(); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slotIndex) { - return inventory.getStackInSlotOnClosing(slotIndex); - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return false; - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return true; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /* ISIDEDINVENTORY */ - private int[][] slotMap; - - public int[] getSizeInventorySide(int side) { - return slotMap[side]; - } - - private void configureSided() { - slotMap = new int[6][0]; - configureSided(Defaults.FACINGS, 0, getSizeInventory()); - } - - public InventoryAdapter configureSidedUp(int startSlot, int count) { - return configureSided(Defaults.FACING_UP, startSlot, count); - } - - public InventoryAdapter configureSidedDown(int startSlot, int count) { - return configureSided(Defaults.FACING_DOWN, startSlot, count); - } - - public InventoryAdapter configureSidedNorthSouth(int startSlot, int count) { - return configureSided(Defaults.FACING_NORTHSOUTH, startSlot, count); - } - - public InventoryAdapter configureSidedWestEast(int startSlot, int count) { - return configureSided(Defaults.FACING_WESTEAST, startSlot, count); - } - - public InventoryAdapter configureSidedSides(int startSlot, int count) { - return configureSided(Defaults.FACING_SIDES, startSlot, count); - } - - public InventoryAdapter configureSided(int side, int startSlot, int count) { - return configureSided(new int[]{side}, startSlot, count); - } - - public InventoryAdapter configureSided(int[] sides, int startSlot, int count) { - int[] slots = new int[count]; - for (int i = 0; i < count; i++) { - slots[i] = startSlot + i; - } - - return configureSided(sides, slots); - } - - public InventoryAdapter configureSided(int[] sides, int[] slots) { - for (int side : sides) { - slotMap[side] = slots; - } - - return this; - } - - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - if (!nbttagcompound.hasKey(inventory.getInventoryName())) - return; - - NBTTagList nbttaglist = nbttagcompound.getTagList(inventory.getInventoryName(), 10); - - for (int j = 0; j < nbttaglist.tagCount(); ++j) { - NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); - int index = nbttagcompound2.getByte("Slot"); - inventory.setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(nbttagcompound2)); - } - } - - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < inventory.getSizeInventory(); i++) { - if (inventory.getStackInSlot(i) != null) { - NBTTagCompound nbttagcompound2 = new NBTTagCompound(); - nbttagcompound2.setByte("Slot", (byte) i); - inventory.getStackInSlot(i).writeToNBT(nbttagcompound2); - nbttaglist.appendTag(nbttagcompound2); - } - } - nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist); - } - -} diff --git a/src/main/java/forestry/core/utils/ItemStackMap.java b/src/main/java/forestry/core/utils/ItemStackMap.java index 2cecc37d4..440f58a3f 100755 --- a/src/main/java/forestry/core/utils/ItemStackMap.java +++ b/src/main/java/forestry/core/utils/ItemStackMap.java @@ -13,7 +13,6 @@ package forestry.core.utils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; - import net.minecraftforge.oredict.OreDictionary; public class ItemStackMap extends StackMap { diff --git a/src/main/java/forestry/core/utils/LiquidHelper.java b/src/main/java/forestry/core/utils/LiquidHelper.java index ac019db20..98be60181 100755 --- a/src/main/java/forestry/core/utils/LiquidHelper.java +++ b/src/main/java/forestry/core/utils/LiquidHelper.java @@ -10,110 +10,66 @@ ******************************************************************************/ package forestry.core.utils; -import java.util.HashMap; -import java.util.LinkedList; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBucket; import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import cpw.mods.fml.common.registry.LanguageRegistry; - -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidHandler; import forestry.api.recipes.RecipeManagers; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; -import forestry.core.render.TextureManager; +import forestry.core.fluids.Fluids; +import forestry.core.items.ItemLiquidContainer; +import forestry.core.proxy.Proxies; public class LiquidHelper { - private static final LinkedList myLiquids = new LinkedList(); - private static final HashMap liquidMap = new HashMap(); - - public static boolean isEmptyLiquidData() { - return FluidContainerRegistry.getRegisteredFluidContainerData().length <= 0; - } - - public static boolean isEmptyContainer(ItemStack empty) { - return FluidContainerRegistry.isEmptyContainer(empty); - } - - public static FluidContainerData getEmptyContainer(ItemStack empty, FluidStack liquid) { - for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (cont.fluid.isFluidEqual(liquid) && (cont.emptyContainer != null && cont.emptyContainer.isItemEqual(empty))) - return cont; + public static void injectLiquidContainer(Fluids fluid, ItemStack filled) { + Item item = filled.getItem(); + if (item.getContainerItem() instanceof ItemBucket) { + LiquidHelper.injectLiquidContainer(fluid, Defaults.BUCKET_VOLUME, filled, new ItemStack(Items.bucket)); + return; + } else if (item instanceof ItemLiquidContainer) { + ItemLiquidContainer liquidContainer = (ItemLiquidContainer)item; + switch (liquidContainer.getType()) { + case CAN: + LiquidHelper.injectTinContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.canEmpty.getItemStack()); + return; + case CAPSULE: + LiquidHelper.injectWaxContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.waxCapsule.getItemStack()); + return; + case REFRACTORY: + LiquidHelper.injectRefractoryContainer(fluid, Defaults.BUCKET_VOLUME, filled, ForestryItem.refractoryEmpty.getItemStack()); + return; + } } - - return null; + Proxies.log.warning("Unable to inject liquid container: " + filled); } - public static FluidContainerData getLiquidContainer(ItemStack container) { - for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (cont.filledContainer.isItemEqual(container)) - return cont; - } - return null; + public static void injectLiquidContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { + injectLiquidContainer(fluid, volume, filled, empty, null, 0); } - public static FluidContainerData createLiquidData(String ident, FluidStack stillLiquid, ItemStack filled, ItemStack container) { - return new FluidContainerData(new FluidStack(getOrCreateLiquid(ident), Defaults.BUCKET_VOLUME), filled, container); + public static void injectWaxContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { + injectLiquidContainer(fluid, volume, filled, empty, ForestryItem.beeswax.getItemStack(), 10); } - public static boolean isLiquid(String ident, FluidStack stack) { - return FluidRegistry.getFluidID(ident) == stack.fluidID; + public static void injectRefractoryContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { + injectLiquidContainer(fluid, volume, filled, empty, ForestryItem.refractoryWax.getItemStack(), 10); } - public static boolean exists(String ident) { - return FluidRegistry.isFluidRegistered(ident); + public static void injectTinContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty) { + injectLiquidContainer(fluid, volume, filled, empty, ForestryItem.ingotTin.getItemStack(), 5); } - public static Fluid getFluid(String ident) { - return FluidRegistry.getFluid(ident); - } - - public static Fluid getOrCreateLiquid(String ident) { - if (!FluidRegistry.isFluidRegistered(ident)) { - Fluid fluid = new Fluid(ident); - FluidRegistry.registerFluid(fluid); - myLiquids.add(ident); - } - liquidMap.put(ident, FluidRegistry.getFluid(ident)); - return FluidRegistry.getFluid(ident); - } - - public static FluidStack getLiquid(String name, int amount) { - return FluidRegistry.getFluidStack(name, amount); - } - - public static void injectLiquidContainer(String name, int volume, ItemStack filled, ItemStack empty) { - injectLiquidContainer(name, volume, filled, empty, null, 0); - } - - public static void injectWaxContainer(String name, int volume, ItemStack filled, ItemStack empty) { - injectLiquidContainer(name, volume, filled, empty, ForestryItem.beeswax.getItemStack(), 10); - } - - public static void injectRefractoryContainer(String name, int volume, ItemStack filled, ItemStack empty) { - injectLiquidContainer(name, volume, filled, empty, ForestryItem.refractoryWax.getItemStack(), 10); - } - - public static void injectTinContainer(String name, int volume, ItemStack filled, ItemStack empty) { - injectLiquidContainer(name, volume, filled, empty, ForestryItem.ingotTin.getItemStack(), 5); - } - - public static void injectLiquidContainer(String name, int volume, ItemStack filled, ItemStack empty, ItemStack remnant, int chance) { - FluidStack contained = getLiquid(name, volume); + public static void injectLiquidContainer(Fluids fluid, int volume, ItemStack filled, ItemStack empty, ItemStack remnant, int chance) { + FluidStack contained = fluid.getFluid(volume); if (contained == null) - throw new IllegalArgumentException(String.format("Attempted to inject a liquid container for the non-existent liquid '%s'.", name)); + throw new IllegalArgumentException(String.format("Attempted to inject a liquid container for the non-existent liquid '%s'.", fluid)); FluidContainerData container = new FluidContainerData(contained, filled, empty); FluidContainerRegistry.registerFluidContainer(container); @@ -126,142 +82,4 @@ public class LiquidHelper { RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[] { container.filledContainer }, container.fluid); } - public static void resetLiquidIcons(IIconRegister register) { - for (String fluidString : myLiquids) { - Fluid fluid = getFluid(fluidString); - IIcon icon = TextureManager.getInstance().registerTex(register, "liquid/" + fluid.getName()); - fluid.setIcons(icon); - - } - } - - public static boolean handleRightClick(IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) { - if (player == null) { - return false; - } - ItemStack current = player.inventory.getCurrentItem(); - if (current != null) { - - FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current); - - if (fill && liquid != null) { - int used = tank.fill(side, liquid, true); - - if (used > 0) { - if (!player.capabilities.isCreativeMode) { - player.inventory.setInventorySlotContents(player.inventory.currentItem, StackUtils.consumeItem(current)); - player.inventory.markDirty(); - } - return true; - } - - } else if (drain) { - - FluidStack available = tank.drain(side, Integer.MAX_VALUE, false); - if (available != null) { - ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current); - - liquid = FluidContainerRegistry.getFluidForFilledItem(filled); - if (liquid != null) { - - if (current.stackSize > 1) { - if (!player.inventory.addItemStackToInventory(filled)) - return false; - player.inventory.setInventorySlotContents(player.inventory.currentItem, StackUtils.consumeItem(current)); - player.inventory.markDirty(); - } else { - player.inventory.setInventorySlotContents(player.inventory.currentItem, StackUtils.consumeItem(current)); - player.inventory.setInventorySlotContents(player.inventory.currentItem, filled); - player.inventory.markDirty(); - } - - tank.drain(side, liquid.amount, true); - return true; - } - } - } - } - return false; - } - - public static void processContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean processFilled, boolean processEmpty) { - ItemStack input = inv.getStackInSlot(inputSlot); - - if (input == null) - return; - - if (processFilled && drainContainers(fluidHandler, inv, inputSlot, outputSlot)) - return; - - if (processEmpty && fluidToFill != null) - fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill); - } - - public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) { - return fillContainers(fluidHandler, inv, inputSlot, outputSlot, fluidToFill, true); - } - - public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill, boolean doFill) { - ItemStack input = inv.getStackInSlot(inputSlot); - ItemStack output = inv.getStackInSlot(outputSlot); - ItemStack filled = getFilledContainer(fluidToFill, input); - if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && StackUtils.isIdenticalItem(filled, output)))) { - FluidStack fluidInContainer = getFluidStackInContainer(filled); - FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false); - if (drain != null && drain.amount == fluidInContainer.amount) { - if (doFill) { - fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true); - if (output == null) - inv.setInventorySlotContents(outputSlot, filled); - else - output.stackSize++; - inv.decrStackSize(inputSlot, 1); - } - return true; - } - } - return false; - } - - public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) { - ItemStack input = inv.getStackInSlot(inputSlot); - ItemStack output = inv.getStackInSlot(outputSlot); - - if (input != null) { - FluidStack fluidInContainer = getFluidStackInContainer(input); - ItemStack emptyItem = input.getItem().getContainerItem(input); - if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && StackUtils.isIdenticalItem(output, emptyItem)))) { - int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false); - if (used >= fluidInContainer.amount) { - fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true); - if (emptyItem != null) - if (output == null) - inv.setInventorySlotContents(outputSlot, emptyItem); - else - output.stackSize++; - inv.decrStackSize(inputSlot, 1); - return true; - } - } - } - return false; - } - - public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) { - if (fluid == null || empty == null) - return null; - return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty); - } - - public static FluidStack getFluidStackInContainer(ItemStack stack) { - return FluidContainerRegistry.getFluidForFilledItem(stack); - } - - public static boolean containsFluidStack(ItemStack stack, FluidStack fluidStack) { - return FluidContainerRegistry.containsFluid(stack, fluidStack); - } - - public static boolean containsFluid(ItemStack stack, Fluid fluid) { - return FluidContainerRegistry.containsFluid(stack, new FluidStack(fluid, 1)); - } } diff --git a/src/main/java/forestry/core/utils/NBTUtil.java b/src/main/java/forestry/core/utils/NBTUtil.java index 59cd1c1fc..5ad5089d7 100644 --- a/src/main/java/forestry/core/utils/NBTUtil.java +++ b/src/main/java/forestry/core/utils/NBTUtil.java @@ -12,11 +12,21 @@ package forestry.core.utils; import com.google.common.collect.ForwardingList; import cpw.mods.fml.common.ObfuscationReflectionHelper; - import java.util.ArrayList; import java.util.List; - -import net.minecraft.nbt.*; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagByte; +import net.minecraft.nbt.NBTTagByteArray; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagEnd; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; +import net.minecraft.nbt.NBTTagIntArray; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagLong; +import net.minecraft.nbt.NBTTagShort; +import net.minecraft.nbt.NBTTagString; /** * @author CovertJaguar diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java index fc93320ea..d36d473ec 100644 --- a/src/main/java/forestry/core/utils/PlayerUtil.java +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -1,9 +1,10 @@ package forestry.core.utils; import com.mojang.authlib.GameProfile; - import java.util.UUID; +import forestry.core.interfaces.IOwnable; + public class PlayerUtil { //TODO: use null everywhere instead of an emptyUUID @@ -21,4 +22,12 @@ public class PlayerUtil { return player1.getName() != null && player1.getName().equals(player2.getName()); } + public static String getOwnerName(IOwnable ownable) { + GameProfile profile = ownable.getOwnerProfile(); + if (profile == null) + return StringUtil.localize("gui.derelict"); + else + return profile.getName(); + } + } diff --git a/src/main/java/forestry/core/utils/RecipeUtil.java b/src/main/java/forestry/core/utils/RecipeUtil.java index 89dd8f684..af8054b0d 100755 --- a/src/main/java/forestry/core/utils/RecipeUtil.java +++ b/src/main/java/forestry/core/utils/RecipeUtil.java @@ -10,32 +10,57 @@ ******************************************************************************/ 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 java.util.ArrayList; +import java.util.Collections; +import java.util.List; + 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; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.oredict.OreDictionary; + +import forestry.api.recipes.RecipeManagers; +import forestry.core.fluids.Fluids; +import forestry.core.gui.ContainerDummy; +import forestry.core.interfaces.IDescriptiveRecipe; +import forestry.core.proxy.Proxies; + 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, Fluids output) { if (RecipeManagers.fermenterManager == null) return; - RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.0f, LiquidHelper.getLiquid(output, 1), LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1)); + RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.0f, output.getFluid(1), Fluids.WATER.getFluid(1)); - if (LiquidHelper.exists(Defaults.LIQUID_JUICE)) - RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, LiquidHelper.getLiquid(output, 1), LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, 1)); + if (FluidRegistry.isFluidRegistered(Fluids.JUICE.getFluid())) + RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, output.getFluid(1), Fluids.JUICE.getFluid(1)); - if (LiquidHelper.exists(Defaults.LIQUID_HONEY)) - RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, LiquidHelper.getLiquid(output, 1), LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 1)); + if (FluidRegistry.isFluidRegistered(Fluids.HONEY.getFluid())) + RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, output.getFluid(1), Fluids.HONEY.getFluid(1)); + } + + /** + * Returns a list of the ore dictionary names if they exist. + * Returns a list containing itemStack if there are no ore dictionary names. + * Used for creating recipes that should accept equivalent itemStacks, based on the ore dictionary. + */ + public static List getOreDictRecipeEquivalents(ItemStack itemStack) { + int[] oreDictIds = OreDictionary.getOreIDs(itemStack); + List oreDictNames = new ArrayList(oreDictIds.length); + for (int oreId : oreDictIds) { + String oreDictName = OreDictionary.getOreName(oreId); + oreDictNames.add(oreDictName); + } + if (oreDictNames.isEmpty()) + return Collections.singletonList(itemStack); + return oreDictNames; } public static Object[] getCraftingRecipeAsArray(Object rec) { @@ -100,7 +125,7 @@ public class RecipeUtil { // 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()); + ItemStack stack = StackUtils.createSplitStack(stockStack, 1); stockStack.stackSize--; crafting.setInventorySlotContents(slot, stack); break; @@ -111,7 +136,7 @@ public class RecipeUtil { 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()); + ItemStack stack = StackUtils.createSplitStack(stockStack, 1); stockStack.stackSize--; crafting.setInventorySlotContents(slot, stack); break; diff --git a/src/main/java/forestry/core/utils/RevolvingList.java b/src/main/java/forestry/core/utils/RevolvingList.java new file mode 100644 index 000000000..8a89b9e83 --- /dev/null +++ b/src/main/java/forestry/core/utils/RevolvingList.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.utils; + +import com.google.common.collect.ForwardingCollection; +import java.util.Collection; +import java.util.Deque; +import java.util.LinkedList; + +/** + * + * @author CovertJaguar + * @param + */ +public class RevolvingList extends ForwardingCollection { + + private final Deque list = new LinkedList(); + + public RevolvingList() { + } + + public RevolvingList(Collection collection) { + list.addAll(collection); + } + + @Override + protected Collection delegate() { + return list; + } + + public void rotateLeft() { + if (list.isEmpty()) + return; + list.addFirst(list.removeLast()); + } + + public void rotateRight() { + if (list.isEmpty()) + return; + list.addLast(list.removeFirst()); + } + + public T getCurrent() { + if (list.isEmpty()) + return null; + return list.getFirst(); + } + + public void setCurrent(T e) { + if (!contains(e)) + return; + + if (e == null) + while (getCurrent() != null) { + rotateRight(); + } + else + while (getCurrent() == null || !getCurrent().equals(e)) { + rotateRight(); + } + } + +} diff --git a/src/main/java/forestry/core/utils/Schemata.java b/src/main/java/forestry/core/utils/Schemata.java index 968d6a698..f36670e38 100755 --- a/src/main/java/forestry/core/utils/Schemata.java +++ b/src/main/java/forestry/core/utils/Schemata.java @@ -11,6 +11,7 @@ package forestry.core.utils; import forestry.core.config.Config; +import forestry.core.vect.Vect; public class Schemata { public enum EnumStructureBlock { @@ -96,7 +97,7 @@ public class Schemata { } public boolean isEnabled() { - return !Config.disabledStructures.contains(uid); + return Config.isStructureEnabled(uid); } /** diff --git a/src/main/java/forestry/core/utils/ShapedRecipeCustom.java b/src/main/java/forestry/core/utils/ShapedRecipeCustom.java index b81c79518..eaf71a8a6 100755 --- a/src/main/java/forestry/core/utils/ShapedRecipeCustom.java +++ b/src/main/java/forestry/core/utils/ShapedRecipeCustom.java @@ -10,9 +10,12 @@ ******************************************************************************/ package forestry.core.utils; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.config.ForestryItem; +import forestry.core.interfaces.IDescriptiveRecipe; import java.util.ArrayList; import java.util.HashMap; - import net.minecraft.block.Block; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; @@ -20,25 +23,19 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; - import net.minecraftforge.oredict.OreDictionary; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.config.ForestryItem; -import forestry.core.interfaces.IDescriptiveRecipe; - public class ShapedRecipeCustom implements IDescriptiveRecipe { private final int width; private final int height; - private final Object ingredients[]; + private final Object[] ingredients; private final ItemStack product; private boolean preserveNBT = false; - public ShapedRecipeCustom(int width, int height, Object ingredients[], ItemStack product) { + public ShapedRecipeCustom(int width, int height, Object[] ingredients, ItemStack product) { this.width = width; this.height = height; this.ingredients = ingredients; @@ -170,7 +167,6 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe { } /** - * @param resource * @return true if resource is a valid ingredient in this recipe. */ @SuppressWarnings("unchecked") diff --git a/src/main/java/forestry/core/utils/StackUtils.java b/src/main/java/forestry/core/utils/StackUtils.java index 14ea1fbaf..144977116 100755 --- a/src/main/java/forestry/core/utils/StackUtils.java +++ b/src/main/java/forestry/core/utils/StackUtils.java @@ -25,12 +25,10 @@ import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.oredict.OreDictionary; import forestry.core.config.Defaults; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.TileForestry; +import forestry.core.inventory.InvTools; public class StackUtils { @@ -38,10 +36,6 @@ public class StackUtils { /** * Compares item id, damage and NBT. Accepts wildcard damage. - * - * @param lhs - * @param rhs - * @return */ public static boolean isIdenticalItem(ItemStack lhs, ItemStack rhs) { if (lhs == null || rhs == null) @@ -155,9 +149,6 @@ public class StackUtils { /** * Merges the giving stack into the receiving stack as far as possible - * - * @param giver - * @param receptor */ public static void mergeStacks(ItemStack giver, ItemStack receptor) { if (receptor.stackSize >= 64) @@ -190,10 +181,6 @@ public class StackUtils { /** * Creates a split stack of the specified amount, preserving NBT data, * without decreasing the source stack. - * - * @param stack - * @param amount - * @return */ public static ItemStack createSplitStack(ItemStack stack, int amount) { ItemStack split = new ItemStack(stack.getItem(), amount, stack.getItemDamage()); @@ -209,11 +196,7 @@ public class StackUtils { } /** - * - * @param stacks - * @param maxCountedPerStack The maximum stacksize counted in a single - * stack. -1 for unlimited. - * @return + * @param maxCountedPerStack The maximum stacksize counted in a single stack. -1 for unlimited. */ public static ItemStack[] condenseStacks(ItemStack[] stacks, int maxCountedPerStack, boolean craftingEquivalency) { ArrayList condensed = new ArrayList(); @@ -245,12 +228,16 @@ public class StackUtils { return condensed.toArray(new ItemStack[condensed.size()]); } + public static boolean containsItemStack(Iterable list, ItemStack itemStack) { + for (ItemStack listStack : list) { + if (isIdenticalItem(listStack, itemStack)) + return true; + } + return false; + } + /** * Counts how many full sets are contained in the passed stock - * - * @param set - * @param stock - * @return */ public static int containsSets(ItemStack[] set, ItemStack[] stock) { return containsSets(set, stock, false, false); @@ -258,10 +245,6 @@ public class StackUtils { /** * Counts how many full sets are contained in the passed stock - * - * @param set - * @param stock - * @return */ public static int containsSets(ItemStack[] set, ItemStack[] stock, boolean oreDictionary, boolean craftingTools) { int count = 0; @@ -316,11 +299,6 @@ public class StackUtils { /** * Compare two item stacks for crafting equivalency. - * - * @param base - * @param comparison - * @param oreDictionary - * @return */ public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison, boolean oreDictionary, boolean craftingTools) { if (isCraftingEquivalent(base, comparison)) @@ -356,7 +334,7 @@ public class StackUtils { return isCraftingTool(phantom) && phantom.getItem() == actual.getItem(); } - public static void stowContainerItem(ItemStack itemstack, InventoryAdapter stowing, int slotIndex, EntityPlayer player) { + public static void stowContainerItem(ItemStack itemstack, IInventory stowing, int slotIndex, EntityPlayer player) { if (!itemstack.getItem().hasContainerItem(itemstack)) return; @@ -370,12 +348,12 @@ public class StackUtils { if (container != null) { if (itemstack.getItem().doesContainerItemLeaveCraftingGrid(itemstack)) { - if (!stowing.tryAddStack(container, true)) + if (!InvTools.tryAddStack(stowing, container, true)) if (!player.inventory.addItemStackToInventory(container)) player.dropPlayerItemWithRandomChoice(container, true); } else { - if (!stowing.tryAddStack(container, slotIndex, 1, true)) - if (!stowing.tryAddStack(container, true)) + if (!InvTools.tryAddStack(stowing, container, slotIndex, 1, true)) + if (!InvTools.tryAddStack(stowing, container, true)) player.dropPlayerItemWithRandomChoice(container, true); } } @@ -396,27 +374,6 @@ public class StackUtils { } - public static void replenishByContainer(TileForestry tile, ItemStack inventoryStack, StandardTank tank) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventoryStack); - replenishByContainer(tile, inventoryStack, container, tank); - } - - public static ItemStack replenishByContainer(TileForestry tile, ItemStack inventoryStack, FluidContainerData container, StandardTank tank) { - if (container == null) - return inventoryStack; - - if (tank.fill(container.fluid, false) >= container.fluid.amount) { - tank.fill(container.fluid, true); - if (container.filledContainer != null && container.filledContainer.getItem().hasContainerItem(container.filledContainer)) - inventoryStack = container.emptyContainer.copy(); - else - inventoryStack.stackSize--; - tile.sendNetworkUpdate(); - } - - return inventoryStack; - } - public static ItemStack copyWithRandomSize(ItemStack template, int max, Random rand) { int size = rand.nextInt(max); ItemStack created = template.copy(); @@ -451,4 +408,8 @@ public class StackUtils { public static boolean equals(Block block, ItemStack stack) { return block == getBlock(stack); } + + public static boolean equals(Block block, int meta, ItemStack stack) { + return block == getBlock(stack) && meta == stack.getItemDamage(); + } } diff --git a/src/main/java/forestry/core/utils/StringUtil.java b/src/main/java/forestry/core/utils/StringUtil.java index cfbd90c70..667ceae4d 100755 --- a/src/main/java/forestry/core/utils/StringUtil.java +++ b/src/main/java/forestry/core/utils/StringUtil.java @@ -22,6 +22,10 @@ public class StringUtil { return StatCollector.canTranslate("for." + key); } + public static boolean canTranslateTile(String key) { + return StatCollector.canTranslate("tile.for." + key); + } + public static String localize(String key) { return StatCollector.translateToLocal("for." + key).replace("\\n", "\n").replace("@", "%").replace("\\%", "@"); } @@ -89,4 +93,12 @@ public class StringUtil { public static String floatAsPercent(float val) { return (int) (val * 100) + " %"; } + + public static String line(int length) { + StringBuilder line = new StringBuilder(); + for (int i = 0; i < length; i++) + line.append("-"); + + return line.toString(); + } } diff --git a/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java b/src/main/java/forestry/core/utils/Timer.java old mode 100755 new mode 100644 similarity index 51% rename from src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java rename to src/main/java/forestry/core/utils/Timer.java index 2dee50281..68126fa6b --- a/src/main/java/forestry/apiculture/gui/ContainerBeealyzer.java +++ b/src/main/java/forestry/core/utils/Timer.java @@ -8,19 +8,29 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture.gui; +package forestry.core.utils; -import forestry.core.gui.ContainerAlyzer; -import forestry.core.config.ForestryItem; -import forestry.apiculture.items.ItemBeeGE; -import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory; +import net.minecraft.world.World; -import net.minecraft.entity.player.InventoryPlayer; +/** + * + * @author CovertJaguar + */ +public class Timer { -public class ContainerBeealyzer extends ContainerAlyzer { + private long startTime = Long.MIN_VALUE; - public ContainerBeealyzer(InventoryPlayer inventoryplayer, BeealyzerInventory inventory) { - super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, ItemBeeGE.class); - } + public boolean hasTriggered(World world, int ticks) { + long currentTime = world.getTotalWorldTime(); + if (currentTime >= (ticks + startTime) || startTime > currentTime) { + startTime = currentTime; + return true; + } + return false; + } + + public void reset() { + startTime = Long.MIN_VALUE; + } } diff --git a/src/main/java/forestry/core/utils/Utils.java b/src/main/java/forestry/core/utils/Utils.java index 06bc7b70f..4d7bf0567 100755 --- a/src/main/java/forestry/core/utils/Utils.java +++ b/src/main/java/forestry/core/utils/Utils.java @@ -10,25 +10,15 @@ ******************************************************************************/ package forestry.core.utils; -import buildcraft.api.tools.IToolWrench; -import com.mojang.authlib.GameProfile; -import cpw.mods.fml.common.registry.EntityRegistry; -import forestry.api.arboriculture.EnumGermlingType; -import forestry.api.arboriculture.ITree; -import forestry.api.core.ForestryAPI; -import forestry.api.core.IArmorNaturalist; -import forestry.api.core.ITileStructure; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IIndividual; -import forestry.api.genetics.IPollinatable; -import forestry.core.gadgets.TileForestry; -import forestry.core.proxy.Proxies; -import forestry.plugins.PluginArboriculture; +import java.security.MessageDigest; +import java.security.cert.Certificate; +import java.util.Arrays; +import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.IEntityLivingData; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -37,17 +27,19 @@ import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; -import net.minecraft.util.ChatComponentText; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import java.security.MessageDigest; -import java.security.cert.Certificate; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; +import cpw.mods.fml.common.registry.EntityRegistry; + +import forestry.api.core.ForestryAPI; +import forestry.api.core.ITileStructure; +import forestry.core.gadgets.TileForestry; +import forestry.core.proxy.Proxies; +import forestry.core.vect.Vect; + +import buildcraft.api.tools.IToolWrench; public class Utils { @@ -57,8 +49,7 @@ public class Utils { if (rand == null) rand = new Random(); - int uid = rand.nextInt(); - return uid; + return rand.nextInt(); } public static void dropInventory(TileForestry tile, World world, int x, int y, int z) { @@ -69,7 +60,7 @@ public class Utils { if (tile instanceof ITileStructure) { IInventory inventory = ((ITileStructure) tile).getInventory(); - if (inventory != null) + if (inventory != null) { for (int i = 0; i < inventory.getSizeInventory(); i++) { if (inventory.getStackInSlot(i) == null) continue; @@ -77,55 +68,42 @@ public class Utils { StackUtils.dropItemStackAsEntity(inventory.getStackInSlot(i), world, x, y, z); inventory.setInventorySlotContents(i, null); } - + } } else { - IInventory inventory; - if (tile instanceof IInventory) - inventory = (IInventory) tile; - else - inventory = tile.getInternalInventory(); + for (int slot = 0; slot < tile.getSizeInventory(); slot++) { - if (inventory != null) { - for (int slot = 0; slot < inventory.getSizeInventory(); slot++) { + ItemStack itemstack = tile.getStackInSlot(slot); - ItemStack itemstack = inventory.getStackInSlot(slot); + if (itemstack == null) + continue; - if (itemstack == null) - continue; + float f = world.rand.nextFloat() * 0.8F + 0.1F; + float f1 = world.rand.nextFloat() * 0.8F + 0.1F; + float f2 = world.rand.nextFloat() * 0.8F + 0.1F; - float f = world.rand.nextFloat() * 0.8F + 0.1F; - float f1 = world.rand.nextFloat() * 0.8F + 0.1F; - float f2 = world.rand.nextFloat() * 0.8F + 0.1F; + while (itemstack.stackSize > 0) { - while (itemstack.stackSize > 0) { + int stackPartial = world.rand.nextInt(21) + 10; + if (stackPartial > itemstack.stackSize) + stackPartial = itemstack.stackSize; + ItemStack drop = itemstack.splitStack(stackPartial); + EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, drop); + float accel = 0.05F; + entityitem.motionX = (float) world.rand.nextGaussian() * accel; + entityitem.motionY = (float) world.rand.nextGaussian() * accel + 0.2F; + entityitem.motionZ = (float) world.rand.nextGaussian() * accel; + world.spawnEntityInWorld(entityitem); - int stackPartial = world.rand.nextInt(21) + 10; - if (stackPartial > itemstack.stackSize) - stackPartial = itemstack.stackSize; - ItemStack drop = itemstack.splitStack(stackPartial); - EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, drop); - float accel = 0.05F; - entityitem.motionX = (float) world.rand.nextGaussian() * accel; - entityitem.motionY = (float) world.rand.nextGaussian() * accel + 0.2F; - entityitem.motionZ = (float) world.rand.nextGaussian() * accel; - world.spawnEntityInWorld(entityitem); - - } - - inventory.setInventorySlotContents(slot, null); } + + tile.setInventorySlotContents(slot, null); + } } } - public static boolean hasNaturalistEye(EntityPlayer player) { - ItemStack armorItem = player.inventory.armorInventory[3]; - return armorItem != null && armorItem.getItem() instanceof IArmorNaturalist - && ((IArmorNaturalist) armorItem.getItem()).canSeePollination(player, armorItem, true); - } - public static IInventory getChest(IInventory inventory) { if (!(inventory instanceof TileEntityChest)) return inventory; @@ -229,7 +207,15 @@ public class Utils { return block == Blocks.water || block == Blocks.flowing_water || block == Blocks.lava || block == Blocks.flowing_lava; } - public static boolean isUseableByPlayer(EntityPlayer player, TileEntity tile, World world, int x, int y, int z) { + public static boolean isUseableByPlayer(EntityPlayer player, TileEntity tile) { + int x = tile.xCoord; + int y = tile.yCoord; + int z = tile.zCoord; + World world = tile.getWorldObj(); + + if(tile.isInvalid()) + return false; + if (world.getTileEntity(x, y, z) != tile) return false; @@ -317,60 +303,4 @@ public class Utils { } return hex.toString(); } - - public static ItemStack convertSaplingToGeneticEquivalent(ItemStack foreign) { - - ItemStack ersatz = null; - ITree tree = null; - - for (Map.Entry entry : AlleleManager.ersatzSaplings.entrySet()) { - if (entry.getKey().getItem() != foreign.getItem()) - continue; - if (entry.getKey().getItemDamage() != foreign.getItemDamage()) - continue; - - if (entry.getValue() instanceof ITree) - tree = (ITree) entry.getValue(); - - ersatz = PluginArboriculture.treeInterface.getMemberStack(tree, EnumGermlingType.SAPLING.ordinal()); - ersatz.stackSize = foreign.stackSize; - } - - return ersatz; - } - - public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final int x, final int y, final int z) { - TileEntity tile = world.getTileEntity(x, y, z); - - IPollinatable receiver = null; - if (tile instanceof IPollinatable) - receiver = (IPollinatable) tile; - else if (!world.isAirBlock(x, y, z)) { - - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - - if (Blocks.leaves == block || Blocks.leaves2 == block) { - if ((meta & 4) != 0) { - // no-decay vanilla leaves. http://minecraft.gamepedia.com/Data_values#Leaves - // Treat them as decorative and don't pollinate. - return null; - } - meta = meta % 3; - } - - // Test for ersatz genomes - for (Map.Entry entry : AlleleManager.ersatzSpecimen.entrySet()) { - if (block == StackUtils.getBlock(entry.getKey()) && entry.getKey().getItemDamage() == meta) { - // We matched, replace the leaf block with ours and set the ersatz genome - PluginArboriculture.treeInterface.setLeaves(world, entry.getValue(), owner, x, y, z); - // Now let's pollinate - receiver = (IPollinatable) world.getTileEntity(x, y, z); - } - } - - } - - return receiver; - } } diff --git a/src/main/java/forestry/core/vect/IVect.java b/src/main/java/forestry/core/vect/IVect.java new file mode 100644 index 000000000..b20c33149 --- /dev/null +++ b/src/main/java/forestry/core/vect/IVect.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.vect; + +/** + * Represents a position or dimensions. + */ +public interface IVect { + int getX(); + int getY(); + int getZ(); + + IVect add(IVect other); + IVect add(int x, int y, int z); +} diff --git a/src/main/java/forestry/core/vect/MutableVect.java b/src/main/java/forestry/core/vect/MutableVect.java new file mode 100644 index 000000000..7a765006e --- /dev/null +++ b/src/main/java/forestry/core/vect/MutableVect.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.vect; + +/** + * Represents changeable positions or dimensions. + */ +public class MutableVect implements IVect { + public int x; + public int y; + public int z; + + public MutableVect(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public MutableVect(IVect vect) { + this.x = vect.getX(); + this.y = vect.getY(); + this.z = vect.getZ(); + } + + public MutableVect add(IVect other) { + x += other.getX(); + y += other.getY(); + z += other.getZ(); + return this; + } + + public MutableVect add(int x, int y, int z) { + this.x += x; + this.y += y; + this.z += z; + return this; + } + + public boolean advancePositionInArea(Vect area) { + // Increment z first until end reached + if (z < area.z - 1) + z++; + else { + z = 0; + + if (x < area.x - 1) + x++; + else { + x = 0; + + if (y < area.y - 1) + y++; + else + return false; + } + } + + return true; + } + + @Override + public int getX() { + return x; + } + + @Override + public int getY() { + return y; + } + + @Override + public int getZ() { + return z; + } +} diff --git a/src/main/java/forestry/core/utils/Vect.java b/src/main/java/forestry/core/vect/Vect.java old mode 100755 new mode 100644 similarity index 50% rename from src/main/java/forestry/core/utils/Vect.java rename to src/main/java/forestry/core/vect/Vect.java index 256b8c2d0..a9e0e25c3 --- a/src/main/java/forestry/core/utils/Vect.java +++ b/src/main/java/forestry/core/vect/Vect.java @@ -1,84 +1,110 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.utils; - -/** - * Generic class to represent a position or dimensions. - */ -public class Vect { - public int x; - public int y; - public int z; - - public Vect(int[] dim) { - if (dim.length != 3) - throw new RuntimeException("Cannot instantiate a vector with less or more than 3 points."); - - this.x = dim[0]; - this.y = dim[1]; - this.z = dim[2]; - } - - public Vect(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Vect add(Vect other) { - Vect result = new Vect(x, y, z); - result.x += other.x; - result.y += other.y; - result.z += other.z; - return result; - } - - public Vect multiply(float factor) { - Vect result = new Vect(x, y, z); - result.x *= factor; - result.y *= factor; - result.z *= factor; - return result; - } - - @Override - public String toString() { - return String.format("%sx%sx%s", x, y, z); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + x; - result = prime * result + y; - result = prime * result + z; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Vect other = (Vect) obj; - if (x != other.x) - return false; - if (y != other.y) - return false; - if (z != other.z) - return false; - return true; - } -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.vect; + +import java.util.Random; + +/** + * Represents an unchangeable position or dimensions. + */ +public class Vect implements IVect { + public final int x; + public final int y; + public final int z; + + public Vect(int[] dim) { + if (dim.length != 3) + throw new RuntimeException("Cannot instantiate a vector with less or more than 3 points."); + + this.x = dim[0]; + this.y = dim[1]; + this.z = dim[2]; + } + + public Vect(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public static Vect getRandomPositionInArea(Random random, IVect area) { + int x = random.nextInt(area.getX()); + int y = random.nextInt(area.getY()); + int z = random.nextInt(area.getZ()); + return new Vect(x, y, z); + } + + public static Vect add(IVect... vects) { + int x = 0; + int y = 0; + int z = 0; + for (IVect vect : vects) { + x += vect.getX(); + y += vect.getY(); + z += vect.getZ(); + } + return new Vect(x, y, z); + } + + @Override + public Vect add(IVect other) { + return new Vect(x + other.getX(), y + other.getY(), z + other.getZ()); + } + + @Override + public Vect add(int x, int y, int z) { + return new Vect(this.x + x, this.y + y, this.z + z); + } + + public Vect multiply(float factor) { + return new Vect(Math.round(x * factor), Math.round(y * factor), Math.round(z * factor)); + } + + @Override + public String toString() { + return String.format("%sx%sx%s", x, y, z); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + x; + result = prime * result + y; + result = prime * result + z; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!(obj instanceof Vect)) + return false; + Vect other = (Vect) obj; + return (x == other.x) && (y == other.y) && (z == other.z); + } + + @Override + public int getX() { + return x; + } + + @Override + public int getY() { + return y; + } + + @Override + public int getZ() { + return z; + } +} diff --git a/src/main/java/forestry/core/worldgen/BlockType.java b/src/main/java/forestry/core/worldgen/BlockType.java index 549a49498..7a9756b77 100755 --- a/src/main/java/forestry/core/worldgen/BlockType.java +++ b/src/main/java/forestry/core/worldgen/BlockType.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.core.worldgen; -import net.minecraft.block.Block; -import net.minecraft.world.World; - import forestry.api.world.ITreeGenData; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; +import net.minecraft.block.Block; +import net.minecraft.world.World; public class BlockType { @@ -34,7 +33,13 @@ public class BlockType { public void setBlock(World world, ITreeGenData tree, int x, int y, int z) { world.setBlock(x, y, z, block, meta, Defaults.FLAG_BLOCK_SYNCH); - if (world.getTileEntity(x, y, z) != null) - world.removeTileEntity(x, y, z); + } + + public int getMeta() { + return this.meta; + } + + public Block getBlock() { + return this.block; } } diff --git a/src/main/java/forestry/core/worldgen/WorldGenBase.java b/src/main/java/forestry/core/worldgen/WorldGenBase.java index 488863351..867374d3d 100755 --- a/src/main/java/forestry/core/worldgen/WorldGenBase.java +++ b/src/main/java/forestry/core/worldgen/WorldGenBase.java @@ -11,7 +11,6 @@ package forestry.core.worldgen; import java.util.Random; - import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; @@ -42,15 +41,19 @@ public abstract class WorldGenBase extends WorldGenerator { @Override public final boolean generate(World world, Random random, int x, int y, int z) { + return generate(world, random, x, y, z, false); + } + + public final boolean generate(World world, Random random, int x, int y, int z, boolean forced) { this.world = world; this.rand = random; - boolean result = subGenerate(x, y, z); + boolean result = subGenerate(x, y, z, forced); this.world = null; this.rand = null; return result; } - public boolean subGenerate(int x, int y, int z) { + public boolean subGenerate(int x, int y, int z, boolean forced) { return false; } diff --git a/src/main/java/forestry/core/worldgen/WorldGenMinableMeta.java b/src/main/java/forestry/core/worldgen/WorldGenMinableMeta.java index 810e499f4..89dca4851 100755 --- a/src/main/java/forestry/core/worldgen/WorldGenMinableMeta.java +++ b/src/main/java/forestry/core/worldgen/WorldGenMinableMeta.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.core.worldgen; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; - public class WorldGenMinableMeta extends WorldGenerator { private final Block mineableBlock; diff --git a/src/main/java/forestry/energy/EnergyManager.java b/src/main/java/forestry/energy/EnergyManager.java index ca366191c..6de21acb2 100644 --- a/src/main/java/forestry/energy/EnergyManager.java +++ b/src/main/java/forestry/energy/EnergyManager.java @@ -14,12 +14,12 @@ public class EnergyManager implements IEnergyHandler { } private final int energyPerWork; - protected EnergyStorage energyStorage; + private final EnergyStorage energyStorage; private EnergyTransferMode mode = EnergyTransferMode.BOTH; public EnergyManager(int maxTransfer, int energyPerWork, int capacity) { this.energyPerWork = scaleForDifficulty(energyPerWork); - energyStorage = new EnergyStorage(scaleForDifficulty(capacity), scaleForDifficulty(maxTransfer), scaleForDifficulty(maxTransfer)); + this.energyStorage = new EnergyStorage(scaleForDifficulty(capacity), scaleForDifficulty(maxTransfer), scaleForDifficulty(maxTransfer)); } private static int scaleForDifficulty(int energyPerUse) { @@ -143,8 +143,6 @@ public class EnergyManager implements IEnergyHandler { /** * Sends as much energy as it can to the tile at orientation. * For power sources. Ignores canExtract() - * @param orientation - * @param tile * @return amount sent */ public int sendEnergy(ForgeDirection orientation, TileEntity tile) { @@ -154,9 +152,6 @@ public class EnergyManager implements IEnergyHandler { /** * Sends amount of energy to the tile at orientation. * For power sources. Ignores canExtract() - * @param orientation - * @param tile - * @param amount * @return amount sent */ public int sendEnergy(ForgeDirection orientation, TileEntity tile, int amount) { @@ -175,7 +170,6 @@ public class EnergyManager implements IEnergyHandler { /** * Drains an amount of energy, due to decay from lack of work or other factors - * @param amount */ public void drainEnergy(int amount) { energyStorage.modifyEnergyStored(-amount); @@ -183,7 +177,6 @@ public class EnergyManager implements IEnergyHandler { /** * Creates an amount of energy, generated by engines - * @param amount */ public void generateEnergy(int amount) { energyStorage.modifyEnergyStored(amount); diff --git a/src/main/java/forestry/energy/GuiHandlerEnergy.java b/src/main/java/forestry/energy/GuiHandlerEnergy.java index 6da6891c8..b382f15e6 100755 --- a/src/main/java/forestry/energy/GuiHandlerEnergy.java +++ b/src/main/java/forestry/energy/GuiHandlerEnergy.java @@ -10,9 +10,6 @@ ******************************************************************************/ package forestry.energy; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.core.network.PacketIds; @@ -30,6 +27,8 @@ import forestry.energy.gui.GuiEngineBronze; import forestry.energy.gui.GuiEngineCopper; import forestry.energy.gui.GuiEngineTin; import forestry.energy.gui.GuiGenerator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; public class GuiHandlerEnergy extends GuiHandlerBase { diff --git a/src/main/java/forestry/energy/circuits/CircuitElectricChange.java b/src/main/java/forestry/energy/circuits/CircuitElectricChange.java index 9b9ac78fa..370da2a20 100755 --- a/src/main/java/forestry/energy/circuits/CircuitElectricChange.java +++ b/src/main/java/forestry/energy/circuits/CircuitElectricChange.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.energy.circuits; -import net.minecraft.tileentity.TileEntity; - import forestry.core.circuits.Circuit; import forestry.energy.gadgets.EngineTin; +import net.minecraft.tileentity.TileEntity; public abstract class CircuitElectricChange extends Circuit { diff --git a/src/main/java/forestry/energy/circuits/CircuitFireDampener.java b/src/main/java/forestry/energy/circuits/CircuitFireDampener.java index f8fe35a4e..5c436eb74 100755 --- a/src/main/java/forestry/energy/circuits/CircuitFireDampener.java +++ b/src/main/java/forestry/energy/circuits/CircuitFireDampener.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.energy.circuits; -import net.minecraft.tileentity.TileEntity; - import forestry.core.circuits.Circuit; import forestry.energy.gadgets.EngineCopper; +import net.minecraft.tileentity.TileEntity; public class CircuitFireDampener extends Circuit { diff --git a/src/main/java/forestry/energy/gadgets/EngineBronze.java b/src/main/java/forestry/energy/gadgets/EngineBronze.java index a07753998..0f969f272 100755 --- a/src/main/java/forestry/energy/gadgets/EngineBronze.java +++ b/src/main/java/forestry/energy/gadgets/EngineBronze.java @@ -10,29 +10,13 @@ ******************************************************************************/ package forestry.energy.gadgets; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.ForestryAPI; -import forestry.api.fuels.EngineBronzeFuel; -import forestry.api.fuels.FuelManager; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.Engine; -import forestry.core.gadgets.TileBase; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.GuiId; -import forestry.core.network.PacketPayload; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.TileInventoryAdapter; -import static forestry.factory.gadgets.MachineBottler.SLOT_PRODUCT; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; @@ -40,6 +24,25 @@ import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import forestry.api.core.ForestryAPI; +import forestry.api.fuels.EngineBronzeFuel; +import forestry.api.fuels.FuelManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.Engine; +import forestry.core.gadgets.TileBase; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.network.PacketPayload; + public class EngineBronze extends Engine implements ISidedInventory, ILiquidTankContainer { /* CONSTANTS */ @@ -62,15 +65,11 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank public void fromPacketPayload(PacketPayload payload) { super.fromPacketPayload(payload); - if (payload.intPayload[3] > 0) - shutdown = true; - else - shutdown = false; + shutdown = payload.intPayload[3] > 0; } - public FilteredTank fuelTank; - public FilteredTank heatingTank; + private final FilteredTank fuelTank; + private final FilteredTank heatingTank; private final TankManager tankManager; - private final TileInventoryAdapter inventory; public int burnTime; public int totalTime; public int currentFluidId = -1; @@ -83,7 +82,17 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank super(Defaults.ENGINE_BRONZE_HEAT_MAX, 300000, 5000); setHints(Config.hints.get("engine.bronze")); - inventory = new TileInventoryAdapter(this, 1, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 1, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tankManager.accepts(fluid); + } + + return false; + } + }); fuelTank = new FilteredTank(Defaults.ENGINE_TANK_CAPACITY, FuelManager.bronzeEngineFuel.keySet()); fuelTank.tankMode = StandardTank.TankMode.INPUT; @@ -104,33 +113,15 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank @Override public void updateServerSide() { - super.updateServerSide(); - - // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_CAN) != null) { - - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN)); - if (container != null) { - - StandardTank tank = null; - - if (heatingTank.accepts(container.fluid.getFluid())) - tank = heatingTank; - else if (fuelTank.accepts(container.fluid.getFluid())) - tank = fuelTank; - - if (tank != null) { - inventory.setInventorySlotContents(SLOT_CAN, replenishByContainer(inventory.getStackInSlot(SLOT_CAN), container, tank)); - if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0) - inventory.setInventorySlotContents(0, null); - } - } - } - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) return; + IInventoryAdapter inventory = getInternalInventory(); + // Check if we have suitable items waiting in the item slot + if (inventory.getStackInSlot(SLOT_CAN) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN); + if (getHeatLevel() <= 0.2 && heatingTank.getFluidAmount() <= 0) setErrorState(EnumErrorCode.NOHEAT); else if (burnTime <= 0 && fuelTank.getFluidAmount() <= 0) @@ -156,7 +147,8 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank if (heatStage > 0.25 && shutdown) shutdown(false); else if (shutdown) - if (heatingTank.getFluidAmount() > 0 && heatingTank.getFluid().getFluid().getName().equals(Defaults.LIQUID_LAVA)) { + + if (heatingTank.getFluidAmount() > 0 && Fluids.LAVA.is(heatingTank.getFluid())) { addHeat(Defaults.ENGINE_HEAT_VALUE_LAVA); heatingTank.drain(1, true); } @@ -232,11 +224,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank } /** - * Returns the fuel value (power per cycle) an item of the passed ItemStack - * provides - * - * @param fluid - * @return + * Returns the fuel value (power per cycle) an item of the passed fluid */ private int determineFuelValue(Fluid fluid) { if (FuelManager.bronzeEngineFuel.containsKey(fluid)) @@ -246,8 +234,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank } /** - * - * @param fluid * @return Duration of burn cycle of one bucket */ private int determineBurnTime(Fluid fluid) { @@ -298,13 +284,8 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank return (heatingTank.getFluidAmount() * i) / Defaults.ENGINE_TANK_CAPACITY; } - /** - * Reads saved data - * @param nbt - */ @Override public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); burnTime = nbt.getInteger("EngineBurnTime"); @@ -317,17 +298,11 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank } tankManager.readTanksFromNBT(nbt); - inventory.readFromNBT(nbt); } - /** - * Writes data to save - * @param nbt - */ @Override public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("EngineBurnTime", burnTime); @@ -338,7 +313,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank nbt.setString("currentFluid", fluid.getName()); tankManager.writeTanksToNBT(nbt); - inventory.writeToNBT(nbt); } /* GUI */ @@ -379,143 +353,6 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank iCrafting.sendProgressBarUpdate(containerEngine, i + 5, currentFluidId); } - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - * @param player - * @return - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - * @param slotIndex - * @param itemstack - * @return - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - if (slotIndex == SLOT_CAN) { - FluidStack fluid = LiquidHelper.getFluidStackInContainer(itemstack); - if (fluid == null || fluid.amount <= 0) - return false; - return fuelTank.accepts(fluid.getFluid()) || heatingTank.accepts(fluid.getFluid()); - } - - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /* ISIDEDINVENTORY */ - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack stack, int side) { - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack stack, int side) { - if (!super.canTakeStackFromSide(slotIndex, stack, side)) - return false; - - FluidContainerData container = LiquidHelper.getLiquidContainer(stack); - return container != null; - } - - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - * @return - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); //To change body of generated methods, choose Tools | Templates. - } - - /* ISPECIALINVENTORY */ -// @Override -// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { -// FluidContainerData container = LiquidHelper.getLiquidContainer(stack); -// if (container == null) -// return 0; -// -// return inventory.addStack(stack, false, doAdd); -// } -// -// @Override -// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { -// return null; -// } // IFluidHandler @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { diff --git a/src/main/java/forestry/energy/gadgets/EngineClockwork.java b/src/main/java/forestry/energy/gadgets/EngineClockwork.java index 4a3ceb903..c2675bdd6 100755 --- a/src/main/java/forestry/energy/gadgets/EngineClockwork.java +++ b/src/main/java/forestry/energy/gadgets/EngineClockwork.java @@ -10,17 +10,16 @@ ******************************************************************************/ package forestry.energy.gadgets; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.nbt.NBTTagCompound; - import forestry.core.TemperatureState; import forestry.core.config.Defaults; import forestry.core.gadgets.Engine; import forestry.core.gadgets.TileBase; import forestry.core.utils.DamageSourceForestry; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.FakePlayer; public class EngineClockwork extends Engine { diff --git a/src/main/java/forestry/energy/gadgets/EngineCopper.java b/src/main/java/forestry/energy/gadgets/EngineCopper.java index 9e98ee7f9..febd882a9 100755 --- a/src/main/java/forestry/energy/gadgets/EngineCopper.java +++ b/src/main/java/forestry/energy/gadgets/EngineCopper.java @@ -10,36 +10,43 @@ ******************************************************************************/ package forestry.energy.gadgets; -import buildcraft.api.statements.ITriggerExternal; +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.registry.GameData; -import forestry.api.core.EnumErrorCode; + import forestry.api.core.ForestryAPI; import forestry.api.fuels.FuelManager; +import forestry.core.EnumErrorCode; import forestry.core.TemperatureState; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.gadgets.Engine; import forestry.core.gadgets.TileBase; +import forestry.core.inventory.AdjacentInventoryCache; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.GuiId; -import forestry.core.utils.BlockUtil; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.TileInventoryAdapter; +import forestry.core.utils.GuiUtil; import forestry.factory.triggers.FactoryTriggers; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; +import buildcraft.api.statements.ITriggerExternal; public class EngineCopper extends Engine implements ISidedInventory { @@ -55,15 +62,24 @@ public class EngineCopper extends Engine implements ISidedInventory { private int totalBurnTime; private int ashProduction; private final int ashForItem; - - private final TileInventoryAdapter inventory; + private final AdjacentInventoryCache inventoryCache = new AdjacentInventoryCache(this, getTileCache()); public EngineCopper() { super(Defaults.ENGINE_COPPER_HEAT_MAX, 200000, 4000); setHints(Config.hints.get("engine.copper")); ashForItem = Defaults.ENGINE_COPPER_ASH_FOR_ITEM; - inventory = new TileInventoryAdapter(this, 5, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 5, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return slotIndex == SLOT_FUEL && FuelManager.copperEngineFuel.containsKey(itemStack); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_WASTE_1, SLOT_WASTE_COUNT); + } + }); } @Override @@ -72,7 +88,7 @@ public class EngineCopper extends Engine implements ISidedInventory { } private int getFuelSlot() { - + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_FUEL) == null) return -1; @@ -83,7 +99,7 @@ public class EngineCopper extends Engine implements ISidedInventory { } private int getFreeWasteSlot() { - + IInventoryAdapter inventory = getInternalInventory(); for (int i = SLOT_WASTE_1; i <= SLOT_WASTE_COUNT; i++) { if (inventory.getStackInSlot(i) == null) return i; @@ -99,12 +115,13 @@ public class EngineCopper extends Engine implements ISidedInventory { @Override public void updateServerSide() { - super.updateServerSide(); - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) + if (worldObj.getTotalWorldTime() % 40 != 0) return; + dumpStash(); + if (mayBurn() && burnTime > 0) { setErrorState(EnumErrorCode.OK); return; @@ -114,7 +131,7 @@ public class EngineCopper extends Engine implements ISidedInventory { } int fuelSlot = getFuelSlot(); - if (fuelSlot >= 0 && determineBurnDuration(inventory.getStackInSlot(fuelSlot)) > 0) + if (fuelSlot >= 0 && determineBurnDuration(getInternalInventory().getStackInSlot(fuelSlot)) > 0) setErrorState(EnumErrorCode.OK); else setErrorState(EnumErrorCode.NOFUEL); @@ -138,6 +155,7 @@ public class EngineCopper extends Engine implements ISidedInventory { int wasteslot = getFreeWasteSlot(); if (fuelslot >= 0 && wasteslot >= 0) { + IInventoryAdapter inventory = getInternalInventory(); burnTime = totalBurnTime = determineBurnDuration(inventory.getStackInSlot(fuelslot)); if (burnTime > 0) { fuelItem = inventory.getStackInSlot(fuelslot).getItem(); @@ -188,11 +206,13 @@ public class EngineCopper extends Engine implements ISidedInventory { // If we have reached the necessary amount, we need to add ash int wasteslot = getFreeWasteSlot(); - if (wasteslot >= 0) + if (wasteslot >= 0) { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(wasteslot) == null) inventory.setInventorySlotContents(wasteslot, ForestryItem.ash.getItemStack()); else inventory.getStackInSlot(wasteslot).stackSize++; + } // Reset ashProduction = 0; // try to dump stash @@ -201,9 +221,6 @@ public class EngineCopper extends Engine implements ISidedInventory { /** * Returns the fuel value (power per cycle) an item of the passed ItemStack provides - * - * @param fuel - * @return */ private int determineFuelValue(ItemStack fuel) { if (FuelManager.copperEngineFuel.containsKey(fuel)) @@ -214,9 +231,6 @@ public class EngineCopper extends Engine implements ISidedInventory { /** * Returns the fuel value (power per cycle) an item of the passed ItemStack provides - * - * @param fuel - * @return */ private int determineBurnDuration(ItemStack fuel) { if (FuelManager.copperEngineFuel.containsKey(fuel)) @@ -225,31 +239,22 @@ public class EngineCopper extends Engine implements ISidedInventory { return 0; } - private void dumpStash() { - ForgeDirection[] pipes = BlockUtil.getPipeDirections(worldObj, Coords(), ForgeDirection.UNKNOWN); + /* AUTO-EJECTING */ + private IInventory getWasteInventory() { + IInventoryAdapter inventory = getInternalInventory(); + if (inventory == null) + return null; - if (pipes.length > 0) - dumpToPipe(pipes); + return new InventoryMapper(inventory, SLOT_WASTE_1, SLOT_WASTE_COUNT); } - private void dumpToPipe(ForgeDirection[] pipes) { + private void dumpStash() { + IInventory wasteInventory = getWasteInventory(); + if (wasteInventory == null) + return; - for (int i = SLOT_WASTE_1; i < SLOT_WASTE_1 + SLOT_WASTE_COUNT; i++) { - if (inventory.getStackInSlot(i) == null) - continue; - if (inventory.getStackInSlot(i).stackSize <= 0) - continue; - - ArrayList filtered; - filtered = BlockUtil.filterPipeDirections(pipes, new ForgeDirection[]{getOrientation()}); - - while (inventory.getStackInSlot(i).stackSize > 0 && filtered.size() > 0) { - BlockUtil.putFromStackIntoPipe(this, filtered, inventory.getStackInSlot(i)); - } - - if (inventory.getStackInSlot(i).stackSize <= 0) - inventory.setInventorySlotContents(i, null); - } + if (!InvTools.moveOneItemToPipe(wasteInventory, tileCache)) + InvTools.moveItemStack(wasteInventory, inventoryCache.getAdjacentInventories()); } // / STATE INFORMATION @@ -272,14 +277,11 @@ public class EngineCopper extends Engine implements ISidedInventory { if (fuelSlot < 0) return false; + IInventoryAdapter inventory = getInternalInventory(); return ((float) inventory.getStackInSlot(fuelSlot).stackSize / (float) inventory.getStackInSlot(fuelSlot).getMaxStackSize()) > percentage; } // / LOADING AND SAVING - /** - * Reads saved data - * @param nbttagcompound - */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); @@ -294,15 +296,8 @@ public class EngineCopper extends Engine implements ISidedInventory { totalBurnTime = nbttagcompound.getInteger("EngineTotalTime"); if (nbttagcompound.hasKey("AshProduction")) ashProduction = nbttagcompound.getInteger("AshProduction"); - - // Fuel - inventory.readFromNBT(nbttagcompound); } - /** - * Writes data to save - * @param nbttagcompound - */ @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); @@ -314,8 +309,6 @@ public class EngineCopper extends Engine implements ISidedInventory { nbttagcompound.setInteger("EngineBurnTime", burnTime); nbttagcompound.setInteger("EngineTotalTime", totalBurnTime); nbttagcompound.setInteger("AshProduction", ashProduction); - - inventory.writeToNBT(nbttagcompound); } // / SMP GUI @@ -350,121 +343,6 @@ public class EngineCopper extends Engine implements ISidedInventory { iCrafting.sendProgressBarUpdate(containerEngine, 4, heat); } - // / IINVENTORY - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex >= SLOT_WASTE_1 && slotIndex < SLOT_WASTE_1 + SLOT_WASTE_COUNT; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_FUEL && FuelManager.copperEngineFuel.containsKey(itemstack); - } - - /* ITRIGGERPROVIDER */ @Optional.Method(modid = "BuildCraftAPI|statements") @Override diff --git a/src/main/java/forestry/energy/gadgets/EngineDefinition.java b/src/main/java/forestry/energy/gadgets/EngineDefinition.java index 271f7e1ad..db9f4f0fa 100755 --- a/src/main/java/forestry/energy/gadgets/EngineDefinition.java +++ b/src/main/java/forestry/energy/gadgets/EngineDefinition.java @@ -10,19 +10,17 @@ ******************************************************************************/ package forestry.energy.gadgets; +import forestry.core.gadgets.Engine; +import forestry.core.gadgets.MachineDefinition; +import forestry.core.interfaces.IBlockRenderer; +import forestry.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; -import forestry.core.gadgets.Engine; -import forestry.core.gadgets.MachineDefinition; -import forestry.core.interfaces.IBlockRenderer; -import forestry.core.utils.Utils; - public class EngineDefinition extends MachineDefinition { public EngineDefinition(int meta, String teIdent, Class teClass, IBlockRenderer renderer, IRecipe... recipes) { @@ -44,7 +42,7 @@ public class EngineDefinition extends MachineDefinition { return false; Engine tile = (Engine) world.getTileEntity(x, y, z); - if (player.getCurrentEquippedItem() != null && Utils.canWrench(player, x, y, z)) { + if (Utils.canWrench(player, x, y, z)) { tile.rotateEngine(); Utils.useWrench(player, x, y, z); return true; diff --git a/src/main/java/forestry/energy/gadgets/EngineTin.java b/src/main/java/forestry/energy/gadgets/EngineTin.java index e584daadc..fbbf3931a 100755 --- a/src/main/java/forestry/energy/gadgets/EngineTin.java +++ b/src/main/java/forestry/energy/gadgets/EngineTin.java @@ -17,27 +17,30 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import ic2.api.energy.prefab.BasicSink; - import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuitBoard; import forestry.api.core.ForestryAPI; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.TemperatureState; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.gadgets.Engine; import forestry.core.gadgets.TileBase; import forestry.core.interfaces.ISocketable; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.utils.DelayTimer; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; import forestry.plugins.PluginIC2; +import ic2.api.energy.prefab.BasicSink; +import ic2.api.item.ElectricItem; + public class EngineTin extends Engine implements ISocketable, IInventory { protected static class EuConfig { + public int euForCycle; public int rfPerCycle; public int euStorage; @@ -50,8 +53,7 @@ public class EngineTin extends Engine implements ISocketable, IInventory { } } - private final short batterySlot = 0; - private final InventoryAdapter inventory = new InventoryAdapter(1, "electrical"); + public static final short SLOT_BATTERY = 0; private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); private final EuConfig euConfig = new EuConfig(Defaults.ENGINE_TIN_EU_FOR_CYCLE, Defaults.ENGINE_TIN_ENERGY_PER_CYCLE, Defaults.ENGINE_TIN_MAX_EU_STORED); @@ -63,7 +65,18 @@ public class EngineTin extends Engine implements ISocketable, IInventory { super(Defaults.ENGINE_TIN_HEAT_MAX, 100000, 4000); setHints(Config.hints.get("engine.tin")); - if (PluginIC2.instance.isAvailable()) ic2EnergySink = new BasicSink(this, euConfig.euStorage, 3); + setInternalInventory(new TileInventoryAdapter(this, 1, "electrical") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_BATTERY) { + return ElectricItem.manager.getCharge(itemStack) > 0; + } + return false; + } + }); + + if (PluginIC2.instance.isAvailable()) + ic2EnergySink = new BasicSink(this, euConfig.euStorage, 3); } @Override @@ -76,8 +89,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - if (ic2EnergySink != null) ic2EnergySink.readFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); + if (ic2EnergySink != null) + ic2EnergySink.readFromNBT(nbttagcompound); sockets.readFromNBT(nbttagcompound); ItemStack chip = sockets.getStackInSlot(0); @@ -92,21 +105,23 @@ public class EngineTin extends Engine implements ISocketable, IInventory { public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - if (ic2EnergySink != null) ic2EnergySink.writeToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); + if (ic2EnergySink != null) + ic2EnergySink.writeToNBT(nbttagcompound); sockets.writeToNBT(nbttagcompound); } @Override public void onChunkUnload() { - if (ic2EnergySink != null) ic2EnergySink.onChunkUnload(); + if (ic2EnergySink != null) + ic2EnergySink.onChunkUnload(); super.onChunkUnload(); } @Override public void invalidate() { - if (ic2EnergySink != null) ic2EnergySink.invalidate(); + if (ic2EnergySink != null) + ic2EnergySink.invalidate(); super.invalidate(); } @@ -162,14 +177,14 @@ public class EngineTin extends Engine implements ISocketable, IInventory { return; } - if (inventory.getStackInSlot(batterySlot) != null) - replenishFromBattery(batterySlot); + if (getInternalInventory().getStackInSlot(SLOT_BATTERY) != null) + replenishFromBattery(SLOT_BATTERY); // Updating of gui delayed to prevent it from going crazy if (!delayUpdateTimer.delayPassed(worldObj, 80)) return; - if (currentOutput <= 0) + if (!ic2EnergySink.canUseEnergy(euConfig.euForCycle)) setErrorState(EnumErrorCode.NOFUEL); else setErrorState(EnumErrorCode.OK); @@ -194,7 +209,7 @@ public class EngineTin extends Engine implements ISocketable, IInventory { if (!isActivated()) return; - ic2EnergySink.discharge(inventory.getStackInSlot(slot), euConfig.euForCycle * 3); + ic2EnergySink.discharge(getInternalInventory().getStackInSlot(slot), euConfig.euForCycle * 3); } // / STATE INFORMATION @@ -204,7 +219,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { } public int getStorageScaled(int i) { - if (ic2EnergySink == null) return 0; + if (ic2EnergySink == null) + return 0; return Math.min(i, (int) (ic2EnergySink.getEnergyStored() * i) / ic2EnergySink.getCapacity()); } @@ -239,7 +255,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { heat = j; break; case 3: - if (ic2EnergySink != null) ic2EnergySink.setEnergyStored(j); + if (ic2EnergySink != null) + ic2EnergySink.setEnergyStored(j); break; } @@ -250,9 +267,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { iCrafting.sendProgressBarUpdate(containerEngine, 0, currentOutput); iCrafting.sendProgressBarUpdate(containerEngine, 1, energyManager.toPacketInt()); iCrafting.sendProgressBarUpdate(containerEngine, 2, heat); - if (ic2EnergySink != null) { + if (ic2EnergySink != null) iCrafting.sendProgressBarUpdate(containerEngine, 3, (short) ic2EnergySink.getEnergyStored()); - } } // / ENERGY CONFIG CHANGE @@ -261,75 +277,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { euConfig.rfPerCycle += rfChange; euConfig.euStorage += storageChange; - if (ic2EnergySink != null) ic2EnergySink.setCapacity(euConfig.euStorage); - } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); + if (ic2EnergySink != null) + ic2EnergySink.setCapacity(euConfig.euStorage); } /* ISOCKETABLE */ @@ -358,9 +307,8 @@ public class EngineTin extends Engine implements ISocketable, IInventory { } sockets.setInventorySlotContents(slot, stack); - if (stack == null) { + if (stack == null) return; - } ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitboard(stack); if (chipset != null) diff --git a/src/main/java/forestry/energy/gadgets/MachineGenerator.java b/src/main/java/forestry/energy/gadgets/MachineGenerator.java index bcec54700..f748338a3 100755 --- a/src/main/java/forestry/energy/gadgets/MachineGenerator.java +++ b/src/main/java/forestry/energy/gadgets/MachineGenerator.java @@ -13,66 +13,68 @@ package forestry.energy.gadgets; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; - -import ic2.api.energy.prefab.BasicSource; +import net.minecraftforge.fluids.FluidTankInfo; import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; import forestry.api.fuels.FuelManager; import forestry.api.fuels.GeneratorFuel; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Config; import forestry.core.config.Defaults; -import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; import forestry.core.gadgets.TileBase; import forestry.core.interfaces.ILiquidTankContainer; import forestry.core.interfaces.IRenderableMachine; -import forestry.core.network.EntityNetData; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; import forestry.plugins.PluginIC2; -import net.minecraftforge.fluids.FluidTankInfo; -public class MachineGenerator extends TileBase implements ISpecialInventory, ILiquidTankContainer, IRenderableMachine { +import ic2.api.energy.prefab.BasicSource; + +public class MachineGenerator extends TileBase implements ISidedInventory, ILiquidTankContainer, IRenderableMachine { // / CONSTANTS public static final short SLOT_CAN = 0; public static final int maxEnergy = 30000; - @EntityNetData public final FilteredTank resourceTank; private final TankManager tankManager; private int tickCount = 0; - private final InventoryAdapter inventory = new InventoryAdapter(1, "Items"); protected BasicSource ic2EnergySource; public MachineGenerator() { setHints(Config.hints.get("generator")); + setInternalInventory(new TileInventoryAdapter(this, 1, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tankManager.accepts(fluid); + } + + return false; + } + }); + resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FuelManager.generatorFuel.keySet()); tankManager = new TankManager(resourceTank); - if (PluginIC2.instance.isAvailable()) { + if (PluginIC2.instance.isAvailable()) ic2EnergySource = new BasicSource(this, maxEnergy, 1); - } - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); } @Override @@ -84,49 +86,46 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); - if (ic2EnergySource != null) ic2EnergySource.writeToNBT(nbttagcompound); + if (ic2EnergySource != null) + ic2EnergySource.writeToNBT(nbttagcompound); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); } @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - if (ic2EnergySource != null) ic2EnergySource.readFromNBT(nbttagcompound); + if (ic2EnergySource != null) + ic2EnergySource.readFromNBT(nbttagcompound); tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); } @Override public void onChunkUnload() { - if (ic2EnergySource != null) ic2EnergySource.onChunkUnload(); + if (ic2EnergySource != null) + ic2EnergySource.onChunkUnload(); super.onChunkUnload(); } @Override public void invalidate() { - if (ic2EnergySource != null) ic2EnergySource.invalidate(); + if (ic2EnergySource != null) + ic2EnergySource.invalidate(); super.invalidate(); } + @Override public void updateServerSide() { - - // Check inventory slots for fuel - // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_CAN) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN)); - if (container != null) - - if (resourceTank.accepts(container.fluid.getFluid())) { - inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank)); - if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN, null); - } + if (worldObj.getTotalWorldTime() % 20 == 0) { + // Check inventory slots for fuel + // Check if we have suitable items waiting in the item slot + IInventoryAdapter inventory = getInternalInventory(); + if (inventory.getStackInSlot(SLOT_CAN) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN); } // No work to be done if IC2 is unavailable. @@ -140,8 +139,8 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi if (resourceTank.getFluidAmount() > 0) { GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid()); - if (resourceTank.getFluidAmount() >= fuel.fuelConsumed.amount && - ic2EnergySource.getFreeCapacity() >= fuel.eu) { + if (resourceTank.getFluidAmount() >= fuel.fuelConsumed.amount + && ic2EnergySource.getFreeCapacity() >= fuel.eu) { ic2EnergySource.addEnergy(fuel.eu); this.tickCount++; @@ -168,7 +167,8 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi } public int getStoredScaled(int i) { - if (ic2EnergySource == null) return 0; + if (ic2EnergySource == null) + return 0; return (int) (ic2EnergySource.getEnergyStored() * i) / maxEnergy; } @@ -184,89 +184,19 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { int firstMessageId = tankManager.maxMessageId() + 1; - if (i == firstMessageId) { - if (ic2EnergySource != null) ic2EnergySource.setEnergyStored(j); - } + if (i == firstMessageId) + if (ic2EnergySource != null) + ic2EnergySource.setEnergyStored(j); } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int firstMessageId = tankManager.maxMessageId() + 1; - if (ic2EnergySource != null) { + if (ic2EnergySource != null) iCrafting.sendProgressBarUpdate(container, firstMessageId, (short) ic2EnergySource.getEnergyStored()); - } - } - - /* IINVENTORY */ - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - - FluidContainerData container = LiquidHelper.getLiquidContainer(stack); - if (container == null) - return 0; - - if (container.fluid == null || !FuelManager.generatorFuel.containsKey(container.fluid.getFluid())) - return 0; - - if (inventory.getStackInSlot(SLOT_CAN) == null) { - if (doAdd) - inventory.setInventorySlotContents(SLOT_CAN, stack.copy()); - - return stack.stackSize; - } - - if (!inventory.getStackInSlot(SLOT_CAN).isItemEqual(stack)) - return 0; - - int space = inventory.getStackInSlot(SLOT_CAN).getMaxStackSize() - inventory.getStackInSlot(SLOT_CAN).stackSize; - if (space <= 0) - return 0; - - if (doAdd) - inventory.getStackInSlot(SLOT_CAN).stackSize += stack.stackSize; - - return Math.min(space, stack.stackSize); - - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - return null; } /* ILiquidTankContainer */ @@ -280,6 +210,7 @@ public class MachineGenerator extends TileBase implements ISpecialInventory, ILi return tankManager; } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java index c0f4c498e..32876b6c8 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineBronze.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineBronze.java @@ -10,35 +10,35 @@ ******************************************************************************/ package forestry.energy.gui; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotLiquidContainer; -import forestry.energy.gadgets.EngineBronze; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; +import forestry.energy.gadgets.EngineBronze; + public class ContainerEngineBronze extends ContainerLiquidTanks { + protected final EngineBronze engine; public ContainerEngineBronze(InventoryPlayer player, EngineBronze engine) { - super(engine, engine); + super(engine); this.engine = engine; - this.addSlot(new SlotLiquidContainer(engine, EngineBronze.SLOT_CAN, 143, 40)); + + this.addSlotToContainer(new SlotFiltered(engine, EngineBronze.SLOT_CAN, 143, 40)); int i; - for (i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + for (i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } - for (i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + for (i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return engine.isUseableByPlayer(entityplayer); - } - } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java index bd678ff3d..ef6e5e31c 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineCopper.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineCopper.java @@ -10,35 +10,40 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.energy.gadgets.EngineCopper; public class ContainerEngineCopper extends ContainerForestry { + protected final EngineCopper engine; public ContainerEngineCopper(InventoryPlayer player, EngineCopper tile) { super(tile); this.engine = tile; - this.addSlot(new Slot(tile, 0, 44, 46)); - this.addSlot(new SlotClosed(tile, 1, 98, 35)); - this.addSlot(new SlotClosed(tile, 2, 98, 53)); - this.addSlot(new SlotClosed(tile, 3, 116, 35)); - this.addSlot(new SlotClosed(tile, 4, 116, 53)); + this.addSlotToContainer(new SlotFiltered(tile, 0, 44, 46)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) - this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + this.addSlotToContainer(new SlotOutput(tile, 1, 98, 35)); + this.addSlotToContainer(new SlotOutput(tile, 2, 98, 53)); + this.addSlotToContainer(new SlotOutput(tile, 3, 116, 35)); + this.addSlotToContainer(new SlotOutput(tile, 4, 116, 53)); - for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } @@ -52,12 +57,9 @@ public class ContainerEngineCopper extends ContainerForestry { public void detectAndSendChanges() { super.detectAndSendChanges(); - for (Object crafter : crafters) + for (Object crafter : crafters) { engine.sendGUINetworkData(this, (ICrafting) crafter); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return engine.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/energy/gui/ContainerEngineTin.java b/src/main/java/forestry/energy/gui/ContainerEngineTin.java index d026931ce..1ba9796ad 100755 --- a/src/main/java/forestry/energy/gui/ContainerEngineTin.java +++ b/src/main/java/forestry/energy/gui/ContainerEngineTin.java @@ -15,6 +15,7 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerSocketed; +import forestry.core.gui.slots.SlotFiltered; import forestry.energy.gadgets.EngineTin; public class ContainerEngineTin extends ContainerSocketed { @@ -25,15 +26,16 @@ public class ContainerEngineTin extends ContainerSocketed { super(tile, tile); this.tile = tile; - this.addSlot(new Slot(tile, 0, 84, 53)); + + this.addSlotToContainer(new SlotFiltered(tile, EngineTin.SLOT_BATTERY, 84, 53)); int i; for (i = 0; i < 3; ++i) for (int j = 0; j < 9; ++j) - this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); for (i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); } @Override diff --git a/src/main/java/forestry/energy/gui/ContainerGenerator.java b/src/main/java/forestry/energy/gui/ContainerGenerator.java index 570a909d2..e78b0f858 100755 --- a/src/main/java/forestry/energy/gui/ContainerGenerator.java +++ b/src/main/java/forestry/energy/gui/ContainerGenerator.java @@ -10,34 +10,33 @@ ******************************************************************************/ package forestry.energy.gui; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotLiquidContainer; -import forestry.energy.gadgets.MachineGenerator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; +import forestry.energy.gadgets.MachineGenerator; + public class ContainerGenerator extends ContainerLiquidTanks { protected final MachineGenerator tile; public ContainerGenerator(InventoryPlayer player, MachineGenerator tile) { - super(tile, tile); + super(tile); this.tile = tile; - this.addSlot(new SlotLiquidContainer(tile, MachineGenerator.SLOT_CAN, 22, 38)); - for (int i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + this.addSlotToContainer(new SlotFiltered(tile, MachineGenerator.SLOT_CAN, 22, 38)); - for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); - } + for (int i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } } diff --git a/src/main/java/forestry/energy/gui/GuiEngineBronze.java b/src/main/java/forestry/energy/gui/GuiEngineBronze.java index c73d78556..6a40bab32 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineBronze.java +++ b/src/main/java/forestry/energy/gui/GuiEngineBronze.java @@ -10,16 +10,6 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.IIcon; - -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -import org.lwjgl.opengl.GL11; - import forestry.core.config.Defaults; import forestry.core.gui.WidgetManager; import forestry.core.gui.widgets.TankWidget; @@ -28,12 +18,19 @@ import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; import forestry.energy.gadgets.EngineBronze; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import org.lwjgl.opengl.GL11; public class GuiEngineBronze extends GuiEngine { protected class BiogasSlot extends Widget { - EngineBronze engine; + private final EngineBronze engine; public BiogasSlot(WidgetManager manager, int xPos, int yPos, EngineBronze engine) { super(manager, xPos, yPos); @@ -63,7 +60,7 @@ public class GuiEngineBronze extends GuiEngine { GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F); while (true) { - int x = 0; + int x; if (squaled > 16) { x = 16; @@ -90,8 +87,7 @@ public class GuiEngineBronze extends GuiEngine { if (fluid == null) return StringUtil.localize("gui.empty"); - String tooltip = fluid.getLocalizedName(new FluidStack(fluid, 1)); - return tooltip; + return fluid.getLocalizedName(new FluidStack(fluid, 1)); } } diff --git a/src/main/java/forestry/energy/gui/GuiEngineCopper.java b/src/main/java/forestry/energy/gui/GuiEngineCopper.java index 304746688..d2d33f815 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineCopper.java +++ b/src/main/java/forestry/energy/gui/GuiEngineCopper.java @@ -10,11 +10,9 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; -import forestry.core.utils.StringUtil; import forestry.energy.gadgets.EngineCopper; +import net.minecraft.entity.player.InventoryPlayer; public class GuiEngineCopper extends GuiEngine { diff --git a/src/main/java/forestry/energy/gui/GuiEngineTin.java b/src/main/java/forestry/energy/gui/GuiEngineTin.java index f1942c073..1aac72cea 100755 --- a/src/main/java/forestry/energy/gui/GuiEngineTin.java +++ b/src/main/java/forestry/energy/gui/GuiEngineTin.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.widgets.SocketWidget; import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.StringUtil; import forestry.energy.gadgets.EngineTin; +import net.minecraft.entity.player.InventoryPlayer; public class GuiEngineTin extends GuiEngine { diff --git a/src/main/java/forestry/energy/gui/GuiGenerator.java b/src/main/java/forestry/energy/gui/GuiGenerator.java index 673f10fd4..8f534bd9b 100755 --- a/src/main/java/forestry/energy/gui/GuiGenerator.java +++ b/src/main/java/forestry/energy/gui/GuiGenerator.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.energy.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.energy.gadgets.MachineGenerator; +import net.minecraft.entity.player.InventoryPlayer; public class GuiGenerator extends GuiForestryTitled { diff --git a/src/main/java/forestry/energy/render/RenderEngine.java b/src/main/java/forestry/energy/render/RenderEngine.java index 910709249..b300be8b5 100755 --- a/src/main/java/forestry/energy/render/RenderEngine.java +++ b/src/main/java/forestry/energy/render/RenderEngine.java @@ -10,22 +10,19 @@ ******************************************************************************/ package forestry.energy.render; -import net.minecraft.client.model.ModelBase; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; - -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - import forestry.core.TemperatureState; import forestry.core.config.Defaults; import forestry.core.gadgets.Engine; import forestry.core.interfaces.IBlockRenderer; import forestry.core.proxy.Proxies; import forestry.core.utils.ForestryResource; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.opengl.GL11; public class RenderEngine extends TileEntitySpecialRenderer implements IBlockRenderer { @@ -196,9 +193,11 @@ public class RenderEngine extends TileEntitySpecialRenderer implements IBlockRen Proxies.common.bindTexture(textures[Textures.EXTENSION.ordinal()]); float chamberf = 2F / 16F; - for (int i = 0; i <= step + 2; i += 2) { - extension.render(factor); - GL11.glTranslatef(translate[0] * chamberf, translate[1] * chamberf, translate[2] * chamberf); + if (step > 0) { + for (int i = 0; i <= step + 2; i += 2) { + extension.render(factor); + GL11.glTranslatef(translate[0] * chamberf, translate[1] * chamberf, translate[2] * chamberf); + } } GL11.glPopAttrib(); diff --git a/src/main/java/forestry/factory/GuiHandlerFactory.java b/src/main/java/forestry/factory/GuiHandlerFactory.java index 59a41f147..d639f15ba 100755 --- a/src/main/java/forestry/factory/GuiHandlerFactory.java +++ b/src/main/java/forestry/factory/GuiHandlerFactory.java @@ -10,9 +10,6 @@ ******************************************************************************/ package forestry.factory; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.factory.gadgets.MachineBottler; @@ -45,6 +42,8 @@ import forestry.factory.gui.GuiRaintank; import forestry.factory.gui.GuiSqueezer; import forestry.factory.gui.GuiStill; import forestry.factory.gui.GuiWorktable; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; public class GuiHandlerFactory extends GuiHandlerBase { diff --git a/src/main/java/forestry/factory/gadgets/MachineBottler.java b/src/main/java/forestry/factory/gadgets/MachineBottler.java index 0e9d01fcd..6fc7bfbeb 100755 --- a/src/main/java/forestry/factory/gadgets/MachineBottler.java +++ b/src/main/java/forestry/factory/gadgets/MachineBottler.java @@ -10,26 +10,13 @@ ******************************************************************************/ package forestry.factory.gadgets; -import buildcraft.api.statements.ITriggerExternal; -import cpw.mods.fml.common.Optional; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.ForestryAPI; -import forestry.api.recipes.ICraftingProvider; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; -import forestry.factory.triggers.FactoryTriggers; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Stack; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -38,20 +25,36 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Stack; +import cpw.mods.fml.common.Optional; + +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.ICraftingProvider; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.Utils; +import forestry.factory.triggers.FactoryTriggers; + +import buildcraft.api.statements.ITriggerExternal; public class MachineBottler extends TilePowered implements ISidedInventory, ILiquidTankContainer { @@ -64,6 +67,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq /* RECIPE MANAGMENT */ public static class Recipe { + public final int cyclesPerUnit; public final FluidStack input; public final ItemStack can; @@ -86,12 +90,10 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } public static class RecipeManager implements ICraftingProvider { + public static final ArrayList recipes = new ArrayList(); /** - * - * @param res - * @param empty * @return Recipe matching both res and empty, null if none */ public static Recipe findMatchingRecipe(FluidStack res, ItemStack empty) { @@ -103,13 +105,12 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq if (recipe.matches(res, empty)) return recipe; } - + // No recipe matched. See if the liquid dictionary has anything. - if(FluidContainerRegistry.isEmptyContainer(empty)) { - ItemStack filled = FluidContainerRegistry.fillFluidContainer(res, empty); - if(filled != null) { - FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(filled); - Recipe recipe = new Recipe(CYCLES_FILLING_DEFAULT, fluidStack, empty, filled); + if (FluidHelper.isEmptyContainer(empty)) { + ItemStack filled = FluidHelper.getFilledContainer(res, empty); + if (filled != null) { + Recipe recipe = new Recipe(CYCLES_FILLING_DEFAULT, res, empty, filled); recipes.add(recipe); return recipe; } @@ -119,8 +120,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } /** - * - * @param res * @return true if any recipe has a matching input */ public static boolean isInput(FluidStack res) { @@ -133,19 +132,17 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(new Object[] { recipe.input, recipe.can }, new Object[] { recipe.bottled }); + for (Recipe recipe : recipes) { + recipeList.put(new Object[]{recipe.input, recipe.can}, new Object[]{recipe.bottled}); + } return recipeList; } } - @EntityNetData public final StandardTank resourceTank; private final TankManager tankManager; - private final InventoryAdapter inventory = new InventoryAdapter(3, "Items"); - private boolean productPending = false; private Recipe currentRecipe; @@ -155,16 +152,30 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq public MachineBottler() { super(1100, 50, 4000); + + setInternalInventory(new TileInventoryAdapter(this, 3, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FluidContainerRegistry.isEmptyContainer(itemStack); + } else if (slotIndex == SLOT_CAN) { + FluidStack fluidStack = FluidHelper.getFluidStackInContainer(itemStack); + return RecipeManager.isInput(fluidStack); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } + }); + setHints(Config.hints.get("bottler")); resourceTank = new StandardTank(Defaults.PROCESSOR_TANK_CAPACITY); tankManager = new TankManager(resourceTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.BottlerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -180,17 +191,17 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq nbttagcompound.setBoolean("ProductPending", productPending); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); - for (int i = 0; i < offspring.length; i++) + for (int i = 0; i < offspring.length; i++) { if (offspring[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); offspring[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingProducts", nbttaglist); } @@ -204,8 +215,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("PendingProducts", 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); @@ -217,19 +226,14 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq @Override public void updateServerSide() { - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) + if (worldObj.getTotalWorldTime() % 20 != 0) return; - // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_CAN) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN)); - if (container != null && RecipeManager.isInput(container.fluid)) { + IInventoryAdapter inventory = getInternalInventory(); - inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank)); - if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN, null); - } - } + // Check if we have suitable items waiting in the item slot + if (inventory.getStackInSlot(SLOT_CAN) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN); checkRecipe(); if (getErrorState() == EnumErrorCode.NORECIPE && currentRecipe != null) @@ -237,7 +241,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq if (energyManager.getTotalEnergyStored() == 0) { setErrorState(EnumErrorCode.NOPOWER); - return; } } @@ -272,6 +275,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq // We are done, add products to queue and remove resources pendingProducts.push(currentRecipe.bottled.copy()); + IInventoryAdapter inventory = getInternalInventory(); inventory.decrStackSize(SLOT_RESOURCE, 1); resourceTank.drain(currentRecipe.input.amount, true); checkRecipe(); @@ -283,6 +287,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } public void checkRecipe() { + IInventoryAdapter inventory = getInternalInventory(); Recipe sameRec = RecipeManager.findMatchingRecipe(resourceTank.getFluid(), inventory.getStackInSlot(SLOT_RESOURCE)); if (sameRec == null) @@ -320,7 +325,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } private boolean addProduct(ItemStack product, boolean all) { - return inventory.tryAddStack(product, SLOT_PRODUCT, 1, all); + return InvTools.tryAddStack(getInternalInventory(), product, SLOT_PRODUCT, 1, all); } // / STATE INFORMATION @@ -331,6 +336,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq @Override public boolean hasResourcesMin(float percentage) { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_RESOURCE) == null) return false; @@ -360,6 +366,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; switch (i) { @@ -372,102 +379,13 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, fillingTime); iCrafting.sendProgressBarUpdate(container, i + 1, fillingTotalTime); } - /* IINVENTORY */ - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_PRODUCT; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex == SLOT_RESOURCE) - return FluidContainerRegistry.isEmptyContainer(itemstack); - - if(slotIndex == SLOT_CAN) { - FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack); - return container != null && RecipeManager.isInput(container.fluid); - } - - return false; - } - /* ILIQUIDCONTAINER */ @Override public TankManager getTankManager() { @@ -479,6 +397,7 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq return tankManager.fill(from, resource, doFill); } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } diff --git a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java index 3ce691173..f20c3a415 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCarpenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineCarpenter.java @@ -10,28 +10,11 @@ ******************************************************************************/ package forestry.factory.gadgets; -import forestry.api.core.ForestryAPI; -import forestry.api.recipes.ICarpenterManager; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryItem; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.ShapedRecipeCustom; -import forestry.core.utils.StackUtils; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; -import forestry.factory.gui.ContainerCarpenter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -40,24 +23,45 @@ import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.oredict.OreDictionary; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.ICarpenterManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryItem; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.proxy.Proxies; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.GuiUtil; +import forestry.core.utils.ShapedRecipeCustom; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; +import forestry.factory.gui.ContainerCarpenter; public class MachineCarpenter extends TilePowered implements ISidedInventory, ILiquidTankContainer { /* CONSTANTS */ public final static int SLOT_CRAFTING_1 = 0; + public final static int SLOT_CRAFTING_COUNT = 9; public final static int SLOT_BOX = 9; public final static int SLOT_PRODUCT = 10; public final static int SLOT_CAN_INPUT = 11; @@ -100,25 +104,6 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return internal.matches(inventorycrafting, world); } - public boolean hasLiquid(FluidStack resource) { - if (liquid != null && resource != null) - return liquid.isFluidEqual(resource); - else - return false; - } - - public boolean hasBox(ItemStack resource) { - if (box == null && resource == null) - return true; - else if (box == null) - return true; - - if (box.getItemDamage() > 0) - return box.isItemEqual(resource); - else - return box.getItem() == resource.getItem(); - } - public boolean isIngredient(ItemStack resource) { return internal.isIngredient(resource); } @@ -144,14 +129,24 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL @Override public void addCrating(ItemStack itemStack) { ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained(itemStack); - addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY), + addRecipe(Defaults.CARPENTER_CRATING_CYCLES, Fluids.WATER.getFluid(Defaults.CARPENTER_CRATING_LIQUID_QUANTITY), ForestryItem.crate.getItemStack(), itemStack, new Object[] { "###", "###", "###", '#', uncrated }); - addRecipe(null, new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage()), new Object[] { "#", Character.valueOf('#'), itemStack }); + addRecipe(null, new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage()), new Object[] { "#", '#', itemStack }); + } + + @Override + public void addCratingWithOreDict(ItemStack itemStack) { + ItemStack uncrated = ((forestry.core.items.ItemCrated) itemStack.getItem()).getContained(itemStack); + int[] oreIds = OreDictionary.getOreIDs(uncrated); + for (int oreId : oreIds) { + String oreName = OreDictionary.getOreName(oreId); + addCrating(oreName, uncrated, itemStack); + } } @Override public void addCrating(String toCrate, ItemStack unpack, ItemStack crated) { - addRecipe(Defaults.CARPENTER_CRATING_CYCLES, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.CARPENTER_CRATING_LIQUID_QUANTITY), + addRecipe(Defaults.CARPENTER_CRATING_CYCLES, Fluids.WATER.getFluid(Defaults.CARPENTER_CRATING_LIQUID_QUANTITY), ForestryItem.crate.getItemStack(), crated, new Object[] { "###", "###", "###", '#', toCrate }); addRecipe(null, new ItemStack(unpack.getItem(), 9, unpack.getItemDamage()), new Object[] { "#", '#', crated }); } @@ -181,10 +176,6 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return null; } - public static boolean isResourceLiquid(FluidStack liquid) { - return recipeFluids.contains(liquid.getFluid()); - } - public static boolean isBox(ItemStack resource) { for (Recipe recipe : recipes) { if (StackUtils.isIdenticalItem(recipe.getBox(), resource)) @@ -200,7 +191,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL HashMap recipeList = new HashMap(); for (Recipe recipe : recipes) { - recipeList.put(recipe.internal.getIngredients(), new Object[] { recipe.getCraftingResult() }); + recipeList.put(recipe.internal.getIngredients(), new Object[]{recipe.getCraftingResult()}); } return recipeList; @@ -208,11 +199,9 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } /* MEMBER */ - @EntityNetData public final FilteredTank resourceTank; private final TankManager tankManager; private final TileInventoryAdapter craftingInventory; - private final TileInventoryAdapter accessibleInventory; public MachineCarpenter.Recipe currentRecipe; public MachineCarpenter.Recipe lastRecipe; public ContainerCarpenter activeContainer; @@ -222,7 +211,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL private ItemStack pendingProduct; public ItemStack getBoxStack() { - return accessibleInventory.getStackInSlot(SLOT_BOX); + return getInternalInventory().getStackInSlot(SLOT_BOX); } public MachineCarpenter() { @@ -230,16 +219,38 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL setHints(Config.hints.get("carpenter")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids); craftingInventory = new TileInventoryAdapter(this, 10, "CraftItems"); - accessibleInventory = (TileInventoryAdapter) new TileInventoryAdapter(this, 30, "Items").configureSided(Defaults.FACINGS, SLOT_BOX, 20); + setInternalInventory(new TileInventoryAdapter(this, 30, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tankManager.accepts(fluid); + } else if (slotIndex == SLOT_BOX) { + return MachineCarpenter.RecipeManager.isBox(itemStack); + } + + return true; + } + + @Override + public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { + if (GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT)) { + if (lastRecipe != null) + return lastRecipe.isIngredient(itemStack); + } + return true; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } + }); + InvTools.configureSided(getInternalInventory(), Defaults.FACINGS, SLOT_BOX, 20); tankManager = new TankManager(resourceTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.CarpenterGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -256,7 +267,6 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL tankManager.writeTanksToNBT(nbttagcompound); craftingInventory.writeToNBT(nbttagcompound); - accessibleInventory.writeToNBT(nbttagcompound); // Write pending product if (pendingProduct != null) { @@ -281,21 +291,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL tankManager.readTanksFromNBT(nbttagcompound); - if (nbttagcompound.hasKey("CraftItems")) - craftingInventory.readFromNBT(nbttagcompound); - else { - // FIXME: Legacy conversion for carpenters <= 2.2.2.2 - NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10); - - for (int j = 0; j < nbttaglist.tagCount(); ++j) { - NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(j); - int index = nbttagcompound2.getByte("Slot"); - if (index < 9) - craftingInventory.setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(nbttagcompound2)); - } - - } - accessibleInventory.readFromNBT(nbttagcompound); + craftingInventory.readFromNBT(nbttagcompound); // Load pending product if (nbttagcompound.hasKey("PendingProduct")) { @@ -315,29 +311,22 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL public void setCurrentRecipe(MachineCarpenter.Recipe currentRecipe) { this.currentRecipe = currentRecipe; - if(currentRecipe != null) + if (currentRecipe != null) lastRecipe = currentRecipe; } @Override public void updateServerSide() { - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) + if (worldObj.getTotalWorldTime() % 20 != 0) return; - + IInventoryAdapter accessibleInventory = getInternalInventory(); // Check if we have suitable items waiting in the item slot if (accessibleInventory.getStackInSlot(SLOT_CAN_INPUT) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(accessibleInventory.getStackInSlot(SLOT_CAN_INPUT)); - if (container != null && RecipeManager.isResourceLiquid(container.fluid)) { - - accessibleInventory.setInventorySlotContents(SLOT_CAN_INPUT, - StackUtils.replenishByContainer(this, accessibleInventory.getStackInSlot(SLOT_CAN_INPUT), container, resourceTank)); - if (accessibleInventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0) - accessibleInventory.setInventorySlotContents(SLOT_CAN_INPUT, null); - } + FluidHelper.drainContainers(tankManager, accessibleInventory, SLOT_CAN_INPUT); } - if (worldObj.getTotalWorldTime() % 40 * 10 != 0) + if (worldObj.getTotalWorldTime() % 40 != 0) return; if (currentRecipe == null) { @@ -416,14 +405,15 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL if (resourceTank.getFluidAmount() < currentRecipe.liquid.amount) return false; + IInventoryAdapter accessibleInventory = getInternalInventory(); // Check whether boxes are available if (currentRecipe.box != null) if (accessibleInventory.getStackInSlot(SLOT_BOX) == 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); + ItemStack[] set = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + ItemStack[] stock = InvTools.getStacks(accessibleInventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);; return StackUtils.containsSets(set, stock, true, false) > 0; } @@ -439,20 +429,20 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } // Remove boxes if (recipe.box != null) { - ItemStack removed = accessibleInventory.decrStackSize(SLOT_BOX, 1); + ItemStack removed = getInternalInventory().decrStackSize(SLOT_BOX, 1); if (removed == null || removed.stackSize == 0) return false; } - - return removeSets(1, craftingInventory.getStacks(SLOT_CRAFTING_1, 9)); + return removeSets(1, InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT)); } private boolean removeSets(int count, ItemStack[] set) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, owner); - return accessibleInventory.removeSets(count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); + EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile()); + return InvTools.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); } private boolean tryAddPending() { + IInventoryAdapter accessibleInventory = getInternalInventory(); if (accessibleInventory.getStackInSlot(SLOT_PRODUCT) == null) { accessibleInventory.setInventorySlotContents(SLOT_PRODUCT, pendingProduct.copy()); pendingProduct = null; @@ -481,6 +471,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL if (currentRecipe == null) return false; + IInventoryAdapter accessibleInventory = getInternalInventory(); // Stop working if the output slot cannot take more if (accessibleInventory.getStackInSlot(SLOT_PRODUCT) != null && accessibleInventory.getStackInSlot(SLOT_PRODUCT).getMaxStackSize() - accessibleInventory.getStackInSlot(SLOT_PRODUCT).stackSize < currentRecipe @@ -507,94 +498,8 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return Utils.rateTankLevel(getResourceScaled(100)); } - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return accessibleInventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return accessibleInventory.getStackInSlot(i); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - accessibleInventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return accessibleInventory.decrStackSize(i, j); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return accessibleInventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return accessibleInventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; switch (i) { @@ -607,18 +512,13 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, packageTime); iCrafting.sendProgressBarUpdate(container, i + 1, totalTime); } - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return accessibleInventory; - } - /** * @return Inaccessible crafting inventory for the craft grid. */ @@ -626,43 +526,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return craftingInventory; } - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_PRODUCT) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_PRODUCT) - return false; - - if (slotIndex == SLOT_BOX) - return RecipeManager.isBox(itemstack); - - if (slotIndex == SLOT_CAN_INPUT) - return FluidContainerRegistry.isContainer(itemstack); - - if (slotIndex >= SLOT_INVENTORY_1 && slotIndex < SLOT_INVENTORY_1 + SLOT_INVENTORY_COUNT) { - if (lastRecipe == null) - return true; - return lastRecipe.isIngredient(itemstack); - } - - return false; - } - - // ILIQUIDCONTAINER IMPLEMENTATION + // IFLUIDCONTAINER IMPLEMENTATION @Override public int fill(ForgeDirection direction, FluidStack resource, boolean doFill) { return tankManager.fill(direction, resource, doFill); @@ -673,6 +537,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL return tankManager; } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } diff --git a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java index cf1b0a6e7..2e57edc2c 100755 --- a/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java +++ b/src/main/java/forestry/factory/gadgets/MachineCentrifuge.java @@ -10,30 +10,6 @@ ******************************************************************************/ package forestry.factory.gadgets; -import buildcraft.api.statements.ITriggerExternal; -import cpw.mods.fml.common.Optional; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; -import forestry.api.recipes.ICentrifugeManager; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.StackUtils; -import forestry.factory.triggers.FactoryTriggers; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -42,14 +18,45 @@ import java.util.Map; import java.util.Set; import java.util.Stack; -public class MachineCentrifuge extends TilePowered implements ISidedInventory, ISpecialInventory { +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.common.Optional; + +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.ICentrifugeManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.GuiUtil; +import forestry.factory.triggers.FactoryTriggers; + +import buildcraft.api.statements.ITriggerExternal; + +public class MachineCentrifuge extends TilePowered implements ISidedInventory { /* CONSTANTS */ public static final int SLOT_RESOURCE = 0; public static final int SLOT_PRODUCT_1 = 1; + public static final int SLOT_PRODUCT_COUNT = 9; /* RECIPE MANAGMENT */ public static class Recipe { + public final int timePerItem; public final ItemStack resource; public final HashMap products; @@ -76,6 +83,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I } public static class RecipeManager implements ICentrifugeManager { + public static final ArrayList recipes = new ArrayList(); @Override @@ -134,7 +142,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I } /* MEMBER */ - private final InventoryAdapter inventory = new InventoryAdapter(10, "Items"); public MachineCentrifuge.Recipe currentRecipe; private final Stack pendingProducts = new Stack(); @@ -143,12 +150,18 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I public MachineCentrifuge() { super(800, 40, Defaults.MACHINE_MAX_ENERGY); - setHints(Config.hints.get("centrifuge")); - } + setInternalInventory(new TileInventoryAdapter(this, 10, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return slotIndex == SLOT_RESOURCE && RecipeManager.findMatchingRecipe(itemStack) != null; + } - @Override - public String getInventoryName() { - return getUnlocalizedName(); + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT); + } + }); + setHints(Config.hints.get("centrifuge")); } @Override @@ -164,17 +177,16 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I nbttagcompound.setInteger("ProductionTime", productionTime); nbttagcompound.setInteger("TimePerItem", timePerItem); - inventory.writeToNBT(nbttagcompound); - NBTTagList nbttaglist = new NBTTagList(); ItemStack[] offspring = pendingProducts.toArray(new ItemStack[pendingProducts.size()]); - for (int i = 0; i < offspring.length; i++) + for (int i = 0; i < offspring.length; i++) { if (offspring[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte) i); offspring[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } + } nbttagcompound.setTag("PendingProducts", nbttaglist); } @@ -185,8 +197,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I productionTime = nbttagcompound.getInteger("ProductionTime"); timePerItem = nbttagcompound.getInteger("TimePerItem"); - inventory.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("PendingProducts", 10); for (int i = 0; i < nbttaglist.tagCount(); i++) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); @@ -209,7 +219,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I if (energyManager.getTotalEnergyStored() == 0) { setErrorState(EnumErrorCode.NOPOWER); - return; } } @@ -240,13 +249,14 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I } // We are done, add products to queue - for (Map.Entry entry : currentRecipe.products.entrySet()) + for (Map.Entry entry : currentRecipe.products.entrySet()) { if (entry.getValue() >= 100) pendingProducts.push(entry.getKey().copy()); else if (worldObj.rand.nextInt(100) < entry.getValue()) pendingProducts.push(entry.getKey().copy()); + } - inventory.decrStackSize(SLOT_RESOURCE, 1); + getInternalInventory().decrStackSize(SLOT_RESOURCE, 1); checkRecipe(); resetRecipe(); @@ -255,7 +265,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I } public void checkRecipe() { - Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE)); + Recipe sameRec = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); if (sameRec == null) setErrorState(EnumErrorCode.NORECIPE); @@ -292,7 +302,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I } private boolean addProduct(ItemStack product, boolean all) { - return inventory.tryAddStack(product, 1, getSizeInventory() - 1, all); + return InvTools.tryAddStack(getInternalInventory(), product, 1, getSizeInventory() - 1, all); } @Override @@ -302,6 +312,7 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I @Override public boolean hasResourcesMin(float percentage) { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_RESOURCE) == null) return false; @@ -337,142 +348,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I iCrafting.sendProgressBarUpdate(container, 1, timePerItem); } - /* IINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex >= SLOT_PRODUCT_1 && slotIndex < SLOT_PRODUCT_1 + 9) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_RESOURCE && RecipeManager.findMatchingRecipe(itemstack) != null) - return true; - - return false; - } - - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISPECIALINVENTORY */ - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - - ItemStack product = null; - - for (int i = SLOT_PRODUCT_1; i < inventory.getSizeInventory(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - product = StackUtils.createSplitStack(stack, 1); - if (doRemove) - decrStackSize(i, 1); - - break; - } - - if (product != null) - return new ItemStack[] { product }; - else - return new ItemStack[0]; - } - - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - ItemStack resource = inventory.getStackInSlot(SLOT_RESOURCE); - if (resource == null) { - if (doAdd) - inventory.setInventorySlotContents(SLOT_RESOURCE, stack.copy()); - return stack.stackSize; - } - - if (!StackUtils.isIdenticalItem(resource, stack)) - return 0; - - int space = resource.getMaxStackSize() - resource.stackSize; - if (space <= 0) - return 0; - - if (doAdd) - if (stack.stackSize <= space) - resource.stackSize += stack.stackSize; - else - resource.stackSize += space; - - return Math.min(stack.stackSize, space); - } - /* ITRIGGERPROVIDER */ @Optional.Method(modid = "BuildCraftAPI|statements") @Override diff --git a/src/main/java/forestry/factory/gadgets/MachineFabricator.java b/src/main/java/forestry/factory/gadgets/MachineFabricator.java index f591b17db..aba79452b 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFabricator.java +++ b/src/main/java/forestry/factory/gadgets/MachineFabricator.java @@ -14,10 +14,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import forestry.api.core.EnumErrorCode; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -25,34 +25,39 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; import forestry.api.recipes.IFabricatorManager; +import forestry.core.EnumErrorCode; import forestry.core.config.Defaults; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; import forestry.core.gadgets.TileBase; import forestry.core.gadgets.TilePowered; import forestry.core.interfaces.ICrafter; import forestry.core.interfaces.ICraftingPlan; import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryIterator; +import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.utils.InventoryAdapter; +import forestry.core.utils.GuiUtil; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.StackUtils; -import net.minecraftforge.fluids.FluidTankInfo; -public class MachineFabricator extends TilePowered implements ICrafter, ISpecialInventory, ILiquidTankContainer { +public class MachineFabricator extends TilePowered implements ICrafter, ILiquidTankContainer, ISidedInventory { /* RECIPE MANAGMENT */ public static class Recipe { - private final ItemStack plan; + private final ItemStack plan; private final FluidStack molten; private final ShapedRecipeCustom internal; @@ -62,27 +67,15 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial this.internal = internal; } - public boolean matches(ItemStack plan) { - if (this.plan == null) - return true; - else if (plan == null) - return false; - - if (this.plan.getItemDamage() == Defaults.WILDCARD) - return plan.getItem() == this.plan.getItem(); - else - return plan.isItemEqual(this.plan); - } - public boolean matches(ItemStack plan, ItemStack[][] resources) { - if (!this.matches(plan)) + if (this.plan != null && !StackUtils.isCraftingEquivalent(this.plan, plan)) return false; return internal.matches(resources); } public boolean hasLiquid(FluidStack resource) { - if(resource == null) + if (resource == null) return molten == null; if (!resource.isFluidEqual(molten)) @@ -106,14 +99,15 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial } public static class Smelting { - ItemStack resource; - FluidStack product; - int meltingPoint; + + private final ItemStack resource; + private final FluidStack product; + private final int meltingPoint; public Smelting(ItemStack resource, FluidStack molten, int meltingPoint) { - if(resource == null) + if (resource == null) throw new IllegalArgumentException("Resource cannot be null"); - if(molten == null) + if (molten == null) throw new IllegalArgumentException("Molten cannot be null"); this.resource = resource; @@ -121,10 +115,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial this.meltingPoint = meltingPoint; } - public boolean matches(ItemStack resource) { - return this.resource.isItemEqual(resource); - } - public boolean matches(FluidStack product) { return this.product.isFluidEqual(product); } @@ -143,6 +133,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial } public static class RecipeManager implements IFabricatorManager { + public static final ArrayList recipes = new ArrayList(); public static final ArrayList smeltings = new ArrayList(); @@ -156,48 +147,37 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial smeltings.add(new Smelting(resource, molten, meltingPoint)); } - public static Recipe findMatchingRecipe(ItemStack plan) { - for (Recipe recipe : recipes) - if (recipe.matches(plan)) - return recipe; - - return null; - } - - public static Recipe findMatchingRecipeIfSmelted(ItemStack plan, FluidStack liquid, ItemStack itemToMelt, ItemStack[] resources) { - Smelting smelting = findMatchingSmelting(itemToMelt); - if (smelting == null || (liquid != null && !smelting.matches(liquid))) - return findMatchingRecipe(plan, liquid, resources); - - FluidStack liquidIfSmelted; - if (liquid != null) { - liquidIfSmelted = liquid.copy(); - liquidIfSmelted.amount += smelting.getProduct().amount * itemToMelt.stackSize; - } else { - liquidIfSmelted = smelting.getProduct().copy(); - liquidIfSmelted.amount *= itemToMelt.stackSize; - } - return findMatchingRecipe(plan, liquidIfSmelted, resources); - } - public static Recipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) { ItemStack[][] gridResources = new ItemStack[3][3]; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { gridResources[j][i] = resources[i * 3 + j]; + } + } - for (Recipe recipe : recipes) + for (Recipe recipe : recipes) { if (recipe.matches(plan, gridResources)) if (recipe.hasLiquid(liquid)) return recipe; + } return null; } + public static boolean isPlan(ItemStack plan) { + for (Recipe recipe : recipes) { + if (StackUtils.isIdenticalItem(recipe.getPlan(), plan)) + return true; + } + + return false; + } + public static boolean isResourceLiquid(FluidStack liquid) { - for (Recipe recipe : recipes) + for (Recipe recipe : recipes) { if (recipe.hasLiquid(liquid)) return true; + } return false; } @@ -206,9 +186,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial if (resource == null) return null; - for (Smelting smelting : smeltings) - if (smelting.matches(resource)) + for (Smelting smelting : smeltings) { + if (StackUtils.isCraftingEquivalent(smelting.resource, resource)) return smelting; + } return null; } @@ -217,9 +198,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial if (product == null) return null; - for (Smelting smelting : smeltings) + for (Smelting smelting : smeltings) { if (smelting.matches(product)) return smelting; + } return null; } @@ -228,12 +210,12 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(recipe.internal.getIngredients(), new Object[] { recipe.internal.getRecipeOutput() }); + for (Recipe recipe : recipes) { + recipeList.put(recipe.internal.getIngredients(), new Object[]{recipe.internal.getRecipeOutput()}); + } return recipeList; } - } /* CONSTANTS */ @@ -243,13 +225,14 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial public static final short SLOT_PLAN = 1; public static final short SLOT_RESULT = 2; public static final short SLOT_CRAFTING_1 = 3; + public static final short SLOT_CRAFTING_COUNT = 9; public static final short SLOT_INVENTORY_1 = 12; public static final short SLOT_INVENTORY_COUNT = 18; /* MEMBER */ + private final InventoryMapper invCrafting; private final TankManager tankManager; - private FilteredTank moltenTank; - private final InventoryAdapter inventory = new InventoryAdapter(30, "Items"); + private final FilteredTank moltenTank; private int heat = 0; private int guiMeltingPoint = 0; @@ -257,17 +240,28 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial public MachineFabricator() { super(1100, 50, 3300); - Fluid liquidGlass = FluidRegistry.getFluid(Defaults.LIQUID_GLASS); - moltenTank = new FilteredTank(2 * Defaults.BUCKET_VOLUME, liquidGlass); + setInternalInventory(new TileInventoryAdapter(this, 30, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_METAL) { + return RecipeManager.findMatchingSmelting(itemStack) != null; + } else if (slotIndex == SLOT_PLAN) { + return RecipeManager.isPlan(itemStack); + } + return GuiUtil.isIndexInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return slotIndex == SLOT_RESULT; + } + }); + invCrafting = new InventoryMapper(getInternalInventory(), SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + moltenTank = new FilteredTank(2 * Defaults.BUCKET_VOLUME, Fluids.GLASS.getFluid()); moltenTank.tankMode = StandardTank.TankMode.INTERNAL; tankManager = new TankManager(moltenTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.FabricatorGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -289,9 +283,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial pendingSmelt.writeToNBT(smelt); nbttagcompound.setTag("PendingSmelt", smelt); } - - // / Inventory - inventory.writeToNBT(nbttagcompound); } @Override @@ -309,14 +300,12 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial pendingSmelt = FluidStack.loadFluidStackFromNBT(smelt); } - // / Inventory - inventory.readFromNBT(nbttagcompound); - } /* UPDATING */ @Override public void updateServerSide() { + IInventoryAdapter inventory = getInternalInventory(); // Add pending smelt if (pendingSmelt != null) { @@ -342,11 +331,10 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial this.dissipateHeat(); - if (energyManager.getTotalEnergyStored() == 0 && heat == 0) { + if (energyManager.getTotalEnergyStored() == 0 && heat == 0) setErrorState(EnumErrorCode.NOPOWER); - } else if (getErrorState() == EnumErrorCode.NOPOWER) { + else if (getErrorState() == EnumErrorCode.NOPOWER) setErrorState(EnumErrorCode.OK); - } } @Override @@ -372,20 +360,11 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial this.heat--; } - public Object[] getPlan() { - if (inventory.getStackInSlot(SLOT_PLAN) == null) - return null; - - Recipe myRecipe = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN)); - if (myRecipe == null) - return null; - - return myRecipe.internal.getIngredients(); - } - private Recipe getRecipe() { - return RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(), - inventory.getStacks(SLOT_CRAFTING_1, 9)); + IInventoryAdapter inventory = getInternalInventory(); + ItemStack plan = inventory.getStackInSlot(SLOT_PLAN); + ItemStack[] crafting = InvTools.getStacks(inventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting); } /* ICRAFTER */ @@ -406,7 +385,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial @Override public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { - if(slotIndex != SLOT_RESULT) + if (slotIndex != SLOT_RESULT) return null; Recipe myRecipe = getRecipe(); @@ -415,9 +394,11 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial FluidStack liquid = myRecipe.molten; + IInventoryAdapter inventory = getInternalInventory(); // Remove resources - if (removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, false)) { - removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, true); + ItemStack[] crafting = InvTools.getStacks(inventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + if (removeFromInventory(1, crafting, player, false)) { + removeFromInventory(1, crafting, player, true); moltenTank.drain(liquid.amount, true); } else if (consumeRecipe) { removeFromCraftMatrix(myRecipe); @@ -438,20 +419,20 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial } private void removeFromCraftMatrix(Recipe recipe) { - - for (int i = 0; i < 9; i++) { - if (inventory.getStackInSlot(SLOT_CRAFTING_1 + i) == null) + for (IInvSlot slot : InventoryIterator.getIterable(invCrafting)) { + if (slot.getStackInSlot() == null) continue; - inventory.decrStackSize(SLOT_CRAFTING_1 + i, 1); + slot.decreaseStackInSlot(); } } private boolean removeFromInventory(int count, ItemStack[] set, EntityPlayer player, boolean doRemove) { - if (doRemove) { - return inventory.removeSets(count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); - } else { - ItemStack[] stock = inventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + IInventoryAdapter inventory = getInternalInventory(); + if (doRemove) + return InvTools.removeSets(inventory, count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); + else { + ItemStack[] stock = InvTools.getStacks(inventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); return StackUtils.containsSets(set, stock) >= count; } } @@ -463,9 +444,16 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial @Override public boolean hasWork() { - Recipe recipe = RecipeManager.findMatchingRecipeIfSmelted(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(), inventory.getStackInSlot(SLOT_METAL), - inventory.getStacks(SLOT_CRAFTING_1, 9)); - return recipe != null; + IInventoryAdapter inventory = getInternalInventory(); + ItemStack itemToMelt = inventory.getStackInSlot(SLOT_METAL); + Smelting smelting = RecipeManager.findMatchingSmelting(itemToMelt); + if (smelting != null && moltenTank.fill(smelting.getProduct(), false) > 0) + return true; + + ItemStack plan = inventory.getStackInSlot(SLOT_PLAN); + ItemStack[] resources = InvTools.getStacks(inventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + + return RecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), resources) != null; } public int getHeatScaled(int i) { @@ -500,6 +488,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial } /* SMP */ + @Override public void getGUINetworkData(int i, int j) { int messageId = tankManager.maxMessageId() + 1; @@ -509,99 +498,13 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial guiMeltingPoint = j; } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int messageId = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, messageId, heat); iCrafting.sendProgressBarUpdate(container, messageId + 1, getMeltingPoint()); } - // / ISPECIALINVENTORY - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (from == ForgeDirection.UP && RecipeManager.findMatchingSmelting(stack) != null) - return inventory.addStack(stack, SLOT_METAL, 1, false, doAdd); - return inventory.addStack(stack, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, false, doAdd); - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - ItemStack taken; - if (doRemove) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, owner); - taken = this.takenFromSlot(SLOT_RESULT, false, player); - } else { - taken = this.getResult(); - } - - if (taken != null) - return new ItemStack[] { taken }; - else - return new ItemStack[0]; - } - - // / IINVENTORY - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - /* ILIQUIDCONTAINER */ @Override public TankManager getTankManager() { diff --git a/src/main/java/forestry/factory/gadgets/MachineFermenter.java b/src/main/java/forestry/factory/gadgets/MachineFermenter.java index 3b1925a95..160fb366f 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFermenter.java +++ b/src/main/java/forestry/factory/gadgets/MachineFermenter.java @@ -10,29 +10,13 @@ ******************************************************************************/ package forestry.factory.gadgets; -import buildcraft.api.statements.ITriggerExternal; -import cpw.mods.fml.common.Optional; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.ForestryAPI; -import forestry.api.fuels.FuelManager; -import forestry.api.recipes.IFermenterManager; -import forestry.api.recipes.IVariableFermentable; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; -import forestry.factory.triggers.FactoryTriggers; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Map; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -40,18 +24,38 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Map; +import cpw.mods.fml.common.Optional; + +import forestry.api.core.ForestryAPI; +import forestry.api.fuels.FuelManager; +import forestry.api.recipes.IFermenterManager; +import forestry.api.recipes.IVariableFermentable; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; +import forestry.factory.triggers.FactoryTriggers; + +import buildcraft.api.statements.ITriggerExternal; public class MachineFermenter extends TilePowered implements ISidedInventory, ILiquidTankContainer { @@ -135,12 +139,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL @Override public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) { - addRecipe(resource, fermentationValue, modifier, output, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000)); + addRecipe(resource, fermentationValue, modifier, output, Fluids.WATER.getFluid(1000)); } public static Recipe findMatchingRecipe(ItemStack res, FluidStack liqu) { - for (int i = 0; i < recipes.size(); i++) { - Recipe recipe = recipes.get(i); + for (Recipe recipe : recipes) { if (recipe.matches(res, liqu)) return recipe; } @@ -148,19 +151,19 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL } public static boolean isResource(ItemStack resource) { - for (int i = 0; i < recipes.size(); i++) { - Recipe recipe = recipes.get(i); - if (recipe.resource.getItemDamage() == Defaults.WILDCARD - && recipe.resource.getItem() == resource.getItem()) { + if (resource == null) + return false; + + for (Recipe recipe : recipes) { + if (StackUtils.isCraftingEquivalent(recipe.resource, resource)) return true; - } else if (recipe.resource.isItemEqual(resource)) { - return true; - } } return false; } public static boolean isLiquidResource(FluidStack liquid) { + if (liquid == null) + return false; return recipeFluidInputs.contains(liquid.getFluid()); } @@ -173,20 +176,17 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL HashMap recipeList = new HashMap(); for (Recipe recipe : recipes) { - recipeList.put(new Object[] { recipe.resource, recipe.liquid }, new Object[] { recipe.output }); + recipeList.put(new Object[]{recipe.resource, recipe.liquid}, new Object[]{recipe.output}); } return recipeList; } } - @EntityNetData public final FilteredTank resourceTank; - @EntityNetData public final FilteredTank productTank; private final TankManager tankManager; - private final InventoryAdapter inventory = new InventoryAdapter(5, "Items"); private Recipe currentRecipe; private float currentResourceModifier; public int fermentationTime = 0; @@ -197,6 +197,27 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL public MachineFermenter() { super(2000, 150, 8000); + setInternalInventory(new TileInventoryAdapter(this, 5, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return RecipeManager.isResource(itemStack); + } else if (slotIndex == SLOT_INPUT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return resourceTank.accepts(fluid); + } else if (slotIndex == SLOT_CAN_INPUT) { + return FluidHelper.isEmptyContainer(itemStack); + } else if (slotIndex == SLOT_FUEL) { + return FuelManager.fermenterFuel.containsKey(itemStack); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_CAN_OUTPUT; + } + }); setHints(Config.hints.get("fermenter")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs); resourceTank.tankMode = StandardTank.TankMode.INPUT; @@ -205,11 +226,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL tankManager = new TankManager(resourceTank, productTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.FermenterGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -226,7 +242,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL nbttagcompound.setInteger("FuelCurrentFerment", fuelCurrentFerment); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); } @@ -241,46 +256,32 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL fuelCurrentFerment = nbttagcompound.getInteger("FuelCurrentFerment"); tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); } @Override public void updateServerSide() { - // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_INPUT) != null) { - - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_INPUT)); - if (container != null && RecipeManager.isLiquidResource(container.fluid)) { - - inventory.setInventorySlotContents(SLOT_INPUT, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_INPUT), container, resourceTank)); - if (inventory.getStackInSlot(SLOT_INPUT).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_INPUT, null); - - } - } - // Can/capsule input/output needs to be handled here. - if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) { - FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), productTank.getFluid()); - - if (container != null) { - inventory.setInventorySlotContents(SLOT_CAN_OUTPUT, bottleIntoContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), inventory.getStackInSlot(SLOT_CAN_OUTPUT), container, - productTank)); - if (inventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN_INPUT, null); - } - } - - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) + if (worldObj.getTotalWorldTime() % 20 != 0) return; + IInventoryAdapter inventory = getInternalInventory(); + // Check if we have suitable items waiting in the item slot + if (inventory.getStackInSlot(SLOT_INPUT) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_INPUT); - if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null) { + // Can/capsule input/output needs to be handled here. + if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) { + FluidStack fluidStack = productTank.getFluid(); + if (fluidStack != null) + FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); + } + + if (RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null) if (resourceTank.getFluidAmount() < fuelCurrentFerment) setErrorState(EnumErrorCode.NORESOURCE); else setErrorState(EnumErrorCode.OK); - } else if (inventory.getStackInSlot(SLOT_FUEL) == null && fuelBurnTime <= 0) + else if (inventory.getStackInSlot(SLOT_FUEL) == null && fuelBurnTime <= 0) setErrorState(EnumErrorCode.NOFUEL); else if (energyManager.getTotalEnergyStored() == 0) setErrorState(EnumErrorCode.NOPOWER); @@ -295,6 +296,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL checkRecipe(); resetRecipe(); + IInventoryAdapter inventory = getInternalInventory(); if (currentRecipe != null) { currentResourceModifier = determineResourceMod(inventory.getStackInSlot(SLOT_RESOURCE)); decrStackSize(SLOT_RESOURCE, 1); @@ -315,9 +317,8 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL // input are checked, add output if possible if (!addProduct(new FluidStack(currentRecipe.output, - Math.round(fermented * currentRecipe.modifier * currentResourceModifier)))) { + Math.round(fermented * currentRecipe.modifier * currentResourceModifier)))) return false; // the output tank is too full, TODO: check/add error code? - } fuelBurnTime--; resourceTank.drain(fuelCurrentFerment, true); @@ -352,12 +353,12 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL productTank.fill(output, true); return true; - } else { + } else return false; - } } private void checkRecipe() { + IInventoryAdapter inventory = getInternalInventory(); Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()); if (currentRecipe != sameRec) @@ -377,9 +378,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL /** * Returns the burnTime an item of the passed ItemStack provides - * - * @param item - * @return */ private int determineFuelValue(ItemStack item) { if (item == null) @@ -410,13 +408,14 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL @Override public boolean isWorking() { + IInventoryAdapter inventory = getInternalInventory(); if (currentRecipe == null && RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) return false; if (fuelBurnTime > 0) return resourceTank.getFluidAmount() > 0 && productTank.getFluidAmount() < Defaults.PROCESSOR_TANK_CAPACITY; - else - return determineFuelValue(getFuelStack()) > 0; + else + return determineFuelValue(getFuelStack()) > 0; } @Override @@ -437,6 +436,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL @Override public boolean hasWork() { + IInventoryAdapter inventory = getInternalInventory(); if (this.getFuelStack() == null && fuelBurnTime <= 0) return false; else if (fuelBurnTime <= 0) @@ -491,14 +491,15 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL } public ItemStack getFermentationStack() { - return inventory.getStackInSlot(SLOT_RESOURCE); + return getInternalInventory().getStackInSlot(SLOT_RESOURCE); } public ItemStack getFuelStack() { - return inventory.getStackInSlot(SLOT_FUEL); + return getInternalInventory().getStackInSlot(SLOT_FUEL); } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { int firstMessageId = tankManager.maxMessageId() + 1; @@ -508,10 +509,11 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL fuelTotalTime = j; else if (i == firstMessageId + 2) fermentationTime = j; - else if (i == firstMessageId + 3) + else if (i == firstMessageId + 3) fermentationTotalTime = j; } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int firstMessageId = tankManager.maxMessageId() + 1; @@ -521,134 +523,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL iCrafting.sendProgressBarUpdate(container, firstMessageId + 3, fermentationTotalTime); } - /* INVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_CAN_OUTPUT) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex == SLOT_RESOURCE && RecipeManager.isResource(itemstack)) - return true; - - - if (slotIndex == SLOT_INPUT) { - FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack); - return container != null && RecipeManager.isLiquidResource(container.fluid); - } - - if (slotIndex == SLOT_CAN_INPUT && LiquidHelper.isEmptyContainer(itemstack)) { - return true; - } - if (slotIndex == SLOT_FUEL && FuelManager.fermenterFuel.containsKey(itemstack)) - return true; - - return false; - } - - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - /* ILiquidTankContainer */ @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { @@ -680,6 +554,7 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL return tankManager; } + @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } diff --git a/src/main/java/forestry/factory/gadgets/MachineMoistener.java b/src/main/java/forestry/factory/gadgets/MachineMoistener.java index c3970bdec..a3a809a57 100755 --- a/src/main/java/forestry/factory/gadgets/MachineMoistener.java +++ b/src/main/java/forestry/factory/gadgets/MachineMoistener.java @@ -10,56 +10,59 @@ ******************************************************************************/ package forestry.factory.gadgets; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.MoistenerFuel; -import forestry.api.recipes.IMoistenerManager; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.gadgets.TileBase; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.interfaces.IRenderableMachine; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import forestry.api.core.ForestryAPI; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.MoistenerFuel; +import forestry.api.recipes.IMoistenerManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.gadgets.TileBase; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.interfaces.IRenderableMachine; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.GuiUtil; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; -public class MachineMoistener extends TileBase implements ISpecialInventory, ISidedInventory, ILiquidTankContainer, IRenderableMachine { +public class MachineMoistener extends TileBase implements ISidedInventory, ILiquidTankContainer, IRenderableMachine { /* CONSTANTS */ private static final short SLOT_STASH_1 = 0; + private static final short SLOT_STASH_COUNT = 6; private static final short SLOT_RESERVOIR_1 = 6; + private static final short SLOT_RESERVOIR_COUNT = 3; private static final short SLOT_WORKING = 9; private static final short SLOT_PRODUCT = 10; private static final short SLOT_RESOURCE = 11; - private static final short SLOTS_COUNT_RESERVOIR = 3; - private static final short SLOTS_COUNT_STASH = 6; /* RECIPE MANAGMENT */ public static class Recipe { + public final int timePerItem; public final ItemStack resource; public final ItemStack product; @@ -81,6 +84,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } public static class RecipeManager implements IMoistenerManager { + public static final ArrayList recipes = new ArrayList(); @Override @@ -89,11 +93,11 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } public static boolean isResource(ItemStack resource) { - if(resource == null) + if (resource == null) return false; - for(Recipe rec : recipes) { - if(StackUtils.isIdenticalItem(resource, rec.resource)) + for (Recipe rec : recipes) { + if (StackUtils.isIdenticalItem(resource, rec.resource)) return true; } @@ -101,8 +105,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } public static Recipe findMatchingRecipe(ItemStack item) { - for (int i = 0; i < recipes.size(); i++) { - Recipe recipe = recipes.get(i); + for (Recipe recipe : recipes) { if (recipe.matches(item)) return recipe; } @@ -113,18 +116,16 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(new ItemStack[] { recipe.resource }, new ItemStack[] { recipe.product }); + for (Recipe recipe : recipes) { + recipeList.put(new ItemStack[]{recipe.resource}, new ItemStack[]{recipe.product}); + } return recipeList; } } - @EntityNetData public final FilteredTank resourceTank; private final TankManager tankManager; - private final InventoryAdapter inventory = new InventoryAdapter(12, "Items"); - //private ItemStack[] inventoryStacks = new ItemStack[12]; public MachineMoistener.Recipe currentRecipe; public int burnTime = 0; @@ -135,16 +136,39 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi private ItemStack pendingProduct; public MachineMoistener() { + setInternalInventory(new TileInventoryAdapter(this, 12, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) + return RecipeManager.isResource(itemStack); + + if (GuiUtil.isIndexInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) + return FuelManager.moistenerResource.containsKey(itemStack); + + if (slotIndex == SLOT_PRODUCT) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return resourceTank.accepts(fluid); + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + if (slotIndex == SLOT_PRODUCT) + return true; + + if (GuiUtil.isIndexInRange(slotIndex, SLOT_STASH_1, SLOT_STASH_COUNT)) + return !FuelManager.moistenerResource.containsKey(itemstack); + + return false; + } + }); setHints(Config.hints.get("moistener")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); tankManager = new TankManager(resourceTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.MoistenerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -160,7 +184,6 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi nbttagcompound.setInteger("ProductionTime", productionTime); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); // Write pending product if (pendingProduct != null) { @@ -184,7 +207,6 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi productionTime = nbttagcompound.getInteger("ProductionTime"); tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); // Load pending product if (nbttagcompound.hasKey("PendingProduct")) { @@ -202,16 +224,10 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi @Override public void updateServerSide() { + IInventoryAdapter inventory = getInternalInventory(); // Check if we have suitable water container waiting in the item slot - if (inventory.getStackInSlot(SLOT_PRODUCT) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_PRODUCT)); - if (container != null && resourceTank.accepts(container.fluid.getFluid())) { - - inventory.setInventorySlotContents(SLOT_PRODUCT, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_PRODUCT), container, resourceTank)); - if (inventory.getStackInSlot(SLOT_PRODUCT).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_PRODUCT, null); - } - } + if (inventory.getStackInSlot(SLOT_PRODUCT) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_PRODUCT); // Let's get to work int lightvalue = worldObj.getBlockLightValue(xCoord, yCoord + 1, zCoord); @@ -259,19 +275,19 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi tryAddPending(); // Try to start process else // Make sure we have a new item in the working slot. - if (rotateWorkingSlot()) { - checkRecipe(); + if (rotateWorkingSlot()) { + checkRecipe(); - // Let's see if we have a valid resource in the working slot - if (inventory.getStackInSlot(SLOT_WORKING) == null) - return; + // Let's see if we have a valid resource in the working slot + if (inventory.getStackInSlot(SLOT_WORKING) == null) + return; - if (FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(SLOT_WORKING))) { - MoistenerFuel res = FuelManager.moistenerResource.get(inventory.getStackInSlot(SLOT_WORKING)); - burnTime = totalTime = res.moistenerValue; - } - } else - rotateReservoir(); + if (FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(SLOT_WORKING))) { + MoistenerFuel res = FuelManager.moistenerResource.get(inventory.getStackInSlot(SLOT_WORKING)); + burnTime = totalTime = res.moistenerValue; + } + } else + rotateReservoir(); if (currentRecipe != null) setErrorState(EnumErrorCode.OK); @@ -283,7 +299,8 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi if (pendingProduct == null) return false; - if(inventory.tryAddStack(pendingProduct, SLOT_PRODUCT, 1, true)) { + IInventoryAdapter inventory = getInternalInventory(); + if (InvTools.tryAddStack(inventory, pendingProduct, SLOT_PRODUCT, 1, true)) { pendingProduct = null; return true; } @@ -292,7 +309,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } public void checkRecipe() { - Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE)); + Recipe sameRec = RecipeManager.findMatchingRecipe(getInternalInventory().getStackInSlot(SLOT_RESOURCE)); if (currentRecipe != sameRec) { currentRecipe = sameRec; resetRecipe(); @@ -316,6 +333,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi private int getFreeSlot(ItemStack deposit, int startSlot, int endSlot, boolean emptyOnly) { int slot = -1; + IInventoryAdapter inventory = getInternalInventory(); for (int i = startSlot; i < endSlot; i++) { ItemStack slotStack = inventory.getStackInSlot(i); // Empty slots are okay. @@ -343,7 +361,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } private int getFreeReservoirSlot(ItemStack deposit) { - return getFreeSlot(deposit, SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOTS_COUNT_RESERVOIR, false); + return getFreeSlot(deposit, SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT, false); } @@ -352,6 +370,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi int stage = -1; int resourceSlot = -1; + IInventoryAdapter inventory = getInternalInventory(); for (int i = startSlot; i < endSlot; i++) { ItemStack slotStack = inventory.getStackInSlot(i); if (slotStack == null) @@ -371,6 +390,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } private boolean rotateWorkingSlot() { + IInventoryAdapter inventory = getInternalInventory(); // Put working slot contents into inventory if space is available if (inventory.getStackInSlot(SLOT_WORKING) != null) { // Get the result of the consumed item in the working slot @@ -398,7 +418,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi return true; // Let's look for a new resource to put into the working slot. - int resourceSlot = getNextResourceSlot(SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOTS_COUNT_RESERVOIR); + int resourceSlot = getNextResourceSlot(SLOT_RESERVOIR_1, SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT); // Nothing found, stop. if (resourceSlot < 0) return false; @@ -410,7 +430,9 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi private void rotateReservoir() { ArrayList slotsToShift = new ArrayList(); - for (int i = SLOT_RESERVOIR_1; i < SLOT_RESERVOIR_1 + SLOTS_COUNT_RESERVOIR; i++) { + IInventoryAdapter inventory = getInternalInventory(); + + for (int i = SLOT_RESERVOIR_1; i < SLOT_RESERVOIR_1 + SLOT_RESERVOIR_COUNT; i++) { if (inventory.getStackInSlot(i) == null) continue; @@ -460,6 +482,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi public boolean hasFuelMin(float percentage) { int max = 0; int avail = 0; + IInventoryAdapter inventory = getInternalInventory(); for (int i = SLOT_STASH_1; i < SLOT_RESERVOIR_1; i++) { if (inventory.getStackInSlot(i) == null) { @@ -479,6 +502,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } public boolean hasResourcesMin(float percentage) { + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_RESOURCE) == null) return false; @@ -520,149 +544,6 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi return EnumTankLevel.EMPTY; } - /* IINVENTORY */ - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex == SLOT_PRODUCT) - return true; - - if(slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH) { - return !FuelManager.moistenerResource.containsKey(itemstack); - } - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex == SLOT_RESOURCE) - return RecipeManager.isResource(itemstack); - - if(slotIndex >= SLOT_STASH_1 && slotIndex < SLOT_STASH_1 + SLOTS_COUNT_STASH - 2) { - return FuelManager.moistenerResource.containsKey(itemstack); - } - - return false; - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - - FluidContainerData container = LiquidHelper.getLiquidContainer(stack); - if (container != null && resourceTank.accepts(container.fluid.getFluid())) { - return inventory.addStack(stack, SLOT_PRODUCT, 1, false, doAdd); - } - - // Try to add to resource slot if input is from top or bottom. - if (from == ForgeDirection.UP || from == ForgeDirection.DOWN) { - return inventory.addStack(stack, SLOT_RESOURCE, 1, false, doAdd); - } - - return inventory.addStack(stack, SLOT_STASH_1, SLOTS_COUNT_STASH - 2, false, doAdd); - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - ItemStack product; - - ItemStack slotStack = inventory.getStackInSlot(SLOT_PRODUCT); - if (slotStack != null && slotStack.stackSize > 0) { - - product = new ItemStack(slotStack.getItem(), 1, slotStack.getItemDamage()); - if (doRemove) { - inventory.decrStackSize(SLOT_PRODUCT, 1); - } - return new ItemStack[] { product }; - } else - for (int i = 0; i < SLOT_RESERVOIR_1; i++) { - slotStack = inventory.getStackInSlot(i); - if (slotStack == null) - continue; - - if (!FuelManager.moistenerResource.containsKey(slotStack)) { - product = new ItemStack(slotStack.getItem(), 1, slotStack.getItemDamage()); - if (doRemove) { - inventory.decrStackSize(i, 1); - } - return new ItemStack[] { product }; - } - } - - return StackUtils.EMPTY_STACK_ARRAY; - } - /* ILiquidTankContainer */ @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { @@ -674,6 +555,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi return tankManager; } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } @@ -699,6 +581,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; @@ -718,6 +601,7 @@ public class MachineMoistener extends TileBase implements ISpecialInventory, ISi } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, burnTime); diff --git a/src/main/java/forestry/factory/gadgets/MachineRaintank.java b/src/main/java/forestry/factory/gadgets/MachineRaintank.java index 64d5ae494..de3c2ceab 100755 --- a/src/main/java/forestry/factory/gadgets/MachineRaintank.java +++ b/src/main/java/forestry/factory/gadgets/MachineRaintank.java @@ -10,21 +10,6 @@ ******************************************************************************/ package forestry.factory.gadgets; -import forestry.api.core.BiomeHelper; -import forestry.api.core.EnumErrorCode; -import forestry.api.core.ForestryAPI; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.gadgets.TileBase; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.GuiId; -import forestry.core.utils.Fluids; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -32,28 +17,58 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.biome.BiomeGenBase; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import forestry.api.core.BiomeHelper; +import forestry.api.core.ForestryAPI; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.gadgets.TileBase; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; + public class MachineRaintank extends TileBase implements ISidedInventory, ILiquidTankContainer { /* CONSTANTS */ public static final short SLOT_RESOURCE = 0; public static final short SLOT_PRODUCT = 1; - private static final FluidStack STACK_WATER = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, Defaults.RAINTANK_AMOUNT_PER_UPDATE); + private static final FluidStack STACK_WATER = Fluids.WATER.getFluid(Defaults.RAINTANK_AMOUNT_PER_UPDATE); /* MEMBER */ - public FilteredTank resourceTank; + private final FilteredTank resourceTank; private final TankManager tankManager; - private final InventoryAdapter inventory = new InventoryAdapter(3, "Items"); private boolean isValidBiome = true; private int fillingTime; private ItemStack usedEmpty; public MachineRaintank() { + setInternalInventory(new TileInventoryAdapter(this, 3, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FluidHelper.isFillableContainer(itemStack, Fluids.WATER.getFluid(1000)); + } + return false; + } + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } + }); setHints(Config.hints.get("raintank")); resourceTank = new FilteredTank(Defaults.RAINTANK_TANK_CAPACITY, FluidRegistry.WATER); @@ -74,11 +89,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui super.validate(); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.RaintankGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -91,7 +101,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui nbttagcompound.setBoolean("IsValidBiome", isValidBiome); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); } @Override @@ -101,7 +110,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui isValidBiome = nbttagcompound.getBoolean("IsValidBiome"); tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); } @Override @@ -120,6 +128,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui if (worldObj.getTotalWorldTime() % 16 != 0) return; + IInventoryAdapter inventory = getInternalInventory(); if (!StackUtils.isIdenticalItem(usedEmpty, inventory.getStackInSlot(SLOT_RESOURCE))) { fillingTime = 0; usedEmpty = null; @@ -132,7 +141,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui tryToStartFillling(); else { fillingTime--; - if (fillingTime <= 0 && LiquidHelper.fillContainers(this, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get())) + if (fillingTime <= 0 && FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.getFluid())) fillingTime = 0; } } @@ -143,7 +152,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui private void tryToStartFillling() { // Nothing to do if no empty cans are available - if (!LiquidHelper.fillContainers(this, inventory, SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.get(), false)) + if (!FluidHelper.fillContainers(tankManager, getInternalInventory(), SLOT_RESOURCE, SLOT_PRODUCT, Fluids.WATER.getFluid(), false)) return; fillingTime = Defaults.RAINTANK_FILLING_TIME; @@ -153,119 +162,8 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui return (fillingTime * i) / Defaults.RAINTANK_FILLING_TIME; } - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_PRODUCT; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - if (!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if (slotIndex != SLOT_RESOURCE) - return false; - - return LiquidHelper.getEmptyContainer(itemstack, STACK_WATER) != null; - } - /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; switch (i) { @@ -275,6 +173,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, fillingTime); @@ -311,6 +210,7 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui return tankManager; } + @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } diff --git a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java index b51346295..e05fb6097 100755 --- a/src/main/java/forestry/factory/gadgets/MachineSqueezer.java +++ b/src/main/java/forestry/factory/gadgets/MachineSqueezer.java @@ -10,39 +10,6 @@ ******************************************************************************/ package forestry.factory.gadgets; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; -import forestry.api.recipes.ISqueezerManager; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -50,17 +17,53 @@ import java.util.HashSet; import java.util.Map; import java.util.Stack; -public class MachineSqueezer extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer { +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; + +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.ISqueezerManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.proxy.Proxies; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.StackUtils; +import forestry.core.utils.Utils; + +public class MachineSqueezer extends TilePowered implements ISidedInventory, ILiquidTankContainer { /* CONSTANTS */ - private static final short SLOT_RESOURCE_1 = 0; - private static final short SLOTS_RESOURCE_COUNT = 9; - private static final short SLOT_REMNANT = 9; - private static final short SLOT_CAN_INPUT = 10; - private static final short SLOT_CAN_OUTPUT = 11; + public static final short SLOT_RESOURCE_1 = 0; + public static final short SLOTS_RESOURCE_COUNT = 9; + public static final short SLOT_REMNANT = 9; + public static final short SLOT_REMNANT_COUNT = 1; + public static final short SLOT_CAN_INPUT = 10; + public static final short SLOT_CAN_OUTPUT = 11; /* RECIPE MANAGMENT */ public static class Recipe { + public final int timePerItem; public final ItemStack[] resources; public final FluidStack liquid; @@ -81,6 +84,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I } public static class RecipeManager implements ISqueezerManager { + public static final ArrayList recipes = new ArrayList(); public static final HashSet recipeFluids = new HashSet(); public static final HashSet recipeInputs = new HashSet(); @@ -111,9 +115,10 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I public static boolean canUse(ItemStack itemStack) { if (recipeInputs.contains(itemStack)) return true; - for (ItemStack recipeInput : recipeInputs) + for (ItemStack recipeInput : recipeInputs) { if (StackUtils.isCraftingEquivalent(recipeInput, itemStack)) return true; + } return false; } @@ -121,8 +126,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(recipe.resources, new Object[] { recipe.remnants, recipe.liquid }); + for (Recipe recipe : recipes) { + recipeList.put(recipe.resources, new Object[]{recipe.remnants, recipe.liquid}); + } return recipeList; } @@ -130,30 +136,43 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I /* MEMBER */ private final TankManager tankManager; - @EntityNetData public final FilteredTank productTank; - private final InventoryAdapter inventory = new InventoryAdapter(12, "Items"); private Recipe currentRecipe; - private final Stack pendingLiquids = new Stack(); - private final Stack pendingRemnants = new Stack(); private int productionTime; private int timePerItem; public MachineSqueezer() { super(1100, 50, 4000); + setInternalInventory(new TileInventoryAdapter(this, 12, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_CAN_INPUT) + return FluidHelper.isEmptyContainer(itemStack); + + if (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { + if (FluidHelper.isEmptyContainer(itemStack)) + return false; + + if (RecipeManager.canUse(itemStack)) + return true; + } + + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; + } + }); setHints(Config.hints.get("squeezer")); productTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluids); productTank.tankMode = StandardTank.TankMode.OUTPUT; tankManager = new TankManager(productTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.SqueezerGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -167,33 +186,6 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I nbttagcompound.setInteger("ProductionTime", productionTime); nbttagcompound.setInteger("TimePerItem", timePerItem); - // Inventory - inventory.writeToNBT(nbttagcompound); - - // Pending remnants - NBTTagList nbttaglist = new NBTTagList(); - ItemStack[] remnants = pendingRemnants.toArray(new ItemStack[pendingRemnants.size()]); - for (int i = 0; i < remnants.length; i++) - if (remnants[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - remnants[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - nbttagcompound.setTag("PendingRemnants", nbttaglist); - - // Pending liquids - nbttaglist = new NBTTagList(); - FluidStack[] liquids = pendingLiquids.toArray(new FluidStack[pendingLiquids.size()]); - for (int i = 0; i < liquids.length; i++) - if (liquids[i] != null) { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - liquids[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - nbttagcompound.setTag("PendingLiquids", nbttaglist); - tankManager.writeTanksToNBT(nbttagcompound); } @@ -203,24 +195,6 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I productionTime = nbttagcompound.getInteger("ProductionTime"); timePerItem = nbttagcompound.getInteger("TimePerItem"); - - // Inventory - inventory.readFromNBT(nbttagcompound); - - // Pending remnants - NBTTagList nbttaglist = nbttagcompound.getTagList("PendingRemnants", 10); - for (int i = 0; i < nbttaglist.tagCount(); i++) { - NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); - pendingRemnants.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); - } - - // Pending liquids - nbttaglist = nbttagcompound.getTagList("PendingLiquids", 10); - for (int i = 0; i < nbttaglist.tagCount(); i++) { - NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); - pendingLiquids.add(FluidStack.loadFluidStackFromNBT(nbttagcompound1)); - } - tankManager.readTanksFromNBT(nbttagcompound); checkRecipe(); @@ -230,28 +204,23 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I @Override public void updateServerSide() { + if (worldObj.getTotalWorldTime() % 20 != 0) + return; + + IInventoryAdapter inventory = getInternalInventory(); // Can/capsule input/output needs to be handled here. if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) { - - FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), productTank.getFluid()); - if (container != null) { - inventory.setInventorySlotContents(SLOT_CAN_OUTPUT, bottleIntoContainer(inventory.getStackInSlot(SLOT_CAN_INPUT), inventory.getStackInSlot(SLOT_CAN_OUTPUT), container, productTank)); - if (inventory.getStackInSlot(SLOT_CAN_INPUT).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN_INPUT, null); - } - + FluidStack fluidStack = productTank.getFluid(); + if (fluidStack != null) + FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid()); } - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) - return; - checkRecipe(); if (getErrorState() == EnumErrorCode.NORECIPE && currentRecipe != null) setErrorState(EnumErrorCode.OK); if (energyManager.getTotalEnergyStored() == 0) { setErrorState(EnumErrorCode.NOPOWER); - return; } } @@ -260,13 +229,24 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I checkRecipe(); - // If we add pending products, we skip to the next work cycle. - tryAddPending(); - - if (!pendingLiquids.isEmpty() || !pendingRemnants.isEmpty()) + if (getErrorState() == EnumErrorCode.NORECIPE) return false; - // Continue work if nothing needs to be added + FluidStack resultFluid = currentRecipe.liquid.copy(); + if (productTank.fill(resultFluid, false) < resultFluid.amount) { + setErrorState(EnumErrorCode.NOSPACETANK); + return false; + } + + ItemStack remnant = null; + if (currentRecipe.remnants != null) { + remnant = currentRecipe.remnants.copy(); + if (!InvTools.tryAddStack(getInternalInventory(), remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true, false)) { + setErrorState(EnumErrorCode.NOSPACE); + return false; + } + } + if (productionTime <= 0) return false; @@ -283,22 +263,21 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I if (!removeResources(currentRecipe.resources)) return false; - // We are done, add products to queue - pendingLiquids.push(currentRecipe.liquid.copy()); - if (currentRecipe.remnants != null && worldObj.rand.nextInt(100) < currentRecipe.chance) - pendingRemnants.push(currentRecipe.remnants.copy()); + productTank.fill(resultFluid, true); + if (remnant != null && worldObj.rand.nextInt(100) < currentRecipe.chance) + InvTools.tryAddStack(getInternalInventory(), remnant, SLOT_REMNANT, SLOT_REMNANT_COUNT, true); + + setErrorState(EnumErrorCode.OK); checkRecipe(); resetRecipe(); - tryAddPending(); - setErrorState(EnumErrorCode.OK); - return true; } private void checkRecipe() { - Recipe sameRec = RecipeManager.findMatchingRecipe(inventory.getStacks(SLOT_RESOURCE_1, 9)); + ItemStack[] resources = InvTools.getStacks(getInternalInventory(), SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT); + Recipe sameRec = RecipeManager.findMatchingRecipe(resources); if (sameRec == null) setErrorState(EnumErrorCode.NORECIPE); @@ -320,45 +299,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I timePerItem = currentRecipe.timePerItem; } - private boolean tryAddPending() { - - if (!pendingLiquids.isEmpty()) { - FluidStack next = pendingLiquids.peek(); - if (addProduct(next)) { - pendingLiquids.pop(); - return true; - } - } - - if (!pendingRemnants.isEmpty()) { - ItemStack next = pendingRemnants.peek(); - if (addRemnant(next)) { - pendingRemnants.pop(); - return true; - } - } - - if (!pendingLiquids.isEmpty() || !pendingRemnants.isEmpty()) - setErrorState(EnumErrorCode.NOSPACE); - return false; - } - - private boolean addProduct(FluidStack stack) { - stack.amount -= productTank.fill(stack, true); - - if (stack.amount <= 0) - return true; - else - return false; - } - - private boolean addRemnant(ItemStack stack) { - return inventory.tryAddStack(stack, SLOT_REMNANT, 1, true); - } - private boolean removeResources(ItemStack[] stacks) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, owner); - return inventory.removeSets(1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true); + EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile()); + return InvTools.removeSets(getInternalInventory(), 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true); } @Override @@ -388,6 +331,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; switch (i) { @@ -400,142 +344,13 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, productionTime); iCrafting.sendProgressBarUpdate(container, i + 1, timePerItem); } - /* IINVENTORY */ - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - - if(slotIndex == SLOT_CAN_INPUT) { - return LiquidHelper.isEmptyContainer(itemstack); - } - - if(slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT) { - if (LiquidHelper.isEmptyContainer(itemstack)) - return false; - - if (RecipeManager.canUse(itemstack)) - return true; - } - - return false; - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_REMNANT || slotIndex == SLOT_CAN_OUTPUT; - } - - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_CAN_INPUT || (slotIndex >= SLOT_RESOURCE_1 && slotIndex < SLOT_RESOURCE_1 + SLOTS_RESOURCE_COUNT); - } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - - // Try to add to can slot if input is from top or bottom. - if (LiquidHelper.isEmptyContainer(stack)) { - return inventory.addStack(stack, SLOT_CAN_INPUT, 1, false, doAdd); - } else { - return inventory.addStack(stack, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, false, doAdd); - } - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - ItemStack product; - - if (inventory.getStackInSlot(SLOT_CAN_OUTPUT) != null) { - - product = new ItemStack(inventory.getStackInSlot(SLOT_CAN_OUTPUT).getItem(), 1, inventory.getStackInSlot(SLOT_CAN_OUTPUT).getItemDamage()); - if (doRemove) { - inventory.decrStackSize(SLOT_CAN_OUTPUT, 1); - } - return new ItemStack[] { product }; - } else { - - if (inventory.getStackInSlot(SLOT_REMNANT) == null) - return StackUtils.EMPTY_STACK_ARRAY; - - product = new ItemStack(inventory.getStackInSlot(SLOT_REMNANT).getItem(), 1, inventory.getStackInSlot(SLOT_REMNANT).getItemDamage()); - if (doRemove) { - inventory.decrStackSize(SLOT_REMNANT, 1); - } - return new ItemStack[] { product }; - } - - } - /* ILIQUIDCONTAINER IMPLEMENTATION */ @Override public TankManager getTankManager() { @@ -547,6 +362,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I return tankManager.fill(from, resource, doFill); } + @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { return tankManager.drain(from, resource, doDrain); } diff --git a/src/main/java/forestry/factory/gadgets/MachineStill.java b/src/main/java/forestry/factory/gadgets/MachineStill.java index bf5ded4ea..7f8554312 100755 --- a/src/main/java/forestry/factory/gadgets/MachineStill.java +++ b/src/main/java/forestry/factory/gadgets/MachineStill.java @@ -10,43 +10,42 @@ ******************************************************************************/ package forestry.factory.gadgets; -import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; -import forestry.api.recipes.IStillManager; -import forestry.api.core.EnumErrorCode; -import forestry.core.config.Config; -import forestry.core.config.Defaults; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.gadgets.TileBase; -import forestry.core.gadgets.TilePowered; -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.network.EntityNetData; -import forestry.core.network.GuiId; -import forestry.core.utils.EnumTankLevel; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; +import forestry.api.core.ForestryAPI; +import forestry.api.recipes.IStillManager; +import forestry.core.EnumErrorCode; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; +import forestry.core.fluids.tanks.StandardTank; +import forestry.core.gadgets.TileBase; +import forestry.core.gadgets.TilePowered; +import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; +import forestry.core.network.GuiId; +import forestry.core.utils.EnumTankLevel; +import forestry.core.utils.Utils; -public class MachineStill extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer { +public class MachineStill extends TilePowered implements ISidedInventory, ILiquidTankContainer { /* CONSTANTS */ public static final short SLOT_PRODUCT = 0; @@ -54,31 +53,31 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid public static final short SLOT_CAN = 2; public static class Recipe { + public final int timePerUnit; public final FluidStack input; public final FluidStack output; public Recipe(int timePerUnit, FluidStack input, FluidStack output) { this.timePerUnit = timePerUnit; - if(input == null) + if (input == null) throw new IllegalArgumentException("Still recipes need an input. Input was null."); - if(output == null) + if (output == null) throw new IllegalArgumentException("Still recipes need an output. Output was null."); this.input = input; this.output = output; } public boolean matches(FluidStack res) { - if (res == null && input == null) - return true; - else if (res == null || input == null) + if (res == null) return false; - else - return input.isFluidEqual(res); + + return input.isFluidEqual(res); } } public static class RecipeManager implements IStillManager { + public static final ArrayList recipes = new ArrayList(); public static final HashSet recipeFluidInputs = new HashSet(); public static final HashSet recipeFluidOutputs = new HashSet(); @@ -93,8 +92,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid } public static Recipe findMatchingRecipe(FluidStack item) { - for (int i = 0; i < recipes.size(); i++) { - Recipe recipe = recipes.get(i); + for (Recipe recipe : recipes) { if (recipe.matches(item)) return recipe; } @@ -109,22 +107,19 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid public Map getRecipes() { HashMap recipeList = new HashMap(); - for (Recipe recipe : recipes) - recipeList.put(new Object[] { recipe.input }, new Object[] { recipe.output }); + for (Recipe recipe : recipes) { + recipeList.put(new Object[]{recipe.input}, new Object[]{recipe.output}); + } return recipeList; } } /* MEMBER */ - @EntityNetData public final FilteredTank resourceTank; - @EntityNetData public final FilteredTank productTank; private final TankManager tankManager; - private final InventoryAdapter inventory = new InventoryAdapter(3, "Items"); - private Recipe currentRecipe; private FluidStack bufferedLiquid; public int distillationTime = 0; @@ -132,6 +127,23 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid public MachineStill() { super(1100, 50, 8000); + setInternalInventory(new TileInventoryAdapter(this, 3, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == SLOT_RESOURCE) { + return FluidHelper.isEmptyContainer(itemStack); + } else if (slotIndex == SLOT_CAN) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return resourceTank.accepts(fluid); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) { + return slotIndex == SLOT_PRODUCT; + } + }); setHints(Config.hints.get("still")); resourceTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, RecipeManager.recipeFluidInputs); resourceTank.tankMode = StandardTank.TankMode.INPUT; @@ -140,11 +152,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid tankManager = new TankManager(resourceTank, productTank); } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { player.openGui(ForestryAPI.instance, GuiId.StillGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord); @@ -158,7 +165,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid nbttagcompound.setInteger("DistillationTotalTime", distillationTotalTime); tankManager.writeTanksToNBT(nbttagcompound); - inventory.writeToNBT(nbttagcompound); } @Override @@ -169,7 +175,6 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid distillationTotalTime = nbttagcompound.getInteger("DistillationTotalTime"); tankManager.readTanksFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); checkRecipe(); } @@ -177,39 +182,27 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid @Override public void updateServerSide() { + if (worldObj.getTotalWorldTime() % 20 * 10 != 0) + return; + + IInventoryAdapter inventory = getInternalInventory(); // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_CAN) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN)); - - if (container != null && resourceTank.accepts(container.fluid.getFluid())) { - - inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, resourceTank)); - if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN, null); - - } - } + if (inventory.getStackInSlot(SLOT_CAN) != null) + FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN); // Can product liquid if possible if (inventory.getStackInSlot(SLOT_RESOURCE) != null) { - FluidContainerData container = LiquidHelper.getEmptyContainer(inventory.getStackInSlot(SLOT_RESOURCE), productTank.getFluid()); - if (container != null) { - inventory.setInventorySlotContents(SLOT_PRODUCT, bottleIntoContainer(inventory.getStackInSlot(SLOT_RESOURCE), inventory.getStackInSlot(SLOT_PRODUCT), container, productTank)); - if (inventory.getStackInSlot(SLOT_RESOURCE).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_RESOURCE, null); - } + FluidStack fluidStack = productTank.getFluid(); + if (fluidStack != null) + FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid()); } - if (worldObj.getTotalWorldTime() % 20 * 10 != 0) - return; - checkRecipe(); if (getErrorState() == EnumErrorCode.NORECIPE && currentRecipe != null) setErrorState(EnumErrorCode.OK); if (energyManager.getTotalEnergyStored() == 0) { setErrorState(EnumErrorCode.NOPOWER); - return; } } @@ -312,6 +305,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid } /* SMP GUI */ + @Override public void getGUINetworkData(int i, int j) { i -= tankManager.maxMessageId() + 1; switch (i) { @@ -324,140 +318,14 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid } } + @Override public void sendGUINetworkData(Container container, ICrafting iCrafting) { int i = tankManager.maxMessageId() + 1; iCrafting.sendProgressBarUpdate(container, i, distillationTime); iCrafting.sendProgressBarUpdate(container, i + 1, distillationTotalTime); } - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - int inventorySlot; - - FluidContainerData container = LiquidHelper.getLiquidContainer(stack); - if (container != null && resourceTank.accepts(container.fluid.getFluid())) - inventorySlot = SLOT_CAN; - else if (LiquidHelper.isEmptyContainer(stack)) - inventorySlot = SLOT_RESOURCE; - else - return 0; - - return inventory.addStack(stack, inventorySlot, 1, false, doAdd); - } - - /** - * Transport pipes cannot extract items from the still. - */ - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - ItemStack product = null; - - if (inventory.getStackInSlot(SLOT_PRODUCT) != null) { - - product = new ItemStack(inventory.getStackInSlot(SLOT_PRODUCT).getItem(), 1, inventory.getStackInSlot(SLOT_PRODUCT).getItemDamage()); - if (doRemove) { - inventory.decrStackSize(SLOT_PRODUCT, 1); - } - } - - if (product != null) - return new ItemStack[] { product }; - else - return StackUtils.EMPTY_STACK_ARRAY; - } - - /* IINVENTORY */ - @Override public int getSizeInventory() { return inventory.getSizeInventory(); } - @Override public ItemStack getStackInSlot(int i) { return inventory.getStackInSlot(i); } - @Override public ItemStack decrStackSize(int i, int j) { return inventory.decrStackSize(i, j); } - @Override public void setInventorySlotContents(int i, ItemStack itemstack) { inventory.setInventorySlotContents(i, itemstack); } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return inventory.getStackInSlotOnClosing(slot); } - @Override public int getInventoryStackLimit() { return inventory.getInventoryStackLimit(); } - @Override public void openInventory() {} - @Override public void closeInventory() {} - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - /* ISIDEDINVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return inventory; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - return slotIndex == SLOT_PRODUCT; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex == SLOT_RESOURCE) - return LiquidHelper.isEmptyContainer(itemstack); - - if(slotIndex == SLOT_CAN) { - FluidContainerData container = LiquidHelper.getLiquidContainer(itemstack); - return container != null && resourceTank.accepts(container.fluid.getFluid()); - } - - return false; - } - - /* ILiquidTankContainer */ + /* IFluidHandler */ @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { return tankManager.fill(from, resource, doFill); @@ -488,6 +356,7 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid return tankManager; } + @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { return tankManager.getTankInfo(from); } diff --git a/src/main/java/forestry/factory/gadgets/MillRainmaker.java b/src/main/java/forestry/factory/gadgets/MillRainmaker.java index 438d95216..12098ae3b 100755 --- a/src/main/java/forestry/factory/gadgets/MillRainmaker.java +++ b/src/main/java/forestry/factory/gadgets/MillRainmaker.java @@ -10,20 +10,15 @@ ******************************************************************************/ package forestry.factory.gadgets; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import net.minecraftforge.common.util.ForgeDirection; - -import forestry.api.core.ISpecialInventory; import forestry.api.fuels.FuelManager; import forestry.api.fuels.RainSubstrate; import forestry.core.gadgets.Mill; import forestry.core.gadgets.TileBase; import forestry.core.proxy.Proxies; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; -public class MillRainmaker extends Mill implements ISpecialInventory { +public class MillRainmaker extends Mill { private int duration; private boolean reverse; @@ -32,11 +27,6 @@ public class MillRainmaker extends Mill implements ISpecialInventory { speed = 0.01f; } - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - @Override public void openGui(EntityPlayer player, TileBase tile) { if (!Proxies.common.isSimulating(player.worldObj)) @@ -117,86 +107,78 @@ public class MillRainmaker extends Mill implements ISpecialInventory { } } - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (charge != 0) - return 0; - - if (!FuelManager.rainSubstrate.containsKey(stack)) - return 0; - - RainSubstrate substrate = FuelManager.rainSubstrate.get(stack); - if (!substrate.item.isItemEqual(stack)) - return 0; - - if (doAdd) - addCharge(substrate); - return 1; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - return null; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(int var1) { - return null; - } - - @Override - public ItemStack decrStackSize(int var1, int var2) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - return null; - } - - @Override - public void setInventorySlotContents(int var1, ItemStack var2) { - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } + // TODO: Give Rainmaker a real inventory and a GUI with slots +// @Override +// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { +// if (charge != 0) +// return 0; +// +// if (!FuelManager.rainSubstrate.containsKey(stack)) +// return 0; +// +// RainSubstrate substrate = FuelManager.rainSubstrate.get(stack); +// if (!substrate.item.isItemEqual(stack)) +// return 0; +// +// if (doAdd) +// addCharge(substrate); +// return 1; +// } +// +// @Override +// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { +// return null; +// } +// +// @Override +// public int getSizeInventory() { +// return 0; +// } +// +// @Override +// public ItemStack getStackInSlot(int var1) { +// return null; +// } +// +// @Override +// public ItemStack decrStackSize(int var1, int var2) { +// return null; +// } +// +// @Override +// public ItemStack getStackInSlotOnClosing(int var1) { +// return null; +// } +// +// @Override +// public void setInventorySlotContents(int var1, ItemStack var2) { +// } +// +// @Override +// public int getInventoryStackLimit() { +// return 0; +// } +// +// @Override +// public void openInventory() { +// } +// +// @Override +// public void closeInventory() { +// } +// +// @Override +// public boolean isUseableByPlayer(EntityPlayer player) { +// return Utils.isUseableByPlayer(player, this); +// } +// +// @Override +// public boolean hasCustomInventoryName() { +// return false; +// } +// +// @Override +// public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { +// return false; +// } } diff --git a/src/main/java/forestry/factory/gadgets/TileWorktable.java b/src/main/java/forestry/factory/gadgets/TileWorktable.java index aef345581..1e06ee8b2 100755 --- a/src/main/java/forestry/factory/gadgets/TileWorktable.java +++ b/src/main/java/forestry/factory/gadgets/TileWorktable.java @@ -13,15 +13,16 @@ package forestry.factory.gadgets; import forestry.api.core.ForestryAPI; import forestry.core.gadgets.TileBase; import forestry.core.interfaces.ICrafter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.ForestryPacket; import forestry.core.network.GuiId; import forestry.core.network.PacketIds; import forestry.core.network.PacketTileNBT; import forestry.core.network.PacketTileUpdate; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; 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; @@ -30,6 +31,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.nbt.NBTTagCompound; + public class TileWorktable extends TileBase implements ICrafter { /* CONSTANTS */ @@ -44,11 +46,10 @@ public class TileWorktable extends TileBase implements ICrafter { private InventoryCrafting currentCrafting; private final RecipeMemory memorized; private final TileInventoryAdapter craftingInventory; - private final TileInventoryAdapter accessibleInventory; public TileWorktable() { craftingInventory = new TileInventoryAdapter(this, 10, "CraftItems"); - accessibleInventory = new TileInventoryAdapter(this, 18, "Items"); + setInternalInventory(new TileInventoryAdapter(this, 18, "Items").disableAutomation()); memorized = new RecipeMemory(); } @@ -64,7 +65,6 @@ public class TileWorktable extends TileBase implements ICrafter { super.writeToNBT(nbttagcompound); craftingInventory.writeToNBT(nbttagcompound); - accessibleInventory.writeToNBT(nbttagcompound); memorized.writeToNBT(nbttagcompound); } @@ -74,7 +74,6 @@ public class TileWorktable extends TileBase implements ICrafter { super.readFromNBT(nbttagcompound); craftingInventory.readFromNBT(nbttagcompound); - accessibleInventory.readFromNBT(nbttagcompound); memorized.readFromNBT(nbttagcompound); } @@ -153,16 +152,16 @@ public class TileWorktable extends TileBase implements ICrafter { if (currentRecipe == null) return false; - ItemStack[] recipeItems = craftingInventory.getStacks(SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); - ItemStack[] inventory = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + ItemStack[] recipeItems = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + ItemStack[] inventory = InvTools.getStacks(getInternalInventory(), SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); ItemStack recipeOutput = currentRecipe.getRecipeOutput(worldObj); return RecipeUtil.canCraftRecipe(worldObj, recipeItems, recipeOutput, inventory); } private boolean removeResources(EntityPlayer player) { - ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9); - return accessibleInventory.removeSets(1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); + ItemStack[] set = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); + return InvTools.removeSets(getInternalInventory(), 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); } @Override @@ -194,12 +193,6 @@ public class TileWorktable extends TileBase implements ICrafter { return null; } - /* INVENTORY */ - @Override - public InventoryAdapter getInternalInventory() { - return accessibleInventory; - } - /** * @return Inaccessible crafting inventory for the craft grid. */ diff --git a/src/main/java/forestry/factory/gui/ContainerBottler.java b/src/main/java/forestry/factory/gui/ContainerBottler.java index 7d4d2e27f..8a31d4d38 100755 --- a/src/main/java/forestry/factory/gui/ContainerBottler.java +++ b/src/main/java/forestry/factory/gui/ContainerBottler.java @@ -10,38 +10,38 @@ ******************************************************************************/ package forestry.factory.gui; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotLiquidContainer; -import forestry.factory.gadgets.MachineBottler; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; +import forestry.factory.gadgets.MachineBottler; + public class ContainerBottler extends ContainerLiquidTanks { protected final MachineBottler tile; public ContainerBottler(InventoryPlayer player, MachineBottler tile) { - super(tile, tile); + super(tile); this.tile = tile; - this.addSlot(new SlotLiquidContainer(tile, MachineBottler.SLOT_RESOURCE, 116, 19, true)); - this.addSlot(new SlotClosed(tile, MachineBottler.SLOT_PRODUCT, 116, 55)); - this.addSlot(new SlotLiquidContainer(tile, MachineBottler.SLOT_CAN, 26, 38)); + + this.addSlotToContainer(new SlotFiltered(tile, MachineBottler.SLOT_RESOURCE, 116, 19)); + this.addSlotToContainer(new SlotOutput(tile, MachineBottler.SLOT_PRODUCT, 116, 55)); + this.addSlotToContainer(new SlotFiltered(tile, MachineBottler.SLOT_CAN, 26, 38)); int var3; - for (var3 = 0; var3 < 3; ++var3) - for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } - for (var3 = 0; var3 < 9; ++var3) - this.addSlot(new Slot(player, var3, 8 + var3 * 18, 142)); + for (var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot(player, var3, 8 + var3 * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerCarpenter.java b/src/main/java/forestry/factory/gui/ContainerCarpenter.java index a418c847c..43434d124 100755 --- a/src/main/java/forestry/factory/gui/ContainerCarpenter.java +++ b/src/main/java/forestry/factory/gui/ContainerCarpenter.java @@ -15,11 +15,9 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotCraftAuto; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotLocked; import forestry.core.gui.slots.SlotOutput; import forestry.core.interfaces.IContainerCrafting; @@ -28,30 +26,17 @@ import forestry.factory.gadgets.MachineCarpenter; public class ContainerCarpenter extends ContainerLiquidTanks implements IContainerCrafting { - private class SlotCrate extends SlotCraftAuto { - - public SlotCrate(IContainerCrafting container, IInventory iinventory, int slotNumber, int x, int y) { - super(container, iinventory, slotNumber, x, y); - } - - @Override - public boolean isItemValid(ItemStack stack) { - return MachineCarpenter.RecipeManager.isBox(stack); - } - } private MachineCarpenter machine; private final IInventory craftingInventory; - private IInventory internalInventory; public final InventoryCraftingAuto craftMatrix; public final InventoryCraftResult craftResult; public ContainerCarpenter(InventoryPlayer inventoryplayer, MachineCarpenter tile) { - super(tile.getInternalInventory(), tile); + super(tile); machine = tile; machine.activeContainer = this; craftingInventory = machine.getCraftingInventory(); - internalInventory = machine.getInternalInventory(); craftMatrix = new InventoryCraftingAuto(this, 3, 3); craftResult = new InventoryCraftResult(); @@ -59,36 +44,36 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlot(new Slot(internalInventory, MachineCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); + addSlotToContainer(new Slot(machine, MachineCarpenter.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); } } // Liquid Input - this.addSlot(new SlotLiquidContainer(internalInventory, MachineCarpenter.SLOT_CAN_INPUT, 120, 20)); + this.addSlotToContainer(new SlotFiltered(machine, MachineCarpenter.SLOT_CAN_INPUT, 120, 20)); // Boxes - this.addSlot(new SlotCrate(this, internalInventory, MachineCarpenter.SLOT_BOX, 83, 20)); + this.addSlotToContainer(new SlotFiltered(machine, MachineCarpenter.SLOT_BOX, 83, 20)); // Product - this.addSlot(new SlotOutput(internalInventory, MachineCarpenter.SLOT_PRODUCT, 120, 56)); + this.addSlotToContainer(new SlotOutput(machine, MachineCarpenter.SLOT_PRODUCT, 120, 56)); // CraftResult display - addSlot(new SlotLocked(craftResult, 0, 80, 51)); + addSlotToContainer(new SlotLocked(craftResult, 0, 80, 51)); // Crafting matrix for (int l = 0; l < 3; l++) { for (int k1 = 0; k1 < 3; k1++) { - addSlot(new SlotCraftMatrix(this, craftingInventory, k1 + l * 3, 10 + k1 * 18, 20 + l * 18)); + addSlotToContainer(new SlotCraftMatrix(this, craftingInventory, k1 + l * 3, 10 + k1 * 18, 20 + l * 18)); } } // Player inventory for (int i1 = 0; i1 < 3; i1++) { for (int l1 = 0; l1 < 9; l1++) { - addSlot(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); + addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); } } // Player hotbar for (int j1 = 0; j1 < 9; j1++) { - addSlot(new Slot(inventoryplayer, j1, 8 + j1 * 18, 194)); + addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 194)); } // Update crafting matrix with current contents of tileentity. @@ -98,7 +83,7 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain } public ContainerCarpenter(MachineCarpenter tile) { - super(tile.getInternalInventory(), tile); + super(tile); craftMatrix = new InventoryCraftingAuto(this, 3, 3); craftResult = new InventoryCraftResult(); craftingInventory = tile.getCraftingInventory(); @@ -115,12 +100,6 @@ public class ContainerCarpenter extends ContainerLiquidTanks implements IContain updateProductSlot(); } - /** - * Replaces the original onCraftMatrixChanged - * - * @param iinventory - * @param slot - */ @Override public void onCraftMatrixChanged(IInventory iinventory, int slot) { craftingInventory.setInventorySlotContents(slot, iinventory.getStackInSlot(slot)); diff --git a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java index bdf321b41..d567731d4 100755 --- a/src/main/java/forestry/factory/gui/ContainerCentrifuge.java +++ b/src/main/java/forestry/factory/gui/ContainerCentrifuge.java @@ -15,7 +15,8 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineCentrifuge; public class ContainerCentrifuge extends ContainerForestry { @@ -28,20 +29,20 @@ public class ContainerCentrifuge extends ContainerForestry { this.tile = tile; // Resource - this.addSlot(new Slot(tile, 0, 34, 37)); + this.addSlotToContainer(new SlotFiltered(tile, 0, 34, 37)); // Product Inventory for (int l = 0; l < 3; l++) for (int k = 0; k < 3; k++) - addSlot(new SlotClosed(tile, 1 + k + l * 3, 98 + k * 18, 19 + l * 18)); + addSlotToContainer(new SlotOutput(tile, 1 + k + l * 3, 98 + k * 18, 19 + l * 18)); // Player inventory for (int i1 = 0; i1 < 3; i1++) for (int l1 = 0; l1 < 9; l1++) - addSlot(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); + addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); // Player hotbar for (int j1 = 0; j1 < 9; j1++) - addSlot(new Slot(player, j1, 8 + j1 * 18, 142)); + addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 142)); } @Override diff --git a/src/main/java/forestry/factory/gui/ContainerFabricator.java b/src/main/java/forestry/factory/gui/ContainerFabricator.java index 1fa32ba2a..a59e8133f 100755 --- a/src/main/java/forestry/factory/gui/ContainerFabricator.java +++ b/src/main/java/forestry/factory/gui/ContainerFabricator.java @@ -10,46 +10,45 @@ ******************************************************************************/ package forestry.factory.gui; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotCrafter; -import forestry.factory.gadgets.MachineFabricator; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotCrafter; +import forestry.core.gui.slots.SlotFiltered; +import forestry.factory.gadgets.MachineFabricator; + public class ContainerFabricator extends ContainerLiquidTanks { - private final MachineFabricator tile; - public ContainerFabricator(InventoryPlayer playerInventory, MachineFabricator tile) { - super(tile, tile); - this.tile = tile; + super(tile); // Internal inventory for (int i = 0; i < 2; i++) for (int k = 0; k < 9; k++) - addSlot(new Slot(tile, MachineFabricator.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 84 + i * 18)); + addSlotToContainer(new Slot(tile, MachineFabricator.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 84 + i * 18)); // Molten resource - this.addSlot(new Slot(tile, MachineFabricator.SLOT_METAL, 26, 21)); + this.addSlotToContainer(new SlotFiltered(tile, MachineFabricator.SLOT_METAL, 26, 21)); // Plan - this.addSlot(new Slot(tile, MachineFabricator.SLOT_PLAN, 139, 17)); + this.addSlotToContainer(new SlotFiltered(tile, MachineFabricator.SLOT_PLAN, 139, 17)); // Result - this.addSlot(new SlotCrafter(playerInventory.player, tile, tile, MachineFabricator.SLOT_RESULT, 139, 53)); + this.addSlotToContainer(new SlotCrafter(playerInventory.player, tile, tile, MachineFabricator.SLOT_RESULT, 139, 53)); // Crafting matrix for (int l = 0; l < 3; l++) for (int k = 0; k < 3; k++) - addSlot(new Slot(tile, MachineFabricator.SLOT_CRAFTING_1 + k + l * 3, 67 + k * 18, 17 + l * 18)); + addSlotToContainer(new Slot(tile, MachineFabricator.SLOT_CRAFTING_1 + k + l * 3, 67 + k * 18, 17 + l * 18)); // Player inventory for (int i = 0; i < 3; i++) for (int k = 0; k < 9; k++) - addSlot(new Slot(playerInventory, k + i * 9 + 9, 8 + k * 18, 129 + i * 18)); + addSlotToContainer(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(playerInventory, j, 8 + j * 18, 187)); + addSlotToContainer(new Slot(playerInventory, j, 8 + j * 18, 187)); } diff --git a/src/main/java/forestry/factory/gui/ContainerFermenter.java b/src/main/java/forestry/factory/gui/ContainerFermenter.java index 5d43389d3..7f09a2758 100755 --- a/src/main/java/forestry/factory/gui/ContainerFermenter.java +++ b/src/main/java/forestry/factory/gui/ContainerFermenter.java @@ -10,39 +10,39 @@ ******************************************************************************/ package forestry.factory.gui; -import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.gui.slots.SlotLiquidContainer; -import forestry.core.gui.slots.SlotOutput; -import forestry.factory.gadgets.MachineFermenter; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +import forestry.core.gui.ContainerLiquidTanks; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; +import forestry.factory.gadgets.MachineFermenter; + public class ContainerFermenter extends ContainerLiquidTanks { + protected final MachineFermenter fermenter; public ContainerFermenter(InventoryPlayer player, MachineFermenter fermenter) { - super(fermenter, fermenter); + super(fermenter); this.fermenter = fermenter; - this.addSlot(new SlotCustom(fermenter, MachineFermenter.SLOT_RESOURCE, 85, 23).setExclusion(true)); - this.addSlot(new SlotCustom(fermenter, MachineFermenter.SLOT_FUEL, 75, 57).setExclusion(true)); - this.addSlot(new SlotOutput(fermenter, MachineFermenter.SLOT_CAN_OUTPUT, 150, 58)); - this.addSlot(new SlotLiquidContainer(fermenter, MachineFermenter.SLOT_CAN_INPUT, 150, 22, true)); - this.addSlot(new SlotLiquidContainer(fermenter, MachineFermenter.SLOT_INPUT, 10, 40)); - for (int i = 0; i < 3; ++i) - for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_RESOURCE, 85, 23)); + this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_FUEL, 75, 57)); + this.addSlotToContainer(new SlotOutput(fermenter, MachineFermenter.SLOT_CAN_OUTPUT, 150, 58)); + this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_CAN_INPUT, 150, 22)); + this.addSlotToContainer(new SlotFiltered(fermenter, MachineFermenter.SLOT_INPUT, 10, 40)); - for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + for (int i = 0; i < 3; ++i) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(player, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18)); + } + } + + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return fermenter.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerMoistener.java b/src/main/java/forestry/factory/gui/ContainerMoistener.java index 0a12d2390..0841c4daa 100755 --- a/src/main/java/forestry/factory/gui/ContainerMoistener.java +++ b/src/main/java/forestry/factory/gui/ContainerMoistener.java @@ -10,13 +10,13 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; import forestry.core.gui.slots.SlotCraftAuto; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotWorking; import forestry.core.interfaces.IContainerCrafting; import forestry.factory.gadgets.MachineMoistener; @@ -26,45 +26,47 @@ public class ContainerMoistener extends ContainerLiquidTanks implements IContain protected final MachineMoistener tile; public ContainerMoistener(InventoryPlayer player, MachineMoistener tile) { - super(tile, tile); + super(tile); this.tile = tile; + // Stash - for (int l = 0; l < 2; l++) - for (int k1 = 0; k1 < 3; k1++) - addSlot(new Slot(tile, k1 + l * 3, 39 + k1 * 18, 16 + l * 18)); + for (int l = 0; l < 2; l++) { + for (int k1 = 0; k1 < 3; k1++) { + addSlotToContainer(new SlotFiltered(tile, k1 + l * 3, 39 + k1 * 18, 16 + l * 18)); + } + } // Reservoir - for (int k1 = 0; k1 < 3; k1++) - addSlot(new Slot(tile, k1 + 6, 39 + k1 * 18, 22 + 36)); + for (int k1 = 0; k1 < 3; k1++) { + addSlotToContainer(new SlotFiltered(tile, k1 + 6, 39 + k1 * 18, 22 + 36)); + } // Working slot - this.addSlot(new SlotWorking(tile, 9, 105, 37)); + this.addSlotToContainer(new SlotWorking(tile, 9, 105, 37)); // Product slot - this.addSlot(new Slot(tile, 10, 143, 55)); + this.addSlotToContainer(new SlotFiltered(tile, 10, 143, 55)); // Boxes - this.addSlot(new SlotCraftAuto(this, tile, 11, 143, 19)); + this.addSlotToContainer(new SlotCraftAuto(this, tile, 11, 143, 19)); // Player inventory int var3; - for (var3 = 0; var3 < 3; ++var3) - for (int var4 = 0; var4 < 9; ++var4) - this.addSlot(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot(player, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } - for (var3 = 0; var3 < 9; ++var3) - this.addSlot(new Slot(player, var3, 8 + var3 * 18, 142)); + for (var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot(player, var3, 8 + var3 * 18, 142)); + } } @Override public void onCraftMatrixChanged(IInventory iinventory, int slot) { - inventory.setInventorySlotContents(slot, iinventory.getStackInSlot(slot)); + tile.setInventorySlotContents(slot, iinventory.getStackInSlot(slot)); tile.checkRecipe(); } - @Override - public boolean canInteractWith(EntityPlayer player) { - return this.tile.isUseableByPlayer(player); - } - } diff --git a/src/main/java/forestry/factory/gui/ContainerRaintank.java b/src/main/java/forestry/factory/gui/ContainerRaintank.java index ad0b0afa6..84e2ae3c0 100755 --- a/src/main/java/forestry/factory/gui/ContainerRaintank.java +++ b/src/main/java/forestry/factory/gui/ContainerRaintank.java @@ -10,38 +10,32 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineRaintank; public class ContainerRaintank extends ContainerLiquidTanks { - protected MachineRaintank tile; - public ContainerRaintank(InventoryPlayer player, MachineRaintank tile) { - super(tile, tile); + super(tile); - this.tile = tile; - this.addSlot(new SlotLiquidContainer(tile, MachineRaintank.SLOT_RESOURCE, 116, 19, true)); - this.addSlot(new SlotClosed(tile, MachineRaintank.SLOT_PRODUCT, 116, 55)); + this.addSlotToContainer(new SlotFiltered(tile, MachineRaintank.SLOT_RESOURCE, 116, 19)); + this.addSlotToContainer(new SlotOutput(tile, MachineRaintank.SLOT_PRODUCT, 116, 55)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) - this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return tile.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerSqueezer.java b/src/main/java/forestry/factory/gui/ContainerSqueezer.java index 7c236ca59..a67e31e23 100755 --- a/src/main/java/forestry/factory/gui/ContainerSqueezer.java +++ b/src/main/java/forestry/factory/gui/ContainerSqueezer.java @@ -11,43 +11,38 @@ package forestry.factory.gui; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineSqueezer; public class ContainerSqueezer extends ContainerLiquidTanks { - protected MachineSqueezer tile; - public ContainerSqueezer(InventoryPlayer player, MachineSqueezer tile) { - super(tile, tile); - - this.tile = tile; + super(tile); // Resource inventory for (int l = 0; l < 3; l++) for (int k = 0; k < 3; k++) - addSlot(new Slot(tile, k + l * 3, 19 + k * 18, 18 + l * 18)); + addSlotToContainer(new SlotFiltered(tile, k + l * 3, 19 + k * 18, 18 + l * 18)); // Remnants slot - this.addSlot(new SlotClosed(tile, 9, 123, 19)); + this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SLOT_REMNANT, 123, 19)); // Can slot - this.addSlot(new SlotLiquidContainer(tile, 10, 106, 55, true)); + this.addSlotToContainer(new SlotFiltered(tile, MachineSqueezer.SLOT_CAN_INPUT, 106, 55)); // Output slot - this.addSlot(new SlotClosed(tile, 11, 140, 55)); + this.addSlotToContainer(new SlotOutput(tile, MachineSqueezer.SLOT_CAN_OUTPUT, 140, 55)); // Player inventory for (int i1 = 0; i1 < 3; i1++) for (int l1 = 0; l1 < 9; l1++) - addSlot(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); + addSlotToContainer(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); // Player hotbar for (int j1 = 0; j1 < 9; j1++) - addSlot(new Slot(player, j1, 8 + j1 * 18, 142)); + addSlotToContainer(new Slot(player, j1, 8 + j1 * 18, 142)); } } diff --git a/src/main/java/forestry/factory/gui/ContainerStill.java b/src/main/java/forestry/factory/gui/ContainerStill.java index fa384ee0f..68ecffa7a 100755 --- a/src/main/java/forestry/factory/gui/ContainerStill.java +++ b/src/main/java/forestry/factory/gui/ContainerStill.java @@ -10,37 +10,33 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerLiquidTanks; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.factory.gadgets.MachineStill; public class ContainerStill extends ContainerLiquidTanks { - protected MachineStill processor; public ContainerStill(InventoryPlayer player, MachineStill tile) { - super(tile, tile); + super(tile); - this.processor = tile; - this.addSlot(new Slot(tile, MachineStill.SLOT_PRODUCT, 150, 54)); - this.addSlot(new SlotLiquidContainer(tile, MachineStill.SLOT_RESOURCE, 150, 18, true)); - this.addSlot(new SlotLiquidContainer(tile, MachineStill.SLOT_CAN, 10, 36)); + this.addSlotToContainer(new SlotOutput(tile, MachineStill.SLOT_PRODUCT, 150, 54)); + this.addSlotToContainer(new SlotFiltered(tile, MachineStill.SLOT_RESOURCE, 150, 18)); + this.addSlotToContainer(new SlotFiltered(tile, MachineStill.SLOT_CAN, 10, 36)); - for (int i = 0; i < 3; ++i) - for (int j = 0; j < 9; ++j) - this.addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } - for (int i = 0; i < 9; ++i) - this.addSlot(new Slot(player, i, 8 + i * 18, 142)); + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142)); + } } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return processor.isUseableByPlayer(entityplayer); - } } diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/factory/gui/ContainerWorktable.java index 472064ebe..f843aa304 100755 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/factory/gui/ContainerWorktable.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import forestry.core.utils.StackUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import forestry.core.gui.ContainerForestry; import forestry.core.gui.IGuiSelectable; @@ -25,52 +24,49 @@ import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; +import forestry.core.utils.StackUtils; import forestry.factory.gadgets.TileWorktable; -import net.minecraft.item.ItemStack; public class ContainerWorktable extends ContainerForestry implements IContainerCrafting, IGuiSelectable { - EntityPlayer player; - TileWorktable tile; - IInventory craftingInventory; - IInventory internalInventory; - InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); - InventoryCraftResult craftResult = new InventoryCraftResult(); - long lastUpdate; + private final EntityPlayer player; + private final TileWorktable tile; + private final InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + private long lastUpdate; public ContainerWorktable(EntityPlayer player, TileWorktable tile) { - super(tile.getInternalInventory()); + super(tile); this.tile = tile; - craftingInventory = tile.getCraftingInventory(); - internalInventory = tile.getInternalInventory(); + IInventory craftingInventory = tile.getCraftingInventory(); + IInventory internalInventory = tile.getInternalInventory(); // Internal inventory for (int i = 0; i < 2; i++) { for (int k = 0; k < 9; k++) { - addSlot(new Slot(internalInventory, TileWorktable.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); + addSlotToContainer(new Slot(internalInventory, TileWorktable.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18)); } } // Crafting matrix for (int l = 0; l < 3; l++) { for (int k1 = 0; k1 < 3; k1++) { - addSlot(new SlotCraftMatrix(this, craftingInventory, k1 + l * 3, 11 + k1 * 18, 20 + l * 18)); + addSlotToContainer(new SlotCraftMatrix(this, craftingInventory, k1 + l * 3, 11 + k1 * 18, 20 + l * 18)); } } // CraftResult display - addSlot(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38)); + addSlotToContainer(new SlotCrafter(player, craftingInventory, tile, TileWorktable.SLOT_CRAFTING_RESULT, 77, 38)); // Player inventory for (int i1 = 0; i1 < 3; i1++) { for (int l1 = 0; l1 < 9; l1++) { - addSlot(new Slot(player.inventory, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); + addSlotToContainer(new Slot(player.inventory, l1 + i1 * 9 + 9, 8 + l1 * 18, 136 + i1 * 18)); } } // Player hotbar for (int j1 = 0; j1 < 9; j1++) { - addSlot(new Slot(player.inventory, j1, 8 + j1 * 18, 194)); + addSlotToContainer(new Slot(player.inventory, j1, 8 + j1 * 18, 194)); } // Update crafting matrix with current contents of tileentity. @@ -107,7 +103,7 @@ public class ContainerWorktable extends ContainerForestry implements IContainerC private void updateMatrix() { for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { - craftMatrix.setInventorySlotContents(i, craftingInventory.getStackInSlot(i)); + craftMatrix.setInventorySlotContents(i, tile.getCraftingInventory().getStackInSlot(i)); } } diff --git a/src/main/java/forestry/factory/gui/GuiBottler.java b/src/main/java/forestry/factory/gui/GuiBottler.java index fd24dc271..6d0293689 100755 --- a/src/main/java/forestry/factory/gui/GuiBottler.java +++ b/src/main/java/forestry/factory/gui/GuiBottler.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineBottler; +import net.minecraft.entity.player.InventoryPlayer; public class GuiBottler extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiCarpenter.java b/src/main/java/forestry/factory/gui/GuiCarpenter.java index 655e8df89..a6bb17de7 100755 --- a/src/main/java/forestry/factory/gui/GuiCarpenter.java +++ b/src/main/java/forestry/factory/gui/GuiCarpenter.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineCarpenter; +import net.minecraft.entity.player.InventoryPlayer; public class GuiCarpenter extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiCentrifuge.java b/src/main/java/forestry/factory/gui/GuiCentrifuge.java index dde1b62c8..a81cf5470 100755 --- a/src/main/java/forestry/factory/gui/GuiCentrifuge.java +++ b/src/main/java/forestry/factory/gui/GuiCentrifuge.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.factory.gadgets.MachineCentrifuge; +import net.minecraft.entity.player.InventoryPlayer; public class GuiCentrifuge extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiFabricator.java b/src/main/java/forestry/factory/gui/GuiFabricator.java index f2b48da1c..21cb5f40e 100755 --- a/src/main/java/forestry/factory/gui/GuiFabricator.java +++ b/src/main/java/forestry/factory/gui/GuiFabricator.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.ReservoirWidget; import forestry.factory.gadgets.MachineFabricator; +import net.minecraft.entity.player.InventoryPlayer; public class GuiFabricator extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiFermenter.java b/src/main/java/forestry/factory/gui/GuiFermenter.java index 1d51ba00b..752659428 100755 --- a/src/main/java/forestry/factory/gui/GuiFermenter.java +++ b/src/main/java/forestry/factory/gui/GuiFermenter.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineFermenter; +import net.minecraft.entity.player.InventoryPlayer; public class GuiFermenter extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiMoistener.java b/src/main/java/forestry/factory/gui/GuiMoistener.java index e4fbd864d..22b0ed895 100755 --- a/src/main/java/forestry/factory/gui/GuiMoistener.java +++ b/src/main/java/forestry/factory/gui/GuiMoistener.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineMoistener; +import net.minecraft.entity.player.InventoryPlayer; public class GuiMoistener extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiRaintank.java b/src/main/java/forestry/factory/gui/GuiRaintank.java index 02a93a01c..457d2b534 100755 --- a/src/main/java/forestry/factory/gui/GuiRaintank.java +++ b/src/main/java/forestry/factory/gui/GuiRaintank.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineRaintank; +import net.minecraft.entity.player.InventoryPlayer; public class GuiRaintank extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiStill.java b/src/main/java/forestry/factory/gui/GuiStill.java index 2fcb8cd1f..cbfc65c0f 100755 --- a/src/main/java/forestry/factory/gui/GuiStill.java +++ b/src/main/java/forestry/factory/gui/GuiStill.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestryTitled; import forestry.core.gui.widgets.TankWidget; import forestry.factory.gadgets.MachineStill; +import net.minecraft.entity.player.InventoryPlayer; public class GuiStill extends GuiForestryTitled { diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/factory/gui/GuiWorktable.java index 36248e8b5..27cb8d04f 100755 --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/factory/gui/GuiWorktable.java @@ -44,20 +44,14 @@ public class GuiWorktable extends GuiForestryTitled { @Override public void draw(int startX, int startY) { - GL11.glPushAttrib(GL11.GL_ENABLE_BIT); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - RenderHelper.enableGUIStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - ItemStack output = getOutputStack(); if (output != null) manager.gui.drawItemStack(output, startX + xPos, startY + yPos); - //RenderHelper.disableStandardItemLighting(); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (worktable.getMemory().isLocked(slotNumber)) { manager.gui.setZLevel(110f); diff --git a/src/main/java/forestry/factory/gui/SlotCraftMatrix.java b/src/main/java/forestry/factory/gui/SlotCraftMatrix.java index e627b984b..39ed2820f 100755 --- a/src/main/java/forestry/factory/gui/SlotCraftMatrix.java +++ b/src/main/java/forestry/factory/gui/SlotCraftMatrix.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.factory.gui; -import net.minecraft.inventory.IInventory; - import forestry.core.gui.slots.SlotForestry; import forestry.core.interfaces.IContainerCrafting; +import net.minecraft.inventory.IInventory; /** * Informs the passed container of slot changes. Contains a dummy itemstack. diff --git a/src/main/java/forestry/factory/recipes/CraftGuideBottler.java b/src/main/java/forestry/factory/recipes/CraftGuideBottler.java index b430f0623..70d426fda 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideBottler.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideBottler.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.factory.gadgets.MachineBottler; import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -20,10 +22,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.factory.gadgets.MachineBottler; - public class CraftGuideBottler implements RecipeProvider { private final Slot[] slots = new Slot[4]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideCarpenter.java b/src/main/java/forestry/factory/recipes/CraftGuideCarpenter.java index df737e54c..ecf5213cd 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideCarpenter.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideCarpenter.java @@ -10,8 +10,11 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.utils.RecipeUtil; +import forestry.factory.gadgets.MachineCarpenter; import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -20,11 +23,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.utils.RecipeUtil; -import forestry.factory.gadgets.MachineCarpenter; - public class CraftGuideCarpenter implements RecipeProvider { private final Slot[] slots = new Slot[12]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java b/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java index 243bdba52..f24659aaa 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideCentrifuge.java @@ -10,11 +10,12 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.factory.gadgets.MachineCentrifuge; import java.util.ArrayList; import java.util.Map.Entry; - import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ChanceSlot; import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -23,10 +24,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.factory.gadgets.MachineCentrifuge; - public class CraftGuideCentrifuge implements RecipeProvider { private final Slot[] slots = new Slot[11]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideCustomRecipes.java b/src/main/java/forestry/factory/recipes/CraftGuideCustomRecipes.java index e1309171c..e1ed7c04d 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideCustomRecipes.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideCustomRecipes.java @@ -10,19 +10,17 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.interfaces.IDescriptiveRecipe; +import forestry.core.utils.RecipeUtil; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; import uristqwerty.CraftGuide.api.RecipeProvider; import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.interfaces.IDescriptiveRecipe; -import forestry.core.utils.RecipeUtil; - public class CraftGuideCustomRecipes implements RecipeProvider { private final ItemSlot[] slots = new ItemSlot[10]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideFabricator.java b/src/main/java/forestry/factory/recipes/CraftGuideFabricator.java index f193a0a59..67b48c5b6 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideFabricator.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideFabricator.java @@ -10,8 +10,11 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.utils.RecipeUtil; +import forestry.factory.gadgets.MachineFabricator; import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -20,11 +23,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.utils.RecipeUtil; -import forestry.factory.gadgets.MachineFabricator; - public class CraftGuideFabricator implements RecipeProvider { private final Slot[] slots = new Slot[12]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideFermenter.java b/src/main/java/forestry/factory/recipes/CraftGuideFermenter.java index 970966bca..60c8b403f 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideFermenter.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideFermenter.java @@ -10,13 +10,14 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.api.fuels.FuelManager; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.factory.gadgets.MachineFermenter; import java.util.ArrayList; import java.util.List; - import net.minecraft.item.ItemStack; - import net.minecraftforge.fluids.FluidStack; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -25,11 +26,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.api.fuels.FuelManager; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.factory.gadgets.MachineFermenter; - public class CraftGuideFermenter implements RecipeProvider { private final Slot[] slots = new Slot[5]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideIntegration.java b/src/main/java/forestry/factory/recipes/CraftGuideIntegration.java index ed00830e9..9ead8d2f4 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideIntegration.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideIntegration.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.factory.recipes; -import java.lang.reflect.Method; - import forestry.core.proxy.Proxies; +import java.lang.reflect.Method; public class CraftGuideIntegration { diff --git a/src/main/java/forestry/factory/recipes/CraftGuideSqueezer.java b/src/main/java/forestry/factory/recipes/CraftGuideSqueezer.java index e7a1286dc..0fcc8ca10 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideSqueezer.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideSqueezer.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.factory.gadgets.MachineSqueezer; import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ChanceSlot; import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; @@ -21,10 +23,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.factory.gadgets.MachineSqueezer; - public class CraftGuideSqueezer implements RecipeProvider { private final Slot[] slots = new Slot[12]; diff --git a/src/main/java/forestry/factory/recipes/CraftGuideStill.java b/src/main/java/forestry/factory/recipes/CraftGuideStill.java index 5384e84ad..2bce6fff2 100755 --- a/src/main/java/forestry/factory/recipes/CraftGuideStill.java +++ b/src/main/java/forestry/factory/recipes/CraftGuideStill.java @@ -10,8 +10,10 @@ ******************************************************************************/ package forestry.factory.recipes; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.factory.gadgets.MachineStill; import net.minecraft.item.ItemStack; - import uristqwerty.CraftGuide.api.ItemSlot; import uristqwerty.CraftGuide.api.LiquidSlot; import uristqwerty.CraftGuide.api.RecipeGenerator; @@ -20,10 +22,6 @@ import uristqwerty.CraftGuide.api.RecipeTemplate; import uristqwerty.CraftGuide.api.Slot; import uristqwerty.CraftGuide.api.SlotType; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.factory.gadgets.MachineStill; - public class CraftGuideStill implements RecipeProvider { private final Slot[] slots = new Slot[3]; diff --git a/src/main/java/forestry/factory/recipes/RecipeMemory.java b/src/main/java/forestry/factory/recipes/RecipeMemory.java index 02524f5e3..444c56019 100644 --- a/src/main/java/forestry/factory/recipes/RecipeMemory.java +++ b/src/main/java/forestry/factory/recipes/RecipeMemory.java @@ -12,8 +12,11 @@ package forestry.factory.recipes; import forestry.api.core.INBTTagable; import forestry.core.gui.ContainerDummy; -import forestry.core.utils.InventoryAdapter; +import forestry.core.inventory.InventoryAdapter; import forestry.core.utils.PlainInventory; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; @@ -25,10 +28,6 @@ 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 { @@ -162,6 +161,8 @@ public class RecipeMemory implements INBTTagable { Recipe memory = getMemorized(crafting, world); if (memory != null) { + if (memory.isLocked() != recipe.isLocked()) + recipe.toggleLock(); int index = recipes.indexOf(memory); recipes.set(index, recipe); return; diff --git a/src/main/java/forestry/farming/EventHandlerFarming.java b/src/main/java/forestry/farming/EventHandlerFarming.java index b0049dba9..a2ed61201 100755 --- a/src/main/java/forestry/farming/EventHandlerFarming.java +++ b/src/main/java/forestry/farming/EventHandlerFarming.java @@ -10,16 +10,13 @@ ******************************************************************************/ package forestry.farming; -import net.minecraft.block.Block; - import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -import net.minecraftforge.event.entity.player.BonemealEvent; - import forestry.core.config.ForestryBlock; import forestry.core.proxy.Proxies; import forestry.farming.gadgets.BlockMushroom; +import net.minecraft.block.Block; +import net.minecraftforge.event.entity.player.BonemealEvent; public class EventHandlerFarming { diff --git a/src/main/java/forestry/farming/FarmTarget.java b/src/main/java/forestry/farming/FarmTarget.java index b707f5d98..0d2853b61 100755 --- a/src/main/java/forestry/farming/FarmTarget.java +++ b/src/main/java/forestry/farming/FarmTarget.java @@ -1,53 +1,53 @@ -/******************************************************************************* - * 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.farming; - -import forestry.core.utils.Vect; - -public class FarmTarget { - - private Vect start; - private int yOffset; - private int extent; - private int limit; - - public FarmTarget(Vect start) { - this.start = start; - } - - public void setYOffset(int yOffset) { - this.yOffset = yOffset; - } - - public void setLimit(int limit) { - this.limit = limit; - } - - public void setExtent(int extent) { - this.extent = extent; - } - - public Vect getStart() { - return start; - } - - public int getYOffset() { - return this.yOffset; - } - - public int getLimit() { - return limit; - } - - public int getExtent() { - return extent; - } -} +/******************************************************************************* + * 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.farming; + +import forestry.core.vect.Vect; + +public class FarmTarget { + + private final Vect start; + private int yOffset; + private int extent; + private int limit; + + public FarmTarget(Vect start) { + this.start = start; + } + + public void setYOffset(int yOffset) { + this.yOffset = yOffset; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public void setExtent(int extent) { + this.extent = extent; + } + + public Vect getStart() { + return start; + } + + public int getYOffset() { + return this.yOffset; + } + + public int getLimit() { + return limit; + } + + public int getExtent() { + return extent; + } +} diff --git a/src/main/java/forestry/farming/GuiHandlerFarming.java b/src/main/java/forestry/farming/GuiHandlerFarming.java index 88456e447..4f4538a4d 100755 --- a/src/main/java/forestry/farming/GuiHandlerFarming.java +++ b/src/main/java/forestry/farming/GuiHandlerFarming.java @@ -10,9 +10,6 @@ ******************************************************************************/ package forestry.farming; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.core.network.PacketIds; @@ -21,6 +18,8 @@ import forestry.core.proxy.Proxies; import forestry.farming.gadgets.TileFarmPlain; import forestry.farming.gui.ContainerFarm; import forestry.farming.gui.GuiFarm; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; public class GuiHandlerFarming extends GuiHandlerBase { diff --git a/src/main/java/forestry/farming/gadgets/BlockFarm.java b/src/main/java/forestry/farming/gadgets/BlockFarm.java index 4a156aaca..270f55bd1 100755 --- a/src/main/java/forestry/farming/gadgets/BlockFarm.java +++ b/src/main/java/forestry/farming/gadgets/BlockFarm.java @@ -33,7 +33,6 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.core.gadgets.BlockStructure; import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; -import forestry.farming.gadgets.TileFarm.EnumFarmBlock; import forestry.plugins.PluginFarming; public class BlockFarm extends BlockStructure { @@ -62,10 +61,10 @@ public class BlockFarm extends BlockStructure { } @Override - public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) { ArrayList drops = getDrops(world, x, y, z, 0, 0); if (drops.isEmpty()) - return super.getPickBlock(target, world, x, y, z); + return super.getPickBlock(target, world, x, y, z, player); return drops.get(0); } @@ -155,7 +154,7 @@ public class BlockFarm extends BlockStructure { @SideOnly(Side.CLIENT) public IIcon getBlockTextureFromSideAndMetadata(EnumFarmBlock type, int side, int metadata) { - return StackUtils.getBlock(type.base).getIcon(side, type.base.getItemDamage()); + return StackUtils.getBlock(type.getBase()).getIcon(side, type.getBase().getItemDamage()); } @SideOnly(Side.CLIENT) @@ -185,20 +184,17 @@ public class BlockFarm extends BlockStructure { @Override public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) { - if (world.getBlockMetadata(x, y, z) == 5) - return true; - else - return false; + return world.getBlockMetadata(x, y, z) == 5; } @Override @SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { TileEntity tile = world.getTileEntity(x, y, z); - ItemStack base = EnumFarmBlock.BRICK_STONE.base; + ItemStack base = EnumFarmBlock.BRICK_STONE.getBase(); if (tile instanceof TileFarm) - base = ((TileFarm) tile).farmBlock.base; + base = ((TileFarm) tile).farmBlock.getBase(); return StackUtils.getBlock(base).getIcon(side, base.getItemDamage()); } diff --git a/src/main/java/forestry/farming/gadgets/BlockMushroom.java b/src/main/java/forestry/farming/gadgets/BlockMushroom.java index b61eff722..6c9c4b73d 100755 --- a/src/main/java/forestry/farming/gadgets/BlockMushroom.java +++ b/src/main/java/forestry/farming/gadgets/BlockMushroom.java @@ -10,11 +10,15 @@ ******************************************************************************/ package forestry.farming.gadgets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.core.IItemTyped; +import forestry.core.config.Defaults; +import forestry.core.proxy.Proxies; +import forestry.farming.worldgen.WorldGenBigMushroom; import java.util.ArrayList; import java.util.List; import java.util.Random; - -import forestry.core.IItemTyped; import net.minecraft.block.Block; import net.minecraft.block.BlockSapling; import net.minecraft.client.renderer.texture.IIconRegister; @@ -26,13 +30,6 @@ import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.core.config.Defaults; -import forestry.core.proxy.Proxies; -import forestry.farming.worldgen.WorldGenBigMushroom; - public class BlockMushroom extends BlockSapling implements IItemTyped { public enum MushroomType { @@ -104,21 +101,16 @@ public class BlockMushroom extends BlockSapling implements IItemTyped { @Override public void func_149878_d(World world, int i, int j, int k, Random random) { - int type = world.getBlockMetadata(i, j, k) & 0x03; - - if(type >= generators.length) - return; + MushroomType type = getTypeFromMeta(world.getBlockMetadata(i, j, k)); world.setBlockToAir(i, j, k); - if (!generators[type].generate(world, random, i, j, k)) - world.setBlock(i, j, k, this, type, 0); + if (!generators[type.ordinal()].generate(world, random, i, j, k)) + world.setBlock(i, j, k, this, type.ordinal(), 0); } @Override public MushroomType getTypeFromMeta(int meta) { - meta %= 3; - if (meta >= MushroomType.values().length) - return null; + meta %= MushroomType.values().length; return MushroomType.values()[meta]; } @@ -141,12 +133,11 @@ public class BlockMushroom extends BlockSapling implements IItemTyped { public IIcon getIcon(int side, int meta) { MushroomType type = getTypeFromMeta(meta); - if (type == MushroomType.BROWN) - return Blocks.brown_mushroom.getIcon(side, meta); - else if (type == MushroomType.RED) - return Blocks.red_mushroom.getIcon(side, meta); - else - return null; + switch (type) { + case BROWN: return Blocks.brown_mushroom.getIcon(side, meta); + case RED: return Blocks.red_mushroom.getIcon(side, meta); + default: return null; + } } } diff --git a/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java b/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java new file mode 100644 index 000000000..2a3e538e1 --- /dev/null +++ b/src/main/java/forestry/farming/gadgets/EnumFarmBlock.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.farming.gadgets; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.core.render.TextureManager; + +public enum EnumFarmBlock { + BRICK_STONE(new ItemStack(Blocks.stonebrick, 1, 0)), + BRICK_MOSSY(new ItemStack(Blocks.stonebrick, 1, 1)), + BRICK_CRACKED(new ItemStack(Blocks.stonebrick, 1, 2)), + BRICK(new ItemStack(Blocks.brick_block)), + SANDSTONE_SMOOTH(new ItemStack(Blocks.sandstone, 1, 2)), + SANDSTONE_CHISELED(new ItemStack(Blocks.sandstone, 1, 1)), + BRICK_NETHER(new ItemStack(Blocks.nether_brick)), + BRICK_CHISELED(new ItemStack(Blocks.stonebrick, 1, 3)), + QUARTZ(new ItemStack(Blocks.quartz_block, 1, 0)), + QUARTZ_CHISELED(new ItemStack(Blocks.quartz_block, 1, 1)), + QUARTZ_LINES(new ItemStack(Blocks.quartz_block, 1, 2)); + + @SideOnly(Side.CLIENT) + private static List icons; + + @SideOnly(Side.CLIENT) + public static void registerIcons(IIconRegister register) { + TextureManager textureManager = TextureManager.getInstance(); + icons = Arrays.asList( + textureManager.registerTex(register, "farm/plain"), + textureManager.registerTex(register, "farm/reverse"), + textureManager.registerTex(register, "farm/top"), + textureManager.registerTex(register, "farm/band"), + textureManager.registerTex(register, "farm/gears"), + textureManager.registerTex(register, "farm/hatch"), + textureManager.registerTex(register, "farm/valve"), + textureManager.registerTex(register, "farm/control") + ); + } + + private final ItemStack base; + + private EnumFarmBlock(ItemStack base) { + this.base = base; + } + + @SideOnly(Side.CLIENT) + public IIcon getIcon(int type) { + return icons.get(type); + } + + public void saveToCompound(NBTTagCompound compound) { + compound.setInteger("FarmBlock", this.ordinal()); + } + + public String getName() { + return base.getItem().getItemStackDisplayName(base); + } + + public ItemStack getBase() { + return base; + } + + public static EnumFarmBlock getFromCompound(NBTTagCompound compound) { + + if (compound != null) { + int farmBlockOrdinal = compound.getInteger("FarmBlock"); + if (farmBlockOrdinal < EnumFarmBlock.values().length) + return EnumFarmBlock.values()[farmBlockOrdinal]; + } + + return EnumFarmBlock.BRICK_STONE; + } +} diff --git a/src/main/java/forestry/farming/gadgets/StructureLogicFarm.java b/src/main/java/forestry/farming/gadgets/StructureLogicFarm.java index 88036724b..ec5acea0d 100755 --- a/src/main/java/forestry/farming/gadgets/StructureLogicFarm.java +++ b/src/main/java/forestry/farming/gadgets/StructureLogicFarm.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.farming.gadgets; -import java.util.HashSet; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.tileentity.TileEntity; - import forestry.api.core.ITileStructure; import forestry.api.farming.IFarmComponent; import forestry.core.gadgets.BlockStructure.EnumStructureState; import forestry.core.gadgets.StructureLogic; import forestry.core.utils.Schemata; import forestry.core.utils.Schemata.EnumStructureBlock; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.HashSet; import java.util.Set; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; public class StructureLogicFarm extends StructureLogic { diff --git a/src/main/java/forestry/farming/gadgets/TileControl.java b/src/main/java/forestry/farming/gadgets/TileControl.java index 848168371..f5e6280d1 100755 --- a/src/main/java/forestry/farming/gadgets/TileControl.java +++ b/src/main/java/forestry/farming/gadgets/TileControl.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.farming.gadgets; -import java.util.Collection; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.core.ITileStructure; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmComponent; import forestry.api.farming.IFarmListener; import forestry.api.farming.IFarmLogic; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; public class TileControl extends TileFarm implements IFarmListener { @@ -62,10 +59,6 @@ public class TileControl extends TileFarm implements IFarmListener { return true; } - @Override - protected void createInventory() { - } - /* IFARMLISTENER */ @Override public boolean cancelTask(IFarmLogic logic, ForgeDirection direction) { diff --git a/src/main/java/forestry/farming/gadgets/TileFarm.java b/src/main/java/forestry/farming/gadgets/TileFarm.java index 15e94981e..763dc388d 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarm.java +++ b/src/main/java/forestry/farming/gadgets/TileFarm.java @@ -10,11 +10,8 @@ ******************************************************************************/ package forestry.farming.gadgets; -import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; @@ -29,12 +26,10 @@ import forestry.api.farming.Farmables; import forestry.api.farming.IFarmComponent; import forestry.api.farming.IFarmListener; import forestry.core.gadgets.TileForestry; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.GuiId; import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Utils; public abstract class TileFarm extends TileForestry implements IFarmComponent { @@ -47,74 +42,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { public static final int TYPE_VALVE = 6; public static final int TYPE_CONTROL = 7; - public enum EnumFarmBlock { - - BRICK_STONE(new ItemStack(Blocks.stonebrick, 1, 0)), - BRICK_MOSSY(new ItemStack(Blocks.stonebrick, 1, 1)), - BRICK_CRACKED(new ItemStack(Blocks.stonebrick, 1, 2)), - BRICK(new ItemStack(Blocks.brick_block)), - SANDSTONE_SMOOTH(new ItemStack(Blocks.sandstone, 1, 2)), - SANDSTONE_CHISELED(new ItemStack(Blocks.sandstone, 1, 1)), - BRICK_NETHER(new ItemStack(Blocks.nether_brick)), - BRICK_CHISELED(new ItemStack(Blocks.stonebrick, 1, 3)), - QUARTZ(new ItemStack(Blocks.quartz_block, 1, 0)), - QUARTZ_CHISELED(new ItemStack(Blocks.quartz_block, 1, 1)), - QUARTZ_LINES(new ItemStack(Blocks.quartz_block, 1, 2)); - public final ItemStack base; - - private EnumFarmBlock(ItemStack base) { - this.base = base; - } - @SideOnly(Side.CLIENT) - private static IIcon[] icons; - - @SideOnly(Side.CLIENT) - public static void registerIcons(IIconRegister register) { - - icons = new IIcon[8]; - // for(int i = 0; i < values().length; i++) { - // generateTexturesIfNeeded(values()[i]); - - icons[0] = TextureManager.getInstance().registerTex(register, "farm/plain"); - icons[1] = TextureManager.getInstance().registerTex(register, "farm/reverse"); - icons[2] = TextureManager.getInstance().registerTex(register, "farm/top"); - icons[3] = TextureManager.getInstance().registerTex(register, "farm/band"); - icons[4] = TextureManager.getInstance().registerTex(register, "farm/gears"); - icons[5] = TextureManager.getInstance().registerTex(register, "farm/hatch"); - icons[6] = TextureManager.getInstance().registerTex(register, "farm/valve"); - icons[7] = TextureManager.getInstance().registerTex(register, "farm/control"); - // } - } - - @SideOnly(Side.CLIENT) - public IIcon getIcon(int type) { - return icons[type]; - } - - public void saveToCompound(NBTTagCompound compound) { - compound.setInteger("FarmBlock", this.ordinal()); - } - - public String getName() { - return base.getItem().getItemStackDisplayName(base); - } - - public ItemStack getCraftingIngredient() { - return base; - } - - public static EnumFarmBlock getFromCompound(NBTTagCompound compound) { - - if (compound != null) { - int farmBlockOrdinal = compound.getInteger("FarmBlock"); - if (farmBlockOrdinal < EnumFarmBlock.values().length) - return EnumFarmBlock.values()[farmBlockOrdinal]; - } - - return EnumFarmBlock.BRICK_STONE; - } - } - public TileFarm() { this.structureLogic = Farmables.farmInterface.createFarmStructureLogic(this); } @@ -131,8 +58,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { /* SAVING & LOADING */ @Override public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - this.isMaster = nbttagcompound.getBoolean("IsMaster"); this.masterX = nbttagcompound.getInteger("MasterX"); this.masterY = nbttagcompound.getInteger("MasterY"); @@ -144,10 +69,9 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { if (isMaster) makeMaster(); - if (inventory != null) - inventory.readFromNBT(nbttagcompound); - structureLogic.readFromNBT(nbttagcompound); + + super.readFromNBT(nbttagcompound); } @Override @@ -161,9 +85,6 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { farmBlock.saveToCompound(nbttagcompound); - if (inventory != null) - inventory.writeToNBT(nbttagcompound); - structureLogic.writeToNBT(nbttagcompound); } @@ -225,22 +146,29 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { return null; } - /* INVENTORY MANAGMENT */ - protected TileInventoryAdapter inventory; - - protected abstract void createInventory(); - /* TILEFORESTRY */ @Override public PacketPayload getPacketPayload() { - PacketPayload payload = new PacketPayload(0, 1); + PacketPayload payload = new PacketPayload(0, 3); payload.shortPayload[0] = (short) farmBlock.ordinal(); + + payload.shortPayload[1] = (short) (isMaster() ? 1 : 0); + + // so the client can know if it is part of an integrated structure + payload.shortPayload[2] = (short) masterY; + return payload; } @Override public void fromPacketPayload(PacketPayload payload) { EnumFarmBlock farmType = EnumFarmBlock.values()[payload.shortPayload[0]]; + if (payload.shortPayload[1] > 0) + makeMaster(); + + // so the client can know if it is part of an integrated structure + this.masterY = payload.shortPayload[2]; + if (this.farmBlock != farmType) { this.farmBlock = farmType; worldObj.func_147479_m(xCoord, yCoord, zCoord); @@ -268,8 +196,8 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { setCentralTE(null); this.isMaster = true; - if (inventory == null) - createInventory(); + if (worldObj != null && !worldObj.isRemote) + sendNetworkUpdate(); } @Override @@ -284,22 +212,19 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { @Override public ITileStructure getCentralTE() { - if (!isIntegratedIntoStructure() || !hasMaster()) + if (!isIntegratedIntoStructure()) return null; - if (!isMaster) { - TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ); - if (tile instanceof ITileStructure) { - ITileStructure master = (ITileStructure) worldObj.getTileEntity(masterX, masterY, masterZ); - if (master.isMaster()) - return master; - else - return null; - } else - return null; - } else + if (isMaster) return this; + TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ); + if (tile instanceof ITileStructure) { + ITileStructure master = (ITileStructure)tile; + if (master.isMaster()) + return master; + } + return null; } private boolean isSameTile(TileEntity tile) { @@ -332,8 +257,13 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { } @Override - public IInventory getInventory() { - return inventory; + public final IInventory getInventory() { + return getStructureInventory(); + } + + @Override + public IInventoryAdapter getStructureInventory() { + return getInternalInventory(); } @Override @@ -348,10 +278,4 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent { @Override public void removeListener(IFarmListener listener) { } - - /* INTERACTION */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord); - } } diff --git a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java index 0638c4766..9c7514fd9 100755 --- a/src/main/java/forestry/farming/gadgets/TileFarmPlain.java +++ b/src/main/java/forestry/farming/gadgets/TileFarmPlain.java @@ -19,8 +19,6 @@ import java.util.Set; import java.util.Stack; import java.util.TreeMap; -import forestry.api.core.BiomeHelper; -import forestry.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -32,13 +30,12 @@ import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuitBoard; +import forestry.api.core.BiomeHelper; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.farming.ICrop; @@ -47,44 +44,50 @@ import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmListener; import forestry.api.farming.IFarmLogic; import forestry.api.farming.IFarmable; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.GameMode; import forestry.core.config.Config; import forestry.core.config.Defaults; +import forestry.core.fluids.FluidHelper; +import forestry.core.fluids.Fluids; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FilteredTank; import forestry.core.interfaces.IClimatised; import forestry.core.interfaces.IHintSource; import forestry.core.interfaces.ISocketable; -import forestry.core.interfaces.ILiquidTankContainer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.proxy.Proxies; import forestry.core.utils.DelayTimer; -import forestry.core.fluids.tanks.StandardTank; -import forestry.core.fluids.tanks.FilteredTank; -import forestry.core.fluids.TankManager; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.LiquidHelper; +import forestry.core.utils.GuiUtil; import forestry.core.utils.StackUtils; -import forestry.core.utils.TileInventoryAdapter; -import forestry.core.utils.Vect; +import forestry.core.utils.Utils; +import forestry.core.vect.Vect; import forestry.farming.FarmTarget; import forestry.farming.logic.FarmLogicArboreal; import forestry.plugins.PluginFarming; -public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource, ILiquidTankContainer { +public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable, IClimatised, IHintSource { public static final int SLOT_RESOURCES_1 = 0; + public static final int SLOT_RESOURCES_COUNT = 6; public static final int SLOT_GERMLINGS_1 = 6; + public static final int SLOT_GERMLINGS_COUNT = 6; public static final int SLOT_PRODUCTION_1 = 12; - public static final int SLOT_COUNT_RESERVOIRS = 6; - public static final int SLOT_COUNT_PRODUCTION = 8; + public static final int SLOT_PRODUCTION_COUNT = 8; public static final int SLOT_FERTILIZER = 20; + public static final int SLOT_FERTILIZER_COUNT = 1; public static final int SLOT_CAN = 21; + public static final int SLOT_CAN_COUNT = 1; - public static final int SLOT_COUNT = 22; + public static final int SLOT_COUNT = SLOT_RESOURCES_COUNT + SLOT_GERMLINGS_COUNT + SLOT_PRODUCTION_COUNT + SLOT_FERTILIZER_COUNT + SLOT_CAN_COUNT; - public static final int DELAY_HYDRATION = 100; - public static final float RAINFALL_MODIFIER_CAP = 15f; - public static final int BUFFER_FERTILIZER = 200; + private static final int DELAY_HYDRATION = 100; + private static final float RAINFALL_MODIFIER_CAP = 15f; + private static final int BUFFER_FERTILIZER = 200; private IFarmLogic[] farmLogics = new IFarmLogic[4]; @@ -94,8 +97,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets"); - private final FilteredTank liquidTank; - private final TankManager tankManager; + private TankManager tankManager; private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops. private final Stack pendingCrops = new Stack(); @@ -112,8 +114,6 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable public TileFarmPlain() { fertilizerValue = GameMode.getGameMode().getIntegerSetting("farms.fertilizer.value"); - liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); - tankManager = new TankManager(liquidTank); } @Override @@ -134,7 +134,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable refreshFarmLogics(); - tankManager.readTanksFromNBT(nbttagcompound); + if (tankManager != null) + tankManager.readTanksFromNBT(nbttagcompound); } @Override @@ -146,15 +147,11 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable nbttagcompound.setInteger("HydrationDelay", hydrationDelay); nbttagcompound.setInteger("TicksSinceRainfall", ticksSinceRainfall); - tankManager.writeTanksToNBT(nbttagcompound); + if (tankManager != null) + tankManager.writeTanksToNBT(nbttagcompound); } /* UPDATING */ - @Override - public void initialize() { - setBiomeInformation(); - } - @Override protected void updateServerSide() { super.updateServerSide(); @@ -177,14 +174,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable return; // Check if we have suitable items waiting in the item slot - if (inventory.getStackInSlot(SLOT_CAN) != null) { - FluidContainerData container = LiquidHelper.getLiquidContainer(inventory.getStackInSlot(SLOT_CAN)); - if (container != null && liquidTank.accepts(container.fluid.getFluid())) { - - inventory.setInventorySlotContents(SLOT_CAN, StackUtils.replenishByContainer(this, inventory.getStackInSlot(SLOT_CAN), container, liquidTank)); - if (inventory.getStackInSlot(SLOT_CAN).stackSize <= 0) - inventory.setInventorySlotContents(SLOT_CAN, null); - } + if (getInternalInventory().getStackInSlot(SLOT_CAN) != null) { + FluidHelper.drainContainers(tankManager, getInternalInventory(), SLOT_CAN); } } @@ -366,16 +357,34 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable } } - @Override protected void createInventory() { - inventory = new TileInventoryAdapter(this, SLOT_COUNT, "Items"); + setInternalInventory(new TileInventoryAdapter(this, SLOT_COUNT, "Items") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (GuiUtil.isIndexInRange(slotIndex, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT)) { + return acceptsAsFertilizer(itemStack); + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT)) { + return acceptsAsGermling(itemStack); + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT)) { + return acceptsAsResource(itemStack); + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) { + Fluid fluid = FluidHelper.getFluidInContainer(itemStack); + return tankManager.accepts(fluid); + } + return false; + } + + @Override + public boolean canExtractItem(int slotIndex, ItemStack stack, int side) { + return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT); + } + }); + FilteredTank liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER); + tankManager = new TankManager(liquidTank); } @Override public boolean doWork() { - - setBiomeInformation(); - // System.out.println("Starting doWork()"); if (targets == null) { createTargets(); @@ -383,9 +392,6 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable } else if (checkTimer.delayPassed(worldObj, 400)) setExtents(); - if (inventory == null) - createInventory(); - // System.out.println("Targets set"); if (tryAddPending()) return true; @@ -453,7 +459,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable else hasFertilizer = true; - FluidStack liquid = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, logic.getWaterConsumption(getHydrationModifier())); + FluidStack liquid = Fluids.WATER.getFluid(logic.getWaterConsumption(getHydrationModifier())); if (liquid.amount > 0 && !hasLiquid(liquid)) continue; else @@ -545,21 +551,21 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable } private void addProduceToInventory(ItemStack produce) { - + IInventoryAdapter inventory = getInternalInventory(); for (IFarmLogic logic : getFarmLogics()) { // Germlings try to go into germling slots first. if (logic.isAcceptedGermling(produce)) - produce.stackSize -= inventory.addStack(produce, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS, false, true); + produce.stackSize -= InvTools.addStack(inventory, produce, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT, false, true); if (produce.stackSize <= 0) return; if (logic.isAcceptedResource(produce)) - produce.stackSize -= inventory.addStack(produce, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS, false, true); + produce.stackSize -= InvTools.addStack(inventory, produce, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT, false, true); if (produce.stackSize <= 0) return; } - produce.stackSize -= inventory.addStack(produce, SLOT_PRODUCTION_1, SLOT_COUNT_PRODUCTION, false, true); + produce.stackSize -= InvTools.addStack(inventory, produce, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT, false, true); } private boolean cullCrop(ICrop crop, IFarmLogic provider) { @@ -576,7 +582,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable } // Check water - FluidStack liquid = LiquidHelper.getLiquid(Defaults.LIQUID_WATER, provider.getWaterConsumption(getHydrationModifier())); + FluidStack liquid = Fluids.WATER.getFluid(provider.getWaterConsumption(getHydrationModifier())); if (liquid.amount > 0 && !hasLiquid(liquid)) { setErrorState(EnumErrorCode.NOLIQUID); return false; @@ -596,13 +602,15 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable for (IFarmListener listener : eventHandlers) listener.afterCropHarvest(harvested, crop); + IInventoryAdapter inventory = getInternalInventory(); + // Stow harvest. for (ItemStack harvest : harvested) { // Special case germlings for (IFarmLogic logic : farmLogics) if (logic.isAcceptedGermling(harvest)) { - harvest.stackSize -= inventory.addStack(harvest, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS, false, true); + harvest.stackSize -= InvTools.addStack(inventory, harvest, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT, false, true); break; } @@ -610,7 +618,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable if (harvest.stackSize <= 0) continue; - harvest.stackSize -= inventory.addStack(harvest, SLOT_PRODUCTION_1, SLOT_COUNT_PRODUCTION, false, true); + harvest.stackSize -= InvTools.addStack(inventory, harvest, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT, false, true); if (harvest.stackSize <= 0) continue; @@ -625,7 +633,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable return false; ItemStack next = pendingProduce.peek(); - if (inventory.tryAddStack(next, SLOT_PRODUCTION_1, SLOT_COUNT_PRODUCTION, true, true)) { + if (InvTools.tryAddStack(getInternalInventory(), next, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT, true, true)) { pendingProduce.pop(); return true; } @@ -641,6 +649,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable return; } + IInventoryAdapter inventory = getInternalInventory(); ItemStack fertilizer = inventory.getStackInSlot(SLOT_FERTILIZER); if (fertilizer == null || fertilizer.stackSize <= 0) return; @@ -681,18 +690,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable public void makeMaster() { super.makeMaster(); refreshFarmLogics(); + createInventory(); } - @Override - public void onStructureReset() { - super.onStructureReset(); - } - - public StandardTank[] getTanks() { - return new StandardTank[] {liquidTank}; - } - - @Override public TankManager getTankManager() { return tankManager; } @@ -769,51 +769,51 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable @Override public boolean hasResources(ItemStack[] resources) { - return inventory.contains(resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS); + return InvTools.contains(getInternalInventory(), resources, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT); } public boolean hasResourcesAmount(int amount) { - return inventory.containsAmount(amount, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS); + return InvTools.containsAmount(getInternalInventory(), amount, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT); } public boolean hasGermlingsPercent(float percent) { - return inventory.containsPercent(percent, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS); + return InvTools.containsPercent(getInternalInventory(), percent, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT); } public boolean hasFertilizerPercent(float percent) { - return inventory.containsPercent(percent, SLOT_FERTILIZER, 1); + return InvTools.containsPercent(getInternalInventory(), percent, SLOT_FERTILIZER, 1); } @Override public void removeResources(ItemStack[] resources) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, owner); - inventory.removeSets(1, resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS, player, false, true, true); + EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile()); + InvTools.removeSets(getInternalInventory(), 1, resources, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT, player, false, true, true); } @Override public boolean hasLiquid(FluidStack liquid) { - return liquidTank.getFluidAmount() >= liquid.amount; + return tankManager.get(0).getFluidAmount() >= liquid.amount; } @Override public void removeLiquid(FluidStack liquid) { - liquidTank.drain(liquid.amount, true); + tankManager.drain(liquid, true); } public boolean hasGermlings(ItemStack[] germlings) { - return inventory.contains(germlings, SLOT_GERMLINGS_1, SLOT_COUNT_RESERVOIRS); + return InvTools.contains(getInternalInventory(), germlings, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT); } @Override public boolean plantGermling(IFarmable germling, World world, int x, int y, int z) { - - for (int i = SLOT_GERMLINGS_1; i < SLOT_GERMLINGS_1 + SLOT_COUNT_RESERVOIRS; i++) { + IInventoryAdapter inventory = getInternalInventory(); + for (int i = SLOT_GERMLINGS_1; i < SLOT_GERMLINGS_1 + SLOT_GERMLINGS_COUNT; i++) { if (inventory.getStackInSlot(i) == null) continue; if (!germling.isGermling(inventory.getStackInSlot(i))) continue; - EntityPlayer player = Proxies.common.getPlayer(world, owner); + EntityPlayer player = Proxies.common.getPlayer(world, getOwnerProfile()); if (!germling.plantSaplingAt(player, inventory.getStackInSlot(i), world, x, y, z)) continue; @@ -877,9 +877,9 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable return StackUtils.isIdenticalItem(PluginFarming.farmFertilizer, itemstack); } - int[] coords; - int[] offset; - int[] area; + private int[] coords; + private int[] offset; + private int[] area; @Override public int[] getCoords() { @@ -904,7 +904,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable /* NETWORK GUI */ public void getGUINetworkData(int i, int j) { - i -= tankManager.maxMessageId() + 1; + if (tankManager != null) + i -= tankManager.maxMessageId() + 1; switch (i) { case 0: storedFertilizer = j; @@ -989,35 +990,4 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable public boolean isOwnable() { return true; } - - /* ILiquidTankContainer */ - @Override - public int fill(ForgeDirection direction, FluidStack resource, boolean doFill) { - return tankManager.fill(direction, resource, doFill); - } - - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - return tankManager.drain(from, resource, doDrain); - } - - @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - return tankManager.drain(from, maxDrain, doDrain); - } - - @Override - public boolean canFill(ForgeDirection from, Fluid fluid) { - return tankManager.canFill(from, fluid); - } - - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) { - return tankManager.canDrain(from, fluid); - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) { - return tankManager.getTankInfo(from); - } } diff --git a/src/main/java/forestry/farming/gadgets/TileGearbox.java b/src/main/java/forestry/farming/gadgets/TileGearbox.java index b7bd656ef..dd5d4ddef 100644 --- a/src/main/java/forestry/farming/gadgets/TileGearbox.java +++ b/src/main/java/forestry/farming/gadgets/TileGearbox.java @@ -12,7 +12,7 @@ package forestry.farming.gadgets; import forestry.api.core.ITileStructure; import forestry.api.farming.IFarmHousing; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.gadgets.TileForestry; import forestry.core.interfaces.IPowerHandler; import forestry.energy.EnergyManager; @@ -33,10 +33,6 @@ public class TileGearbox extends TileFarm implements IPowerHandler { fixedType = TYPE_GEARS; } - @Override - protected void createInventory() { - } - @Override public boolean hasFunction() { return true; diff --git a/src/main/java/forestry/farming/gadgets/TileHatch.java b/src/main/java/forestry/farming/gadgets/TileHatch.java index f80f814f0..96570fcff 100755 --- a/src/main/java/forestry/farming/gadgets/TileHatch.java +++ b/src/main/java/forestry/farming/gadgets/TileHatch.java @@ -10,29 +10,39 @@ ******************************************************************************/ package forestry.farming.gadgets; -import buildcraft.api.statements.ITriggerExternal; -import cpw.mods.fml.common.Optional; -import forestry.api.core.ITileStructure; -import forestry.core.utils.BlockUtil; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Utils; -import forestry.farming.triggers.FarmingTriggers; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidContainerRegistry; - -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.common.Optional; + +import forestry.api.core.ITileStructure; +import forestry.core.inventory.AdjacentInventoryCache; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.ITileFilter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.wrappers.InventoryMapper; +import forestry.farming.triggers.FarmingTriggers; + +import buildcraft.api.statements.ITriggerExternal; + public class TileHatch extends TileFarm implements ISidedInventory { + private static final ForgeDirection[] dumpDirections = new ForgeDirection[] { ForgeDirection.DOWN }; + + private final AdjacentInventoryCache inventoryCache = new AdjacentInventoryCache(this, getTileCache(), new ITileFilter() { + + @Override + public boolean matches(TileEntity tile) { + return !(tile instanceof TileFarm) && tile.yCoord < yCoord; + } + }, null); + public TileHatch() { fixedType = TYPE_HATCH; } @@ -42,10 +52,6 @@ public class TileHatch extends TileFarm implements ISidedInventory { return true; } - @Override - protected void createInventory() { - } - @Override protected void updateServerSide() { if (worldObj.getTotalWorldTime() % 40 == 0) @@ -53,276 +59,29 @@ public class TileHatch extends TileFarm implements ISidedInventory { } /* AUTO-EJECTING */ + private IInventory getProductInventory() { + IInventoryAdapter inventory = getStructureInventory(); + return new InventoryMapper(inventory, TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_PRODUCTION_COUNT); + } + protected void dumpStash() { - - if (!hasMaster()) + IInventory productInventory = getProductInventory(); + if (productInventory == null) return; - ArrayList pipes = new ArrayList(); - ForgeDirection[] tmp = BlockUtil.getPipeDirections(worldObj, Coords(), ForgeDirection.UP); - Collections.addAll(pipes, tmp); - - if (pipes.size() > 0) - dumpToPipe(pipes); - else { - IInventory[] inventories = BlockUtil.getAdjacentInventories(worldObj, Coords(), ForgeDirection.UP); - dumpToInventory(inventories); + if (!InvTools.moveOneItemToPipe(productInventory, tileCache, dumpDirections)) { + InvTools.moveItemStack(productInventory, inventoryCache.getAdjacentInventories()); } } - private void dumpToPipe(ArrayList pipes) { - - ItemStack[] products = extractItem(true, ForgeDirection.DOWN, 1); - for (ItemStack product : products) - while (product.stackSize > 0) - BlockUtil.putFromStackIntoPipe(this, pipes, product); - - } - - private void dumpToInventory(IInventory[] inventories) { - - ITileStructure central = getCentralTE(); - if (central == null) - return; - IInventory inv = central.getInventory(); - - for (int i = TileFarmPlain.SLOT_PRODUCTION_1; i < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION; i++) { - if (inv.getStackInSlot(i) == null) - continue; - - ItemStack stack = inv.getStackInSlot(i); - - if (stack.stackSize <= 0) - continue; - - for (IInventory inventory : inventories) { - - // Don't dump in arboretums! - if (inventory.getSizeInventory() < 4) - continue; - - // Get complete inventory (for double chests) - IInventory completeInventory = Utils.getChest(inventory); - if (completeInventory instanceof ISidedInventory) { - ISidedInventory sidedInventory = (ISidedInventory) completeInventory; - int[] slots = sidedInventory.getAccessibleSlotsFromSide(ForgeDirection.UP.ordinal()); - for (int sl = 0; sl < slots.length; ++sl) { - StackUtils.stowInInventory(stack, sidedInventory, true, sl, 1); - } - } else { - StackUtils.stowInInventory(stack, completeInventory, true); - if (stack.stackSize <= 0) { - inv.setInventorySlotContents(i, null); - break; - } - } - } - } - - } - /* IINVENTORY */ @Override - public InventoryAdapter getInternalInventory() { - return (InventoryAdapter)getStructureInventory(); - } + public IInventoryAdapter getInternalInventory() { + ITileStructure central = getCentralTE(); + if (central instanceof TileFarmPlain) + return ((TileFarmPlain) central).getInternalInventory(); - private IInventory getStructureInventory() { - - if (hasMaster()) { - ITileStructure central = getCentralTE(); - if (central != null) - return central.getInventory(); - } - - return null; - } - - @Override - public int getSizeInventory() { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getSizeInventory(); - else - return 0; - } - - @Override - public ItemStack getStackInSlot(int slotIndex) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlot(slotIndex); - else - return null; - } - - @Override - public ItemStack decrStackSize(int slotIndex, int amount) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.decrStackSize(slotIndex, amount); - else - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slotIndex) { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getStackInSlotOnClosing(slotIndex); - else - return null; - } - - @Override - public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { - IInventory inv = getStructureInventory(); - if (inv != null) - inv.setInventorySlotContents(slotIndex, itemstack); - } - - @Override - public int getInventoryStackLimit() { - IInventory inv = getStructureInventory(); - if (inv != null) - return inv.getInventoryStackLimit(); - else - return 0; - } - - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if(!super.canTakeStackFromSide(slotIndex, itemstack, side)) - return false; - - if(slotIndex >= TileFarmPlain.SLOT_PRODUCTION_1 && slotIndex < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION) - return true; - - return false; - } - - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - - if (!hasMaster()) - return false; - - ITileStructure struct = getCentralTE(); - if (!(struct instanceof TileFarmPlain)) - return false; - - if(!super.canPutStackFromSide(slotIndex, itemstack, side)) - return false; - - TileFarmPlain housing = (TileFarmPlain) struct; - if (slotIndex == TileFarmPlain.SLOT_FERTILIZER && housing.acceptsAsFertilizer(itemstack)) - return true; - if (slotIndex >= TileFarmPlain.SLOT_RESOURCES_1 && slotIndex < TileFarmPlain.SLOT_RESOURCES_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS - && housing.acceptsAsResource(itemstack)) - return true; - if (slotIndex >= TileFarmPlain.SLOT_GERMLINGS_1 && slotIndex < TileFarmPlain.SLOT_GERMLINGS_1 + TileFarmPlain.SLOT_COUNT_RESERVOIRS - && housing.acceptsAsGermling(itemstack)) - return true; - if(slotIndex == TileFarmPlain.SLOT_CAN) - return FluidContainerRegistry.isFilledContainer(itemstack); - - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - - IInventory inv; - if (hasMaster()) { - ITileStructure central = getCentralTE(); - if (central == null) - return new ItemStack[0]; - inv = getCentralTE().getInventory(); - } else - return StackUtils.EMPTY_STACK_ARRAY; - - ItemStack product = null; - - for (int i = TileFarmPlain.SLOT_PRODUCTION_1; i < TileFarmPlain.SLOT_PRODUCTION_1 + TileFarmPlain.SLOT_COUNT_PRODUCTION; i++) { - if (inv.getStackInSlot(i) == null) - continue; - - ItemStack stack = inv.getStackInSlot(i); - - if (doRemove) - product = inv.decrStackSize(i, 1); - else { - product = stack.copy(); - product.stackSize = 1; - } - break; - } - - if (product != null) - return new ItemStack[] { product }; - else - return StackUtils.EMPTY_STACK_ARRAY; + return super.getInternalInventory(); } /* ITRIGGERPROVIDER */ diff --git a/src/main/java/forestry/farming/gadgets/TileValve.java b/src/main/java/forestry/farming/gadgets/TileValve.java index d39fb84b1..318a5e92d 100755 --- a/src/main/java/forestry/farming/gadgets/TileValve.java +++ b/src/main/java/forestry/farming/gadgets/TileValve.java @@ -10,15 +10,14 @@ ******************************************************************************/ package forestry.farming.gadgets; +import forestry.core.fluids.TankManager; +import forestry.core.fluids.tanks.FakeTank; +import forestry.core.interfaces.ILiquidTankContainer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; - -import forestry.core.interfaces.ILiquidTankContainer; -import forestry.core.fluids.TankManager; -import forestry.core.fluids.tanks.FakeTank; import net.minecraftforge.fluids.FluidTankInfo; public class TileValve extends TileFarm implements ILiquidTankContainer { @@ -33,10 +32,6 @@ public class TileValve extends TileFarm implements ILiquidTankContainer { return true; } - @Override - protected void createInventory() { - } - /* ILIQUIDTANKCONTAINER */ @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { diff --git a/src/main/java/forestry/farming/gui/ContainerFarm.java b/src/main/java/forestry/farming/gui/ContainerFarm.java index b2e55fa4d..88ae85103 100755 --- a/src/main/java/forestry/farming/gui/ContainerFarm.java +++ b/src/main/java/forestry/farming/gui/ContainerFarm.java @@ -12,78 +12,66 @@ package forestry.farming.gui; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import forestry.api.farming.IFarmLogic; import forestry.core.fluids.TankManager; import forestry.core.fluids.tanks.StandardTank; import forestry.core.gui.ContainerSocketed; -import forestry.core.gui.slots.SlotCustom; -import forestry.core.gui.slots.SlotForestry; -import forestry.core.gui.slots.SlotLiquidContainer; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; -import forestry.core.utils.TileInventoryAdapter; import forestry.farming.gadgets.TileFarmPlain; -import forestry.plugins.PluginFarming; public class ContainerFarm extends ContainerSocketed { private final TileFarmPlain tile; public ContainerFarm(InventoryPlayer playerinventory, TileFarmPlain tile) { - super(playerinventory, tile); + super(tile, tile); this.tile = tile; - IInventory inventory = tile.getInventory(); - // Tile will not have an inventory client side. - if (inventory == null) - inventory = new TileInventoryAdapter(tile, TileFarmPlain.SLOT_COUNT, "Items"); - // Resources for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlot(new SlotResources(inventory, tile.getFarmLogics(), TileFarmPlain.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18)); + addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18)); } } // Germlings for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - addSlot(new SlotGermlings(inventory, tile.getFarmLogics(), TileFarmPlain.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18)); + addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18)); } } // Production 1 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - addSlot(new SlotOutput(inventory, TileFarmPlain.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18)); + addSlotToContainer(new SlotOutput(tile, TileFarmPlain.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18)); } } // Production 2 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - addSlot(new SlotOutput(inventory, TileFarmPlain.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18)); + addSlotToContainer(new SlotOutput(tile, TileFarmPlain.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18)); } } // Fertilizer - addSlot(new SlotCustom(inventory, TileFarmPlain.SLOT_FERTILIZER, 63, 95, PluginFarming.farmFertilizer)); + addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_FERTILIZER, 63, 95)); // Can Slot - addSlot(new SlotLiquidContainer(inventory, TileFarmPlain.SLOT_CAN, 15, 95)); + addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_CAN, 15, 95)); // Player inventory for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { - addSlot(new Slot(playerinventory, j + i * 9 + 9, 28 + j * 18, 138 + i * 18)); + addSlotToContainer(new Slot(playerinventory, j + i * 9 + 9, 28 + j * 18, 138 + i * 18)); } } // Player hotbar for (int i = 0; i < 9; i++) { - addSlot(new Slot(playerinventory, i, 28 + i * 18, 196)); + addSlotToContainer(new Slot(playerinventory, i, 28 + i * 18, 196)); } } @@ -120,41 +108,4 @@ public class ContainerFarm extends ContainerSocketed { return tile.getTankManager().get(slot); } - private class SlotResources extends SlotForestry { - - private final IFarmLogic[] logics; - - public SlotResources(IInventory inventory, IFarmLogic[] logics, int slotIndex, int xPos, int yPos) { - super(inventory, slotIndex, xPos, yPos); - this.logics = logics; - } - - @Override - public boolean isItemValid(ItemStack stack) { - for (IFarmLogic logic : logics) { - if (logic != null && logic.isAcceptedResource(stack)) - return true; - } - return false; - } - } - - private class SlotGermlings extends SlotForestry { - - private final IFarmLogic[] logics; - - public SlotGermlings(IInventory inventory, IFarmLogic[] logics, int slotIndex, int xPos, int yPos) { - super(inventory, slotIndex, xPos, yPos); - this.logics = logics; - } - - @Override - public boolean isItemValid(ItemStack stack) { - for (IFarmLogic logic : logics) { - if (logic != null && logic.isAcceptedGermling(stack)) - return true; - } - return false; - } - } } diff --git a/src/main/java/forestry/farming/gui/GuiFarm.java b/src/main/java/forestry/farming/gui/GuiFarm.java index 6220f0cdc..652c5709b 100755 --- a/src/main/java/forestry/farming/gui/GuiFarm.java +++ b/src/main/java/forestry/farming/gui/GuiFarm.java @@ -10,12 +10,6 @@ ******************************************************************************/ package forestry.farming.gui; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.util.IIcon; - -import org.lwjgl.opengl.GL11; - import forestry.api.farming.IFarmLogic; import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; @@ -28,6 +22,10 @@ import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; import forestry.farming.gadgets.TileFarmPlain; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.util.IIcon; +import org.lwjgl.opengl.GL11; public class GuiFarm extends GuiForestry { diff --git a/src/main/java/forestry/farming/items/ItemFarmBlock.java b/src/main/java/forestry/farming/items/ItemFarmBlock.java index 875840447..c3919e267 100755 --- a/src/main/java/forestry/farming/items/ItemFarmBlock.java +++ b/src/main/java/forestry/farming/items/ItemFarmBlock.java @@ -18,7 +18,7 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import forestry.core.gadgets.IStructureBlockItem; -import forestry.farming.gadgets.TileFarm.EnumFarmBlock; +import forestry.farming.gadgets.EnumFarmBlock; public class ItemFarmBlock extends ItemBlock implements IStructureBlockItem { diff --git a/src/main/java/forestry/farming/logic/Crop.java b/src/main/java/forestry/farming/logic/Crop.java index 06985d5d6..26fc1f203 100755 --- a/src/main/java/forestry/farming/logic/Crop.java +++ b/src/main/java/forestry/farming/logic/Crop.java @@ -18,12 +18,12 @@ import net.minecraft.world.World; import forestry.api.farming.ICrop; import forestry.core.config.Defaults; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; public abstract class Crop implements ICrop { - protected World world; - protected Vect position; + protected final World world; + protected final Vect position; public Crop(World world, Vect position) { this.world = world; diff --git a/src/main/java/forestry/farming/logic/CropBlock.java b/src/main/java/forestry/farming/logic/CropBlock.java index b7990157f..3ba012417 100755 --- a/src/main/java/forestry/farming/logic/CropBlock.java +++ b/src/main/java/forestry/farming/logic/CropBlock.java @@ -10,19 +10,17 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.core.proxy.Proxies; +import forestry.core.vect.Vect; import java.util.Collection; - import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; - public class CropBlock extends Crop { - Block block; - int meta; + protected final Block block; + protected final int meta; public CropBlock(World world, Block block, int meta, Vect position) { super(world, position); diff --git a/src/main/java/forestry/farming/logic/CropFruit.java b/src/main/java/forestry/farming/logic/CropFruit.java index 82538f73d..a65c0c4f6 100755 --- a/src/main/java/forestry/farming/logic/CropFruit.java +++ b/src/main/java/forestry/farming/logic/CropFruit.java @@ -10,22 +10,20 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.ArrayList; -import java.util.Collection; - -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - import forestry.api.genetics.IFruitBearer; import forestry.api.genetics.IFruitFamily; import forestry.core.network.PacketFXSignal; import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; public class CropFruit extends Crop { - IFruitFamily family; + private final IFruitFamily family; public CropFruit(World world, Vect position, IFruitFamily family) { super(world, position); diff --git a/src/main/java/forestry/farming/logic/CropPeat.java b/src/main/java/forestry/farming/logic/CropPeat.java index 9c180b115..af55bd49a 100755 --- a/src/main/java/forestry/farming/logic/CropPeat.java +++ b/src/main/java/forestry/farming/logic/CropPeat.java @@ -13,15 +13,14 @@ package forestry.farming.logic; import forestry.core.gadgets.BlockSoil; import forestry.core.proxy.Proxies; import forestry.core.utils.BlockUtil; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.Collection; - public class CropPeat extends Crop { public CropPeat(World world, Vect position) { diff --git a/src/main/java/forestry/farming/logic/CropRubber.java b/src/main/java/forestry/farming/logic/CropRubber.java index 21906120e..4d7349485 100755 --- a/src/main/java/forestry/farming/logic/CropRubber.java +++ b/src/main/java/forestry/farming/logic/CropRubber.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.core.config.Defaults; +import forestry.core.proxy.Proxies; +import forestry.core.vect.Vect; +import forestry.plugins.PluginIC2; import java.util.ArrayList; import java.util.Collection; - import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.core.config.Defaults; -import forestry.core.proxy.Proxies; -import forestry.core.utils.Vect; -import forestry.plugins.PluginIC2; - public class CropRubber extends CropBlock { public CropRubber(World world, Block block, int meta, Vect position) { diff --git a/src/main/java/forestry/farming/logic/FarmLogic.java b/src/main/java/forestry/farming/logic/FarmLogic.java index e054c7389..7ad6160a7 100755 --- a/src/main/java/forestry/farming/logic/FarmLogic.java +++ b/src/main/java/forestry/farming/logic/FarmLogic.java @@ -10,29 +10,32 @@ ******************************************************************************/ package forestry.farming.logic; -import forestry.api.farming.IFarmHousing; -import forestry.api.farming.IFarmLogic; -import forestry.core.config.Defaults; -import forestry.core.config.ForestryBlock; -import forestry.core.render.SpriteSheet; -import forestry.core.utils.Vect; +import java.util.HashSet; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; -import java.util.HashSet; +import forestry.api.farming.IFarmHousing; +import forestry.api.farming.IFarmLogic; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryBlock; +import forestry.core.render.SpriteSheet; +import forestry.core.vect.IVect; +import forestry.core.vect.Vect; public abstract class FarmLogic implements IFarmLogic { - IFarmHousing housing; + protected final IFarmHousing housing; - boolean isManual; + protected boolean isManual; - static HashSet breakable = new HashSet(); + private static final HashSet breakable = new HashSet(); public FarmLogic(IFarmHousing housing) { this.housing = housing; @@ -68,8 +71,8 @@ public abstract class FarmLogic implements IFarmLogic { return SpriteSheet.ITEMS.getLocation(); } - protected final boolean isAirBlock(Vect position) { - return getWorld().isAirBlock(position.x, position.y, position.z); + protected final boolean isAirBlock(IVect position) { + return getWorld().isAirBlock(position.getX(), position.getY(), position.getZ()); } protected final boolean isAirBlock(Block block) { @@ -81,20 +84,20 @@ public abstract class FarmLogic implements IFarmLogic { world.getBlockMetadata(position.x, position.y, position.z) == 0; } - protected final boolean isWoodBlock(Vect position) { + protected final boolean isWoodBlock(IVect position) { Block block = getBlock(position); - return block.isWood(getWorld(), position.x, position.y, position.z); + return block.isWood(getWorld(), position.getX(), position.getY(), position.getZ()); } - protected final Block getBlock(Vect position) { - return getWorld().getBlock(position.x, position.y, position.z); + protected final Block getBlock(IVect position) { + return getWorld().getBlock(position.getX(), position.getY(), position.getZ()); } - protected final int getBlockMeta(Vect position) { - return getWorld().getBlockMetadata(position.x, position.y, position.z); + protected final int getBlockMeta(IVect position) { + return getWorld().getBlockMetadata(position.getX(), position.getY(), position.getZ()); } - protected final ItemStack getAsItemStack(Vect position) { + protected final ItemStack getAsItemStack(IVect position) { return new ItemStack(getBlock(position), 1, getBlockMeta(position)); } diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index f7f623ed8..b4df54aa0 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -19,7 +19,14 @@ import forestry.api.farming.IFarmable; import forestry.core.config.ForestryBlock; import forestry.core.gadgets.BlockSoil; import forestry.core.render.SpriteSheet; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.Stack; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; @@ -31,14 +38,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.Stack; - public class FarmLogicArboreal extends FarmLogicHomogeneous { public FarmLogicArboreal(IFarmHousing housing, ItemStack[] resource, ItemStack ground, IFarmable[] germlings) { @@ -102,7 +101,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { Vect offset = new Vect(housing.getOffset()); Vect min = coords.add(offset); - Vect max = coords.add(offset).add(area); + Vect max = min.add(area); AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, getWorld().getHeight(), max.z); List list = getWorld().getEntitiesWithinAABB(Entity.class, harvestBox); @@ -128,8 +127,6 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { @Override public Collection harvest(int x, int y, int z, ForgeDirection direction, int extent) { - Collection crops = null; - Vect start = new Vect(x, y, z); if (!lastExtentsHarvest.containsKey(start)) lastExtentsHarvest.put(start, 0); @@ -139,7 +136,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { lastExtent = 0; Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent); - crops = getHarvestBlocks(position); + Collection crops = getHarvestBlocks(position); lastExtent++; lastExtentsHarvest.put(start, lastExtent); diff --git a/src/main/java/forestry/farming/logic/FarmLogicCereal.java b/src/main/java/forestry/farming/logic/FarmLogicCereal.java index 1d06d7f02..2880c647c 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCereal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCereal.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.farming.logic; -import net.minecraft.init.Items; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.farming.Farmables; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; +import net.minecraft.init.Items; +import net.minecraft.util.IIcon; public class FarmLogicCereal extends FarmLogicCrops { diff --git a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java index 8cfec943f..59cf78c51 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCocoa.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCocoa.java @@ -10,30 +10,27 @@ ******************************************************************************/ package forestry.farming.logic; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmHousing; +import forestry.api.farming.IFarmable; +import forestry.core.vect.MutableVect; +import forestry.core.vect.Vect; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; import java.util.Stack; - import net.minecraft.block.Block; import net.minecraft.block.BlockLog; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmHousing; -import forestry.api.farming.IFarmable; -import forestry.core.utils.Vect; -import java.util.HashSet; -import java.util.Set; - public class FarmLogicCocoa extends FarmLogic { private final IFarmable cocoa = new FarmableCocoa(); @@ -105,8 +102,6 @@ public class FarmLogicCocoa extends FarmLogic { @Override public Collection harvest(int x, int y, int z, ForgeDirection direction, int extent) { - Collection crops = null; - Vect start = new Vect(x, y, z); if (!lastExtentsHarvest.containsKey(start)) lastExtentsHarvest.put(start, 0); @@ -116,7 +111,7 @@ public class FarmLogicCocoa extends FarmLogic { lastExtent = 0; Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent); - crops = getHarvestBlocks(position); + Collection crops = getHarvestBlocks(position); lastExtent++; lastExtentsHarvest.put(start, lastExtent); @@ -127,7 +122,7 @@ public class FarmLogicCocoa extends FarmLogic { World world = getWorld(); - Vect current = position; + MutableVect current = new MutableVect(position); while (isWoodBlock(current) && BlockLog.func_150165_c(getBlockMeta(current)) == 3) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { @@ -139,7 +134,7 @@ public class FarmLogicCocoa extends FarmLogic { return housing.plantGermling(cocoa, world, candidate.x, candidate.y, candidate.z); } - current = current.add(new Vect(0, 1, 0)); + current.y++; if (current.y - position.y > 1) break; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicCrops.java b/src/main/java/forestry/farming/logic/FarmLogicCrops.java index 9baa9f173..c80ed7bb4 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicCrops.java +++ b/src/main/java/forestry/farming/logic/FarmLogicCrops.java @@ -16,7 +16,12 @@ import forestry.api.farming.IFarmable; import forestry.core.config.Defaults; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.IVect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Stack; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; @@ -25,15 +30,10 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Stack; - public abstract class FarmLogicCrops extends FarmLogicWatered { private final IFarmable[] seeds; - private static ItemStack farmland = new ItemStack(Blocks.farmland, 1, Defaults.WILDCARD); + private static final ItemStack farmland = new ItemStack(Blocks.farmland, 1, Defaults.WILDCARD); public FarmLogicCrops(IFarmHousing housing, IFarmable[] seeds) { super(housing, @@ -75,7 +75,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered { Vect offset = new Vect(housing.getOffset()); Vect min = coords.add(offset); - Vect max = coords.add(offset).add(area); + Vect max = min.add(area); AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z); List list = housing.getWorld().getEntitiesWithinAABB(Entity.class, harvestBox); @@ -107,7 +107,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered { if (!isAirBlock(position) && !Utils.isReplaceableBlock(getWorld(), position.x, position.y, position.z)) continue; - ItemStack below = getAsItemStack(position.add(new Vect(0, -1, 0))); + ItemStack below = getAsItemStack(position.add(0, -1, 0)); if (ground.getItem() != below.getItem()) continue; if (below.getItemDamage() <= 0) @@ -119,11 +119,11 @@ public abstract class FarmLogicCrops extends FarmLogicWatered { return false; } - private boolean trySetCrop(Vect position) { + private boolean trySetCrop(IVect position) { World world = getWorld(); for (IFarmable candidate : seeds) - if (housing.plantGermling(candidate, world, position.x, position.y, position.z)) + if (housing.plantGermling(candidate, world, position.getX(), position.getY(), position.getZ())) return true; return false; diff --git a/src/main/java/forestry/farming/logic/FarmLogicGourd.java b/src/main/java/forestry/farming/logic/FarmLogicGourd.java index 8fcb2d31a..39a425f83 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicGourd.java +++ b/src/main/java/forestry/farming/logic/FarmLogicGourd.java @@ -10,24 +10,20 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.Collection; -import java.util.Stack; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.Farmables; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import java.util.Stack; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicGourd extends FarmLogic { diff --git a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java index b832d8970..cf31c5407 100644 --- a/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java +++ b/src/main/java/forestry/farming/logic/FarmLogicHomogeneous.java @@ -14,12 +14,11 @@ import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.utils.BlockUtil; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; -import java.util.ArrayList; - public abstract class FarmLogicHomogeneous extends FarmLogic { protected final ItemStack[] resource; diff --git a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java index 218e2fc25..2a4e36a80 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicInfernal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicInfernal.java @@ -10,26 +10,22 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.Collection; -import java.util.Stack; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.Farmables; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import java.util.Stack; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicInfernal extends FarmLogicHomogeneous { @@ -93,7 +89,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous { if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) continue; - ItemStack below = getAsItemStack(position.add(new Vect(0, -1, 0))); + ItemStack below = getAsItemStack(position.add(0, -1, 0)); if (!isAcceptedGround(below)) continue; diff --git a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java index 3aa2f21bc..462a7e3bd 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicOrchard.java +++ b/src/main/java/forestry/farming/logic/FarmLogicOrchard.java @@ -10,29 +10,25 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Stack; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.genetics.IFruitBearer; import forestry.core.config.ForestryItem; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.Stack; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicOrchard extends FarmLogic { @@ -86,8 +82,6 @@ public class FarmLogicOrchard extends FarmLogic { @Override public Collection harvest(int x, int y, int z, ForgeDirection direction, int extent) { - Collection crops = null; - Vect start = new Vect(x, y, z); if (!lastExtents.containsKey(start)) lastExtents.put(start, 0); @@ -99,7 +93,7 @@ public class FarmLogicOrchard extends FarmLogic { // Proxies.log.finest("Logic %s is searching in direction %s at %s/%s/%s with extension %s.", getClass(), direction, x, y, z, lastExtent); Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent); - crops = getHarvestBlocks(position); + Collection crops = getHarvestBlocks(position); lastExtent++; lastExtents.put(start, lastExtent); diff --git a/src/main/java/forestry/farming/logic/FarmLogicPeat.java b/src/main/java/forestry/farming/logic/FarmLogicPeat.java index 7b9eb0326..71f29440a 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicPeat.java +++ b/src/main/java/forestry/farming/logic/FarmLogicPeat.java @@ -14,22 +14,18 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; -import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.gadgets.BlockSoil; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import java.util.Stack; import net.minecraft.block.Block; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import java.util.Collection; -import java.util.Stack; - public class FarmLogicPeat extends FarmLogicWatered { public FarmLogicPeat(IFarmHousing housing) { @@ -77,7 +73,7 @@ public class FarmLogicPeat extends FarmLogicWatered { Vect position = translateWithOffset(x, y, z, direction, i); ItemStack occupant = getAsItemStack(position); - if (occupant == null) + if (occupant.getItem() == null) continue; Block block = BlockSoil.getBlockFromItem(occupant.getItem()); diff --git a/src/main/java/forestry/farming/logic/FarmLogicPoale.java b/src/main/java/forestry/farming/logic/FarmLogicPoale.java index c4546de0f..be2972b46 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicPoale.java +++ b/src/main/java/forestry/farming/logic/FarmLogicPoale.java @@ -10,30 +10,26 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.Collection; -import java.util.Stack; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.Farmables; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import java.util.Stack; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicPoale extends FarmLogic { - IFarmable[] germlings; + private final IFarmable[] germlings; public FarmLogicPoale(IFarmHousing housing) { super(housing); diff --git a/src/main/java/forestry/farming/logic/FarmLogicRubber.java b/src/main/java/forestry/farming/logic/FarmLogicRubber.java index 7dcc81f01..deda9bb20 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicRubber.java +++ b/src/main/java/forestry/farming/logic/FarmLogicRubber.java @@ -10,30 +10,26 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Stack; - -import net.minecraft.block.Block; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import forestry.plugins.PluginIC2; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.Stack; +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicRubber extends FarmLogic { @@ -98,7 +94,6 @@ public class FarmLogicRubber extends FarmLogic { if (inActive) return null; - Collection crops = null; Vect start = new Vect(x, y, z); if (!lastExtents.containsKey(start)) lastExtents.put(start, 0); @@ -108,7 +103,7 @@ public class FarmLogicRubber extends FarmLogic { lastExtent = 0; Vect position = translateWithOffset(x, y + 1, z, direction, lastExtent); - crops = getHarvestBlocks(position); + Collection crops = getHarvestBlocks(position); lastExtent++; lastExtents.put(start, lastExtent); diff --git a/src/main/java/forestry/farming/logic/FarmLogicShroom.java b/src/main/java/forestry/farming/logic/FarmLogicShroom.java index 9126b4df5..0fae43117 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicShroom.java +++ b/src/main/java/forestry/farming/logic/FarmLogicShroom.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.ArrayList; -import java.util.Collection; - -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.farming.Farmables; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; +import java.util.ArrayList; +import java.util.Collection; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; public class FarmLogicShroom extends FarmLogicArboreal { diff --git a/src/main/java/forestry/farming/logic/FarmLogicSucculent.java b/src/main/java/forestry/farming/logic/FarmLogicSucculent.java index e87c7da8b..5a58bd316 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicSucculent.java +++ b/src/main/java/forestry/farming/logic/FarmLogicSucculent.java @@ -10,30 +10,26 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.Collection; -import java.util.Stack; - -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; - import forestry.api.farming.Farmables; import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.Collection; +import java.util.Stack; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; public class FarmLogicSucculent extends FarmLogic { - IFarmable[] germlings; + private final IFarmable[] germlings; public FarmLogicSucculent(IFarmHousing housing) { super(housing); diff --git a/src/main/java/forestry/farming/logic/FarmLogicVegetable.java b/src/main/java/forestry/farming/logic/FarmLogicVegetable.java index 1116fadac..73d12aeca 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicVegetable.java +++ b/src/main/java/forestry/farming/logic/FarmLogicVegetable.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.farming.logic; -import net.minecraft.init.Items; -import net.minecraft.util.IIcon; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.farming.Farmables; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; +import net.minecraft.init.Items; +import net.minecraft.util.IIcon; public class FarmLogicVegetable extends FarmLogicCrops { diff --git a/src/main/java/forestry/farming/logic/FarmLogicWatered.java b/src/main/java/forestry/farming/logic/FarmLogicWatered.java index 5a0281b50..176d3133d 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicWatered.java +++ b/src/main/java/forestry/farming/logic/FarmLogicWatered.java @@ -11,13 +11,13 @@ package forestry.farming.logic; import forestry.api.farming.IFarmHousing; -import forestry.core.config.Defaults; -import forestry.core.proxy.Proxies; +import forestry.core.fluids.Fluids; import forestry.core.utils.BlockUtil; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.StackUtils; import forestry.core.utils.Utils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import java.util.ArrayList; +import java.util.Collection; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -25,15 +25,12 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import java.util.ArrayList; -import java.util.Collection; - public abstract class FarmLogicWatered extends FarmLogic { - protected ItemStack ground; + protected final ItemStack ground; private final ItemStack[] resource; - private static final FluidStack STACK_WATER = new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_WATER), 1000); + private static final FluidStack STACK_WATER = Fluids.WATER.getFluid(1000); ArrayList produce = new ArrayList(); @@ -157,7 +154,7 @@ public abstract class FarmLogicWatered extends FarmLogic { // don't place water close to other water for (int x = -2; x <= 2; x++) { for (int z = -2; z <= 2; z++) { - Vect offsetPosition = position.add(new Vect(x, 0, z)); + Vect offsetPosition = position.add(x, 0, z); if (isWaterSourceBlock(world, offsetPosition)) return false; } @@ -165,12 +162,12 @@ public abstract class FarmLogicWatered extends FarmLogic { // don't place water if it can flow into blocks next to it for (int x = -1; x <= 1; x++) { - Vect offsetPosition = position.add(new Vect(x, 0, 0)); + Vect offsetPosition = position.add(x, 0, 0); if (isAirBlock(offsetPosition)) return false; } for (int z = -1; z <= 1; z++) { - Vect offsetPosition = position.add(new Vect(0, 0, z)); + Vect offsetPosition = position.add(0, 0, z); if (isAirBlock(offsetPosition)) return false; } diff --git a/src/main/java/forestry/farming/logic/FarmableCocoa.java b/src/main/java/forestry/farming/logic/FarmableCocoa.java index 47d0a380b..d4d410279 100755 --- a/src/main/java/forestry/farming/logic/FarmableCocoa.java +++ b/src/main/java/forestry/farming/logic/FarmableCocoa.java @@ -10,6 +10,10 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.utils.BlockUtil; +import forestry.core.vect.Vect; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -18,11 +22,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; -import forestry.core.utils.BlockUtil; -import forestry.core.utils.Vect; - public class FarmableCocoa implements IFarmable { public static final Block COCOA_PLANT = Blocks.cocoa; diff --git a/src/main/java/forestry/farming/logic/FarmableFarmCraftory.java b/src/main/java/forestry/farming/logic/FarmableFarmCraftory.java index bf8fa7cf2..77df32c42 100755 --- a/src/main/java/forestry/farming/logic/FarmableFarmCraftory.java +++ b/src/main/java/forestry/farming/logic/FarmableFarmCraftory.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.utils.StackUtils; +import forestry.core.vect.Vect; +import forestry.plugins.PluginFarmCraftory; import java.util.Collection; - import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; -import forestry.plugins.PluginFarmCraftory; - public class FarmableFarmCraftory implements IFarmable { Collection germlings; @@ -41,10 +39,7 @@ public class FarmableFarmCraftory implements IFarmable { return false; Block block = world.getBlock(x, y, z); - if (block != PluginFarmCraftory.blockSingle && block != PluginFarmCraftory.blockMulti) - return false; - else - return true; + return block == PluginFarmCraftory.blockSingle || block == PluginFarmCraftory.blockMulti; } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableGE.java b/src/main/java/forestry/farming/logic/FarmableGE.java index 556c6cb4b..b3be02ec4 100755 --- a/src/main/java/forestry/farming/logic/FarmableGE.java +++ b/src/main/java/forestry/farming/logic/FarmableGE.java @@ -15,7 +15,7 @@ import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; import forestry.arboriculture.genetics.TreeGenome; import forestry.core.config.ForestryBlock; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -36,7 +36,7 @@ public class FarmableGE implements IFarmable { public ICrop getCropAt(World world, int x, int y, int z) { Block block = world.getBlock(x, y, z); - if (block.isAir(world, x, y, z) || !block.isWood(world, x, y, z)) + if (!block.isWood(world, x, y, z)) return null; return new CropBlock(world, block, world.getBlockMetadata(x, y, z), new Vect(x, y, z)); diff --git a/src/main/java/forestry/farming/logic/FarmableGenericCrop.java b/src/main/java/forestry/farming/logic/FarmableGenericCrop.java index 60c7c7d55..db5c8f8ae 100755 --- a/src/main/java/forestry/farming/logic/FarmableGenericCrop.java +++ b/src/main/java/forestry/farming/logic/FarmableGenericCrop.java @@ -10,15 +10,14 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.vect.Vect; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; -import forestry.core.utils.Vect; - public class FarmableGenericCrop implements IFarmable { private final ItemStack seed; @@ -33,14 +32,7 @@ public class FarmableGenericCrop implements IFarmable { @Override public boolean isSaplingAt(World world, int x, int y, int z) { - - if (world.isAirBlock(x, y, z)) - return false; - - if (world.getBlock(x, y, z) != block) - return false; - else - return true; + return world.getBlock(x, y, z) == block; } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableGenericSapling.java b/src/main/java/forestry/farming/logic/FarmableGenericSapling.java index d75de37c5..0be2d42b2 100755 --- a/src/main/java/forestry/farming/logic/FarmableGenericSapling.java +++ b/src/main/java/forestry/farming/logic/FarmableGenericSapling.java @@ -10,22 +10,20 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.utils.StackUtils; +import forestry.core.vect.Vect; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; - public class FarmableGenericSapling implements IFarmable { - final Block sapling; - final int saplingMeta; - - ItemStack[] windfall; + private final Block sapling; + private final int saplingMeta; + private final ItemStack[] windfall; public FarmableGenericSapling(Block sapling, int saplingMeta, ItemStack... windfall) { this.sapling = sapling; diff --git a/src/main/java/forestry/farming/logic/FarmableGourd.java b/src/main/java/forestry/farming/logic/FarmableGourd.java index 989fedc80..9841a90ab 100755 --- a/src/main/java/forestry/farming/logic/FarmableGourd.java +++ b/src/main/java/forestry/farming/logic/FarmableGourd.java @@ -18,13 +18,13 @@ import forestry.api.farming.ICrop; import forestry.api.farming.IFarmable; import forestry.core.config.Defaults; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; public class FarmableGourd implements IFarmable { - public ItemStack seed; - public ItemStack stem; - public ItemStack fruit; + private final ItemStack seed; + private final ItemStack stem; + private final ItemStack fruit; public FarmableGourd(ItemStack seed, ItemStack stem, ItemStack fruit) { this.seed = seed; @@ -37,10 +37,7 @@ public class FarmableGourd implements IFarmable { if (world.isAirBlock(x, y, z)) return false; - if (!StackUtils.equals(world.getBlock(x, y, z), stem)) - return false; - - return true; + return StackUtils.equals(world.getBlock(x, y, z), stem); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmableStacked.java b/src/main/java/forestry/farming/logic/FarmableStacked.java index 6b22e542f..626cd0776 100755 --- a/src/main/java/forestry/farming/logic/FarmableStacked.java +++ b/src/main/java/forestry/farming/logic/FarmableStacked.java @@ -10,21 +10,20 @@ ******************************************************************************/ package forestry.farming.logic; +import forestry.api.farming.ICrop; +import forestry.api.farming.IFarmable; +import forestry.core.config.Defaults; +import forestry.core.utils.StackUtils; +import forestry.core.vect.Vect; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import forestry.api.farming.ICrop; -import forestry.api.farming.IFarmable; -import forestry.core.config.Defaults; -import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; - public class FarmableStacked implements IFarmable { - Block block; - int matureHeight; + private final Block block; + private final int matureHeight; public FarmableStacked(Block block, int matureHeight) { this.block = block; diff --git a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java index 83b810b17..843d44b95 100755 --- a/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java +++ b/src/main/java/forestry/farming/logic/FarmableVanillaSapling.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.farming.logic; -import java.util.Map; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -19,8 +17,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.api.arboriculture.ITree; -import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IIndividual; +import forestry.core.utils.GeneticsUtil; import forestry.plugins.PluginArboriculture; public class FarmableVanillaSapling extends FarmableGenericSapling { @@ -31,17 +29,11 @@ public class FarmableVanillaSapling extends FarmableGenericSapling { @Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, int x, int y, int z) { - ITree tree = null; - for (Map.Entry entry : AlleleManager.ersatzSaplings.entrySet()) - if (entry.getKey().isItemEqual(germling) && entry.getValue() instanceof ITree) { - tree = (ITree) entry.getValue(); - break; - } - - if (tree == null) + IIndividual tree = GeneticsUtil.getGeneticEquivalent(germling); + if (!(tree instanceof ITree)) return false; - return PluginArboriculture.treeInterface.plantSapling(world, tree, player.getGameProfile(), x, y, z); + return PluginArboriculture.treeInterface.plantSapling(world, (ITree)tree, player.getGameProfile(), x, y, z); } } diff --git a/src/main/java/forestry/farming/logic/FarmableVanillaShroom.java b/src/main/java/forestry/farming/logic/FarmableVanillaShroom.java index 4754ebf3a..d6c068b42 100755 --- a/src/main/java/forestry/farming/logic/FarmableVanillaShroom.java +++ b/src/main/java/forestry/farming/logic/FarmableVanillaShroom.java @@ -10,18 +10,17 @@ ******************************************************************************/ package forestry.farming.logic; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import forestry.api.farming.ICrop; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.proxy.Proxies; import forestry.core.utils.StackUtils; -import forestry.core.utils.Vect; +import forestry.core.vect.Vect; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class FarmableVanillaShroom extends FarmableGenericSapling { diff --git a/src/main/java/forestry/farming/proxy/ClientProxyFarming.java b/src/main/java/forestry/farming/proxy/ClientProxyFarming.java index a7da85f32..db427229a 100755 --- a/src/main/java/forestry/farming/proxy/ClientProxyFarming.java +++ b/src/main/java/forestry/farming/proxy/ClientProxyFarming.java @@ -12,13 +12,11 @@ package forestry.farming.proxy; import cpw.mods.fml.client.registry.RenderingRegistry; - -import net.minecraftforge.client.MinecraftForgeClient; - import forestry.core.config.ForestryBlock; import forestry.farming.render.FarmItemRenderer; import forestry.farming.render.FarmRenderingHandler; import forestry.plugins.PluginFarming; +import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxyFarming extends ProxyFarming { diff --git a/src/main/java/forestry/farming/render/FarmItemRenderer.java b/src/main/java/forestry/farming/render/FarmItemRenderer.java index 21b94dbe2..1f65bf0c5 100755 --- a/src/main/java/forestry/farming/render/FarmItemRenderer.java +++ b/src/main/java/forestry/farming/render/FarmItemRenderer.java @@ -20,11 +20,15 @@ import org.lwjgl.opengl.GL11; import forestry.core.utils.StackUtils; import forestry.farming.gadgets.BlockFarm; -import forestry.farming.gadgets.TileFarm.EnumFarmBlock; +import forestry.farming.gadgets.EnumFarmBlock; public class FarmItemRenderer implements IItemRenderer { private void renderFarmBlock(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) { + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); Tessellator tessellator = Tessellator.instance; BlockFarm block = (BlockFarm) StackUtils.getBlock(item); @@ -76,6 +80,7 @@ public class FarmItemRenderer implements IItemRenderer { block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopAttrib(); } @Override diff --git a/src/main/java/forestry/farming/render/FarmRenderingHandler.java b/src/main/java/forestry/farming/render/FarmRenderingHandler.java index 4d703ae35..46487c7d9 100755 --- a/src/main/java/forestry/farming/render/FarmRenderingHandler.java +++ b/src/main/java/forestry/farming/render/FarmRenderingHandler.java @@ -10,15 +10,14 @@ ******************************************************************************/ package forestry.farming.render; -import net.minecraft.block.Block; -import net.minecraft.client.renderer.EntityRenderer; -import net.minecraft.client.renderer.RenderBlocks; -import net.minecraft.world.IBlockAccess; - import forestry.core.config.ForestryBlock; import forestry.core.render.OverlayRenderingHandler; import forestry.farming.gadgets.BlockFarm; import forestry.plugins.PluginFarming; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.world.IBlockAccess; public class FarmRenderingHandler extends OverlayRenderingHandler { diff --git a/src/main/java/forestry/farming/triggers/TriggerLowFertilizer.java b/src/main/java/forestry/farming/triggers/TriggerLowFertilizer.java index 755dbd358..1c833a2b0 100755 --- a/src/main/java/forestry/farming/triggers/TriggerLowFertilizer.java +++ b/src/main/java/forestry/farming/triggers/TriggerLowFertilizer.java @@ -16,7 +16,6 @@ import forestry.api.core.ITileStructure; import forestry.core.triggers.Trigger; import forestry.farming.gadgets.TileFarmPlain; import forestry.farming.gadgets.TileHatch; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; diff --git a/src/main/java/forestry/farming/worldgen/WorldGenBigMushroom.java b/src/main/java/forestry/farming/worldgen/WorldGenBigMushroom.java index a46b69ea8..5494ab277 100755 --- a/src/main/java/forestry/farming/worldgen/WorldGenBigMushroom.java +++ b/src/main/java/forestry/farming/worldgen/WorldGenBigMushroom.java @@ -14,15 +14,13 @@ package forestry.farming.worldgen; +import forestry.core.config.Defaults; import java.util.Random; - import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; -import forestry.core.config.Defaults; - // Referenced classes of package net.minecraft.src: // WorldGenerator, World, Block, BlockLeaves, // BlockGrass, BlockMycelium, BlockFlower diff --git a/src/main/java/forestry/food/BeverageEffectAntidote.java b/src/main/java/forestry/food/BeverageEffectAntidote.java index c8648fb86..892bad0a6 100755 --- a/src/main/java/forestry/food/BeverageEffectAntidote.java +++ b/src/main/java/forestry/food/BeverageEffectAntidote.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.food; +import forestry.core.proxy.Proxies; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.world.World; -import forestry.core.proxy.Proxies; - public class BeverageEffectAntidote extends BeverageEffect { private float chance = 0.2f; diff --git a/src/main/java/forestry/food/GuiHandlerFood.java b/src/main/java/forestry/food/GuiHandlerFood.java index 826ef6a2a..2f3c0f0ca 100755 --- a/src/main/java/forestry/food/GuiHandlerFood.java +++ b/src/main/java/forestry/food/GuiHandlerFood.java @@ -10,14 +10,14 @@ ******************************************************************************/ package forestry.food; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.food.gui.ContainerInfuser; import forestry.food.gui.GuiInfuser; import forestry.food.items.ItemInfuser.InfuserInventory; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class GuiHandlerFood extends GuiHandlerBase { @Override @@ -29,7 +29,10 @@ public class GuiHandlerFood extends GuiHandlerBase { switch (GuiId.values()[id]) { case InfuserGUI: - return new GuiInfuser(player.inventory, new InfuserInventory(player)); + ItemStack infuser = player.getCurrentEquippedItem(); + if (infuser == null) + return null; + return new GuiInfuser(player.inventory, new InfuserInventory(player, infuser)); default: return null; @@ -45,7 +48,10 @@ public class GuiHandlerFood extends GuiHandlerBase { switch (GuiId.values()[id]) { case InfuserGUI: - return new ContainerInfuser(player.inventory, new InfuserInventory(player)); + ItemStack infuser = player.getCurrentEquippedItem(); + if (infuser == null) + return null; + return new ContainerInfuser(player.inventory, new InfuserInventory(player, infuser)); default: return null; diff --git a/src/main/java/forestry/food/gui/ContainerInfuser.java b/src/main/java/forestry/food/gui/ContainerInfuser.java index 4935d518d..f780569e6 100755 --- a/src/main/java/forestry/food/gui/ContainerInfuser.java +++ b/src/main/java/forestry/food/gui/ContainerInfuser.java @@ -15,11 +15,10 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.config.ForestryItem; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.core.proxy.Proxies; -import forestry.food.items.ItemBeverage; import forestry.food.items.ItemInfuser.InfuserInventory; public class ContainerInfuser extends ContainerForestry { @@ -31,24 +30,24 @@ public class ContainerInfuser extends ContainerForestry { this.inventory = inventory; // Input - this.addSlot(new SlotCustom(inventory, 0, 152, 12, ForestryItem.beverage.getItemStack())); + this.addSlotToContainer(new SlotFiltered(inventory, 0, 152, 12)); // Output - this.addSlot(new SlotCustom(inventory, 1, 152, 72, ItemBeverage.class)); + this.addSlotToContainer(new SlotOutput(inventory, 1, 152, 72)); // Ingredients - this.addSlot(new Slot(inventory, 2, 12, 12)); - this.addSlot(new Slot(inventory, 3, 12, 32)); - this.addSlot(new Slot(inventory, 4, 12, 52)); - this.addSlot(new Slot(inventory, 5, 12, 72)); + this.addSlotToContainer(new SlotFiltered(inventory, 2, 12, 12)); + this.addSlotToContainer(new SlotFiltered(inventory, 3, 12, 32)); + this.addSlotToContainer(new SlotFiltered(inventory, 4, 12, 52)); + this.addSlotToContainer(new SlotFiltered(inventory, 5, 12, 72)); // Player inventory for (int i1 = 0; i1 < 3; i1++) for (int l1 = 0; l1 < 9; l1++) - addSlot(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); + addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18)); // Player hotbar for (int j1 = 0; j1 < 9; j1++) - addSlot(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); + addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161)); } @Override diff --git a/src/main/java/forestry/food/gui/GuiInfuser.java b/src/main/java/forestry/food/gui/GuiInfuser.java index 6178e44b7..4bd839eb1 100755 --- a/src/main/java/forestry/food/gui/GuiInfuser.java +++ b/src/main/java/forestry/food/gui/GuiInfuser.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.food.gui; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; - import forestry.api.food.BeverageManager; import forestry.core.config.Defaults; import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; import forestry.food.items.ItemInfuser.InfuserInventory; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; public class GuiInfuser extends GuiForestry { diff --git a/src/main/java/forestry/food/items/ItemAmbrosia.java b/src/main/java/forestry/food/items/ItemAmbrosia.java index 5c9acb1d8..3e27ee04f 100755 --- a/src/main/java/forestry/food/items/ItemAmbrosia.java +++ b/src/main/java/forestry/food/items/ItemAmbrosia.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.food.items; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; - import forestry.core.config.Defaults; import forestry.core.items.ItemForestryFood; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; public class ItemAmbrosia extends ItemForestryFood { diff --git a/src/main/java/forestry/food/items/ItemBeverage.java b/src/main/java/forestry/food/items/ItemBeverage.java index 1e69a1a9a..acaf1804c 100755 --- a/src/main/java/forestry/food/items/ItemBeverage.java +++ b/src/main/java/forestry/food/items/ItemBeverage.java @@ -10,9 +10,15 @@ ******************************************************************************/ package forestry.food.items; -import java.util.List; - +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.food.BeverageManager; +import forestry.api.food.IBeverageEffect; +import forestry.core.config.Config; import forestry.core.items.ItemForestryFood; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; @@ -24,15 +30,6 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.util.IIcon; import net.minecraft.world.World; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import forestry.api.food.BeverageManager; -import forestry.api.food.IBeverageEffect; -import forestry.core.config.Config; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; - public class ItemBeverage extends ItemForestryFood { public static class BeverageInfo { @@ -110,7 +107,7 @@ public class ItemBeverage extends ItemForestryFood { } - public BeverageInfo[] beverages; + public final BeverageInfo[] beverages; public ItemBeverage(BeverageInfo... beverages) { super(1, 0.2f); diff --git a/src/main/java/forestry/food/items/ItemInfuser.java b/src/main/java/forestry/food/items/ItemInfuser.java index a4518c939..4e1457a7b 100755 --- a/src/main/java/forestry/food/items/ItemInfuser.java +++ b/src/main/java/forestry/food/items/ItemInfuser.java @@ -10,14 +10,6 @@ ******************************************************************************/ package forestry.food.items; -import java.util.ArrayList; -import java.util.Arrays; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import forestry.api.core.ForestryAPI; import forestry.api.food.BeverageManager; import forestry.api.food.IBeverageEffect; @@ -25,11 +17,18 @@ import forestry.api.food.IInfuserManager; import forestry.api.food.IIngredientManager; import forestry.core.CreativeTabForestry; import forestry.core.config.ForestryItem; +import forestry.core.inventory.ItemInventory; import forestry.core.items.ItemForestry; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.food.BeverageEffect; import forestry.plugins.PluginManager; +import java.util.ArrayList; +import java.util.Arrays; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class ItemInfuser extends ItemForestry { @@ -229,15 +228,16 @@ public class ItemInfuser extends ItemForestry { } // / INVENTORY MANAGMENT - public static class InfuserInventory implements IInventory { + public static class InfuserInventory extends ItemInventory { - private final ItemStack[] inventoryStacks = new ItemStack[6]; private final short inputSlot = 0; private final short outputSlot = 1; private final short ingredientSlot1 = 2; + private final short ingredientSlotCount = 4; private final EntityPlayer player; - public InfuserInventory(EntityPlayer player) { + public InfuserInventory(EntityPlayer player, ItemStack itemStack) { + super(ItemInfuser.class, 6, itemStack); this.player = player; } @@ -290,25 +290,6 @@ public class ItemInfuser extends ItemForestry { } - @Override - public ItemStack decrStackSize(int i, int j) { - if (inventoryStacks[i] == null) - return null; - - ItemStack product; - if (inventoryStacks[i].stackSize <= j) { - product = inventoryStacks[i]; - inventoryStacks[i] = null; - return product; - } else { - product = inventoryStacks[i].splitStack(j); - if (inventoryStacks[i].stackSize == 0) - inventoryStacks[i] = null; - - return product; - } - } - @Override public void markDirty() { if (!Proxies.common.isSimulating(player.worldObj)) @@ -316,61 +297,19 @@ public class ItemInfuser extends ItemForestry { trySeasoning(); } - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventoryStacks[i] = itemstack; - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventoryStacks[i]; - } - - @Override - public int getSizeInventory() { - return inventoryStacks.length; - } - @Override public String getInventoryName() { return "Infuser"; } @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return true; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - if (inventoryStacks[slot] == null) - return null; - ItemStack toReturn = inventoryStacks[slot]; - inventoryStacks[slot] = null; - return toReturn; - } - - @Override - public boolean hasCustomInventoryName() { - return true; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return true; + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (slotIndex == inputSlot) { + ForestryItem.beverage.isItemEqual(itemStack); + } else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) { + BeverageManager.infuserManager.isIngredient(itemStack); + } + return false; } } diff --git a/src/main/java/forestry/lepidopterology/ButterflySpawner.java b/src/main/java/forestry/lepidopterology/ButterflySpawner.java index 0fd991a00..8e9e9f505 100755 --- a/src/main/java/forestry/lepidopterology/ButterflySpawner.java +++ b/src/main/java/forestry/lepidopterology/ButterflySpawner.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.lepidopterology; -import net.minecraft.world.World; - import forestry.api.arboriculture.ILeafTickHandler; import forestry.api.arboriculture.ITree; import forestry.api.lepidopterology.IButterfly; import forestry.core.proxy.Proxies; import forestry.lepidopterology.entities.EntityButterfly; import forestry.plugins.PluginLepidopterology; +import net.minecraft.world.World; public class ButterflySpawner implements ILeafTickHandler { diff --git a/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java b/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java index 0e9167c05..22a65e6e5 100755 --- a/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java +++ b/src/main/java/forestry/lepidopterology/GuiHandlerLepidopterology.java @@ -15,9 +15,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import forestry.core.GuiHandlerBase; +import forestry.core.gui.ContainerAlyzer; import forestry.core.network.GuiId; import forestry.lepidopterology.genetics.ButterflyHelper; -import forestry.lepidopterology.gui.ContainerFlutterlyzer; import forestry.lepidopterology.gui.GuiFlutterlyzer; import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; @@ -33,11 +33,11 @@ public class GuiHandlerLepidopterology extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case FlutterlyzerGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; - return new ContainerFlutterlyzer(player.inventory, new FlutterlyzerInventory(player, equipped)); + return new ContainerAlyzer(new FlutterlyzerInventory(player, equipped), player); case LepidopteristChestGUI: return getNaturalistChestContainer(ButterflyHelper.UID, player, world, x, y, z, guiData); @@ -58,7 +58,7 @@ public class GuiHandlerLepidopterology extends GuiHandlerBase { switch (GuiId.values()[cleanId]) { case FlutterlyzerGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; diff --git a/src/main/java/forestry/lepidopterology/MatingRecipe.java b/src/main/java/forestry/lepidopterology/MatingRecipe.java index 51572ce42..3edb71581 100755 --- a/src/main/java/forestry/lepidopterology/MatingRecipe.java +++ b/src/main/java/forestry/lepidopterology/MatingRecipe.java @@ -10,15 +10,14 @@ ******************************************************************************/ package forestry.lepidopterology; +import forestry.api.lepidopterology.EnumFlutterType; +import forestry.api.lepidopterology.IButterfly; +import forestry.plugins.PluginLepidopterology; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; -import forestry.api.lepidopterology.EnumFlutterType; -import forestry.api.lepidopterology.IButterfly; -import forestry.plugins.PluginLepidopterology; - public class MatingRecipe implements IRecipe { private final ItemStack unknown; @@ -65,6 +64,8 @@ public class MatingRecipe implements IRecipe { } else if(PluginLepidopterology.butterflyInterface.isMember(crafting.getStackInSlot(i), EnumFlutterType.SERUM.ordinal())) serum = PluginLepidopterology.butterflyInterface.getMember(crafting.getStackInSlot(i)); } + if (butterfly == null || serum == null) + return null; IButterfly mated = butterfly.copy(); mated.mate(serum); diff --git a/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java b/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java index 6c9fb9288..26d9c9c56 100644 --- a/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java +++ b/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java @@ -10,7 +10,8 @@ ******************************************************************************/ package forestry.lepidopterology.commands; -import forestry.core.commands.*; +import forestry.core.commands.CommandHelpers; +import forestry.core.commands.SubCommand; import forestry.lepidopterology.entities.EntityButterfly; import net.minecraft.command.ICommandSender; import net.minecraft.world.World; diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java index d968b5aaa..483db22cd 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.lepidopterology.entities; -import net.minecraft.entity.player.EntityPlayer; import forestry.lepidopterology.entities.EntityButterfly.EnumButterflyState; +import net.minecraft.entity.player.EntityPlayer; public class AIButterflyFlee extends AIButterflyMovement { - private EntityPlayer player; - public AIButterflyFlee(EntityButterfly entity) { super(entity); setMutexBits(3); @@ -25,7 +23,7 @@ public class AIButterflyFlee extends AIButterflyMovement { @Override public boolean shouldExecute() { - player = entity.worldObj.getClosestPlayerToEntity(entity, entity.getButterfly().getGenome().getPrimary().getFlightDistance()); + EntityPlayer player = entity.worldObj.getClosestPlayerToEntity(entity, entity.getButterfly().getGenome().getPrimary().getFlightDistance()); if (player == null || player.isSneaking()) return false; diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyInteract.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyInteract.java index 9ad6ea3e3..bc4056294 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyInteract.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyInteract.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.lepidopterology.entities; -import net.minecraft.util.ChunkCoordinates; - import forestry.lepidopterology.entities.EntityButterfly.EnumButterflyState; +import net.minecraft.util.ChunkCoordinates; public abstract class AIButterflyInteract extends AIButterflyBase { diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyMate.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyMate.java index a585e1982..6772956f4 100644 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyMate.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyMate.java @@ -10,17 +10,11 @@ ******************************************************************************/ package forestry.lepidopterology.entities; -import java.util.Map; - -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -import forestry.api.arboriculture.ITreeRoot; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IIndividual; +import forestry.api.genetics.IPollinatable; import forestry.api.lepidopterology.IButterflyNursery; -import forestry.core.utils.StackUtils; +import forestry.core.utils.GeneticsUtil; + +import net.minecraft.tileentity.TileEntity; public class AIButterflyMate extends AIButterflyInteract { @@ -30,7 +24,6 @@ public class AIButterflyMate extends AIButterflyInteract { /** * Should lay egg? - * @return */ @Override protected boolean canInteract() { @@ -45,23 +38,13 @@ public class AIButterflyMate extends AIButterflyInteract { if (tile instanceof IButterflyNursery) nursery = (IButterflyNursery) tile; - else - for (Map.Entry entry : AlleleManager.ersatzSpecimen.entrySet()) { - - if (!StackUtils.equals(entity.worldObj.getBlock(rest.posX, rest.posY, rest.posZ), entry.getKey())) - continue; - - int meta = entity.worldObj.getBlockMetadata(rest.posX, rest.posY, rest.posZ); - if (StackUtils.equals(Blocks.leaves, entry.getKey())) - meta = meta & 3; - if (entry.getKey().getItemDamage() != meta) - continue; - - // We matched, replace the leaf block with ours and set the ersatz genome - ((ITreeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees")).setLeaves(entity.worldObj, entry.getValue(), null, rest.posX, rest.posY, rest.posZ); - // Now let's pollinate - nursery = (IButterflyNursery) entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ); + else { + IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ); + if (pollinatable instanceof IButterflyNursery) { + nursery = (IButterflyNursery) pollinatable; } + } + if (nursery == null) return false; diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java index bf47c918f..f4248f92a 100644 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java @@ -11,7 +11,7 @@ package forestry.lepidopterology.entities; import forestry.api.genetics.IPollinatable; -import forestry.core.utils.Utils; +import forestry.core.utils.GeneticsUtil; public class AIButterflyPollinate extends AIButterflyInteract { @@ -21,14 +21,13 @@ public class AIButterflyPollinate extends AIButterflyInteract { /** * Should pollinate? - * @return */ @Override protected boolean canInteract() { if (entity.cooldownPollination > 0) return false; - IPollinatable pollinatable = Utils.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ); + IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ); if (pollinatable == null) return false; diff --git a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java index 9656b22ea..f922e3ae4 100755 --- a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java +++ b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java @@ -10,21 +10,8 @@ ******************************************************************************/ package forestry.lepidopterology.entities; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCreature; -import net.minecraft.entity.IEntityLivingData; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.DamageSource; -import net.minecraft.util.MathHelper; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import forestry.api.arboriculture.EnumGermlingType; import forestry.api.core.IToolScoop; import forestry.api.genetics.AlleleManager; @@ -45,7 +32,18 @@ import net.minecraft.block.BlockFlower; import net.minecraft.block.BlockWall; import net.minecraft.block.IGrowable; import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCreature; +import net.minecraft.entity.IEntityLivingData; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.IPlantable; diff --git a/src/main/java/forestry/lepidopterology/genetics/AlleleButterflySpecies.java b/src/main/java/forestry/lepidopterology/genetics/AlleleButterflySpecies.java index 2b057c0a9..4320c48ad 100755 --- a/src/main/java/forestry/lepidopterology/genetics/AlleleButterflySpecies.java +++ b/src/main/java/forestry/lepidopterology/genetics/AlleleButterflySpecies.java @@ -10,22 +10,9 @@ ******************************************************************************/ package forestry.lepidopterology.genetics; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - +import com.mojang.authlib.GameProfile; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraftforge.common.BiomeDictionary; - -import com.mojang.authlib.GameProfile; - import forestry.api.core.IIconProvider; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IClassification; @@ -35,6 +22,14 @@ import forestry.api.lepidopterology.IAlleleButterflySpecies; import forestry.api.lepidopterology.IButterflyRoot; import forestry.core.config.Defaults; import forestry.core.genetics.AlleleSpecies; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.BiomeDictionary; public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButterflySpecies { diff --git a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java index 4d1627593..d3db40f39 100755 --- a/src/main/java/forestry/lepidopterology/genetics/Butterfly.java +++ b/src/main/java/forestry/lepidopterology/genetics/Butterfly.java @@ -28,21 +28,20 @@ import forestry.api.lepidopterology.IEntityButterfly; import forestry.core.genetics.Chromosome; import forestry.core.genetics.GenericRatings; import forestry.core.genetics.IndividualLiving; -import forestry.core.utils.StackUtils; import forestry.core.utils.StringUtil; import forestry.core.utils.Utils; import forestry.plugins.PluginLepidopterology; -import net.minecraft.entity.EntityCreature; -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 java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; +import net.minecraft.entity.EntityCreature; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeDictionary; public class Butterfly extends IndividualLiving implements IButterfly { @@ -55,11 +54,7 @@ public class Butterfly extends IndividualLiving implements IButterfly { } public Butterfly(IButterflyGenome genome) { - this(genome, true, 0); - } - - public Butterfly(IButterflyGenome genome, boolean isNatural, int generation) { - super(genome.getLifespan(), isNatural, generation); + super(genome.getLifespan()); this.genome = genome; } @@ -67,22 +62,22 @@ public class Butterfly extends IndividualLiving implements IButterfly { public void addTooltip(List list) { IAlleleButterflySpecies primary = genome.getPrimary(); IAlleleButterflySpecies secondary = genome.getSecondary(); - if (!isPureBred(EnumButterflyChromosome.SPECIES.ordinal())) - list.add("\u00A79" + StringUtil.localize("butterflies.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); + if (!isPureBred(EnumButterflyChromosome.SPECIES)) + list.add(EnumChatFormatting.BLUE + StringUtil.localize("butterflies.hybrid").replaceAll("%PRIMARY",primary.getName()).replaceAll("%SECONDARY",secondary.getName())); if(getMate() != null) - list.add("\u00A7c" + StringUtil.localize("gui.fecundated").toUpperCase(Locale.ENGLISH)); - list.add("\u00A7e" + genome.getActiveAllele(EnumButterflyChromosome.SIZE.ordinal()).getName()); - list.add("\u00A7f" + genome.getActiveAllele(EnumButterflyChromosome.SPEED.ordinal()).getName() + " " + StringUtil.localize("gui.flyer")); - list.add(genome.getActiveAllele(EnumButterflyChromosome.LIFESPAN.ordinal()).getName() + " " + StringUtil.localize("gui.life")); + list.add(EnumChatFormatting.RED + StringUtil.localize("gui.fecundated").toUpperCase(Locale.ENGLISH)); + list.add(EnumChatFormatting.YELLOW + genome.getActiveAllele(EnumButterflyChromosome.SIZE).getName()); + list.add(EnumChatFormatting.WHITE + genome.getActiveAllele(EnumButterflyChromosome.SPEED).getName() + " " + StringUtil.localize("gui.flyer")); + list.add(genome.getActiveAllele(EnumButterflyChromosome.LIFESPAN).getName() + " " + StringUtil.localize("gui.life")); - IAlleleTolerance tempTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE.ordinal()); - list.add("\u00A7aT: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempTolerance.getName()); + IAlleleTolerance tempTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE); + list.add(EnumChatFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempTolerance.getName()); - IAlleleTolerance humidTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE.ordinal()); - list.add("\u00A7aH: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidTolerance.getName()); + IAlleleTolerance humidTolerance = (IAlleleTolerance)getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE); + list.add(EnumChatFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidTolerance.getName()); - list.add("\u00A7c" + GenericRatings.rateActivityTime(genome.getNocturnal(), genome.getPrimary().isNocturnal())); + list.add(EnumChatFormatting.RED + GenericRatings.rateActivityTime(genome.getNocturnal(), genome.getPrimary().isNocturnal())); } /* SAVING & LOADING */ @@ -202,7 +197,7 @@ public class Butterfly extends IndividualLiving implements IButterfly { if (parent1[i] != null && parent2[i] != null) chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]); - return new Butterfly(new ButterflyGenome(chromosomes), true, generation); + return new Butterfly(new ButterflyGenome(chromosomes)); } private IChromosome[] mutateSpecies(IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) { @@ -232,12 +227,10 @@ public class Butterfly extends IndividualLiving implements IButterfly { } for (IButterflyMutation mutation : PluginLepidopterology.butterflyInterface.getMutations(true)) { - float chance = 0; - - if ((chance = mutation.getChance(nursery, allele0, allele1, genome0, genome1)) > 0) - if (world.rand.nextFloat()*100 < chance) { - return PluginLepidopterology.butterflyInterface.templateAsChromosomes(mutation.getTemplate()); - } + float chance = mutation.getChance(nursery, allele0, allele1, genome0, genome1); + if (chance > world.rand.nextFloat() * 100) { + return PluginLepidopterology.butterflyInterface.templateAsChromosomes(mutation.getTemplate()); + } } return null; diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java index f0fff48eb..b14ef54e1 100755 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java @@ -42,7 +42,7 @@ public class ButterflyGenome extends Genome implements IButterflyGenome { // NBT RETRIEVAL public static IAlleleButterflySpecies getSpecies(ItemStack itemStack) { - IAllele speciesAllele = Genome.getPrimaryAllele(itemStack, EnumButterflyChromosome.SPECIES); + IAllele speciesAllele = Genome.getActiveAllele(itemStack, EnumButterflyChromosome.SPECIES); if (speciesAllele instanceof IAlleleButterflySpecies) return (IAlleleButterflySpecies)speciesAllele; else @@ -52,72 +52,72 @@ public class ButterflyGenome extends Genome implements IButterflyGenome { /* SPECIES */ @Override public IAlleleButterflySpecies getPrimary() { - return (IAlleleButterflySpecies) getActiveAllele(EnumButterflyChromosome.SPECIES.ordinal()); + return (IAlleleButterflySpecies) getActiveAllele(EnumButterflyChromosome.SPECIES); } @Override public IAlleleButterflySpecies getSecondary() { - return (IAlleleButterflySpecies) getInactiveAllele(EnumButterflyChromosome.SPECIES.ordinal()); + return (IAlleleButterflySpecies) getInactiveAllele(EnumButterflyChromosome.SPECIES); } @Override public float getSize() { - return ((IAlleleFloat) getActiveAllele(EnumButterflyChromosome.SIZE.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumButterflyChromosome.SIZE)).getValue(); } @Override public int getLifespan() { - return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.LIFESPAN.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.LIFESPAN)).getValue(); } @Override public float getSpeed() { - return ((IAlleleFloat) getActiveAllele(EnumButterflyChromosome.SPEED.ordinal())).getValue(); + return ((IAlleleFloat) getActiveAllele(EnumButterflyChromosome.SPEED)).getValue(); } @Override public int getMetabolism() { - return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.METABOLISM.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.METABOLISM)).getValue(); } @Override public int getFertility() { - return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.FERTILITY.ordinal())).getValue(); + return ((IAlleleInteger) getActiveAllele(EnumButterflyChromosome.FERTILITY)).getValue(); } @Override public EnumTolerance getToleranceTemp() { - return ((AlleleTolerance) getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE.ordinal())).getValue(); + return ((AlleleTolerance) getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE)).getValue(); } @Override public EnumTolerance getToleranceHumid() { - return ((AlleleTolerance) getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE.ordinal())).getValue(); + return ((AlleleTolerance) getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE)).getValue(); } @Override public boolean getNocturnal() { - return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.NOCTURNAL.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.NOCTURNAL)).getValue(); } @Override public boolean getTolerantFlyer() { - return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.TOLERANT_FLYER.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.TOLERANT_FLYER)).getValue(); } @Override public boolean getFireResist() { - return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.FIRE_RESIST.ordinal())).getValue(); + return ((AlleleBoolean) getActiveAllele(EnumButterflyChromosome.FIRE_RESIST)).getValue(); } @Override public IFlowerProvider getFlowerProvider() { - return ((IAlleleFlowers) getActiveAllele(EnumButterflyChromosome.FLOWER_PROVIDER.ordinal())).getProvider(); + return ((IAlleleFlowers) getActiveAllele(EnumButterflyChromosome.FLOWER_PROVIDER)).getProvider(); } @Override public IAlleleButterflyEffect getEffect() { - return (IAlleleButterflyEffect) getActiveAllele(EnumButterflyChromosome.EFFECT.ordinal()); + return (IAlleleButterflyEffect) getActiveAllele(EnumButterflyChromosome.EFFECT); } @Override diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java index 88eee4880..6426fb66b 100755 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyHelper.java @@ -10,19 +10,7 @@ ******************************************************************************/ package forestry.lepidopterology.genetics; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map.Entry; - -import net.minecraft.entity.EntityLiving; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IChromosomeType; @@ -41,6 +29,15 @@ import forestry.core.genetics.SpeciesRoot; import forestry.core.utils.Utils; import forestry.lepidopterology.entities.EntityButterfly; import forestry.plugins.PluginLepidopterology; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Map.Entry; +import net.minecraft.entity.EntityLiving; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; public class ButterflyHelper extends SpeciesRoot implements IButterflyRoot { diff --git a/src/main/java/forestry/lepidopterology/genetics/LepidopteristTracker.java b/src/main/java/forestry/lepidopterology/genetics/LepidopteristTracker.java index 3716a0ab6..0afe9bf8a 100755 --- a/src/main/java/forestry/lepidopterology/genetics/LepidopteristTracker.java +++ b/src/main/java/forestry/lepidopterology/genetics/LepidopteristTracker.java @@ -10,16 +10,14 @@ ******************************************************************************/ package forestry.lepidopterology.genetics; -import net.minecraft.entity.player.EntityPlayer; - import com.mojang.authlib.GameProfile; - import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.IIndividual; import forestry.api.lepidopterology.IButterfly; import forestry.api.lepidopterology.ILepidopteristTracker; import forestry.core.genetics.BreedingTracker; import forestry.plugins.PluginLepidopterology; +import net.minecraft.entity.player.EntityPlayer; public class LepidopteristTracker extends BreedingTracker implements ILepidopteristTracker { diff --git a/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java deleted file mode 100755 index 2c2e3d7cd..000000000 --- a/src/main/java/forestry/lepidopterology/gui/ContainerFlutterlyzer.java +++ /dev/null @@ -1,28 +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.lepidopterology.gui; - -import forestry.core.gui.ContainerAlyzer; -import forestry.core.config.ForestryItem; -import forestry.lepidopterology.items.ItemButterflyGE; -import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; - -import net.minecraft.entity.player.InventoryPlayer; - -public class ContainerFlutterlyzer extends ContainerAlyzer { - - FlutterlyzerInventory inventory; - - public ContainerFlutterlyzer(InventoryPlayer inventoryplayer, FlutterlyzerInventory inventory) { - super(inventoryplayer, inventory, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }, ItemButterflyGE.class); - } - -} diff --git a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java index a14049745..5c65cfca2 100755 --- a/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/gui/GuiFlutterlyzer.java @@ -12,7 +12,6 @@ package forestry.lepidopterology.gui; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; -import forestry.api.genetics.IAlleleEffect; import forestry.api.genetics.IAlleleFlowers; import forestry.api.genetics.IAlleleInteger; import forestry.api.genetics.IAlleleTolerance; @@ -22,27 +21,24 @@ import forestry.api.lepidopterology.IButterfly; import forestry.core.config.ForestryItem; import forestry.core.genetics.AlleleBoolean; import forestry.core.genetics.GenericRatings; +import forestry.core.gui.ContainerAlyzer; import forestry.core.gui.GuiAlyzer; import forestry.core.utils.StringUtil; import forestry.lepidopterology.genetics.ButterflyGenome; import forestry.lepidopterology.items.ItemButterflyGE; import forestry.lepidopterology.items.ItemFlutterlyzer.FlutterlyzerInventory; import forestry.plugins.PluginLepidopterology; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - public class GuiFlutterlyzer extends GuiAlyzer { public GuiFlutterlyzer(EntityPlayer player, FlutterlyzerInventory inventory) { - super(AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"), player, - new ContainerFlutterlyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory()); - - guiName = "gui.flutterlyzer"; + super("rootButterflies", player, new ContainerAlyzer(inventory, player), inventory, "gui.flutterlyzer"); ArrayList butterflyList = new ArrayList(); ((ItemButterflyGE) ForestryItem.butterflyGE.item()).addCreativeItems(butterflyList, false); @@ -105,33 +101,33 @@ public class GuiFlutterlyzer extends GuiAlyzer { drawSpeciesRow(StringUtil.localize("gui.species"), butterfly, EnumButterflyChromosome.SPECIES); newLine(); - drawRow(StringUtil.localize("gui.size"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.SIZE.ordinal()).getName(), - butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.SIZE.ordinal()).getName(), butterfly, EnumButterflyChromosome.SPEED); + drawRow(StringUtil.localize("gui.size"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.SIZE).getName(), + butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.SIZE).getName(), butterfly, EnumButterflyChromosome.SPEED); - drawRow(StringUtil.localize("gui.lifespan"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.LIFESPAN.ordinal()).getName(), - butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.LIFESPAN.ordinal()).getName(), butterfly, + drawRow(StringUtil.localize("gui.lifespan"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.LIFESPAN).getName(), + butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.LIFESPAN).getName(), butterfly, EnumButterflyChromosome.LIFESPAN); - drawRow(StringUtil.localize("gui.speed"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.SPEED.ordinal()).getName(), - butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.SPEED.ordinal()).getName(), butterfly, EnumButterflyChromosome.SPEED); + drawRow(StringUtil.localize("gui.speed"), butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.SPEED).getName(), + butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.SPEED).getName(), butterfly, EnumButterflyChromosome.SPEED); drawRow(StringUtil.localize("gui.metabolism"), GenericRatings.rateMetabolism(butterfly.getGenome().getMetabolism()), - GenericRatings.rateMetabolism(((IAlleleInteger) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.METABOLISM.ordinal())).getValue()), butterfly, EnumButterflyChromosome.METABOLISM); + GenericRatings.rateMetabolism(((IAlleleInteger) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.METABOLISM)).getValue()), butterfly, EnumButterflyChromosome.METABOLISM); drawLine(StringUtil.localize("gui.fertility"), COLUMN_0); - drawFertilityInfo(butterfly.getGenome().getFertility(), COLUMN_1, getColorCoding(butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.FERTILITY.ordinal()) + drawFertilityInfo(butterfly.getGenome().getFertility(), COLUMN_1, getColorCoding(butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.FERTILITY) .isDominant()), 8); - drawFertilityInfo(((IAlleleInteger) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FERTILITY.ordinal())).getValue(), COLUMN_2, getColorCoding(butterfly - .getGenome().getInactiveAllele(EnumButterflyChromosome.FERTILITY.ordinal()).isDominant()), 8); + drawFertilityInfo(((IAlleleInteger) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FERTILITY)).getValue(), COLUMN_2, getColorCoding(butterfly + .getGenome().getInactiveAllele(EnumButterflyChromosome.FERTILITY).isDominant()), 8); newLine(); drawRow(StringUtil.localize("gui.flowers"), butterfly.getGenome().getFlowerProvider().getDescription(), - ((IAlleleFlowers) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FLOWER_PROVIDER.ordinal())).getProvider() + ((IAlleleFlowers) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FLOWER_PROVIDER)).getProvider() .getDescription(), butterfly, EnumButterflyChromosome.FLOWER_PROVIDER); drawRow(StringUtil.localize("gui.effect"), butterfly.getGenome().getEffect().getName(), - butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.EFFECT.ordinal()).getName(), butterfly, + butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.EFFECT).getName(), butterfly, EnumButterflyChromosome.EFFECT); newLine(); @@ -152,8 +148,8 @@ public class GuiFlutterlyzer extends GuiAlyzer { drawRow(StringUtil.localize("gui.climate"), AlleleManager.climateHelper.toDisplay(butterfly.getGenome().getPrimary().getTemperature()), AlleleManager.climateHelper.toDisplay(butterfly.getGenome().getPrimary().getTemperature()), butterfly, EnumButterflyChromosome.SPECIES); - IAlleleTolerance tempToleranceActive = (IAlleleTolerance)butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE.ordinal()); - IAlleleTolerance tempToleranceInactive = (IAlleleTolerance)butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE.ordinal()); + IAlleleTolerance tempToleranceActive = (IAlleleTolerance)butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE); + IAlleleTolerance tempToleranceInactive = (IAlleleTolerance)butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE); drawLine(StringUtil.localize("gui.temptol"), COLUMN_0); drawToleranceInfo(tempToleranceActive, COLUMN_1); drawToleranceInfo(tempToleranceInactive, COLUMN_2); @@ -163,8 +159,8 @@ public class GuiFlutterlyzer extends GuiAlyzer { drawRow(StringUtil.localize("gui.humidity"), AlleleManager.climateHelper.toDisplay(butterfly.getGenome().getPrimary().getHumidity()), AlleleManager.climateHelper.toDisplay(butterfly.getGenome().getPrimary().getHumidity()), butterfly, EnumButterflyChromosome.SPECIES); - IAlleleTolerance humidToleranceActive = (IAlleleTolerance)butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE.ordinal()); - IAlleleTolerance humidToleranceInactive = (IAlleleTolerance)butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE.ordinal()); + IAlleleTolerance humidToleranceActive = (IAlleleTolerance)butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE); + IAlleleTolerance humidToleranceInactive = (IAlleleTolerance)butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE); drawLine(StringUtil.localize("gui.humidtol"), COLUMN_0); drawToleranceInfo(humidToleranceActive, COLUMN_1); drawToleranceInfo(humidToleranceInactive, COLUMN_2); @@ -182,7 +178,7 @@ public class GuiFlutterlyzer extends GuiAlyzer { nocturnal0 = butterfly.getGenome().getPrimary().isNocturnal() ? yes : no; diurnal0 = !butterfly.getGenome().getPrimary().isNocturnal() ? yes : no; } - if(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.NOCTURNAL.ordinal())).getValue()) { + if(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.NOCTURNAL)).getValue()) { nocturnal1 = diurnal1 = yes; } else { nocturnal1 = butterfly.getGenome().getSecondary().isNocturnal() ? yes : no; @@ -200,13 +196,13 @@ public class GuiFlutterlyzer extends GuiAlyzer { newLine(); String primary = StringUtil.readableBoolean(butterfly.getGenome().getTolerantFlyer(), yes, no); - String secondary = StringUtil.readableBoolean(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.TOLERANT_FLYER.ordinal())).getValue(), yes, + String secondary = StringUtil.readableBoolean(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.TOLERANT_FLYER)).getValue(), yes, no); drawRow(StringUtil.localize("gui.flyer"), primary, secondary, butterfly, EnumButterflyChromosome.TOLERANT_FLYER); primary = StringUtil.readableBoolean(butterfly.getGenome().getFireResist(), yes, no); - secondary = StringUtil.readableBoolean(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FIRE_RESIST.ordinal())).getValue(), yes, + secondary = StringUtil.readableBoolean(((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FIRE_RESIST)).getValue(), yes, no); drawRow(StringUtil.localize("gui.fireresist"), primary, secondary, butterfly, EnumButterflyChromosome.FIRE_RESIST); diff --git a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java index 520258050..6aff66d0f 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java +++ b/src/main/java/forestry/lepidopterology/items/ItemButterflyGE.java @@ -28,6 +28,7 @@ import forestry.core.utils.Utils; import forestry.lepidopterology.entities.EntityButterfly; import forestry.lepidopterology.genetics.ButterflyGenome; import forestry.plugins.PluginLepidopterology; +import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; @@ -38,8 +39,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; -import java.util.List; - public class ItemButterflyGE extends ItemGE { private final EnumFlutterType type; @@ -61,7 +60,7 @@ public class ItemButterflyGE extends ItemGE { } @Override - protected IIndividual getIndividual(ItemStack itemstack) { + public IButterfly getIndividual(ItemStack itemstack) { return PluginLepidopterology.butterflyInterface.getMember(itemstack); } diff --git a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java index a7f66e480..ac5ff30a3 100755 --- a/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java +++ b/src/main/java/forestry/lepidopterology/items/ItemFlutterlyzer.java @@ -15,15 +15,14 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import forestry.core.utils.AlyzerInventory; import forestry.api.core.ForestryAPI; import forestry.api.core.Tabs; import forestry.api.lepidopterology.IButterfly; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Config; -import forestry.core.config.ForestryItem; import forestry.core.interfaces.IErrorSource; import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.AlyzerInventory; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; @@ -33,21 +32,14 @@ public class ItemFlutterlyzer extends ItemInventoried { public static class FlutterlyzerInventory extends AlyzerInventory implements IErrorSource, IHintSource { - public FlutterlyzerInventory(EntityPlayer player) { - super(ItemFlutterlyzer.class, 7); - this.player = player; - } - public FlutterlyzerInventory(EntityPlayer player, ItemStack itemStack) { super(ItemFlutterlyzer.class, 7, itemStack); this.player = player; } - private boolean isEnergy(ItemStack itemstack) { - if (itemstack == null || itemstack.stackSize <= 0) - return false; - - return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack); + @Override + protected boolean isSpecimen(ItemStack itemStack) { + return PluginLepidopterology.butterflyInterface.isMember(itemStack); } private void tryAnalyze() { diff --git a/src/main/java/forestry/lepidopterology/proxy/ClientProxyLepidopterology.java b/src/main/java/forestry/lepidopterology/proxy/ClientProxyLepidopterology.java index d2b1f94da..72426cac4 100755 --- a/src/main/java/forestry/lepidopterology/proxy/ClientProxyLepidopterology.java +++ b/src/main/java/forestry/lepidopterology/proxy/ClientProxyLepidopterology.java @@ -11,13 +11,11 @@ package forestry.lepidopterology.proxy; import cpw.mods.fml.client.registry.RenderingRegistry; - -import net.minecraftforge.client.MinecraftForgeClient; - import forestry.core.config.ForestryItem; import forestry.lepidopterology.entities.EntityButterfly; import forestry.lepidopterology.render.ButterflyItemRenderer; import forestry.lepidopterology.render.RenderButterfly; +import net.minecraftforge.client.MinecraftForgeClient; public class ClientProxyLepidopterology extends ProxyLepidopterology { diff --git a/src/main/java/forestry/lepidopterology/render/ButterflyItemRenderer.java b/src/main/java/forestry/lepidopterology/render/ButterflyItemRenderer.java index 531e21195..67fb890b8 100755 --- a/src/main/java/forestry/lepidopterology/render/ButterflyItemRenderer.java +++ b/src/main/java/forestry/lepidopterology/render/ButterflyItemRenderer.java @@ -10,22 +10,19 @@ ******************************************************************************/ package forestry.lepidopterology.render; +import forestry.api.lepidopterology.IButterfly; +import forestry.core.proxy.Proxies; +import forestry.lepidopterology.entities.EntityButterfly; +import forestry.plugins.PluginLepidopterology; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.item.ItemStack; - import net.minecraftforge.client.IItemRenderer; - import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -import forestry.api.lepidopterology.IButterfly; -import forestry.core.proxy.Proxies; -import forestry.lepidopterology.entities.EntityButterfly; -import forestry.plugins.PluginLepidopterology; - public class ButterflyItemRenderer implements IItemRenderer { private final ModelButterfly model; diff --git a/src/main/java/forestry/lepidopterology/render/ModelButterfly.java b/src/main/java/forestry/lepidopterology/render/ModelButterfly.java index 48dffa992..2c0457100 100755 --- a/src/main/java/forestry/lepidopterology/render/ModelButterfly.java +++ b/src/main/java/forestry/lepidopterology/render/ModelButterfly.java @@ -14,7 +14,6 @@ import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.MathHelper; - import org.lwjgl.opengl.GL11; public class ModelButterfly extends ModelBase { diff --git a/src/main/java/forestry/lepidopterology/render/RenderButterfly.java b/src/main/java/forestry/lepidopterology/render/RenderButterfly.java index b2083ac86..8f93636b5 100755 --- a/src/main/java/forestry/lepidopterology/render/RenderButterfly.java +++ b/src/main/java/forestry/lepidopterology/render/RenderButterfly.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.lepidopterology.render; +import forestry.lepidopterology.entities.EntityButterfly; import net.minecraft.client.renderer.entity.RenderLiving; import net.minecraft.entity.Entity; -import net.minecraft.util.ResourceLocation; - -import forestry.lepidopterology.entities.EntityButterfly; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; public class RenderButterfly extends RenderLiving { diff --git a/src/main/java/forestry/mail/EnumDeliveryState.java b/src/main/java/forestry/mail/EnumDeliveryState.java index 776192db6..1165837b9 100755 --- a/src/main/java/forestry/mail/EnumDeliveryState.java +++ b/src/main/java/forestry/mail/EnumDeliveryState.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.mail; -import java.util.Locale; - import forestry.api.mail.IPostalState; +import java.util.Locale; public enum EnumDeliveryState implements IPostalState { OK, NO_MAILBOX, NOT_MAILABLE, ALREADY_MAILED, NOT_POSTPAID, MAILBOX_FULL, RESPONSE_NOT_MAILABLE; diff --git a/src/main/java/forestry/mail/EnumStationState.java b/src/main/java/forestry/mail/EnumStationState.java index 8402fe4bf..3dfa094d8 100755 --- a/src/main/java/forestry/mail/EnumStationState.java +++ b/src/main/java/forestry/mail/EnumStationState.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.mail; -import java.util.Locale; - import forestry.api.mail.IPostalState; +import java.util.Locale; public enum EnumStationState implements IPostalState { OK, INSUFFICIENT_OFFER, INSUFFICIENT_TRADE_GOOD, INSUFFICIENT_BUFFER, INSUFFICIENT_PAPER, INSUFFICIENT_STAMPS; diff --git a/src/main/java/forestry/mail/GuiHandlerMail.java b/src/main/java/forestry/mail/GuiHandlerMail.java index a360f14d8..e32d8c0f0 100755 --- a/src/main/java/forestry/mail/GuiHandlerMail.java +++ b/src/main/java/forestry/mail/GuiHandlerMail.java @@ -10,10 +10,6 @@ ******************************************************************************/ package forestry.mail; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import forestry.core.GuiHandlerBase; import forestry.core.network.GuiId; import forestry.mail.gadgets.MachineMailbox; @@ -34,6 +30,9 @@ import forestry.mail.gui.GuiTrader; import forestry.mail.items.ItemCatalogue; import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemLetter.LetterInventory; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class GuiHandlerMail extends GuiHandlerBase { @@ -45,7 +44,7 @@ public class GuiHandlerMail extends GuiHandlerBase { switch (GuiId.values()[id]) { case CatalogueGUI: - ItemStack cata = getEquippedItem(player); + ItemStack cata = player.getCurrentEquippedItem(); if (cata == null) return null; @@ -55,7 +54,7 @@ public class GuiHandlerMail extends GuiHandlerBase { return null; case LetterGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; @@ -86,7 +85,7 @@ public class GuiHandlerMail extends GuiHandlerBase { switch (GuiId.values()[id]) { case CatalogueGUI: - ItemStack cata = getEquippedItem(player); + ItemStack cata = player.getCurrentEquippedItem(); if (cata == null) return null; @@ -96,12 +95,12 @@ public class GuiHandlerMail extends GuiHandlerBase { return null; case LetterGUI: - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; if (equipped.getItem() instanceof ItemLetter) - return new ContainerLetter(player, new LetterInventory(getEquippedItem(player))); + return new ContainerLetter(player, new LetterInventory(equipped)); else return null; diff --git a/src/main/java/forestry/mail/Letter.java b/src/main/java/forestry/mail/Letter.java index 237b93273..4dec87f0f 100755 --- a/src/main/java/forestry/mail/Letter.java +++ b/src/main/java/forestry/mail/Letter.java @@ -10,25 +10,26 @@ ******************************************************************************/ package forestry.mail; +import forestry.api.core.INBTTagable; +import forestry.api.mail.ILetter; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.IStamps; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.utils.StringUtil; import java.util.List; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; - -import forestry.api.core.INBTTagable; -import forestry.api.mail.ILetter; -import forestry.api.mail.IStamps; -import forestry.api.mail.IMailAddress; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.StringUtil; import org.apache.commons.lang3.StringUtils; public class Letter implements ILetter, INBTTagable { // CONSTANTS public static final short SLOT_ATTACHMENT_1 = 0; + public static final short SLOT_ATTACHMENT_COUNT = 18; public static final short SLOT_POSTAGE_1 = 18; + public static final short SLOT_POSTAGE_COUNT = 4; private boolean isProcessed = false; @@ -88,12 +89,12 @@ public class Letter implements ILetter, INBTTagable { @Override public ItemStack[] getPostage() { - return inventory.getStacks(SLOT_POSTAGE_1, 4); + return InvTools.getStacks(inventory, SLOT_POSTAGE_1, SLOT_POSTAGE_COUNT); } @Override public ItemStack[] getAttachments() { - return inventory.getStacks(SLOT_ATTACHMENT_1, 18); + return InvTools.getStacks(inventory, SLOT_ATTACHMENT_1, SLOT_ATTACHMENT_COUNT); } @Override @@ -110,7 +111,7 @@ public class Letter implements ILetter, INBTTagable { @Override public void addAttachment(ItemStack itemstack) { - inventory.tryAddStack(itemstack, false); + InvTools.tryAddStack(inventory, itemstack, false); } @Override @@ -137,16 +138,9 @@ public class Letter implements ILetter, INBTTagable { @Override public boolean isMailable() { - // Can't resend an already sent letter - if (this.isProcessed) - return false; - // Requires at least one recipient - if (this.recipient != null && this.recipient.length > 0) - return true; - - return false; + return !isProcessed && recipient != null && recipient.length > 0; } @Override @@ -179,7 +173,7 @@ public class Letter implements ILetter, INBTTagable { @Override public void addStamps(ItemStack stamps) { - this.inventory.tryAddStack(stamps, SLOT_POSTAGE_1, 4, false); + InvTools.tryAddStack(inventory, stamps, SLOT_POSTAGE_1, 4, false); } @Override diff --git a/src/main/java/forestry/mail/MailAddress.java b/src/main/java/forestry/mail/MailAddress.java index d5ea3a8fd..ee54ed71f 100644 --- a/src/main/java/forestry/mail/MailAddress.java +++ b/src/main/java/forestry/mail/MailAddress.java @@ -14,19 +14,17 @@ import com.mojang.authlib.GameProfile; import forestry.api.core.INBTTagable; import forestry.api.mail.EnumAddressee; import forestry.api.mail.IMailAddress; -import forestry.core.network.EntityNetData; import forestry.core.utils.PlayerUtil; +import java.util.Locale; +import java.util.UUID; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTUtil; -import java.util.Locale; -import java.util.UUID; - public class MailAddress implements INBTTagable, IMailAddress { + private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0, 0), ""); - @EntityNetData + private EnumAddressee type; - @EntityNetData private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players public MailAddress() { @@ -47,17 +45,16 @@ public class MailAddress implements INBTTagable, IMailAddress { throw new IllegalArgumentException("name must not be null"); this.type = EnumAddressee.TRADER; - this.gameProfile = new GameProfile(new UUID(0, 0), name); + this.gameProfile = new GameProfile(null, name); } public MailAddress(IMailAddress address) { this.type = address.getType(); if (type == EnumAddressee.TRADER) { String name = address.getName(); - this.gameProfile = new GameProfile(new UUID(0, 0), name); - } else if (type == EnumAddressee.PLAYER) { + this.gameProfile = new GameProfile(null, name); + } else if (type == EnumAddressee.PLAYER) this.gameProfile = address.getPlayerProfile(); - } } public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) { @@ -78,7 +75,7 @@ public class MailAddress implements INBTTagable, IMailAddress { @Override public boolean isValid() { - return !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile); + return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile); } @Override @@ -100,7 +97,7 @@ public class MailAddress implements INBTTagable, IMailAddress { @Override public int hashCode() { - return gameProfile.hashCode(); + return gameProfile.getName().hashCode(); } @Override @@ -115,11 +112,10 @@ public class MailAddress implements INBTTagable, IMailAddress { @Override public String toString() { String name = getName().toLowerCase(Locale.ENGLISH); - if (isPlayer()) { + if (isPlayer()) return type + "-" + name + "-" + gameProfile.getId(); - } else { + else return type + "-" + name; - } } @Override diff --git a/src/main/java/forestry/mail/POBox.java b/src/main/java/forestry/mail/POBox.java index 5fbc694f2..ee4eea106 100755 --- a/src/main/java/forestry/mail/POBox.java +++ b/src/main/java/forestry/mail/POBox.java @@ -17,9 +17,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.WorldSavedData; import forestry.api.mail.ILetter; -import forestry.api.mail.PostManager; import forestry.api.mail.IMailAddress; -import forestry.core.utils.InventoryAdapter; +import forestry.api.mail.PostManager; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; public class POBox extends WorldSavedData implements IInventory { @@ -27,7 +28,7 @@ public class POBox extends WorldSavedData implements IInventory { public static final short SLOT_SIZE = 84; private IMailAddress address; - private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters"); + private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters").disableAutomation(); public POBox(IMailAddress address) { super(SAVE_NAME + address); @@ -70,7 +71,8 @@ public class POBox extends WorldSavedData implements IInventory { letterstack.setTagCompound(nbttagcompound); this.markDirty(); - return this.letters.tryAddStack(letterstack, true); + + return InvTools.tryAddStack(letters, letterstack, true); } public POBoxInfo getPOBoxInfo() { @@ -152,7 +154,7 @@ public class POBox extends WorldSavedData implements IInventory { @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return true; + return letters.isItemValidForSlot(i, itemstack); } } diff --git a/src/main/java/forestry/mail/PacketHandlerMail.java b/src/main/java/forestry/mail/PacketHandlerMail.java index d971f9446..3df5b6e8e 100755 --- a/src/main/java/forestry/mail/PacketHandlerMail.java +++ b/src/main/java/forestry/mail/PacketHandlerMail.java @@ -10,11 +10,6 @@ ******************************************************************************/ package forestry.mail; -import java.io.DataInputStream; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; - import forestry.core.interfaces.IPacketHandler; import forestry.core.network.PacketIds; import forestry.core.network.PacketUpdate; @@ -22,9 +17,12 @@ import forestry.core.proxy.Proxies; import forestry.mail.gui.ContainerCatalogue; import forestry.mail.gui.ContainerLetter; import forestry.mail.gui.ContainerTradeName; -import forestry.mail.network.PacketPOBoxInfo; import forestry.mail.network.PacketLetterInfo; +import forestry.mail.network.PacketPOBoxInfo; import forestry.plugins.PluginMail; +import java.io.DataInputStream; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; public class PacketHandlerMail implements IPacketHandler { diff --git a/src/main/java/forestry/mail/PostOffice.java b/src/main/java/forestry/mail/PostOffice.java index 611765e40..ab62ba76f 100755 --- a/src/main/java/forestry/mail/PostOffice.java +++ b/src/main/java/forestry/mail/PostOffice.java @@ -10,24 +10,22 @@ ******************************************************************************/ package forestry.mail; -import java.io.File; -import java.util.LinkedHashMap; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; -import net.minecraft.world.WorldSavedData; - import forestry.api.mail.EnumPostage; import forestry.api.mail.ILetter; +import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostOffice; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.IPostalState; import forestry.api.mail.IStamps; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; -import forestry.api.mail.IMailAddress; import forestry.core.config.ForestryItem; +import java.io.File; +import java.util.LinkedHashMap; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.WorldSavedData; public class PostOffice extends WorldSavedData implements IPostOffice { @@ -124,7 +122,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice { for (EnumPostage postage : postages) { - int collected = 0; + int collected; if (collectedPostage[postage.ordinal()] <= 0) continue; diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index 507f78daf..c5e929806 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -10,33 +10,30 @@ ******************************************************************************/ package forestry.mail; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - +import forestry.api.mail.EnumAddressee; import forestry.api.mail.ILetter; +import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostOffice; import forestry.api.mail.IPostRegistry; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; -import forestry.api.mail.IMailAddress; -import forestry.api.mail.EnumAddressee; import forestry.core.config.ForestryItem; import forestry.mail.items.ItemLetter; import forestry.plugins.PluginMail; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; public class PostRegistry implements IPostRegistry { public static PostOffice cachedPostOffice; - public static final HashMap cachedPOBoxes = new HashMap(); - public static final HashMap cachedTradeStations = new HashMap(); + public static final Map cachedPOBoxes = new HashMap(); + public static final Map cachedTradeStations = new HashMap(); /** * @param world the Minecraft world the PO box will be in @@ -95,8 +92,11 @@ public class PostRegistry implements IPostRegistry { @Override public TradeStation getTradeStation(World world, IMailAddress address) { + if (address.getName() == null) + return null; + if (cachedTradeStations.containsKey(address)) - return (TradeStation)cachedTradeStations.get(address); + return (TradeStation) cachedTradeStations.get(address); TradeStation trade = (TradeStation) world.loadItemData(TradeStation.class, TradeStation.SAVE_NAME + address); @@ -222,5 +222,4 @@ public class PostRegistry implements IPostRegistry { return ForestryItem.letters.isItemEqual(itemstack); } - } diff --git a/src/main/java/forestry/mail/PostalCarrier.java b/src/main/java/forestry/mail/PostalCarrier.java index ca0301eaf..65178a60b 100755 --- a/src/main/java/forestry/mail/PostalCarrier.java +++ b/src/main/java/forestry/mail/PostalCarrier.java @@ -10,19 +10,21 @@ ******************************************************************************/ package forestry.mail; -import java.util.Locale; - -import forestry.api.mail.*; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.world.World; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - +import forestry.api.mail.EnumAddressee; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.IPostOffice; +import forestry.api.mail.IPostalCarrier; +import forestry.api.mail.IPostalState; +import forestry.api.mail.ITradeStation; +import forestry.api.mail.PostManager; import forestry.core.render.TextureManager; import forestry.core.utils.StringUtil; import forestry.plugins.PluginMail; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; public class PostalCarrier implements IPostalCarrier { @@ -59,15 +61,11 @@ public class PostalCarrier implements IPostalCarrier { } private IPostalState handleTradeLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { - IPostalState state = EnumDeliveryState.NOT_MAILABLE; - ITradeStation trade = PostManager.postRegistry.getTradeStation(world, recipient); if (trade == null) return EnumDeliveryState.NO_MAILBOX; - state = trade.handleLetter(world, recipient, letterstack, doLodge); - - return state; + return trade.handleLetter(world, recipient, letterstack, doLodge); } private EnumDeliveryState storeInPOBox(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) { diff --git a/src/main/java/forestry/mail/SaveEventHandlerMail.java b/src/main/java/forestry/mail/SaveEventHandlerMail.java index 906b63f37..e3bd96af7 100755 --- a/src/main/java/forestry/mail/SaveEventHandlerMail.java +++ b/src/main/java/forestry/mail/SaveEventHandlerMail.java @@ -10,10 +10,9 @@ ******************************************************************************/ package forestry.mail; -import net.minecraft.world.World; - import forestry.core.interfaces.ISaveEventHandler; import forestry.plugins.PluginMail; +import net.minecraft.world.World; public class SaveEventHandlerMail implements ISaveEventHandler { diff --git a/src/main/java/forestry/mail/TickHandlerMailClient.java b/src/main/java/forestry/mail/TickHandlerMailClient.java index ebb367494..cc65cfb8c 100755 --- a/src/main/java/forestry/mail/TickHandlerMailClient.java +++ b/src/main/java/forestry/mail/TickHandlerMailClient.java @@ -14,7 +14,6 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent; - import forestry.mail.gui.GuiMailboxInfo; import forestry.plugins.PluginMail; diff --git a/src/main/java/forestry/mail/TradeStation.java b/src/main/java/forestry/mail/TradeStation.java index 4325a891e..e19ebbb2f 100755 --- a/src/main/java/forestry/mail/TradeStation.java +++ b/src/main/java/forestry/mail/TradeStation.java @@ -10,7 +10,19 @@ ******************************************************************************/ package forestry.mail; +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.world.World; +import net.minecraft.world.WorldSavedData; + import com.mojang.authlib.GameProfile; + import forestry.api.mail.EnumPostage; import forestry.api.mail.ILetter; import forestry.api.mail.IMailAddress; @@ -20,22 +32,66 @@ import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; import forestry.core.config.ForestryItem; -import forestry.core.utils.InventoryAdapter; -import forestry.core.utils.PlayerUtil; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.InventoryAdapter; +import forestry.core.utils.GuiUtil; import forestry.core.utils.StackUtils; import forestry.mail.items.ItemLetter; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.world.World; -import net.minecraft.world.WorldSavedData; -import java.util.ArrayList; +public class TradeStation extends WorldSavedData implements ITradeStation, IInventoryAdapter { -public class TradeStation extends WorldSavedData implements ITradeStation, ISidedInventory { + public static class TradeStationInventory extends InventoryAdapter { + + public TradeStationInventory(int size, String name) { + super(size, name); + } + + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + + ArrayList slots = new ArrayList(); + + for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++) + slots.add(i); + for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++) + slots.add(i); + for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) + slots.add(i); + + int[] slotsInt = new int[slots.size()]; + for (int i = 0; i < slots.size(); i++) + slotsInt[i] = slots.get(i); + + return slotsInt; + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemStack, int side) { + return GuiUtil.isIndexInRange(slot, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (GuiUtil.isIndexInRange(slotIndex, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) { + for (int i = 0; i < SLOT_TRADEGOOD_COUNT; i++) { + ItemStack tradeGood = getStackInSlot(SLOT_TRADEGOOD + i); + if (StackUtils.isIdenticalItem(tradeGood, itemStack)) + return true; + } + return false; + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) { + Item item = itemStack.getItem(); + return item == Items.paper; + } else if (GuiUtil.isIndexInRange(slotIndex, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { + Item item = itemStack.getItem(); + return item instanceof IStamps; + } + + return false; + } + } // / CONSTANTS public static final String SAVE_NAME = "TradePO_"; @@ -58,7 +114,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide private IMailAddress address; private boolean isVirtual = false; private boolean isInvalid = false; - private final InventoryAdapter inventory = new InventoryAdapter(SLOT_SIZE, "INV"); + private final InventoryAdapter inventory = new TradeStationInventory(SLOT_SIZE, "INV"); // / CONSTRUCTORS public TradeStation(GameProfile owner, IMailAddress address) { @@ -139,7 +195,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide @Override public TradeStationInfo getTradeInfo() { - ItemStack[] condensedRequired = StackUtils.condenseStacks(inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)); + ItemStack[] condensedRequired = StackUtils.condenseStacks(InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)); // Set current state EnumStationState state = EnumStationState.OK; @@ -171,7 +227,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1)) return EnumStationState.INSUFFICIENT_PAPER; - int ordersToFill = StackUtils.containsSets(inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments()); + int ordersToFill = StackUtils.containsSets(InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments()); // Not a single match. if (ordersToFill <= 0) @@ -188,7 +244,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide ordersToFill = fillable; // Check for sufficient output buffer - int storable = countStorablePayment(ordersToFill, inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)); + int storable = countStorablePayment(ordersToFill, InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)); if (storable <= 0) return EnumStationState.INSUFFICIENT_BUFFER; @@ -233,11 +289,11 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide // Store received items for (int i = 0; i < ordersToFill; i++) { - for (ItemStack stack : inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) { + for (ItemStack stack : InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) { if (stack == null) continue; - - inventory.tryAddStack(stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false); + + InvTools.tryAddStack(inventory, stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false); } } @@ -277,7 +333,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide // How many orders are fillable? int itemCount = 0; - for (ItemStack stack : inventory.getStacks(SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) { + + for (ItemStack stack : InvTools.getStacks(inventory, SLOT_SEND_BUFFER, SLOT_SEND_BUFFER_COUNT)) { if (stack != null && stack.isItemEqual(tradegood) && ItemStack.areItemStackTagsEqual(stack, tradegood)) itemCount += stack.stackSize; } @@ -287,9 +344,9 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide public boolean canReceivePayment() { InventoryAdapter test = inventory.copy(); - ItemStack [] payment = inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT); + ItemStack [] payment = InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT); - return test.tryAddStacksCopy(payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true); + return InvTools.tryAddStacksCopy(test, payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true); } private int countStorablePayment(int max, ItemStack[] exchange) { @@ -298,7 +355,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide int count = 0; for (int i = 0; i < max; i++) { - if (test.tryAddStacksCopy(exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true)) + if (InvTools.tryAddStacksCopy(test, exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true)) count++; else break; @@ -335,8 +392,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide private boolean hasPaper(int amountRequired) { int amountFound = 0; - - for (ItemStack stack : inventory.getStacks(SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) { + + for (ItemStack stack : InvTools.getStacks(inventory, SLOT_LETTERS_1, SLOT_LETTERS_COUNT)) { if (stack != null) amountFound += stack.stackSize; @@ -360,8 +417,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide private boolean canPayPostage(int postage) { int posted = 0; - - for (ItemStack stamp : inventory.getStacks(SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { + + for (ItemStack stamp : InvTools.getStacks(inventory, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { if (stamp == null) continue; @@ -405,7 +462,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide private int getNumStamps(EnumPostage postage) { int count = 0; - for (ItemStack stamp : inventory.getStacks(SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { + for (ItemStack stamp : InvTools.getStacks(inventory, SLOT_STAMPS_1, SLOT_STAMPS_COUNT)) { if (stamp == null) continue; if (!(stamp.getItem() instanceof IStamps)) @@ -456,7 +513,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide // Remove stuff until we are only left with the remnants for (int i = 0; i < filled; i++) { - ItemStack[] condensedRequired = StackUtils.condenseStacks(inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)); + ItemStack[] required = InvTools.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT); + ItemStack[] condensedRequired = StackUtils.condenseStacks(required); for (ItemStack req : condensedRequired) { for (int j = 0; j < pool.length; j++) { ItemStack pol = pool[j]; @@ -529,7 +587,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide @Override public boolean isUseableByPlayer(EntityPlayer player) { - return PlayerUtil.isSameGameProfile(owner, player.getGameProfile()); + return true; } @Override @@ -540,69 +598,43 @@ public class TradeStation extends WorldSavedData implements ITradeStation, ISide public void closeInventory() { } + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) { + return inventory.isItemValidForSlot(i, itemStack); + } + @Override public boolean hasCustomInventoryName() { return true; } - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemStack) { - if (itemStack == null || itemStack.getItem() == null) - return false; - - if (slot >= SLOT_LETTERS_1 && slot < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT) - return itemStack.getItem() == Items.paper; - - if (slot >= SLOT_STAMPS_1 && slot < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT) - return IStamps.class.isAssignableFrom(itemStack.getItem().getClass()); - - if (slot >= SLOT_SEND_BUFFER && slot < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT) { - ItemStack item = new ItemStack(itemStack.getItem(), 1, itemStack.getItemDamage()); - return inventory.contains(item, SLOT_TRADEGOOD, SLOT_TRADEGOOD_COUNT); - } - - return false; - } - @Override public int[] getAccessibleSlotsFromSide(int side) { - return getAccessibleSlotsFromSide(side, false); - } - - public int[] getAccessibleSlotsFromSide(int side, boolean permission) { - - ArrayList slots = new ArrayList(); - - for (int i = SLOT_LETTERS_1; i < SLOT_LETTERS_1 + SLOT_LETTERS_COUNT; i++) - slots.add(i); - for (int i = SLOT_STAMPS_1; i < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; i++) - slots.add(i); - if (permission) { - for (int i = SLOT_RECEIVE_BUFFER; i < SLOT_RECEIVE_BUFFER + SLOT_RECEIVE_BUFFER_COUNT; i++) - slots.add(i); - } - for (int i = SLOT_SEND_BUFFER; i < SLOT_SEND_BUFFER + SLOT_SEND_BUFFER_COUNT; i++) - slots.add(i); - - int[] slotsInt = new int[slots.size()]; - for (int i = 0; i < slots.size(); i++) - slotsInt[i] = slots.get(i).intValue(); - - return slotsInt; + return inventory.getAccessibleSlotsFromSide(side); } @Override public boolean canInsertItem(int slot, ItemStack itemStack, int side) { - return isItemValidForSlot(slot, itemStack); + return inventory.canInsertItem(slot, itemStack, side); } @Override public boolean canExtractItem(int slot, ItemStack itemStack, int side) { - return canExtractItem(slot, itemStack, side, false); + return inventory.canExtractItem(slot, itemStack, side); } - public boolean canExtractItem(int slot, ItemStack itemStack, int side, boolean permission) { - return permission && slot >= SLOT_RECEIVE_BUFFER && slot < SLOT_RECEIVE_BUFFER + SLOT_RECEIVE_BUFFER_COUNT; + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return inventory.canSlotAccept(slotIndex, itemStack); } + @Override + public boolean isLocked(int slotIndex) { + return inventory.isLocked(slotIndex); + } + + @Override + public IInventoryAdapter configureSided(int[] sides, int[] slots) { + return inventory.configureSided(sides, slots); + } } diff --git a/src/main/java/forestry/mail/commands/CommandMail.java b/src/main/java/forestry/mail/commands/CommandMail.java index 7967c996a..da9585882 100644 --- a/src/main/java/forestry/mail/commands/CommandMail.java +++ b/src/main/java/forestry/mail/commands/CommandMail.java @@ -57,9 +57,7 @@ public class CommandMail extends SubCommand { } private String makeTradeListEntry(TradeStationInfo info) { - String entry = "\u00A7c"; - if (info.state == EnumStationState.OK) - entry = "\u00A7a"; + EnumChatFormatting formatting = info.state.isOk() ? EnumChatFormatting.GREEN : EnumChatFormatting.RED; String tradegood = "[ ? ]"; if (info.tradegood != null) @@ -72,7 +70,7 @@ public class CommandMail extends SubCommand { } } - return String.format("%s%-12s | %-20s | %s", entry, info.address.getName(), tradegood, demand); + return String.format("%s%-12s | %-20s | %s", formatting, info.address.getName(), tradegood, demand); } } diff --git a/src/main/java/forestry/mail/gadgets/MachineMailbox.java b/src/main/java/forestry/mail/gadgets/MachineMailbox.java index 39fb314fb..87d3c704d 100755 --- a/src/main/java/forestry/mail/gadgets/MachineMailbox.java +++ b/src/main/java/forestry/mail/gadgets/MachineMailbox.java @@ -10,48 +10,47 @@ ******************************************************************************/ package forestry.mail.gadgets; -import buildcraft.api.statements.ITriggerExternal; +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.world.World; + import com.mojang.authlib.GameProfile; + +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.common.Optional; + import forestry.api.core.ForestryAPI; -import forestry.api.core.ISpecialInventory; import forestry.api.mail.ILetter; import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostalState; import forestry.api.mail.PostManager; import forestry.core.config.Config; import forestry.core.gadgets.TileBase; +import forestry.core.inventory.InventoryAdapter; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; import forestry.mail.EnumDeliveryState; import forestry.mail.IMailContainer; import forestry.mail.POBox; import forestry.mail.PostRegistry; -import forestry.plugins.PluginMail; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.world.World; -import net.minecraftforge.common.util.ForgeDirection; +import forestry.mail.triggers.MailTriggers; -import java.util.Collection; -import java.util.LinkedList; +import buildcraft.api.statements.ITriggerExternal; -public class MachineMailbox extends TileBase implements IMailContainer, ISpecialInventory, ISidedInventory { +public class MachineMailbox extends TileBase implements IMailContainer { private boolean isLinked = false; public MachineMailbox() { setHints(Config.hints.get("mailbox")); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); + setInternalInventory(new InventoryAdapter(POBox.SLOT_SIZE, "Letters").disableAutomation()); } /* GUI */ @@ -84,10 +83,10 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial } /* MAIL HANDLING */ - public IInventory getOrCreateMailInventory(World world, GameProfile playerProfile) { - if (!Proxies.common.isSimulating(world)) - return new InventoryAdapter(POBox.SLOT_SIZE, "Letters"); + if (!Proxies.common.isSimulating(world)) { + return getInternalInventory(); + } IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile); return PostRegistry.getOrCreatePOBox(worldObj, address); @@ -110,9 +109,10 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial public boolean hasMail() { IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile()); - for (int i = 0; i < mailInventory.getSizeInventory(); i++) + for (int i = 0; i < mailInventory.getSizeInventory(); i++) { if (mailInventory.getStackInSlot(i) != null) return true; + } return false; } @@ -122,129 +122,7 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial @Override public Collection getExternalTriggers(ForgeDirection side, TileEntity tile) { LinkedList res = new LinkedList(); - res.add(PluginMail.triggerHasMail); + res.add(MailTriggers.triggerHasMail); return res; } - - /* ISPECIALINVENTORY */ - @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - if (!PostManager.postRegistry.isLetter(stack)) - return 0; - - IPostalState result = tryDispatchLetter(stack, doAdd); - - if (!result.isOk()) - return 0; - else - return 1; - } - - @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - - ItemStack product = null; - IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile()); - - for (int i = 0; i < mailInventory.getSizeInventory(); i++) { - ItemStack slotStack = mailInventory.getStackInSlot(i); - if (slotStack == null) - continue; - - product = slotStack; - if (doRemove) - mailInventory.setInventorySlotContents(i, null); - break; - } - - if (product != null) - return new ItemStack[] { product }; - else - return new ItemStack[0]; - } - - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(int var1) { - return null; - } - - @Override - public ItemStack decrStackSize(int var1, int var2) { - return null; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - return null; - } - - @Override - public void setInventorySlotContents(int var1, ItemStack var2) { - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - return super.canInsertItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - return super.canExtractItem(i, itemstack, j); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public int[] getAccessibleSlotsFromSide(int side) { - return super.getAccessibleSlotsFromSide(side); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } } diff --git a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java index 5352cf720..95499f49b 100755 --- a/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java +++ b/src/main/java/forestry/mail/gadgets/MachinePhilatelist.java @@ -13,14 +13,14 @@ package forestry.mail.gadgets; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import forestry.api.core.ForestryAPI; import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; import forestry.core.gadgets.TileBase; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.GuiId; -import forestry.core.utils.InventoryAdapter; import forestry.core.utils.StackUtils; public class MachinePhilatelist extends TileBase implements IInventory { @@ -30,14 +30,13 @@ public class MachinePhilatelist extends TileBase implements IInventory { public static final short SLOT_BUFFER_1 = 1; public static final short SLOT_BUFFER_COUNT = 27; - private final InventoryAdapter inventory = new InventoryAdapter(28, "INV"); - public MachinePhilatelist() { - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); + setInternalInventory(new TileInventoryAdapter(this, 28, "INV") { + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return itemStack.getItem() instanceof IStamps; + } + }); } @Override @@ -45,21 +44,6 @@ public class MachinePhilatelist extends TileBase implements IInventory { player.openGui(ForestryAPI.instance, GuiId.PhilatelistGUI.ordinal(), worldObj, xCoord, yCoord, zCoord); } - /* SAVING & LOADING */ - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - - inventory.writeToNBT(nbttagcompound); - } - - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - - inventory.readFromNBT(nbttagcompound); - } - // / UPDATING @Override public void updateServerSide() { @@ -68,6 +52,7 @@ public class MachinePhilatelist extends TileBase implements IInventory { ItemStack stamp = null; + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_FILTER) == null) stamp = PostManager.postRegistry.getPostOffice(worldObj).getAnyStamp(1); else { @@ -82,73 +67,4 @@ public class MachinePhilatelist extends TileBase implements IInventory { // Store it. StackUtils.stowInInventory(stamp, inventory, true, SLOT_BUFFER_1, SLOT_BUFFER_COUNT); } - - /* IINVENTORY */ - @Override - public int getSizeInventory() { - return inventory.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return inventory.getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return inventory.decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - inventory.setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inventory.getStackInSlotOnClosing(slot); - } - - @Override - public void markDirty() { - inventory.markDirty(); - } - - @Override - public int getInventoryStackLimit() { - return inventory.getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - return super.isUseableByPlayer(player); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean hasCustomInventoryName() { - return super.hasCustomInventoryName(); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return super.isItemValidForSlot(slotIndex, itemstack); - } - } diff --git a/src/main/java/forestry/mail/gadgets/MachineTrader.java b/src/main/java/forestry/mail/gadgets/MachineTrader.java index 224a2d780..a56fef9b7 100755 --- a/src/main/java/forestry/mail/gadgets/MachineTrader.java +++ b/src/main/java/forestry/mail/gadgets/MachineTrader.java @@ -10,47 +10,44 @@ ******************************************************************************/ package forestry.mail.gadgets; -import buildcraft.api.statements.ITriggerExternal; +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.common.util.ForgeDirection; + import cpw.mods.fml.common.Optional; + import forestry.api.core.ForestryAPI; import forestry.api.mail.IMailAddress; import forestry.api.mail.IStamps; import forestry.api.mail.PostManager; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.gadgets.TileBase; -import forestry.core.network.EntityNetData; +import forestry.core.inventory.IInventoryAdapter; import forestry.core.network.GuiId; +import forestry.core.network.PacketPayload; import forestry.core.proxy.Proxies; -import forestry.core.utils.EnumAccess; -import forestry.core.utils.InventoryAdapter; import forestry.core.utils.StackUtils; import forestry.mail.MailAddress; import forestry.mail.TradeStation; -import forestry.plugins.PluginMail; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; +import forestry.mail.triggers.MailTriggers; -import java.util.Collection; -import java.util.LinkedList; +import buildcraft.api.statements.ITriggerExternal; -public class MachineTrader extends TileBase implements ISidedInventory { +public class MachineTrader extends TileBase { - @EntityNetData - private MailAddress address; + private IMailAddress address; public MachineTrader() { address = new MailAddress(); - } - - @Override - public String getInventoryName() { - return getUnlocalizedName(); + setInternalInventory(new TradeStation.TradeStationInventory(TradeStation.SLOT_SIZE, "INV")); } @Override @@ -63,9 +60,8 @@ public class MachineTrader extends TileBase implements ISidedInventory { @Override public void onRemoval() { - if (isLinked()) { + if (isLinked()) PostManager.postRegistry.deleteTradeStation(worldObj, address); - } } /* SAVING & LOADING */ @@ -84,13 +80,32 @@ public class MachineTrader extends TileBase implements ISidedInventory { public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); - if (nbttagcompound.hasKey("address")) { + if (nbttagcompound.hasKey("address")) address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address")); + } + + @Override + public PacketPayload getPacketPayload() { + if (address == null || address.getName() == null) + return null; + + PacketPayload payload = new PacketPayload(0, 0, 1); + payload.stringPayload[0] = address.getName(); + return payload; + } + + @Override + public void fromPacketPayload(PacketPayload payload) { + if (payload.isEmpty()) { + address = null; + return; } + + String addressName = payload.stringPayload[0]; + address = PostManager.postRegistry.getMailAddress(addressName); } /* UPDATING */ - /** * The trade station should show errors for missing stamps and paper first. * Once it is able to send letters, it should display other error states. @@ -106,19 +121,18 @@ public class MachineTrader extends TileBase implements ISidedInventory { if (!hasPostageMin(3)) errorCode = EnumErrorCode.NOSTAMPS; - if (!hasPaperMin(2)) { + if (!hasPaperMin(2)) if (errorCode == EnumErrorCode.NOSTAMPS) errorCode = EnumErrorCode.NOSTAMPSNOPAPER; else errorCode = EnumErrorCode.NOPAPER; - } if (errorCode != EnumErrorCode.OK) { setErrorState(errorCode); return; } - IInventory inventory = getOrCreateTradeInventory(); + IInventory inventory = getInternalInventory(); ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); if (tradeGood == null) { @@ -133,25 +147,23 @@ public class MachineTrader extends TileBase implements ISidedInventory { } boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.stackSize); - if(!hasSupplies) { + if (!hasSupplies) { setErrorState(EnumErrorCode.NOSUPPLIES); return; } - if (inventory instanceof TradeStation) { - if (!((TradeStation)inventory).canReceivePayment()) { + if (inventory instanceof TradeStation) + if (!((TradeStation) inventory).canReceivePayment()) { setErrorState(EnumErrorCode.NOSPACE); return; } - } setErrorState(EnumErrorCode.OK); } /* STATE INFORMATION */ - public boolean isLinked() { - return address.isValid(); + return address.isValid() && getErrorState() != EnumErrorCode.NOTALPHANUMERIC && getErrorState() != EnumErrorCode.NOTUNIQUE; } /** @@ -161,7 +173,7 @@ public class MachineTrader extends TileBase implements ISidedInventory { private boolean hasItemCount(int startSlot, int countSlots, ItemStack item, int itemCount) { int count = 0; - IInventory tradeInventory = this.getOrCreateTradeInventory(); + IInventory tradeInventory = this.getInternalInventory(); for (int i = startSlot; i < startSlot + countSlots; i++) { ItemStack itemInSlot = tradeInventory.getStackInSlot(i); if (itemInSlot == null) @@ -183,19 +195,19 @@ public class MachineTrader extends TileBase implements ISidedInventory { int count = 0; int total = 0; - IInventory tradeInventory = this.getOrCreateTradeInventory(); + IInventory tradeInventory = this.getInternalInventory(); for (int i = startSlot; i < startSlot + countSlots; i++) { ItemStack itemInSlot = tradeInventory.getStackInSlot(i); - if (itemInSlot == null) { + if (itemInSlot == null) total += 64; - } else { + else { total += itemInSlot.getMaxStackSize(); if (item == null || StackUtils.isIdenticalItem(itemInSlot, item)) count += itemInSlot.stackSize; } } - return ((float)count / (float)total); + return ((float) count / (float) total); } public boolean hasPaperMin(int count) { @@ -203,7 +215,7 @@ public class MachineTrader extends TileBase implements ISidedInventory { } public boolean hasInputBufMin(float percentage) { - IInventory inventory = getOrCreateTradeInventory(); + IInventory inventory = getInternalInventory(); ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD); if (tradeGood == null) return true; @@ -218,7 +230,7 @@ public class MachineTrader extends TileBase implements ISidedInventory { int posted = 0; - IInventory tradeInventory = this.getOrCreateTradeInventory(); + IInventory tradeInventory = this.getInternalInventory(); for (int i = TradeStation.SLOT_STAMPS_1; i < TradeStation.SLOT_STAMPS_1 + TradeStation.SLOT_STAMPS_COUNT; i++) { ItemStack stamp = tradeInventory.getStackInSlot(i); if (stamp == null) @@ -257,124 +269,20 @@ public class MachineTrader extends TileBase implements ISidedInventory { return; } - this.address = new MailAddress(address); + this.address = address; PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address); setErrorState(EnumErrorCode.OK); - } else - this.address = new MailAddress(address); + } } - /* TRADING */ - public IInventory getOrCreateTradeInventory() { - + @Override + public IInventoryAdapter getInternalInventory() { // Handle client side - if (!Proxies.common.isSimulating(worldObj)) - return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV"); - - if (!address.isValid()) - return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV"); - - return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address); - } - - /* ISIDEDINVENTORY */ - - /** - * TODO: just a specialsource workaround - */ - @Override - protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return super.canTakeStackFromSide(slotIndex, itemstack, side); - } - - /** - * TODO: just a specialsource workaround - */ - @Override - protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) { - return super.canPutStackFromSide(slotIndex, itemstack, side); - } - - /* ISIDEDINVENTORY */ - @Override - public int getSizeInventory() { - return getOrCreateTradeInventory().getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int i) { - return getOrCreateTradeInventory().getStackInSlot(i); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return getOrCreateTradeInventory().decrStackSize(i, j); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - getOrCreateTradeInventory().setInventorySlotContents(i, itemstack); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return getOrCreateTradeInventory().getStackInSlotOnClosing(slot); - } - - @Override - public void markDirty() { - getOrCreateTradeInventory().markDirty(); - } - - @Override - public int getInventoryStackLimit() { - return getOrCreateTradeInventory().getInventoryStackLimit(); - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean hasCustomInventoryName() { - return getOrCreateTradeInventory().hasCustomInventoryName(); - } - - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { - return getOrCreateTradeInventory().isItemValidForSlot(slotIndex, itemstack); - } - - @Override - public boolean canInsertItem(int i, ItemStack itemstack, int j) { - IInventory inventory = getOrCreateTradeInventory(); - if (inventory instanceof TradeStation) - return ((TradeStation)getOrCreateTradeInventory()).canInsertItem(i, itemstack, j); - return super.canInsertItem(i, itemstack, j); - } - - @Override - public boolean canExtractItem(int i, ItemStack itemstack, int j) { - IInventory inventory = getOrCreateTradeInventory(); - if (inventory instanceof TradeStation) { - boolean permission = (getAccess() == EnumAccess.SHARED); - return ((TradeStation) getOrCreateTradeInventory()).canExtractItem(i, itemstack, j, permission); + if (!Proxies.common.isSimulating(worldObj) || !address.isValid()) { + return super.getInternalInventory(); } - return super.canExtractItem(i, itemstack, j); - } - @Override - public int[] getAccessibleSlotsFromSide(int side) { - IInventory inventory = getOrCreateTradeInventory(); - if (inventory instanceof TradeStation) { - boolean permission = (getAccess() == EnumAccess.SHARED); - return ((TradeStation) getOrCreateTradeInventory()).getAccessibleSlotsFromSide(side, permission); - } - return super.getAccessibleSlotsFromSide(side); + return (TradeStation)PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address); } /* ITRIGGERPROVIDER */ @@ -382,15 +290,14 @@ public class MachineTrader extends TileBase implements ISidedInventory { @Override public Collection getExternalTriggers(ForgeDirection side, TileEntity tile) { LinkedList res = new LinkedList(); - res.add(PluginMail.lowPaper64); - res.add(PluginMail.lowPaper32); - res.add(PluginMail.lowInput25); - res.add(PluginMail.lowInput10); - res.add(PluginMail.lowPostage40); - res.add(PluginMail.lowPostage20); - res.add(PluginMail.highBuffer90); - res.add(PluginMail.highBuffer75); + res.add(MailTriggers.lowPaper64); + res.add(MailTriggers.lowPaper32); + res.add(MailTriggers.lowInput25); + res.add(MailTriggers.lowInput10); + res.add(MailTriggers.lowPostage40); + res.add(MailTriggers.lowPostage20); + res.add(MailTriggers.highBuffer90); + res.add(MailTriggers.highBuffer75); return res; } - } diff --git a/src/main/java/forestry/mail/gui/ContainerCatalogue.java b/src/main/java/forestry/mail/gui/ContainerCatalogue.java index 4d6728c2c..344c9b1d8 100755 --- a/src/main/java/forestry/mail/gui/ContainerCatalogue.java +++ b/src/main/java/forestry/mail/gui/ContainerCatalogue.java @@ -10,13 +10,21 @@ ******************************************************************************/ package forestry.mail.gui; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Set; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; + import forestry.api.mail.EnumAddressee; import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostalState; import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; -import forestry.core.gui.ContainerForestry; import forestry.core.gui.IGuiSelectable; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; @@ -24,15 +32,8 @@ import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; import forestry.mail.EnumStationState; import forestry.mail.network.PacketLetterInfo; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ICrafting; -import java.util.EnumSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Set; - -public class ContainerCatalogue extends ContainerForestry implements IGuiSelectable { +public class ContainerCatalogue extends Container implements IGuiSelectable { private final EntityPlayer player; private final LinkedHashMap stations; @@ -54,7 +55,6 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta }; public ContainerCatalogue(EntityPlayer player) { - super(player.inventory); this.player = player; // Filter out any trade stations which do not actually offer anything. @@ -228,6 +228,11 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta } } + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + @Override public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) { diff --git a/src/main/java/forestry/mail/gui/ContainerLetter.java b/src/main/java/forestry/mail/gui/ContainerLetter.java index 679ce4f37..da9a6555e 100755 --- a/src/main/java/forestry/mail/gui/ContainerLetter.java +++ b/src/main/java/forestry/mail/gui/ContainerLetter.java @@ -13,24 +13,24 @@ package forestry.mail.gui; import java.util.Iterator; import java.util.UUID; -import org.apache.commons.lang3.StringUtils; - -import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; +import com.mojang.authlib.GameProfile; + +import org.apache.commons.lang3.StringUtils; + +import forestry.api.mail.EnumAddressee; import forestry.api.mail.ILetter; +import forestry.api.mail.IMailAddress; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; -import forestry.api.mail.IMailAddress; import forestry.api.mail.PostManager; import forestry.api.mail.TradeStationInfo; -import forestry.api.mail.EnumAddressee; import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; @@ -38,7 +38,6 @@ import forestry.core.proxy.Proxies; import forestry.mail.Letter; import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemLetter.LetterInventory; -import forestry.mail.items.ItemStamps; import forestry.mail.network.PacketLetterInfo; public class ContainerLetter extends ContainerItemInventory { @@ -58,23 +57,15 @@ public class ContainerLetter extends ContainerItemInventory { inventory.parent.setItemDamage(ItemLetter.encodeMeta(2, ItemLetter.getSize(inventory.parent.getItemDamage()))); // Init slots - Object[] validStamps = new Object[] { ItemStamps.class }; - if (letterInventory.getLetter().isProcessed()) - validStamps = new Object[] {}; // Stamps for (int i = 0; i < 4; i++) - addSlot(new SlotCustom(inventory, Letter.SLOT_POSTAGE_1 + i, 150, 14 + i * 19, validStamps).setStackLimit(1)); + addSlotToContainer(new SlotFiltered(inventory, Letter.SLOT_POSTAGE_1 + i, 150, 14 + i * 19).setStackLimit(1)); // Attachments - if (!letterInventory.getLetter().isProcessed()) - for (int i = 0; i < 2; i++) - for (int j = 0; j < 9; j++) - addSlot(new SlotCustom(inventory, Letter.SLOT_ATTACHMENT_1 + j + i * 9, 17 + j * 18, 98 + i * 18, ItemLetter.class).setExclusion(true)); - else - for (int i = 0; i < 2; i++) - for (int j = 0; j < 9; j++) - addSlot(new SlotClosed(inventory, Letter.SLOT_ATTACHMENT_1 + j + i * 9, 17 + j * 18, 98 + i * 18)); + for (int i = 0; i < 2; i++) + for (int j = 0; j < 9; j++) + addSlotToContainer(new SlotFiltered(inventory, Letter.SLOT_ATTACHMENT_1 + j + i * 9, 17 + j * 18, 98 + i * 18)); // Player inventory for (int i = 0; i < 3; i++) @@ -105,11 +96,6 @@ public class ContainerLetter extends ContainerItemInventory { super.onContainerClosed(entityplayer); } - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - return true; - } - public ILetter getLetter() { return letterInventory.getLetter(); } @@ -129,7 +115,7 @@ public class ContainerLetter extends ContainerItemInventory { break; } - IPostalCarrier postal = null; + IPostalCarrier postal; if(it.hasNext()) postal = it.next(); else @@ -171,7 +157,8 @@ public class ContainerLetter extends ContainerItemInventory { getLetter().setRecipient(recipient); // Update the trading info - updateTradeInfo(player.worldObj, recipient); + if (recipient == null || recipient.isTrader()) + updateTradeInfo(player.worldObj, recipient); // Update info on client Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, type, tradeInfo, recipient), player); @@ -210,12 +197,16 @@ public class ContainerLetter extends ContainerItemInventory { if (!Proxies.common.isSimulating(world)) return; - if (address.isPlayer()) + if (address == null) { + setTradeInfo(null); return; + } ITradeStation station = PostManager.postRegistry.getTradeStation(world, address); - if (station == null) + if (station == null) { + setTradeInfo(null); return; + } setTradeInfo(station.getTradeInfo()); } @@ -235,5 +226,9 @@ public class ContainerLetter extends ContainerItemInventory { private void setTradeInfo(TradeStationInfo info) { this.tradeInfo = info; + if (tradeInfo == null) + getLetter().setRecipient(null); + else + getLetter().setRecipient(tradeInfo.address); } } diff --git a/src/main/java/forestry/mail/gui/ContainerMailbox.java b/src/main/java/forestry/mail/gui/ContainerMailbox.java index b9d30631d..0fdf59bf3 100755 --- a/src/main/java/forestry/mail/gui/ContainerMailbox.java +++ b/src/main/java/forestry/mail/gui/ContainerMailbox.java @@ -10,20 +10,21 @@ ******************************************************************************/ package forestry.mail.gui; -import forestry.api.mail.IMailAddress; -import forestry.api.mail.PostManager; -import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.proxy.Proxies; -import forestry.mail.POBox; -import forestry.mail.gadgets.MachineMailbox; -import forestry.plugins.PluginMail; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.PostManager; +import forestry.core.gui.ContainerForestry; +import forestry.core.gui.slots.SlotOutput; +import forestry.core.proxy.Proxies; +import forestry.mail.POBox; +import forestry.mail.gadgets.MachineMailbox; +import forestry.plugins.PluginMail; + public class ContainerMailbox extends ContainerForestry { public static final short SLOT_LETTERS = 0; @@ -34,27 +35,27 @@ public class ContainerMailbox extends ContainerForestry { public ContainerMailbox(InventoryPlayer player, MachineMailbox tile) { super(tile); + IInventory inventory = tile.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile()); // Mailbox contents this.mailbox = tile; - IInventory inv = mailbox.getOrCreateMailInventory(player.player.worldObj, player.player.getGameProfile()); - if (inv instanceof POBox) - this.mailInventory = (POBox) inv; + if (inventory instanceof POBox) + this.mailInventory = (POBox) inventory; else this.mailInventory = null; for (int i = 0; i < 7; i++) for (int j = 0; j < 12; j++) - addSlot(new SlotClosed(inv, j + i * 9, 8 + j * 18, 8 + i * 18)); + addSlotToContainer(new SlotOutput(inventory, j + i * 9, 8 + j * 18, 8 + i * 18)); // Player inventory for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new Slot(player, j + i * 9 + 9, 35 + j * 18, 145 + i * 18)); + addSlotToContainer(new Slot(player, j + i * 9 + 9, 35 + j * 18, 145 + i * 18)); // Player hotbar for (int i = 0; i < 9; i++) - addSlot(new Slot(player, i, 35 + i * 18, 203)); + addSlotToContainer(new Slot(player, i, 35 + i * 18, 203)); } diff --git a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java index ed4b671f3..5adf0b062 100755 --- a/src/main/java/forestry/mail/gui/ContainerPhilatelist.java +++ b/src/main/java/forestry/mail/gui/ContainerPhilatelist.java @@ -14,10 +14,9 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotClosed; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotOutput; import forestry.mail.gadgets.MachinePhilatelist; -import forestry.mail.items.ItemStamps; public class ContainerPhilatelist extends ContainerForestry { @@ -25,20 +24,20 @@ public class ContainerPhilatelist extends ContainerForestry { super(tile); // Filter - addSlot(new SlotCustom(tile, MachinePhilatelist.SLOT_FILTER, 80, 19, ItemStamps.class)); + addSlotToContainer(new SlotFiltered(tile, MachinePhilatelist.SLOT_FILTER, 80, 19)); // Collected Stamps for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new SlotClosed(tile, j + i * 9 + MachinePhilatelist.SLOT_BUFFER_1, 8 + j * 18, 46 + i * 18)); + addSlotToContainer(new SlotOutput(tile, j + i * 9 + MachinePhilatelist.SLOT_BUFFER_1, 8 + j * 18, 46 + i * 18)); // Player inventory for (int i = 0; i < 3; i++) for (int j = 0; j < 9; j++) - addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 111 + i * 18)); + addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 111 + i * 18)); // Player hotbar for (int i = 0; i < 9; i++) - addSlot(new Slot(player, i, 8 + i * 18, 169)); + addSlotToContainer(new Slot(player, i, 8 + i * 18, 169)); } diff --git a/src/main/java/forestry/mail/gui/ContainerTradeName.java b/src/main/java/forestry/mail/gui/ContainerTradeName.java index b97913f2e..85922220c 100755 --- a/src/main/java/forestry/mail/gui/ContainerTradeName.java +++ b/src/main/java/forestry/mail/gui/ContainerTradeName.java @@ -12,28 +12,24 @@ package forestry.mail.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; -import forestry.core.gui.ContainerForestry; +import org.apache.commons.lang3.StringUtils; + +import forestry.api.mail.IMailAddress; +import forestry.api.mail.PostManager; import forestry.core.network.PacketIds; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; -import forestry.core.utils.InventoryAdapter; import forestry.mail.gadgets.MachineTrader; -import forestry.api.mail.PostManager; -import forestry.api.mail.IMailAddress; -import org.apache.commons.lang3.StringUtils; +public class ContainerTradeName extends Container { -public class ContainerTradeName extends ContainerForestry { - - boolean isLinked; - MachineTrader machine; + protected final MachineTrader machine; public ContainerTradeName(InventoryPlayer player, MachineTrader tile) { - super(new InventoryAdapter(0, "Empty")); machine = tile; - isLinked = machine.isLinked(); } public IMailAddress getAddress() { @@ -62,8 +58,7 @@ public class ContainerTradeName extends ContainerForestry { } @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return true; + public boolean canInteractWith(EntityPlayer entityPlayer) { + return machine.isOwner(entityPlayer); } - } diff --git a/src/main/java/forestry/mail/gui/ContainerTrader.java b/src/main/java/forestry/mail/gui/ContainerTrader.java index 18d34328a..eec4eaf5f 100755 --- a/src/main/java/forestry/mail/gui/ContainerTrader.java +++ b/src/main/java/forestry/mail/gui/ContainerTrader.java @@ -10,18 +10,16 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; +import forestry.api.mail.IMailAddress; import forestry.core.gui.ContainerForestry; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.gui.slots.SlotForestry; +import forestry.core.gui.slots.SlotOutput; import forestry.mail.TradeStation; import forestry.mail.gadgets.MachineTrader; -import forestry.mail.items.ItemStamps; -import forestry.api.mail.IMailAddress; public class ContainerTrader extends ContainerForestry { @@ -31,56 +29,59 @@ public class ContainerTrader extends ContainerForestry { super(tile); machine = tile; - IInventory inventory = machine.getOrCreateTradeInventory(); // Trade good - this.addSlot(new Slot(inventory, TradeStation.SLOT_TRADEGOOD, 78, 109)); + this.addSlotToContainer(new SlotForestry(machine, TradeStation.SLOT_TRADEGOOD, 78, 109).blockShift()); // Exchange - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) - addSlot(new Slot(inventory, TradeStation.SLOT_EXCHANGE_1 + j + i * 2, 69 + j * 18, 55 + i * 18)); + for (int row = 0; row < 2; row++) { + for (int col = 0; col < 2; col++) { + addSlotToContainer(new SlotForestry(machine, TradeStation.SLOT_EXCHANGE_1 + col + row * 2, 69 + col * 18, 55 + row * 18).blockShift()); + } + } // Stamps - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) - addSlot(new SlotCustom(inventory, TradeStation.SLOT_STAMPS_1 + j + i * 2, 15 + j * 18, 37 + i * 18, ItemStamps.class)); + for (int row = 0; row < 2; row++) { + for (int col = 0; col < 2; col++) { + addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_STAMPS_1 + col + row * 2, 15 + col * 18, 37 + row * 18)); + } + } // Letters - for (int i = 0; i < 3; i++) - for (int j = 0; j < 2; j++) - addSlot(new SlotCustom(inventory, TradeStation.SLOT_LETTERS_1 + j + i * 2, 15 + j * 18, 73 + i * 18, Items.paper)); + for (int row = 0; row < 3; row++) { + for (int col = 0; col < 2; col++) { + addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_LETTERS_1 + col + row * 2, 15 + col * 18, 73 + row * 18)); + } + } // Buffers final int bufCols = 5; - for (int i = 0; i < 3; i++) - for (int j = 0; j < bufCols; j++) - addSlot(new Slot(inventory, TradeStation.SLOT_RECEIVE_BUFFER + j + i * bufCols, 123 + j * 18, 19 + i * 18)); + for (int row = 0; row < 3; row++) { + for (int col = 0; col < bufCols; col++) { + addSlotToContainer(new SlotOutput(machine, TradeStation.SLOT_RECEIVE_BUFFER + col + row * bufCols, 123 + col * 18, 19 + row * 18)); + } + } - for (int i = 0; i < 2; i++) - for (int j = 0; j < bufCols; j++) - addSlot(new Slot(inventory, TradeStation.SLOT_SEND_BUFFER + j + i * bufCols, 123 + j * 18, (19 + (18 * 4)) + i * 18)); + for (int row = 0; row < 2; row++) { + for (int col = 0; col < bufCols; col++) { + addSlotToContainer(new SlotFiltered(machine, TradeStation.SLOT_SEND_BUFFER + col + row * bufCols, 123 + col * 18, (19 + (18 * 4)) + row * 18)); + } + } // Player inventory - for (int i = 0; i < 3; i++) - for (int j = 0; j < 9; j++) - addSlot(new Slot(player, j + i * 9 + 9, 33 + j * 18, 138 + i * 18)); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 9; j++) { + addSlotToContainer(new Slot(player, j + i * 9 + 9, 33 + j * 18, 138 + i * 18)); + } + } // Player hotbar - for (int i = 0; i < 9; i++) - addSlot(new Slot(player, i, 33 + i * 18, 196)); - - } - - public boolean isLinked() { - return machine.isLinked(); + for (int i = 0; i < 9; i++) { + addSlotToContainer(new Slot(player, i, 33 + i * 18, 196)); + } } public IMailAddress getAddress() { return machine.getAddress(); } - @Override - public boolean canInteractWith(EntityPlayer entityplayer) { - return true; - } } diff --git a/src/main/java/forestry/mail/gui/GuiCatalogue.java b/src/main/java/forestry/mail/gui/GuiCatalogue.java index 4c380ebb1..3e76ef725 100755 --- a/src/main/java/forestry/mail/gui/GuiCatalogue.java +++ b/src/main/java/forestry/mail/gui/GuiCatalogue.java @@ -10,30 +10,36 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.List; +import forestry.api.mail.EnumAddressee; import forestry.api.mail.TradeStationInfo; import forestry.core.config.SessionVars; import forestry.core.gadgets.TileForestry; import forestry.core.gui.GuiForestry; +import forestry.core.gui.widgets.Widget; import forestry.core.utils.StringUtil; -import forestry.api.mail.EnumAddressee; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; public class GuiCatalogue extends GuiForestry { - GuiButton buttonTrade; - GuiButton buttonClose; + private static final String boldUnderline = EnumChatFormatting.BOLD.toString() + EnumChatFormatting.UNDERLINE; - GuiButton buttonFilter; - GuiButton buttonCopy; +// GuiButton buttonTrade; +// GuiButton buttonClose; - ContainerCatalogue container; + private GuiButton buttonFilter; + private GuiButton buttonCopy; + + private final List tradeInfoWidgets = new ArrayList(); + private final ContainerCatalogue container; public GuiCatalogue(EntityPlayer player) { super(new ResourceLocation("textures/gui/book.png"), new ContainerCatalogue(player)); @@ -73,16 +79,14 @@ public class GuiCatalogue extends GuiForestry { fontRendererObj.drawString(String.format("%s / %s", container.getCurrentPos(), container.getMaxCount()), guiLeft + xSize - 72, guiTop + 12, fontColor.get("gui.book")); + clearTradeInfoWidgets(); if(container.getTradeInfo() != null) drawTradePreview(guiLeft + 38, guiTop + 30); else drawNoTrade(guiLeft + 38, guiTop + 30); buttonFilter.displayString = StringUtil.localize("gui.mail.filter." + container.getFilterIdent()); - if(container.getTradeInfo() == null || !container.getTradeInfo().state.isOk()) - buttonCopy.enabled = false; - else - buttonCopy.enabled = true; + buttonCopy.enabled = container.getTradeInfo() != null && container.getTradeInfo().state.isOk(); } private void drawNoTrade(int x, int y) { @@ -91,30 +95,34 @@ public class GuiCatalogue extends GuiForestry { private void drawTradePreview(int x, int y) { - fontRendererObj.drawString("\u00A7l\u00A7n" + container.getTradeInfo().address.getName(), x, y, fontColor.get("gui.book")); + fontRendererObj.drawString(boldUnderline + container.getTradeInfo().address.getName(), x, y, fontColor.get("gui.book")); TradeStationInfo info = container.getTradeInfo(); fontRendererObj.drawString(String.format(StringUtil.localize("gui.mail.willtrade"), info.owner.getName()), x, y + 18, fontColor.get("gui.book")); - itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, info.tradegood, x, y + 28); - itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, info.tradegood, x, y + 28); + addTradeInfoWidget(new ItemStackWidget(x - guiLeft, y - guiTop + 28, info.tradegood)); - GL11.glDisable(GL11.GL_LIGHTING); fontRendererObj.drawString(StringUtil.localize("gui.mail.tradefor"), x, y + 46, fontColor.get("gui.book")); - GL11.glEnable(GL11.GL_LIGHTING); for (int i = 0; i < container.getTradeInfo().required.length; i++) { - GL11.glDisable(GL11.GL_LIGHTING); - itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, info.required[i], x + i * 18, y + 56); - itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, info.required[i], x + i * 18, y + 56); - GL11.glEnable(GL11.GL_LIGHTING); + addTradeInfoWidget(new ItemStackWidget(x - guiLeft + i * 18, y - guiTop + 56, info.required[i])); } - GL11.glDisable(GL11.GL_LIGHTING); if(info.state.isOk()) - fontRendererObj.drawSplitString("\u00A72" + StringUtil.localize("chat.mail." + info.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book")); + fontRendererObj.drawSplitString(EnumChatFormatting.DARK_GREEN + StringUtil.localize("chat.mail." + info.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book")); else - fontRendererObj.drawSplitString("\u00A74" + StringUtil.localize("chat.mail." + info.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book")); - GL11.glEnable(GL11.GL_LIGHTING); + fontRendererObj.drawSplitString(EnumChatFormatting.DARK_RED + StringUtil.localize("chat.mail." + info.state.getIdentifier()), x, y + 82, 119, fontColor.get("gui.book")); + } + + private void addTradeInfoWidget(ItemStackWidget widget) { + tradeInfoWidgets.add(widget); + widgetManager.add(widget); + } + + private void clearTradeInfoWidgets() { + for (Widget widget : tradeInfoWidgets) { + widgetManager.remove(widget); + } + tradeInfoWidgets.clear(); } @Override diff --git a/src/main/java/forestry/mail/gui/GuiLetter.java b/src/main/java/forestry/mail/gui/GuiLetter.java index 25fd670d9..67b519b15 100755 --- a/src/main/java/forestry/mail/gui/GuiLetter.java +++ b/src/main/java/forestry/mail/gui/GuiLetter.java @@ -10,17 +10,9 @@ ******************************************************************************/ package forestry.mail.gui; -import java.util.ArrayList; - -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.entity.player.EntityPlayer; - -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import forestry.api.mail.IPostalCarrier; +import forestry.api.mail.EnumAddressee; import forestry.api.mail.IMailAddress; +import forestry.api.mail.IPostalCarrier; import forestry.api.mail.PostManager; import forestry.core.config.Defaults; import forestry.core.config.SessionVars; @@ -30,8 +22,13 @@ import forestry.core.gui.GuiTextBox; import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.utils.StringUtil; -import forestry.api.mail.EnumAddressee; import forestry.mail.items.ItemLetter.LetterInventory; +import java.util.ArrayList; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import org.apache.commons.lang3.StringUtils; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; public class GuiLetter extends GuiForestry { @@ -73,11 +70,10 @@ public class GuiLetter extends GuiForestry { private GuiTextField address; private GuiTextBox text; - boolean addressFocus; - boolean textFocus; - - protected final ArrayList tradeInfoWidgets; + private boolean addressFocus; + private boolean textFocus; + private final ArrayList tradeInfoWidgets; private final ContainerLetter container; public GuiLetter(EntityPlayer player, LetterInventory inventory) { @@ -154,6 +150,9 @@ public class GuiLetter extends GuiForestry { if(!isProcessedLetter && !checkedSessionVars) { checkedSessionVars = true; setFromSessionVars(); + String recipient = this.address.getText(); + EnumAddressee recipientType = container.getCarrierType(); + setRecipient(recipient, recipientType); } // Check for focus changes @@ -217,8 +216,10 @@ public class GuiLetter extends GuiForestry { } private void clearTradeInfoWidgets() { - for (Widget widget : tradeInfoWidgets) + for (Widget widget : tradeInfoWidgets) { widgetManager.remove(widget); + } + tradeInfoWidgets.clear(); } @Override @@ -247,7 +248,7 @@ public class GuiLetter extends GuiForestry { address.setText(recipient); EnumAddressee type = EnumAddressee.fromString(typeName); - setRecipient(recipient, type); + container.setCarrierType(type); } SessionVars.clearStringVar("mail.letter.recipient"); diff --git a/src/main/java/forestry/mail/gui/GuiMailbox.java b/src/main/java/forestry/mail/gui/GuiMailbox.java index 7a4682458..100e317a4 100755 --- a/src/main/java/forestry/mail/gui/GuiMailbox.java +++ b/src/main/java/forestry/mail/gui/GuiMailbox.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; import forestry.mail.gadgets.MachineMailbox; +import net.minecraft.entity.player.InventoryPlayer; public class GuiMailbox extends GuiForestry { diff --git a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java index d46c0f8de..612e37025 100755 --- a/src/main/java/forestry/mail/gui/GuiMailboxInfo.java +++ b/src/main/java/forestry/mail/gui/GuiMailboxInfo.java @@ -10,17 +10,15 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.proxy.Proxies; import forestry.core.utils.ForestryResource; import forestry.mail.POBoxInfo; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; public class GuiMailboxInfo extends Gui { diff --git a/src/main/java/forestry/mail/gui/GuiPhilatelist.java b/src/main/java/forestry/mail/gui/GuiPhilatelist.java index d02767d61..3b0a05445 100755 --- a/src/main/java/forestry/mail/gui/GuiPhilatelist.java +++ b/src/main/java/forestry/mail/gui/GuiPhilatelist.java @@ -10,11 +10,10 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; import forestry.mail.gadgets.MachinePhilatelist; +import net.minecraft.entity.player.InventoryPlayer; public class GuiPhilatelist extends GuiForestry { diff --git a/src/main/java/forestry/mail/gui/GuiTradeName.java b/src/main/java/forestry/mail/gui/GuiTradeName.java index d660bc1ca..d8e8f4b47 100755 --- a/src/main/java/forestry/mail/gui/GuiTradeName.java +++ b/src/main/java/forestry/mail/gui/GuiTradeName.java @@ -10,17 +10,14 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.entity.player.InventoryPlayer; - -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.input.Keyboard; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; import forestry.core.utils.StringUtil; import forestry.mail.gadgets.MachineTrader; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.InventoryPlayer; +import org.apache.commons.lang3.StringUtils; +import org.lwjgl.input.Keyboard; public class GuiTradeName extends GuiForestry { diff --git a/src/main/java/forestry/mail/gui/GuiTrader.java b/src/main/java/forestry/mail/gui/GuiTrader.java index 5e9999436..c021cfb8c 100755 --- a/src/main/java/forestry/mail/gui/GuiTrader.java +++ b/src/main/java/forestry/mail/gui/GuiTrader.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.mail.gui; -import net.minecraft.entity.player.InventoryPlayer; - import forestry.core.config.Defaults; import forestry.core.gui.GuiForestry; import forestry.core.utils.StringUtil; import forestry.mail.gadgets.MachineTrader; +import net.minecraft.entity.player.InventoryPlayer; public class GuiTrader extends GuiForestry { diff --git a/src/main/java/forestry/mail/items/ItemCatalogue.java b/src/main/java/forestry/mail/items/ItemCatalogue.java index 9140f005e..a670049d5 100755 --- a/src/main/java/forestry/mail/items/ItemCatalogue.java +++ b/src/main/java/forestry/mail/items/ItemCatalogue.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.mail.items; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import forestry.api.core.ForestryAPI; import forestry.core.items.ItemForestry; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public class ItemCatalogue extends ItemForestry { diff --git a/src/main/java/forestry/mail/items/ItemLetter.java b/src/main/java/forestry/mail/items/ItemLetter.java index d143399e1..a616492f0 100755 --- a/src/main/java/forestry/mail/items/ItemLetter.java +++ b/src/main/java/forestry/mail/items/ItemLetter.java @@ -14,6 +14,7 @@ import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; @@ -25,15 +26,17 @@ import cpw.mods.fml.relauncher.SideOnly; import forestry.api.core.ForestryAPI; import forestry.api.mail.ILetter; -import forestry.api.core.EnumErrorCode; +import forestry.core.EnumErrorCode; import forestry.core.config.Config; +import forestry.core.config.ForestryItem; import forestry.core.interfaces.IErrorSource; import forestry.core.interfaces.IHintSource; +import forestry.core.inventory.ItemInventory; import forestry.core.items.ItemInventoried; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; -import forestry.core.utils.ItemInventory; +import forestry.core.utils.GuiUtil; import forestry.core.utils.StringUtil; import forestry.mail.Letter; @@ -44,9 +47,7 @@ public class ItemLetter extends ItemInventoried { ILetter letter; public LetterInventory(ItemStack itemstack) { - super(ItemLetter.class); - this.parent = itemstack; - this.isItemInventory = true; + super(ItemLetter.class, 0, itemstack); // Set an uid to identify the itemstack on SMP setUID(true); @@ -135,19 +136,24 @@ public class ItemLetter extends ItemInventoried { return letter.isUseableByPlayer(entityplayer); } - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - @Override public ItemStack getStackInSlotOnClosing(int slot) { return letter.getStackInSlotOnClosing(slot); } + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + if (letter.isProcessed()) { + return false; + } else if (GuiUtil.isIndexInRange(slotIndex, Letter.SLOT_POSTAGE_1, Letter.SLOT_POSTAGE_COUNT)) { + Item item = itemStack.getItem(); + return item instanceof ItemStamps; + } else if (GuiUtil.isIndexInRange(slotIndex, Letter.SLOT_ATTACHMENT_1, Letter.SLOT_ATTACHMENT_COUNT)) { + return !ForestryItem.letters.isItemEqual(itemStack); + } + return false; + } + // / IERRORSOURCE @Override public boolean throwsErrors() { @@ -231,10 +237,6 @@ public class ItemLetter extends ItemInventoried { public static int encodeMeta(int state, int size) { int meta = size << 4; meta |= state; - - size = getSize(meta); - state = getState(meta); - return meta; } diff --git a/src/main/java/forestry/mail/items/ItemStamps.java b/src/main/java/forestry/mail/items/ItemStamps.java index 0315d5f81..f4029c064 100755 --- a/src/main/java/forestry/mail/items/ItemStamps.java +++ b/src/main/java/forestry/mail/items/ItemStamps.java @@ -10,13 +10,11 @@ ******************************************************************************/ package forestry.mail.items; -import net.minecraft.item.ItemStack; - import forestry.api.mail.EnumPostage; import forestry.api.mail.IStamps; import forestry.core.CreativeTabForestry; import forestry.core.items.ItemOverlay; -import forestry.core.utils.StringUtil; +import net.minecraft.item.ItemStack; public class ItemStamps extends ItemOverlay implements IStamps { diff --git a/src/main/java/forestry/mail/network/PacketLetterInfo.java b/src/main/java/forestry/mail/network/PacketLetterInfo.java index 857939524..92348d8e7 100644 --- a/src/main/java/forestry/mail/network/PacketLetterInfo.java +++ b/src/main/java/forestry/mail/network/PacketLetterInfo.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.mail.network; +import com.mojang.authlib.GameProfile; +import forestry.api.mail.EnumAddressee; +import forestry.api.mail.IMailAddress; +import forestry.api.mail.PostManager; +import forestry.api.mail.TradeStationInfo; +import forestry.core.network.ForestryPacket; +import forestry.mail.EnumStationState; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.UUID; - import net.minecraft.item.ItemStack; -import com.mojang.authlib.GameProfile; - -import forestry.api.mail.TradeStationInfo; -import forestry.api.mail.IMailAddress; -import forestry.api.mail.EnumAddressee; -import forestry.api.mail.PostManager; -import forestry.core.network.ForestryPacket; -import forestry.mail.EnumStationState; public class PacketLetterInfo extends ForestryPacket { diff --git a/src/main/java/forestry/mail/network/PacketPOBoxInfo.java b/src/main/java/forestry/mail/network/PacketPOBoxInfo.java index 2a8f22e1d..008fb6942 100755 --- a/src/main/java/forestry/mail/network/PacketPOBoxInfo.java +++ b/src/main/java/forestry/mail/network/PacketPOBoxInfo.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.mail.network; +import forestry.core.network.ForestryPacket; +import forestry.mail.POBoxInfo; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import forestry.core.network.ForestryPacket; -import forestry.mail.POBoxInfo; - public class PacketPOBoxInfo extends ForestryPacket { public POBoxInfo poboxInfo; diff --git a/src/main/java/forestry/mail/proxy/ProxyMail.java b/src/main/java/forestry/mail/proxy/ProxyMail.java index acb3221c5..53586dd28 100755 --- a/src/main/java/forestry/mail/proxy/ProxyMail.java +++ b/src/main/java/forestry/mail/proxy/ProxyMail.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.mail.proxy; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - +import forestry.api.mail.IMailAddress; import forestry.core.network.PacketIds; import forestry.core.proxy.Proxies; import forestry.mail.POBoxInfo; import forestry.mail.network.PacketPOBoxInfo; -import forestry.api.mail.IMailAddress; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; public class ProxyMail { diff --git a/src/main/java/forestry/mail/triggers/MailTriggers.java b/src/main/java/forestry/mail/triggers/MailTriggers.java new file mode 100644 index 000000000..aa57d1d73 --- /dev/null +++ b/src/main/java/forestry/mail/triggers/MailTriggers.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.mail.triggers; + +import forestry.core.triggers.Trigger; + +public class MailTriggers { + public static Trigger triggerHasMail; + public static Trigger lowPaper64; + public static Trigger lowPaper32; + public static Trigger lowPostage40; + public static Trigger lowPostage20; + public static Trigger lowInput25; + public static Trigger lowInput10; + public static Trigger highBuffer75; + public static Trigger highBuffer90; + + public static void initialize() { + triggerHasMail = new TriggerHasMail(); + lowPaper64 = new TriggerLowPaper("mail.lowPaper.64", 64); + lowPaper32 = new TriggerLowPaper("mail.lowPaper.32", 32); + lowPostage40 = new TriggerLowStamps("mail.lowStamps.40", 40); + lowPostage20 = new TriggerLowStamps("mail.lowStamps.20", 20); + lowInput25 = new TriggerLowInput("mail.lowInput.25", 0.25f); + lowInput10 = new TriggerLowInput("mail.lowInput.10", 0.1f); + highBuffer75 = new TriggerBuffer("mail.lowBuffer.75", 0.75f); + highBuffer90 = new TriggerBuffer("mail.lowBuffer.90", 0.90f); + } +} diff --git a/src/main/java/forestry/pipes/EnumFilterType.java b/src/main/java/forestry/pipes/EnumFilterType.java index 677a4aca9..863367b5d 100755 --- a/src/main/java/forestry/pipes/EnumFilterType.java +++ b/src/main/java/forestry/pipes/EnumFilterType.java @@ -7,14 +7,13 @@ ******************************************************************************/ package forestry.pipes; -import java.util.Locale; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.core.config.ForestryItem; import forestry.core.render.TextureManager; +import java.util.Locale; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; public enum EnumFilterType { diff --git a/src/main/java/forestry/pipes/GuiHandlerPipes.java b/src/main/java/forestry/pipes/GuiHandlerPipes.java index 938319638..d8cf9d0df 100755 --- a/src/main/java/forestry/pipes/GuiHandlerPipes.java +++ b/src/main/java/forestry/pipes/GuiHandlerPipes.java @@ -7,9 +7,6 @@ ******************************************************************************/ package forestry.pipes; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import buildcraft.transport.Pipe; import buildcraft.transport.TileGenericPipe; import cpw.mods.fml.common.network.IGuiHandler; @@ -17,6 +14,9 @@ import forestry.core.network.GuiId; import forestry.pipes.gui.ContainerPropolisPipe; import forestry.pipes.gui.GuiPropolisPipe; import forestry.plugins.PluginApiculture; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; public class GuiHandlerPipes implements IGuiHandler { diff --git a/src/main/java/forestry/pipes/PipeIconProvider.java b/src/main/java/forestry/pipes/PipeIconProvider.java index bd5de5aac..088050708 100755 --- a/src/main/java/forestry/pipes/PipeIconProvider.java +++ b/src/main/java/forestry/pipes/PipeIconProvider.java @@ -7,12 +7,12 @@ ******************************************************************************/ package forestry.pipes; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.util.IIcon; import buildcraft.api.core.IIconProvider; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import forestry.core.render.TextureManager; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.util.IIcon; public class PipeIconProvider implements IIconProvider { diff --git a/src/main/java/forestry/pipes/PipeItemsPropolis.java b/src/main/java/forestry/pipes/PipeItemsPropolis.java index b223e3b94..c77c59175 100755 --- a/src/main/java/forestry/pipes/PipeItemsPropolis.java +++ b/src/main/java/forestry/pipes/PipeItemsPropolis.java @@ -7,14 +7,6 @@ ******************************************************************************/ package forestry.pipes; -import java.util.ArrayList; -import java.util.LinkedList; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.IIconProvider; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.Pipe; @@ -29,6 +21,13 @@ import forestry.api.genetics.IAllele; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; import forestry.plugins.PluginApiculture; +import java.util.ArrayList; +import java.util.LinkedList; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; public class PipeItemsPropolis extends Pipe { @@ -147,7 +146,7 @@ public class PipeItemsPropolis extends Pipe { // A bit of speed to perhaps prevent bees from popping out of the pipe. try { event.item.setSpeed(TransportConstants.PIPE_NORMAL_SPEED * 20F); - } catch (Throwable error) { + } catch (Throwable ignored) { } } diff --git a/src/main/java/forestry/pipes/PipeLogicPropolis.java b/src/main/java/forestry/pipes/PipeLogicPropolis.java index a051d89fd..7a5dc9cd6 100755 --- a/src/main/java/forestry/pipes/PipeLogicPropolis.java +++ b/src/main/java/forestry/pipes/PipeLogicPropolis.java @@ -7,27 +7,22 @@ ******************************************************************************/ package forestry.pipes; -import java.util.ArrayList; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.Pipe; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.IBee; -import forestry.api.core.ForestryAPI; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; -import forestry.core.network.GuiId; import forestry.core.network.PacketCoordinates; import forestry.core.network.PacketIds; import forestry.core.network.PacketNBT; import forestry.core.network.PacketPayload; import forestry.core.network.PacketUpdate; import forestry.core.proxy.Proxies; +import java.util.ArrayList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; public class PipeLogicPropolis { @@ -86,19 +81,19 @@ public class PipeLogicPropolis { // Special bee filtering if (bee != null) { if (filter == EnumFilterType.PURE_BREED) - return bee.isPureBred(EnumBeeChromosome.SPECIES.ordinal()); + return bee.isPureBred(EnumBeeChromosome.SPECIES); if (filter == EnumFilterType.NOCTURNAL) return bee.getGenome().getNocturnal(); if (filter == EnumFilterType.PURE_NOCTURNAL) - return bee.getGenome().getNocturnal() && bee.isPureBred(EnumBeeChromosome.NOCTURNAL.ordinal()); + return bee.getGenome().getNocturnal() && bee.isPureBred(EnumBeeChromosome.NOCTURNAL); if (filter == EnumFilterType.FLYER) return bee.getGenome().getTolerantFlyer(); if (filter == EnumFilterType.PURE_FLYER) - return bee.getGenome().getTolerantFlyer() && bee.isPureBred(EnumBeeChromosome.TOLERANT_FLYER.ordinal()); + return bee.getGenome().getTolerantFlyer() && bee.isPureBred(EnumBeeChromosome.TOLERANT_FLYER); if (filter == EnumFilterType.CAVE) return bee.getGenome().getCaveDwelling(); if (filter == EnumFilterType.PURE_CAVE) - return bee.getGenome().getCaveDwelling() && bee.isPureBred(EnumBeeChromosome.CAVE_DWELLING.ordinal()); + return bee.getGenome().getCaveDwelling() && bee.isPureBred(EnumBeeChromosome.CAVE_DWELLING); if (filter == EnumFilterType.NATURAL) return bee.isNatural(); } diff --git a/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java b/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java index 165d9c609..35f27da81 100755 --- a/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java +++ b/src/main/java/forestry/pipes/gui/ContainerPropolisPipe.java @@ -6,39 +6,36 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package forestry.pipes.gui; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; -import buildcraft.transport.Pipe; -import forestry.core.gui.ContainerForestry; -import forestry.core.utils.InventoryAdapter; + import forestry.pipes.PipeItemsPropolis; import forestry.pipes.PipeLogicPropolis; -public class ContainerPropolisPipe extends ContainerForestry { +public class ContainerPropolisPipe extends Container { - IInventory playerIInventory; - public PipeLogicPropolis pipeLogic; + public final PipeLogicPropolis pipeLogic; public ContainerPropolisPipe(IInventory playerInventory, PipeItemsPropolis pipe) { - super(new InventoryAdapter(0, "Empty")); - this.playerIInventory = playerInventory; this.pipeLogic = pipe.pipeLogic; - for (int l = 0; l < 3; l++) - for (int k1 = 0; k1 < 9; k1++) - addSlot(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 140 + l * 18)); + for (int l = 0; l < 3; l++) { + for (int k1 = 0; k1 < 9; k1++) { + addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 140 + l * 18)); + } + } - for (int i1 = 0; i1 < 9; i1++) - addSlot(new Slot(playerInventory, i1, 8 + i1 * 18, 198)); + for (int i1 = 0; i1 < 9; i1++) { + addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 198)); + } } @Override - public boolean canInteractWith(EntityPlayer entityplayer) { + public boolean canInteractWith(EntityPlayer p_75145_1_) { return true; } - } diff --git a/src/main/java/forestry/pipes/gui/GuiPropolisPipe.java b/src/main/java/forestry/pipes/gui/GuiPropolisPipe.java index f133b482e..3dbdd2c1a 100755 --- a/src/main/java/forestry/pipes/gui/GuiPropolisPipe.java +++ b/src/main/java/forestry/pipes/gui/GuiPropolisPipe.java @@ -7,16 +7,6 @@ ******************************************************************************/ package forestry.pipes.gui; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map.Entry; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -import org.lwjgl.opengl.GL11; - import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IApiaristTracker; import forestry.api.genetics.AlleleManager; @@ -28,8 +18,8 @@ import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; import forestry.core.gadgets.TileForestry; import forestry.core.genetics.ItemGE; -import forestry.core.gui.widgets.Widget; import forestry.core.gui.GuiForestry; +import forestry.core.gui.widgets.Widget; import forestry.core.proxy.Proxies; import forestry.core.render.SpriteSheet; import forestry.core.utils.StringUtil; @@ -37,6 +27,13 @@ import forestry.pipes.EnumFilterType; import forestry.pipes.PipeItemsPropolis; import forestry.pipes.PipeLogicPropolis; import forestry.plugins.PluginApiculture; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map.Entry; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.opengl.GL11; /** * GuiScreen for propolis pipes. diff --git a/src/main/java/forestry/pipes/network/PacketHandlerPipes.java b/src/main/java/forestry/pipes/network/PacketHandlerPipes.java index 8d08d8d57..bbd0ace57 100755 --- a/src/main/java/forestry/pipes/network/PacketHandlerPipes.java +++ b/src/main/java/forestry/pipes/network/PacketHandlerPipes.java @@ -7,12 +7,6 @@ ******************************************************************************/ package forestry.pipes.network; -import java.io.DataInputStream; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import buildcraft.transport.Pipe; import buildcraft.transport.TileGenericPipe; import forestry.core.interfaces.IPacketHandler; @@ -24,6 +18,11 @@ import forestry.core.proxy.Proxies; import forestry.pipes.PipeItemsPropolis; import forestry.pipes.PipeLogicPropolis; import forestry.pipes.gui.ContainerPropolisPipe; +import java.io.DataInputStream; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; public class PacketHandlerPipes implements IPacketHandler { diff --git a/src/main/java/forestry/pipes/proxy/ClientProxyPipes.java b/src/main/java/forestry/pipes/proxy/ClientProxyPipes.java index b2996274a..f66305bb1 100755 --- a/src/main/java/forestry/pipes/proxy/ClientProxyPipes.java +++ b/src/main/java/forestry/pipes/proxy/ClientProxyPipes.java @@ -7,11 +7,11 @@ ******************************************************************************/ package forestry.pipes.proxy; +import buildcraft.transport.TransportProxyClient; +import forestry.plugins.PluginPropolisPipe; import net.minecraft.item.Item; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; -import buildcraft.transport.TransportProxyClient; -import forestry.plugins.PluginPropolisPipe; public class ClientProxyPipes extends ProxyPipes { diff --git a/src/main/java/forestry/pipes/proxy/ProxyPipes.java b/src/main/java/forestry/pipes/proxy/ProxyPipes.java index 1c6f1a424..3024428fb 100755 --- a/src/main/java/forestry/pipes/proxy/ProxyPipes.java +++ b/src/main/java/forestry/pipes/proxy/ProxyPipes.java @@ -7,11 +7,6 @@ ******************************************************************************/ package forestry.pipes.proxy; -import java.lang.reflect.Constructor; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.client.IItemRenderer; import buildcraft.BuildCraftTransport; import buildcraft.core.CreativeTabBuildCraft; import buildcraft.transport.BlockGenericPipe; @@ -21,6 +16,10 @@ import buildcraft.transport.TransportProxy; import cpw.mods.fml.common.registry.GameRegistry; import forestry.pipes.PipeItemsPropolis; import forestry.plugins.PluginPropolisPipe; +import java.lang.reflect.Constructor; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.IItemRenderer; public class ProxyPipes { diff --git a/src/main/java/forestry/plugins/ForestryPlugin.java b/src/main/java/forestry/plugins/ForestryPlugin.java index c1027b777..302370f82 100755 --- a/src/main/java/forestry/plugins/ForestryPlugin.java +++ b/src/main/java/forestry/plugins/ForestryPlugin.java @@ -11,20 +11,18 @@ package forestry.plugins; import cpw.mods.fml.common.IFuelHandler; -import java.util.Random; - -import net.minecraft.command.ICommand; -import net.minecraft.world.World; - import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.network.IGuiHandler; - import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.IPacketHandler; import forestry.core.interfaces.IPickupHandler; import forestry.core.interfaces.IResupplyHandler; import forestry.core.interfaces.ISaveEventHandler; import java.util.EnumSet; +import java.util.Random; +import net.minecraft.command.ICommand; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; public abstract class ForestryPlugin { @@ -68,7 +66,10 @@ public abstract class ForestryPlugin { return null; } - public void generateSurface(World world, Random rand, int chunkX, int chunkZ) { + public void populateChunk(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGeneratedZ) { + } + + public void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) { } public IPacketHandler getPacketHandler() { diff --git a/src/main/java/forestry/plugins/PluginApiculture.java b/src/main/java/forestry/plugins/PluginApiculture.java index 552930b26..70cd1073f 100644 --- a/src/main/java/forestry/plugins/PluginApiculture.java +++ b/src/main/java/forestry/plugins/PluginApiculture.java @@ -10,6 +10,31 @@ ******************************************************************************/ package forestry.plugins; +import java.util.ArrayList; +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.util.IIcon; +import net.minecraft.util.WeightedRandomChestContent; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; + import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; @@ -20,6 +45,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.FlowerManager; @@ -28,7 +54,6 @@ import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeRoot; import forestry.api.apiculture.IHiveDrop; import forestry.api.apiculture.hives.HiveManager; -import forestry.api.apiculture.hives.IHive; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.core.Tabs; @@ -37,7 +62,8 @@ import forestry.api.genetics.IAllele; import forestry.api.genetics.IClassification; import forestry.api.genetics.IClassification.EnumClassLevel; import forestry.api.recipes.RecipeManagers; -import forestry.apiculture.commands.CommandBeekeeping; +import forestry.api.storage.ICrateRegistry; +import forestry.api.storage.StorageManager; import forestry.apiculture.FlowerProviderCacti; import forestry.apiculture.FlowerProviderEnd; import forestry.apiculture.FlowerProviderGourd; @@ -50,6 +76,7 @@ import forestry.apiculture.GuiHandlerApiculture; import forestry.apiculture.PacketHandlerApiculture; import forestry.apiculture.SaveEventHandlerApiculture; import forestry.apiculture.VillageHandlerApiculture; +import forestry.apiculture.commands.CommandBee; import forestry.apiculture.gadgets.BlockAlveary; import forestry.apiculture.gadgets.BlockBeehives; import forestry.apiculture.gadgets.BlockCandle; @@ -71,6 +98,8 @@ import forestry.apiculture.genetics.AlleleBeeSpecies; import forestry.apiculture.genetics.AlleleEffectAggressive; import forestry.apiculture.genetics.AlleleEffectCreeper; import forestry.apiculture.genetics.AlleleEffectExploration; +import forestry.apiculture.genetics.AlleleEffectFertile; +import forestry.apiculture.genetics.AlleleEffectFungification; import forestry.apiculture.genetics.AlleleEffectGlacial; import forestry.apiculture.genetics.AlleleEffectHeroic; import forestry.apiculture.genetics.AlleleEffectIgnition; @@ -104,15 +133,10 @@ import forestry.apiculture.items.ItemImprinter; import forestry.apiculture.items.ItemWaxCast; import forestry.apiculture.proxy.ProxyApiculture; import forestry.apiculture.trigger.ApicultureTriggers; -import forestry.apiculture.trigger.TriggerNoFrames; import forestry.apiculture.worldgen.HiveDecorator; -import forestry.apiculture.worldgen.HiveEnd; -import forestry.apiculture.worldgen.HiveForest; -import forestry.apiculture.worldgen.HiveJungle; -import forestry.apiculture.worldgen.HiveMeadows; -import forestry.apiculture.worldgen.HiveParched; -import forestry.apiculture.worldgen.HiveSnow; -import forestry.apiculture.worldgen.HiveSwamp; +import forestry.apiculture.worldgen.HiveDescription; +import forestry.apiculture.worldgen.HiveGenHelper; +import forestry.apiculture.worldgen.HiveRegistry; import forestry.core.GameMode; import forestry.core.config.Config; import forestry.core.config.Configuration; @@ -120,6 +144,7 @@ import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.config.Property; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; import forestry.core.gadgets.TileAnalyzer; @@ -127,7 +152,6 @@ import forestry.core.genetics.Allele; import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.IPacketHandler; import forestry.core.interfaces.ISaveEventHandler; -import forestry.core.items.ItemCrated; import forestry.core.items.ItemForestry; import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemOverlay; @@ -135,30 +159,7 @@ import forestry.core.items.ItemOverlay.OverlayInfo; import forestry.core.items.ItemScoop; import forestry.core.proxy.Proxies; import forestry.core.render.EntitySnowFX; -import forestry.core.triggers.Trigger; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.command.ICommand; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.potion.Potion; -import net.minecraft.util.IIcon; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.common.ChestGenHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.oredict.OreDictionary; - -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; @Plugin(pluginID = "Apiculture", name = "Apiculture", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.apiculture.description") public class PluginApiculture extends ForestryPlugin { @@ -183,6 +184,8 @@ public class PluginApiculture extends ForestryPlugin { * See {@link IBeeRoot} for details */ public static IBeeRoot beeInterface; + public static HiveRegistry hiveRegistry; + public static MachineDefinition definitionApiary; public static MachineDefinition definitionChest; public static MachineDefinition definitionBeehouse; @@ -195,6 +198,8 @@ public class PluginApiculture extends ForestryPlugin { MinecraftForge.EVENT_BUS.register(this); + HiveManager.hiveRegistry = hiveRegistry = new HiveRegistry(); + HiveManager.genHelper = new HiveGenHelper(); createHiveDropArrays(); ForestryBlock.apiculture.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "apiculture"); @@ -234,15 +239,6 @@ public class PluginApiculture extends ForestryPlugin { PluginApiculture.proxy.getRendererAnalyzer(Defaults.TEXTURE_PATH_BLOCKS + "/analyzer_"))); ForestryBlock.beehives.registerBlock(new BlockBeehives(), ItemForestryBlock.class, "beehives"); - ForestryBlock.beehives.block().setHarvestLevel("pickaxe", 1, 0); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 1); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 2); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 3); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 4); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 5); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 6); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 7); - ForestryBlock.beehives.block().setHarvestLevel("scoop", 0, 8); createHives(); @@ -266,8 +262,15 @@ public class PluginApiculture extends ForestryPlugin { // Register village components with the Structure registry. VillageHandlerApiculture.registerVillageComponents(); + // Modes + PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.easy); + PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.normal); + PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hard); + PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hardcore); + PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.insane); + // Commands - PluginCore.rootCommand.addChildCommand(new CommandBeekeeping()); + PluginCore.rootCommand.addChildCommand(new CommandBee()); } @Override @@ -277,25 +280,25 @@ public class PluginApiculture extends ForestryPlugin { apicultureConfig = new Configuration(); Property property = apicultureConfig.get("apiary.sidesensitive", CONFIG_CATEGORY, apiarySideSensitive); - property.Comment = "set to false if apiaries should output all items regardless of side a pipe is attached to"; - apiarySideSensitive = Boolean.parseBoolean(property.Value); + property.comment = "set to false if apiaries should output all items regardless of side a pipe is attached to"; + apiarySideSensitive = Boolean.parseBoolean(property.value); property = apicultureConfig.get("render.bees.fancy", CONFIG_CATEGORY, fancyRenderedBees); - property.Comment = "set to true to enable a fancy butterfly-like renderer for bees. (experimental!)"; - fancyRenderedBees = Boolean.parseBoolean(property.Value); + property.comment = "set to true to enable a fancy butterfly-like renderer for bees. (experimental!)"; + fancyRenderedBees = Boolean.parseBoolean(property.value); property = apicultureConfig.get("beekeeping.mode", CONFIG_CATEGORY, "NORMAL"); - property.Comment = "change beekeeping modes here. possible values EASY, NORMAL, HARD, HARDCORE, INSANE. mods may add additional modes."; - beekeepingMode = property.Value.trim(); + property.comment = "change beekeeping modes here. possible values EASY, NORMAL, HARD, HARDCORE, INSANE. mods may add additional modes."; + beekeepingMode = property.value.trim(); Proxies.log.finer("Beekeeping mode read from config: " + beekeepingMode); property = apicultureConfig.get("beekeeping.flowers.custom", CONFIG_CATEGORY, ""); - property.Comment = "add additional flower blocks for apiaries here in the format id:meta. separate blocks using ';'. will be treated like vanilla flowers. not recommended for flowers implemented as tile entities."; - parseAdditionalFlowers(property.Value, FlowerManager.plainFlowers); + property.comment = "add additional flower blocks for apiaries here in the format id:meta. separate blocks using ';'. will be treated like vanilla flowers. not recommended for flowers implemented as tile entities."; + parseAdditionalFlowers(property.value, FlowerManager.plainFlowers); property = apicultureConfig.get("species.blacklist", CONFIG_CATEGORY, ""); - property.Comment = "add species to blacklist identified by their uid and seperated with ';'."; - parseBeeBlacklist(property.Value); + property.comment = "add species to blacklist identified by their uid and seperated with ';'."; + parseBeeBlacklist(property.value); apicultureConfig.save(); @@ -303,12 +306,6 @@ public class PluginApiculture extends ForestryPlugin { createMutations(); registerBeehiveDrops(); - PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.easy); - PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.normal); - PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hard); - PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hardcore); - PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.insane); - // Inducers for swarmer BeeManager.inducers.put(ForestryItem.royalJelly.getItemStack(), 10); @@ -342,10 +339,6 @@ public class PluginApiculture extends ForestryPlugin { Proxies.render.registerVillagerSkin(Defaults.ID_VILLAGER_BEEKEEPER, Defaults.TEXTURE_SKIN_BEEKPEEPER); VillagerRegistry.instance().registerVillageTradeHandler(Defaults.ID_VILLAGER_BEEKEEPER, villageHandler); - // Register world gen - if (Config.generateBeehives) - MinecraftForge.EVENT_BUS.register(HiveDecorator.instance()); - proxy.initializeRendering(); } @@ -432,21 +425,21 @@ public class PluginApiculture extends ForestryPlugin { @Override protected void registerCrates() { - ForestryItem.cratedBeeswax.registerItem(new ItemCrated(ForestryItem.beeswax.getItemStack()), "cratedBeeswax"); - ForestryItem.cratedPollen.registerItem(new ItemCrated(ForestryItem.pollenCluster.getItemStack()), "cratedPollen"); - ForestryItem.cratedPropolis.registerItem(new ItemCrated(ForestryItem.propolis.getItemStack()), "cratedPropolis"); - ForestryItem.cratedHoneydew.registerItem(new ItemCrated(ForestryItem.honeydew.getItemStack()), "cratedHoneydew"); - ForestryItem.cratedRoyalJelly.registerItem(new ItemCrated(ForestryItem.royalJelly.getItemStack()), "cratedRoyalJelly"); + ICrateRegistry crateRegistry = StorageManager.crateRegistry; + crateRegistry.registerCrate(ForestryItem.beeswax.getItemStack(), "cratedBeeswax"); + crateRegistry.registerCrate(ForestryItem.pollenCluster.getItemStack(), "cratedPollen"); + crateRegistry.registerCrate(ForestryItem.propolis.getItemStack(), "cratedPropolis"); + crateRegistry.registerCrate(ForestryItem.honeydew.getItemStack(), "cratedHoneydew"); + crateRegistry.registerCrate(ForestryItem.royalJelly.getItemStack(), "cratedRoyalJelly"); - ForestryItem.cratedHoneycombs.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 0)), "cratedHoneycombs"); - ForestryItem.cratedCocoaComb.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 1)), "cratedCocoaComb"); - ForestryItem.cratedSimmeringCombs.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 2)), "cratedSimmeringCombs"); - ForestryItem.cratedStringyCombs.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 3)), "cratedStringyCombs"); - ForestryItem.cratedFrozenCombs.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 4)), "cratedFrozenCombs"); - ForestryItem.cratedDrippingCombs.registerItem(new ItemCrated(ForestryItem.beeComb.getItemStack(1, 5)), "cratedDrippingCombs"); - - ForestryItem.cratedRefractoryWax.registerItem(new ItemCrated(ForestryItem.refractoryWax.getItemStack()), "cratedRefractoryWax"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 0), "cratedHoneycombs"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 1), "cratedCocoaComb"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 2), "cratedSimmeringCombs"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 3), "cratedStringyCombs"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 4), "cratedFrozenCombs"); + crateRegistry.registerCrate(ForestryItem.beeComb.getItemStack(1, 5), "cratedDrippingCombs"); + crateRegistry.registerCrate(ForestryItem.refractoryWax.getItemStack(), "cratedRefractoryWax"); } @Override @@ -469,36 +462,6 @@ public class PluginApiculture extends ForestryPlugin { // / HABITAT LOCATOR //Proxies.common.addRecipe(ForestryItem.biomeFinder.getItemStack(), // new Object[] { " X ", "X#X", " X ", '#', Items.redstone, 'X', "ingotBronze" }); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(3), - "###", "YXY", - '#', ForestryItem.waxCapsule, - 'X', Items.bone, - 'Y', ForestryItem.pollenCluster); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(3), - "###", "YXY", - '#', ForestryItem.canEmpty, - 'X', Items.bone, - 'Y', ForestryItem.pollenCluster); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(), - "###", "YXY", "###", - '#', ForestryItem.honeyDrop, - 'Y', ForestryItem.fertilizerCompound, - 'X', ForestryItem.waxCapsule); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(), - "###", "YXY", "###", - '#', ForestryItem.honeyDrop, - 'Y', ForestryItem.fertilizerCompound, - 'X', ForestryItem.canEmpty); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(), - "###", "YXY", "###", - '#', ForestryItem.honeyDrop, - 'Y', ForestryItem.pollenCluster, - 'X', ForestryItem.waxCapsule); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(), - "###", "YXY", "###", - '#', ForestryItem.honeyDrop, - 'Y', ForestryItem.pollenCluster, - 'X', ForestryItem.canEmpty); // Bees Proxies.common.addRecipe(ForestryItem.scoop.getItemStack(1), @@ -551,6 +514,7 @@ public class PluginApiculture extends ForestryPlugin { '#', "dustAsh", 'X', ForestryItem.peat, 'Y', ForestryItem.propolis); + // / TORCHES Proxies.common.addRecipe(new ItemStack(Blocks.torch, 3), " # ", " # ", " Y ", @@ -560,20 +524,6 @@ public class PluginApiculture extends ForestryPlugin { "# #", " # ", "# #", '#', ForestryItem.propolis.getItemStack(1, 2)); - // / CANDLES - RecipeManagers.carpenterManager.addRecipe(30, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 600), null, ForestryBlock.candle.getItemStack(24), - " X ", - "###", - "###", - '#', ForestryItem.beeswax, - 'X', Items.string); - RecipeManagers.carpenterManager.addRecipe(10, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 200), null, ForestryBlock.candle.getItemStack(6), - "#X#", - '#', ForestryItem.beeswax, - 'X', ForestryItem.craftingMaterial.getItemStack(1, 2)); - Proxies.common.addShapelessRecipe(ForestryBlock.candle.getItemStack(), ForestryBlock.candle.getItemStack()); - Proxies.common.addShapelessRecipe(ForestryBlock.candle.getItemStack(1, 1), ForestryBlock.candle.getItemStack(1, 1)); - // / WAX CAST Proxies.common.addRecipe(ForestryItem.waxCast.getItemStack(), "###", @@ -636,77 +586,91 @@ public class PluginApiculture extends ForestryPlugin { 'I', Items.iron_ingot, 'W', ForestryItem.craftingMaterial.getItemStack(1, 3)); - // / SQUEEZER - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeyDrop.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, Defaults.FLUID_PER_HONEY_DROP), - ForestryItem.propolis.getItemStack(), 5); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeydew.getItemStack()}, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, Defaults.FLUID_PER_HONEY_DROP)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.sand)}, LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 2000)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.dirt)}, LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 1600)); + if (PluginManager.Module.FACTORY.isEnabled()) { + // / SQUEEZER + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeyDrop.getItemStack()}, Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP), + ForestryItem.propolis.getItemStack(), 5); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.honeydew.getItemStack()}, Fluids.HONEY.getFluid(Defaults.FLUID_PER_HONEY_DROP)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.sand)}, Fluids.LAVA.getFluid(2000)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.dirt)}, Fluids.LAVA.getFluid(1600)); - // / CARPENTER - RecipeManagers.carpenterManager.addRecipe(100, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 2000), null, ForestryItem.beealyzer.getItemStack(), - "X#X", "X#X", "RDR", - '#', Blocks.glass_pane, - 'X', "ingotTin", - 'R', Items.redstone, - 'D', Items.diamond); - RecipeManagers.carpenterManager.addRecipe(50, LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 500), null, ForestryItem.craftingMaterial.getItemStack(1, 6), - " J ", "###", "WPW", - '#', "plankWood", - 'J', ForestryItem.royalJelly, - 'W', ForestryItem.beeswax, - 'P', ForestryItem.pollenCluster); + // / CARPENTER + RecipeManagers.carpenterManager.addRecipe(100, Fluids.WATER.getFluid(2000), null, ForestryItem.beealyzer.getItemStack(), + "X#X", "X#X", "RDR", + '#', Blocks.glass_pane, + 'X', "ingotTin", + 'R', Items.redstone, + 'D', Items.diamond); + RecipeManagers.carpenterManager.addRecipe(50, Fluids.HONEY.getFluid(500), null, ForestryItem.craftingMaterial.getItemStack(1, 6), + " J ", "###", "WPW", + '#', "plankWood", + 'J', ForestryItem.royalJelly, + 'W', ForestryItem.beeswax, + 'P', ForestryItem.pollenCluster); - // / CENTRIFUGE - // Honey combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 0), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Cocoa combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 1), ForestryItem.beeswax.getItemStack(), new ItemStack(Items.dye, 1, 3), 50); - // Simmering combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 2), ForestryItem.refractoryWax.getItemStack(), ForestryItem.phosphor.getItemStack(2), 70); - // Stringy combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 3), ForestryItem.propolis.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); - // Drippig combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 5), ForestryItem.honeydew.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); - // Frozen combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 4), new ItemStack[]{ForestryItem.beeswax.getItemStack(), - ForestryItem.honeyDrop.getItemStack(), new ItemStack(Items.snowball), ForestryItem.pollenCluster.getItemStack(1, 1)}, new int[]{80, 70, 40, 20}); - // Silky combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 6), ForestryItem.honeyDrop.getItemStack(), ForestryItem.propolis.getItemStack(1, 3), 80); - // Parched combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 7), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Mysterious combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 8), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.propolis.getItemStack(1, 2)}, new int[]{40, 100}); - // Irradiated combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 9), new ItemStack[]{}, new int[]{}); - // Powdery combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 10), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.gunpowder)}, new int[]{20, 20, 90}); - // Reddened Combs - RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 11), - new ItemStack[]{ForestryItem.honeyDrop.getItemStack(2, 1)}, new int[]{100}); - // Darkened Combs - RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 12), - new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 1)}, new int[]{100}); - // Omega Combs - RecipeManagers.centrifugeManager.addRecipe(400, ForestryItem.beeComb.getItemStack(1, 13), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 2)}, new int[]{100}); - // Wheaten Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 14), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.wheat)}, new int[]{20, 20, 80}); - // Mossy Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 15), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); - // Mellow Combs - RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 16), new ItemStack[]{ForestryItem.honeydew.getItemStack(), - ForestryItem.beeswax.getItemStack(), new ItemStack(Items.quartz)}, new int[]{60, 20, 30}); + RecipeManagers.carpenterManager.addRecipe(30, Fluids.WATER.getFluid(600), null, ForestryBlock.candle.getItemStack(24), + " X ", + "###", + "###", + '#', ForestryItem.beeswax, + 'X', Items.string); + RecipeManagers.carpenterManager.addRecipe(10, Fluids.WATER.getFluid(200), null, ForestryBlock.candle.getItemStack(6), + "#X#", + '#', ForestryItem.beeswax, + 'X', ForestryItem.craftingMaterial.getItemStack(1, 2)); + Proxies.common.addShapelessRecipe(ForestryBlock.candle.getItemStack(), ForestryBlock.candle.getItemStack()); + Proxies.common.addShapelessRecipe(ForestryBlock.candle.getItemStack(1, 1), ForestryBlock.candle.getItemStack(1, 1)); - // Silk - RecipeManagers.centrifugeManager.addRecipe(5, ForestryItem.propolis.getItemStack(1, 3), new ItemStack[]{ - ForestryItem.craftingMaterial.getItemStack(1, 2), ForestryItem.propolis.getItemStack()}, new int[]{60, 10}); + // / CENTRIFUGE + // Honey combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 0), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); + // Cocoa combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 1), ForestryItem.beeswax.getItemStack(), new ItemStack(Items.dye, 1, 3), 50); + // Simmering combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 2), ForestryItem.refractoryWax.getItemStack(), ForestryItem.phosphor.getItemStack(2), 70); + // Stringy combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 3), ForestryItem.propolis.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); + // Drippig combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 5), ForestryItem.honeydew.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 40); + // Frozen combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 4), new ItemStack[]{ForestryItem.beeswax.getItemStack(), + ForestryItem.honeyDrop.getItemStack(), new ItemStack(Items.snowball), ForestryItem.pollenCluster.getItemStack(1, 1)}, new int[]{80, 70, 40, 20}); + // Silky combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 6), ForestryItem.honeyDrop.getItemStack(), ForestryItem.propolis.getItemStack(1, 3), 80); + // Parched combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 7), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); + // Mysterious combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 8), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), + ForestryItem.propolis.getItemStack(1, 2)}, new int[]{40, 100}); + // Irradiated combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 9), new ItemStack[]{}, new int[]{}); + // Powdery combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 10), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), + ForestryItem.beeswax.getItemStack(), new ItemStack(Items.gunpowder)}, new int[]{20, 20, 90}); + // Reddened Combs + RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 11), + new ItemStack[]{ForestryItem.honeyDrop.getItemStack(2, 1)}, new int[]{100}); + // Darkened Combs + RecipeManagers.centrifugeManager.addRecipe(80, ForestryItem.beeComb.getItemStack(1, 12), + new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 1)}, new int[]{100}); + // Omega Combs + RecipeManagers.centrifugeManager.addRecipe(400, ForestryItem.beeComb.getItemStack(1, 13), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(1, 2)}, new int[]{100}); + // Wheaten Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 14), new ItemStack[]{ForestryItem.honeyDrop.getItemStack(), + ForestryItem.beeswax.getItemStack(), new ItemStack(Items.wheat)}, new int[]{20, 20, 80}); + // Mossy Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 15), ForestryItem.beeswax.getItemStack(), ForestryItem.honeyDrop.getItemStack(), 90); + // Mellow Combs + RecipeManagers.centrifugeManager.addRecipe(20, ForestryItem.beeComb.getItemStack(1, 16), new ItemStack[]{ForestryItem.honeydew.getItemStack(), + ForestryItem.beeswax.getItemStack(), new ItemStack(Items.quartz)}, new int[]{60, 20, 30}); - // / FERMENTER - RecipeManagers.fermenterManager.addRecipe(ForestryItem.honeydew.getItemStack(), 500, 1.0f, LiquidHelper.getLiquid(Defaults.LIQUID_MEAD, 1), - LiquidHelper.getLiquid(Defaults.LIQUID_HONEY, 1)); + // Silk + RecipeManagers.centrifugeManager.addRecipe(5, ForestryItem.propolis.getItemStack(1, 3), new ItemStack[]{ + ForestryItem.craftingMaterial.getItemStack(1, 2), ForestryItem.propolis.getItemStack()}, new int[]{60, 10}); + + // / FERMENTER + RecipeManagers.fermenterManager.addRecipe(ForestryItem.honeydew.getItemStack(), 500, 1.0f, Fluids.SHORT_MEAD.getFluid(1), Fluids.HONEY.getFluid(1)); + } // ANALYZER definitionAnalyzer.recipes = createAlyzerRecipes(ForestryBlock.core.block(), Defaults.DEFINITION_ANALYZER_META); @@ -824,44 +788,23 @@ public class PluginApiculture extends ForestryPlugin { } private void createHives() { - HiveManager.put(HiveManager.forest, new HiveForest(3)); - HiveManager.put(HiveManager.meadows, new HiveMeadows(1)); - HiveManager.put(HiveManager.desert, new HiveParched(1)); - HiveManager.put(HiveManager.jungle, new HiveJungle(4)); - HiveManager.put(HiveManager.end, new HiveEnd(4)); - HiveManager.put(HiveManager.snow, new HiveSnow(2)); - HiveManager.put(HiveManager.swamp, new HiveSwamp(2)); + hiveRegistry.registerHive(HiveRegistry.forest, HiveDescription.FOREST); + hiveRegistry.registerHive(HiveRegistry.meadows, HiveDescription.MEADOWS); + hiveRegistry.registerHive(HiveRegistry.desert, HiveDescription.DESERT); + hiveRegistry.registerHive(HiveRegistry.jungle, HiveDescription.JUNGLE); + hiveRegistry.registerHive(HiveRegistry.end, HiveDescription.END); + hiveRegistry.registerHive(HiveRegistry.snow, HiveDescription.SNOW); + hiveRegistry.registerHive(HiveRegistry.swamp, HiveDescription.SWAMP); } - @Deprecated // deprecated since 3.1. remove when BeeManager.hiveDrops is removed private void updateHiveDrops() { - IHive hive = HiveManager.getForestHive(); - for (IHiveDrop drop : forestDrops) - hive.addDrop(drop); - - hive = HiveManager.getMeadowsHive(); - for (IHiveDrop drop : meadowsDrops) - hive.addDrop(drop); - - hive = HiveManager.getDesertHive(); - for (IHiveDrop drop : desertDrops) - hive.addDrop(drop); - - hive = HiveManager.getJungleHive(); - for (IHiveDrop drop : jungleDrops) - hive.addDrop(drop); - - hive = HiveManager.getEndHive(); - for (IHiveDrop drop : endDrops) - hive.addDrop(drop); - - hive = HiveManager.getSnowHive(); - for (IHiveDrop drop : snowDrops) - hive.addDrop(drop); - - hive = HiveManager.getSwampHive(); - for (IHiveDrop drop : swampDrops) - hive.addDrop(drop); + hiveRegistry.addDrops(HiveRegistry.forest, forestDrops); + hiveRegistry.addDrops(HiveRegistry.meadows, meadowsDrops); + hiveRegistry.addDrops(HiveRegistry.desert, desertDrops); + hiveRegistry.addDrops(HiveRegistry.jungle, jungleDrops); + hiveRegistry.addDrops(HiveRegistry.end, endDrops); + hiveRegistry.addDrops(HiveRegistry.snow, snowDrops); + hiveRegistry.addDrops(HiveRegistry.swamp, swampDrops); } private void createAlleles() { @@ -1028,14 +971,18 @@ public class PluginApiculture extends ForestryPlugin { // Agrarian branch Allele.speciesRural = new AlleleBeeSpecies("speciesRural", false, "bees.species.rural", agrarian, "rustico", 0xfeff8f, 0xffdc16).addProduct( ForestryItem.beeComb.getItemStack(1, 14), 20).setIsSecret(); - // 41 Farmerly - // 42 Agrarian + Allele.speciesFarmerly = new AlleleBeeSpecies("speciesFarmerly", true, "bees.species.farmerly", agrarian, "arator", 0xD39728, 0xffdc16).addProduct( + ForestryItem.beeComb.getItemStack(1, 14), 27).setIsSecret(); + Allele.speciesArgrarian = new AlleleBeeSpecies("speciesArgrarian", true, "bees.species.agrarian", agrarian, "arator", 0xFFCA75, 0xFFE047).addProduct( + ForestryItem.beeComb.getItemStack(1, 14), 35).setIsSecret().setHasEffect(); // Boggy branch Allele.speciesMarshy = new AlleleBeeSpecies("speciesMarshy", true, "bees.species.marshy", boggy, "adorasti", 0x546626, 0xffdc16).addProduct( ForestryItem.beeComb.getItemStack(1, 15), 30).setHumidity(EnumHumidity.DAMP); - // 44 speciesMiry - // 45 speciesBoggy + Allele.speciesMiry = new AlleleBeeSpecies("speciesMiry", true, "bees.species.miry", boggy, "humidium", 0x92AF42, 0xffdc16).addProduct( + ForestryItem.beeComb.getItemStack(1, 15), 36).setHumidity(EnumHumidity.DAMP).setIsSecret(); + Allele.speciesBoggy = new AlleleBeeSpecies("speciesBoggy", true, "bees.species.boggy", boggy, "paluster", 0x698948, 0xffdc16).addProduct( + ForestryItem.beeComb.getItemStack(1, 15), 39).addSpecialty(ForestryItem.peat.getItemStack(1), 8).setHumidity(EnumHumidity.DAMP).setIsSecret(); // Monastic branch Allele.speciesMonastic = new AlleleBeeSpecies("speciesMonastic", false, "bees.species.monastic", monastic, "monachus", 0x42371c, 0xfff7b6) @@ -1075,6 +1022,8 @@ public class PluginApiculture extends ForestryPlugin { Allele.effectReanimation = new AlleleEffectResurrection("effectReanimation", "reanimation", AlleleEffectResurrection.getReanimationList()); Allele.effectResurrection = new AlleleEffectResurrection("effectResurrection", "resurrection", AlleleEffectResurrection.getResurrectionList()); Allele.effectRepulsion = new AlleleEffectRepulsion("effectRepulsion"); + Allele.effectFertile = new AlleleEffectFertile("effectFertile"); + Allele.effectMycophilic = new AlleleEffectFungification("effectMycophilic"); } @@ -1160,6 +1109,16 @@ public class PluginApiculture extends ForestryPlugin { // Agrarian branch BeeTemplates.ruralA = new BeeMutation(Allele.speciesMeadows, Allele.speciesDiligent, BeeTemplates.getRuralTemplate(), 12) .restrictBiomeType(BiomeDictionary.Type.PLAINS).enableStrictBiomeCheck(); + new BeeMutation(Allele.speciesRural, Allele.speciesUnweary, BeeTemplates.getFarmerlyTemplate(), 10) + .restrictBiomeType(BiomeDictionary.Type.PLAINS).enableStrictBiomeCheck(); + new BeeMutation(Allele.speciesFarmerly, Allele.speciesIndustrious, BeeTemplates.getAgrarianTemplate(), 6) + .restrictBiomeType(BiomeDictionary.Type.PLAINS).enableStrictBiomeCheck(); + + // Boggy branch + new BeeMutation(Allele.speciesMarshy, Allele.speciesNoble, BeeTemplates.getMiryTemplate(), 15) + .setTemperatureRainfall(0.75f, 0.94f, 0.75f, 2.0f); + new BeeMutation(Allele.speciesMarshy, Allele.speciesMiry, BeeTemplates.getBoggyTemplate(), 9) + .setTemperatureRainfall(0.75f, 0.94f, 0.75f, 2.0f); // Monastic branch BeeTemplates.secludedA = new BeeMutation(Allele.speciesMonastic, Allele.speciesAustere, BeeTemplates.getSecludedTemplate(), 12); @@ -1210,11 +1169,15 @@ public class PluginApiculture extends ForestryPlugin { beeInterface.registerTemplate(BeeTemplates.getReddenedTemplate()); beeInterface.registerTemplate(BeeTemplates.getOmegaTemplate()); beeInterface.registerTemplate(BeeTemplates.getRuralTemplate()); + beeInterface.registerTemplate(BeeTemplates.getFarmerlyTemplate()); + beeInterface.registerTemplate(BeeTemplates.getAgrarianTemplate()); beeInterface.registerTemplate(BeeTemplates.getLeporineTemplate()); beeInterface.registerTemplate(BeeTemplates.getMerryTemplate()); beeInterface.registerTemplate(BeeTemplates.getTipsyTemplate()); beeInterface.registerTemplate(BeeTemplates.getTrickyTemplate()); beeInterface.registerTemplate(BeeTemplates.getMarshyTemplate()); + beeInterface.registerTemplate(BeeTemplates.getMiryTemplate()); + beeInterface.registerTemplate(BeeTemplates.getBoggyTemplate()); beeInterface.registerTemplate(BeeTemplates.getMonasticTemplate()); beeInterface.registerTemplate(BeeTemplates.getSecludedTemplate()); beeInterface.registerTemplate(BeeTemplates.getHermiticTemplate()); @@ -1279,6 +1242,18 @@ public class PluginApiculture extends ForestryPlugin { return null; } + @Override + public void populateChunk(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) { + if (Config.generateBeehives) + HiveDecorator.instance().decorateHives(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated); + } + + @Override + public void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) { + if (Config.generateBeehives) + HiveDecorator.instance().decorateHives(world, rand, chunkX, chunkZ); + } + @Override public boolean processIMCMessage(IMCMessage message) { if (message.key.equals("add-candle-lighting-id")) { diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index e507bde93..e7b5af342 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -10,6 +10,22 @@ ******************************************************************************/ package forestry.plugins; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.WeightedRandomChestContent; + +import net.minecraftforge.common.ChestGenHooks; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; + import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; @@ -17,6 +33,7 @@ import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.VillagerRegistry; + import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.ITreeRoot; @@ -28,9 +45,6 @@ import forestry.api.genetics.IClassification.EnumClassLevel; import forestry.api.genetics.IFruitFamily; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; -import forestry.arboriculture.CommandSpawnForest; -import forestry.arboriculture.CommandSpawnTree; -import forestry.arboriculture.CommandTreekeepingMode; import forestry.arboriculture.EventHandlerArboriculture; import forestry.arboriculture.FruitProviderNone; import forestry.arboriculture.FruitProviderPod; @@ -41,6 +55,7 @@ import forestry.arboriculture.GuiHandlerArboriculture; import forestry.arboriculture.PacketHandlerArboriculture; import forestry.arboriculture.VillageHandlerArboriculture; import forestry.arboriculture.WoodType; +import forestry.arboriculture.commands.CommandTree; import forestry.arboriculture.gadgets.BlockArbFence; import forestry.arboriculture.gadgets.BlockArbFence.FenceCat; import forestry.arboriculture.gadgets.BlockArbStairs; @@ -86,11 +101,13 @@ import forestry.arboriculture.worldgen.WorldGenBaobab; import forestry.arboriculture.worldgen.WorldGenBirch; import forestry.arboriculture.worldgen.WorldGenCherry; import forestry.arboriculture.worldgen.WorldGenChestnut; +import forestry.arboriculture.worldgen.WorldGenCocobolo; import forestry.arboriculture.worldgen.WorldGenDarkOak; import forestry.arboriculture.worldgen.WorldGenDate; import forestry.arboriculture.worldgen.WorldGenEbony; import forestry.arboriculture.worldgen.WorldGenGiganteum; import forestry.arboriculture.worldgen.WorldGenGreenheart; +import forestry.arboriculture.worldgen.WorldGenIpe; import forestry.arboriculture.worldgen.WorldGenJungle; import forestry.arboriculture.worldgen.WorldGenKapok; import forestry.arboriculture.worldgen.WorldGenLarch; @@ -100,6 +117,7 @@ import forestry.arboriculture.worldgen.WorldGenMahoe; import forestry.arboriculture.worldgen.WorldGenMahogany; import forestry.arboriculture.worldgen.WorldGenMaple; import forestry.arboriculture.worldgen.WorldGenOak; +import forestry.arboriculture.worldgen.WorldGenPadauk; import forestry.arboriculture.worldgen.WorldGenPapaya; import forestry.arboriculture.worldgen.WorldGenPine; import forestry.arboriculture.worldgen.WorldGenPlum; @@ -110,10 +128,12 @@ import forestry.arboriculture.worldgen.WorldGenTeak; import forestry.arboriculture.worldgen.WorldGenWalnut; import forestry.arboriculture.worldgen.WorldGenWenge; import forestry.arboriculture.worldgen.WorldGenWillow; +import forestry.arboriculture.worldgen.WorldGenZebrawood; import forestry.core.GameMode; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; import forestry.core.genetics.Allele; @@ -122,24 +142,8 @@ import forestry.core.interfaces.IPacketHandler; import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemFruit.EnumFruit; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.RecipeUtil; import forestry.core.utils.ShapedRecipeCustom; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.command.ICommand; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.WeightedRandomChestContent; -import net.minecraftforge.common.ChestGenHooks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.oredict.OreDictionary; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; @Plugin(pluginID = "Arboriculture", name = "Arboriculture", author = "Binnie & SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.arboriculture.description") public class PluginArboriculture extends ForestryPlugin { @@ -161,7 +165,8 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.log4, ForestryBlock.log5, ForestryBlock.log6, - ForestryBlock.log7); + ForestryBlock.log7, + ForestryBlock.log8); public static final EnumSet fireproofLogs = EnumSet.of( ForestryBlock.fireproofLog1, ForestryBlock.fireproofLog2, @@ -169,7 +174,8 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.fireproofLog4, ForestryBlock.fireproofLog5, ForestryBlock.fireproofLog6, - ForestryBlock.fireproofLog7); + ForestryBlock.fireproofLog7, + ForestryBlock.fireproofLog8); private static final EnumSet planks = EnumSet.of( ForestryBlock.planks1, ForestryBlock.planks2); @@ -179,10 +185,11 @@ public class PluginArboriculture extends ForestryPlugin { private static final EnumSet slabs = EnumSet.of( ForestryBlock.slabs1, ForestryBlock.slabs2, - ForestryBlock.slabs3); + ForestryBlock.slabs3, + ForestryBlock.slabs4); private static final EnumSet fences = EnumSet.of( ForestryBlock.fences1, - ForestryBlock.fences1); + ForestryBlock.fences2); @Override public void preInit() { @@ -195,6 +202,7 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.log5.registerBlock(new BlockLog(LogCat.CAT4), ItemWoodBlock.class, "log5"); ForestryBlock.log6.registerBlock(new BlockLog(LogCat.CAT5), ItemWoodBlock.class, "log6"); ForestryBlock.log7.registerBlock(new BlockLog(LogCat.CAT6), ItemWoodBlock.class, "log7"); + ForestryBlock.log8.registerBlock(new BlockLog(LogCat.CAT7), ItemWoodBlock.class, "log8"); for (ForestryBlock log : logs) { log.block().setHarvestLevel("axe", 0); @@ -208,6 +216,7 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.fireproofLog5.registerBlock(new BlockFireproofLog(LogCat.CAT4), ItemWoodBlock.class, "fireproofLog5"); ForestryBlock.fireproofLog6.registerBlock(new BlockFireproofLog(LogCat.CAT5), ItemWoodBlock.class, "fireproofLog6"); ForestryBlock.fireproofLog7.registerBlock(new BlockFireproofLog(LogCat.CAT6), ItemWoodBlock.class, "fireproofLog7"); + ForestryBlock.fireproofLog8.registerBlock(new BlockFireproofLog(LogCat.CAT7), ItemWoodBlock.class, "fireproofLog8"); for (ForestryBlock fireproofLog : fireproofLogs) { fireproofLog.block().setHarvestLevel("axe", 0); @@ -233,6 +242,7 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock.slabs1.registerBlock(new BlockSlab(SlabCat.CAT0), ItemWoodBlock.class, "slabs1"); ForestryBlock.slabs2.registerBlock(new BlockSlab(SlabCat.CAT1), ItemWoodBlock.class, "slabs2"); ForestryBlock.slabs3.registerBlock(new BlockSlab(SlabCat.CAT2), ItemWoodBlock.class, "slabs3"); + ForestryBlock.slabs4.registerBlock(new BlockSlab(SlabCat.CAT3), ItemWoodBlock.class, "slabs4"); for (ForestryBlock plank : slabs) { plank.block().setHarvestLevel("axe", 0); @@ -293,6 +303,15 @@ public class PluginArboriculture extends ForestryPlugin { validFences.add(Blocks.fence_gate); validFences.add(Blocks.nether_brick_fence); + // Modes + PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.easy); + PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.normal); + PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hard); + PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hardcore); + PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.insane); + + // Commands + PluginCore.rootCommand.addChildCommand(new CommandTree()); } @Override @@ -309,12 +328,6 @@ public class PluginArboriculture extends ForestryPlugin { registerTemplates(); registerErsatzGenomes(); - PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.easy); - PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.normal); - PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hard); - PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hardcore); - PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.insane); - MinecraftForge.EVENT_BUS.register(new EventHandlerArboriculture()); VillagerRegistry.instance().registerVillagerId(Defaults.ID_VILLAGER_LUMBERJACK); @@ -391,6 +404,10 @@ public class PluginArboriculture extends ForestryPlugin { Proxies.common.addShapelessRecipe(ForestryBlock.planks2.getItemStack(4, i), ForestryBlock.log5.getItemStack(1, i)); for (int i = 0; i < 4; i++) Proxies.common.addShapelessRecipe(ForestryBlock.planks2.getItemStack(4, 4 + i), ForestryBlock.log6.getItemStack(1, i)); + for (int i = 0; i < 4; i++) + Proxies.common.addShapelessRecipe(ForestryBlock.planks2.getItemStack(4, 8 + i), ForestryBlock.log7.getItemStack(1, i)); + for (int i = 0; i < 1; i++) + Proxies.common.addShapelessRecipe(ForestryBlock.planks2.getItemStack(4, 12 + i), ForestryBlock.log8.getItemStack(1, i)); // Fabricator recipes if (PluginManager.Module.FACTORY.isEnabled() && PluginManager.Module.APICULTURE.isEnabled()) { @@ -400,16 +417,13 @@ public class PluginArboriculture extends ForestryPlugin { BlockLog blockLog = (BlockLog) forestryBlock.block(); ForestryBlock fireproofLog = BlockFireproofLog.getFireproofLog(blockLog); - if (forestryBlock == ForestryBlock.log8) - continue; - for (int i = 0; i < 4; i++) { - if (forestryBlock == ForestryBlock.log7 && i > 0) + if (forestryBlock == ForestryBlock.log8 && i > 0) break; ItemStack logStack = forestryBlock.getItemStack(1, i); ItemStack fireproofLogStack = fireproofLog.getItemStack(1, i); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), fireproofLogStack, new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), fireproofLogStack, new Object[]{ " # ", "#X#", " # ", @@ -424,7 +438,7 @@ public class PluginArboriculture extends ForestryPlugin { ForestryBlock fireproofPlank = BlockFireproofPlanks.getFireproofPlanks((BlockPlanks)plank.block()); ItemStack plankStack = plank.getItemStack(1, i); ItemStack fireproofPlankStack = fireproofPlank.getItemStack(5, i); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), fireproofPlankStack, new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), fireproofPlankStack, new Object[]{ "X#X", "#X#", "X#X", @@ -432,11 +446,11 @@ public class PluginArboriculture extends ForestryPlugin { 'X', plankStack}); } plank = ForestryBlock.planks2; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 12; i++) { ForestryBlock fireproofPlank = BlockFireproofPlanks.getFireproofPlanks((BlockPlanks)plank.block()); ItemStack plankStack = plank.getItemStack(1, i); ItemStack fireproofPlankStack = fireproofPlank.getItemStack(5, i); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), fireproofPlankStack, new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), fireproofPlankStack, new Object[]{ "X#X", "#X#", "X#X", @@ -458,64 +472,80 @@ public class PluginArboriculture extends ForestryPlugin { Proxies.common.addShapelessRecipe(ForestryBlock.fireproofPlanks2.getItemStack(4, i), ForestryBlock.fireproofLog5.getItemStack(1, i)); for (int i = 0; i < 4; i++) Proxies.common.addShapelessRecipe(ForestryBlock.fireproofPlanks2.getItemStack(4, 4 + i), ForestryBlock.fireproofLog6.getItemStack(1, i)); + for (int i = 0; i < 4; i++) + Proxies.common.addShapelessRecipe(ForestryBlock.fireproofPlanks2.getItemStack(4, 8 + i), ForestryBlock.fireproofLog7.getItemStack(1, i)); + for (int i = 0; i < 1; i++) + Proxies.common.addShapelessRecipe(ForestryBlock.fireproofPlanks2.getItemStack(4, 12 + i), ForestryBlock.fireproofLog8.getItemStack(1, i)); // Slab recipes - for (int i = 0; i < 8; i++) - Proxies.common.addPriorityRecipe(ForestryBlock.slabs1.getItemStack(6, i), "###", '#', ForestryBlock.planks1.getItemStack(1, i)); - for (int i = 0; i < 8; i++) - Proxies.common.addPriorityRecipe(ForestryBlock.slabs2.getItemStack(6, i), "###", '#', ForestryBlock.planks1.getItemStack(1, 8 + i)); - for (int i = 0; i < 8; i++) - Proxies.common.addPriorityRecipe(ForestryBlock.slabs3.getItemStack(6, i), "###", '#', ForestryBlock.planks2.getItemStack(1, i)); + for (WoodType woodType : WoodType.values()) { + int i = woodType.ordinal(); + if (i < 8) + Proxies.common.addPriorityRecipe(ForestryBlock.slabs1.getItemStack(6, i % 8), "###", '#', ForestryBlock.planks1.getItemStack(1, i % 16)); + else if (i < 16) + Proxies.common.addPriorityRecipe(ForestryBlock.slabs2.getItemStack(6, i % 8), "###", '#', ForestryBlock.planks1.getItemStack(1, i % 16)); + else if (i < 24) + Proxies.common.addPriorityRecipe(ForestryBlock.slabs3.getItemStack(6, i % 8), "###", '#', ForestryBlock.planks2.getItemStack(1, i % 16)); + else if (i < 32) + Proxies.common.addPriorityRecipe(ForestryBlock.slabs4.getItemStack(6, i % 8), "###", '#', ForestryBlock.planks2.getItemStack(1, i % 16)); + else + throw new RuntimeException("Wood type has no slabs defined"); + } // Fence recipes - for (int i = 0; i < 16; i++) - Proxies.common.addRecipe(ForestryBlock.fences1.getItemStack(4, i), "###", "# #", '#', ForestryBlock.planks1.getItemStack(1, i)); - for (int i = 0; i < 8; i++) - Proxies.common.addRecipe(ForestryBlock.fences2.getItemStack(4, i), "###", "# #", '#', ForestryBlock.planks2.getItemStack(1, i)); + for (WoodType woodType : WoodType.values()) { + int i = woodType.ordinal(); + if (i < 16) + Proxies.common.addRecipe(ForestryBlock.fences1.getItemStack(4, i % 16), "###", "# #", '#', ForestryBlock.planks1.getItemStack(1, i % 16)); + else if (i < 32) + Proxies.common.addRecipe(ForestryBlock.fences2.getItemStack(4, i % 16), "###", "# #", '#', ForestryBlock.planks2.getItemStack(1, i % 16)); + else + throw new RuntimeException("Wood type has no fences defined"); + } - // Treealyzer - RecipeManagers.carpenterManager.addRecipe(100, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 2000), null, ForestryItem.treealyzer.getItemStack(), "X#X", "X#X", "RDR", - '#', Blocks.glass_pane, - 'X', "ingotCopper", - 'R', Items.redstone, - 'D', Items.diamond); + if (PluginManager.Module.FACTORY.isEnabled()) { + // Treealyzer + RecipeManagers.carpenterManager.addRecipe(100, Fluids.WATER.getFluid(2000), null, ForestryItem.treealyzer.getItemStack(), "X#X", "X#X", "RDR", + '#', Blocks.glass_pane, + 'X', "ingotCopper", + 'R', Items.redstone, + 'D', Items.diamond); - // SQUEEZER RECIPES - RecipeManagers.squeezerManager.addRecipe(20, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.CHERRY.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 5 * GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed")), ForestryItem.mulch.getItemStack(), 5); - RecipeManagers.squeezerManager.addRecipe(60, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.WALNUT.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 18 * GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed")), ForestryItem.mulch.getItemStack(), 5); - RecipeManagers.squeezerManager.addRecipe(70, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.CHESTNUT.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 22 * GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed")), ForestryItem.mulch.getItemStack(), 2); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.LEMON.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") * 2), ForestryItem.mulch.getItemStack(), (int) Math.floor(GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple") * 0.5f)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.PLUM.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, (int) Math.floor(GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") * 0.5f)), ForestryItem.mulch.getItemStack(), GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple") * 3); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.PAPAYA.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") * 3), ForestryItem.mulch.getItemStack(), (int) Math.floor(GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple") * 0.5f)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.fruits.getItemStack(1, EnumFruit.DATES.ordinal())}, LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, (int) Math.floor(GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") * 0.25)), ForestryItem.mulch.getItemStack(), (int) Math.floor(GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple"))); + // SQUEEZER RECIPES + int seedOilMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + int juiceMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + int mulchMultiplier = GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple"); + RecipeManagers.squeezerManager.addRecipe(20, new ItemStack[]{EnumFruit.CHERRY.getStack()}, Fluids.SEEDOIL.getFluid(5 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 5); + RecipeManagers.squeezerManager.addRecipe(60, new ItemStack[]{EnumFruit.WALNUT.getStack()}, Fluids.SEEDOIL.getFluid(18 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 5); + RecipeManagers.squeezerManager.addRecipe(70, new ItemStack[]{EnumFruit.CHESTNUT.getStack()}, Fluids.SEEDOIL.getFluid(22 * seedOilMultiplier), ForestryItem.mulch.getItemStack(), 2); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.LEMON.getStack()}, Fluids.JUICE.getFluid(juiceMultiplier * 2), ForestryItem.mulch.getItemStack(), (int) Math.floor(mulchMultiplier * 0.5f)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.PLUM.getStack()}, Fluids.JUICE.getFluid((int) Math.floor(juiceMultiplier * 0.5f)), ForestryItem.mulch.getItemStack(), mulchMultiplier * 3); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.PAPAYA.getStack()}, Fluids.JUICE.getFluid(juiceMultiplier * 3), ForestryItem.mulch.getItemStack(), (int) Math.floor(mulchMultiplier * 0.5f)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{EnumFruit.DATES.getStack()}, Fluids.JUICE.getFluid((int) Math.floor(juiceMultiplier * 0.25)), ForestryItem.mulch.getItemStack(), mulchMultiplier); - RecipeUtil.injectLeveledRecipe(ForestryItem.sapling.getItemStack(), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + RecipeUtil.injectLeveledRecipe(ForestryItem.sapling.getItemStack(), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + } // Stairs - for (int i = 0; i < 16; i++) { - WoodType type = WoodType.VALUES[i]; - NBTTagCompound compound = new NBTTagCompound(); - type.saveToCompound(compound); + for (WoodType woodType : WoodType.values()) { + ForestryBlock planks; + int i = woodType.ordinal(); + if (i < 16) + planks = ForestryBlock.planks1; + else if (i < 32) + planks = ForestryBlock.planks2; + else + throw new RuntimeException("Wood type has no planks defined"); - ItemStack stairs = ForestryBlock.stairs.getItemStack(4, 0); + NBTTagCompound compound = new NBTTagCompound(); + woodType.saveToCompound(compound); + + ItemStack stairs = ForestryBlock.stairs.getItemStack(4); stairs.setTagCompound(compound); Proxies.common.addPriorityRecipe(stairs, "# ", "## ", - "###", '#', ForestryBlock.planks1.getItemStack(1, i)); - } - for (int i = 0; i < 8; i++) { - WoodType type = WoodType.VALUES[16 + i]; - NBTTagCompound compound = new NBTTagCompound(); - type.saveToCompound(compound); - - ItemStack stairs = ForestryBlock.stairs.getItemStack(4, 0); - stairs.setTagCompound(compound); - Proxies.common.addPriorityRecipe(stairs, - "# ", - "## ", - "###", - '#', ForestryBlock.planks2.getItemStack(1, i)); + "###", '#', planks.getItemStack(1, i % 16)); } // Grafter @@ -623,6 +653,9 @@ public class PluginArboriculture extends ForestryPlugin { IClassification lamiaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( EnumClassLevel.FAMILY, "lamiaceae", "Lamiaceae"); lamiales.addMemberGroup(lamiaceae); + IClassification bignoniaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( + EnumClassLevel.FAMILY, "bignoniaceae", "Bignoniaceae"); + lamiales.addMemberGroup(bignoniaceae); IClassification ebenaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( EnumClassLevel.FAMILY, "ebenaceae", "Ebenaceae"); @@ -650,7 +683,11 @@ public class PluginArboriculture extends ForestryPlugin { IClassification sapindaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( EnumClassLevel.FAMILY, "sapindaceae", "Sapindaceae"); sapindales.addMemberGroup(sapindaceae); - + IClassification anacardiaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( + EnumClassLevel.FAMILY, "anacardiaceae", "Anacardiaceae"); + sapindales.addMemberGroup(anacardiaceae); + + IClassification caricaceae = AlleleManager.alleleRegistry.createAndRegisterClassification( EnumClassLevel.FAMILY, "caricaceae", "Caricaceae"); brassicales.addMemberGroup(caricaceae); @@ -699,7 +736,17 @@ public class PluginArboriculture extends ForestryPlugin { fabaceae.addMemberGroup(acacia); IClassification millettia = new BranchTrees("millettia", "Millettia"); fabaceae.addMemberGroup(millettia); - + IClassification dalbergia = new BranchTrees("dalbergia", "Dalbergia"); + fabaceae.addMemberGroup(dalbergia); + IClassification pterocarpus = new BranchTrees("pterocarpus", "Pterocarpus"); + fabaceae.addMemberGroup(pterocarpus); + + IClassification tabebuia = new BranchTrees("tabebuia", "Tabebuia"); + bignoniaceae.addMemberGroup(tabebuia); + + IClassification astronium = new BranchTrees("astronium", "Astronium"); + anacardiaceae.addMemberGroup(astronium); + IClassification ochroma = new BranchTrees("ochroma", "Ochroma"); malvaceae.addMemberGroup(ochroma); @@ -772,6 +819,11 @@ public class PluginArboriculture extends ForestryPlugin { final ItemStack lemonLog = ForestryBlock.log6.getItemStack(1, 3); final ItemStack giganteumLog = ForestryBlock.log7.getItemStack(1, 0); + final ItemStack ipeLog = ForestryBlock.log7.getItemStack(1, 1); + final ItemStack padaukLog = ForestryBlock.log7.getItemStack(1, 2); + final ItemStack cocoboloLog = ForestryBlock.log7.getItemStack(1, 3); + + final ItemStack zebrawoodLog = ForestryBlock.log8.getItemStack(1, 0); // Deciduous Allele.treeOak = new AlleleTreeSpecies("treeOak", false, "appleOak", quercus, "robur", @@ -837,8 +889,11 @@ public class PluginArboriculture extends ForestryPlugin { "tectona", proxy.getFoliageColorBasic(), 0x539d12, WorldGenJungle.class, jungleLog) .addFruitFamily(jungle).setLeafIndices("jungle").setVanillaMap(3); Allele.treeTeak = new AlleleTreeSpecies("treeTeak", true, "teak", tectona, "grandis", - 0xfeff8f, 0xffd98f, WorldGenTeak.class, teakLog).addFruitFamily(jungle).setLeafIndices( - "jungle"); + 0xfeff8f, 0xffd98f, WorldGenTeak.class, teakLog) + .addFruitFamily(jungle).setLeafIndices("jungle"); + Allele.treeIpe = new AlleleTreeSpecies("treeIpe", true, "ipe", tabebuia, "serratifolia", + 0xfdd207, 0xad8f04, WorldGenIpe.class, ipeLog) + .addFruitFamily(jungle).setLeafIndices("jungle").setGirth(2); Allele.treeKapok = new AlleleTreeSpecies("treeKapok", true, "kapok", ceiba, "pentandra", 0x89987b, 0x89aa9e, WorldGenKapok.class, kapokLog).addFruitFamily(jungle) .addFruitFamily(prunes).setLeafIndices("jungle"); @@ -847,6 +902,9 @@ public class PluginArboriculture extends ForestryPlugin { Allele.treeEbony = new AlleleTreeSpecies("treeEbony", true, "myrtleEbony", diospyros, "pentamera", 0xa2d24a, 0xc4d24a, WorldGenEbony.class, ebonyLog).addFruitFamily(jungle) .addFruitFamily(prunes).setGirth(3).setLeafIndices("jungle"); + Allele.treeZebrawood = new AlleleTreeSpecies("treeZebrawood", false, "zebrawood", astronium, + "graveolens", 0xa2d24a, 0xc4d24a, WorldGenZebrawood.class, zebrawoodLog) + .addFruitFamily(nux).setGirth(2).setLeafIndices("jungle"); // Diospyros mespiliformis, the Jackalberry (also known as African Ebony // The Gaub Tree, Malabar ebony, Black-and-white Ebony or Pale Moon @@ -877,8 +935,12 @@ public class PluginArboriculture extends ForestryPlugin { Allele.treeDesertAcacia = new AlleleTreeSpecies("treeAcacia", true, "desertAcacia", acacia, "erioloba", 0x748C1C, 0xb3b302, WorldGenAcacia.class, desertAcaciaLog).addFruitFamily(jungle) .addFruitFamily(nux); + Allele.treePadauk = new AlleleTreeSpecies("treePadauk", true, "padauk", pterocarpus, + "soyauxii", 0xd0df8c, 0x435c32, WorldGenPadauk.class, padaukLog).addFruitFamily(jungle); Allele.treeBalsa = new AlleleTreeSpecies("treeBalsa", true, "balsa", ochroma, "pyramidale", 0x59ac00, 0xfeff8f, WorldGenBalsa.class, balsaLog).addFruitFamily(jungle).addFruitFamily(nux); + Allele.treeCocobolo = new AlleleTreeSpecies("treeCocobolo", false, "cocobolo", dalbergia, "retusa", + 0x6aa17a, 0x487d4c, WorldGenCocobolo.class, cocoboloLog).addFruitFamily(jungle); Allele.treeWenge = new AlleleTreeSpecies("treeWenge", true, "wenge", millettia, "laurentii", 0xada157, 0xad8a57, WorldGenWenge.class, wengeLog).addFruitFamily(jungle) .addFruitFamily(nux).setGirth(2); @@ -915,17 +977,17 @@ public class PluginArboriculture extends ForestryPlugin { Allele.fruitApple = new AlleleFruit("fruitApple", new FruitProviderRandom("apple", pomes, new ItemStack(Items.apple), 1.0f).setColour(0xff2e2e).setOverlay("pomes")); Allele.fruitCocoa = new AlleleFruit("fruitCocoa", new FruitProviderPod("cocoa", jungle, EnumPodType.COCOA)); // .setColours(0xecdca5, 0xc4d24a), true); - Allele.fruitChestnut = new AlleleFruit("fruitChestnut", new FruitProviderRipening("chestnut", nux, ForestryItem.fruits.getItemStack(1, EnumFruit.CHESTNUT.ordinal()), 1.0f).setRipeningPeriod(6).setColours(0x7f333d, 0xc4d24a).setOverlay("nuts"), true); - Allele.fruitWalnut = new AlleleFruit("fruitWalnut", new FruitProviderRipening("walnut", nux, ForestryItem.fruits.getItemStack(1, EnumFruit.WALNUT.ordinal()), 1.0f).setRipeningPeriod(8).setColours(0xfba248, 0xc4d24a).setOverlay("nuts"), true); - Allele.fruitCherry = new AlleleFruit("fruitCherry", new FruitProviderRipening("cherry", prunes, ForestryItem.fruits.getItemStack(1, EnumFruit.CHERRY.ordinal()), 1.0f).setColours(0xff2e2e, 0xc4d24a).setOverlay("berries"), true); - Allele.fruitDates = new AlleleFruit("fruitDates", new FruitProviderPod("dates", jungle, EnumPodType.DATES, ForestryItem.fruits.getItemStack(4, EnumFruit.DATES.ordinal()))); - Allele.fruitPapaya = new AlleleFruit("fruitPapaya", new FruitProviderPod("papaya", jungle, EnumPodType.PAPAYA, ForestryItem.fruits.getItemStack(1, EnumFruit.PAPAYA.ordinal()))); + Allele.fruitChestnut = new AlleleFruit("fruitChestnut", new FruitProviderRipening("chestnut", nux, EnumFruit.CHESTNUT.getStack(), 1.0f).setRipeningPeriod(6).setColours(0x7f333d, 0xc4d24a).setOverlay("nuts"), true); + Allele.fruitWalnut = new AlleleFruit("fruitWalnut", new FruitProviderRipening("walnut", nux, EnumFruit.WALNUT.getStack(), 1.0f).setRipeningPeriod(8).setColours(0xfba248, 0xc4d24a).setOverlay("nuts"), true); + Allele.fruitCherry = new AlleleFruit("fruitCherry", new FruitProviderRipening("cherry", prunes, EnumFruit.CHERRY.getStack(), 1.0f).setColours(0xff2e2e, 0xc4d24a).setOverlay("berries"), true); + Allele.fruitDates = new AlleleFruit("fruitDates", new FruitProviderPod("dates", jungle, EnumPodType.DATES, EnumFruit.DATES.getStack(4))); + Allele.fruitPapaya = new AlleleFruit("fruitPapaya", new FruitProviderPod("papaya", jungle, EnumPodType.PAPAYA, EnumFruit.PAPAYA.getStack())); // Allele.fruitCoconut = new AlleleFruit("fruitCoconut", new // FruitProviderPod("coconut", jungle, EnumPodType.COCONUT, new // ItemStack[] { new ItemStack( // ForestryItem.fruits, 1, EnumFruit.COCONUT.ordinal()) })); - Allele.fruitLemon = new AlleleFruit("fruitLemon", new FruitProviderRipening("lemon", prunes, ForestryItem.fruits.getItemStack(1, EnumFruit.LEMON.ordinal()), 1.0f).setColours(0xeeee00, 0x99ff00).setOverlay("citrus"), true); - Allele.fruitPlum = new AlleleFruit("fruitPlum", new FruitProviderRipening("plum", prunes, ForestryItem.fruits.getItemStack(1, EnumFruit.PLUM.ordinal()), 1.0f).setColours(0x663446, 0xeeff1a).setOverlay("plums"), true); + Allele.fruitLemon = new AlleleFruit("fruitLemon", new FruitProviderRipening("lemon", prunes, EnumFruit.LEMON.getStack(), 1.0f).setColours(0xeeee00, 0x99ff00).setOverlay("citrus"), true); + Allele.fruitPlum = new AlleleFruit("fruitPlum", new FruitProviderRipening("plum", prunes, EnumFruit.PLUM.getStack(), 1.0f).setColours(0x663446, 0xeeff1a).setOverlay("plums"), true); // / TREES // GROWTH PROVIDER 1350 - 1399 Allele.growthLightlevel = new AlleleGrowth("growthLightlevel", new GrowthProvider()); @@ -959,10 +1021,14 @@ public class PluginArboriculture extends ForestryPlugin { treeInterface.registerTemplate(TreeTemplates.getDesertAcaciaTemplate()); treeInterface.registerTemplate(TreeTemplates.getWengeTemplate()); treeInterface.registerTemplate(TreeTemplates.getBaobabTemplate()); - + treeInterface.registerTemplate(TreeTemplates.getPadaukTemplate()); + treeInterface.registerTemplate(TreeTemplates.getCocoboloTemplate()); + treeInterface.registerTemplate(TreeTemplates.getTeakTemplate()); + treeInterface.registerTemplate(TreeTemplates.getIpeTemplate()); treeInterface.registerTemplate(TreeTemplates.getKapokTemplate()); treeInterface.registerTemplate(TreeTemplates.getEbonyTemplate()); + treeInterface.registerTemplate(TreeTemplates.getZebrawoodTemplate()); treeInterface.registerTemplate(TreeTemplates.getMahoganyTemplate()); treeInterface.registerTemplate(TreeTemplates.getWillowTemplate()); @@ -989,6 +1055,10 @@ public class PluginArboriculture extends ForestryPlugin { TreeTemplates.templateAsGenome(TreeTemplates.getBirchTemplate()))); AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves, 1, 3), new Tree( TreeTemplates.templateAsGenome(TreeTemplates.getJungleTemplate()))); + AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves2, 1, 0), new Tree( + TreeTemplates.templateAsGenome(TreeTemplates.getAcaciaTemplate()))); + AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves2, 1, 1), new Tree( + TreeTemplates.templateAsGenome(TreeTemplates.getDarkOakTemplate()))); AlleleManager.ersatzSaplings.put(new ItemStack(Blocks.sapling, 1, 0), new Tree( TreeTemplates.templateAsGenome(TreeTemplates.getOakTemplate()))); @@ -1009,7 +1079,7 @@ public class PluginArboriculture extends ForestryPlugin { // Decidious TreeTemplates.limeA = new TreeMutation(Allele.treeBirch, Allele.treeOak, TreeTemplates.getLimeTemplate(), 15); - TreeTemplates.mapleA = new TreeMutation(Allele.treeLime, Allele.treeLarch, + TreeTemplates.mapleA = new TreeMutation(Allele.treeSpruce, Allele.treeLarch, TreeTemplates.getMapleTemplate(), 5); // Fructifera @@ -1041,12 +1111,16 @@ public class PluginArboriculture extends ForestryPlugin { TreeTemplates.getSequoiaTemplate(), 5); // Tropical - TreeTemplates.teakA = new TreeMutation(Allele.treeLime, Allele.treeJungle, + TreeTemplates.teakA = new TreeMutation(Allele.treeDarkOak, Allele.treeJungle, TreeTemplates.getTeakTemplate(), 10); + TreeTemplates.ipeA = new TreeMutation(Allele.treeTeak, Allele.treeDarkOak, + TreeTemplates.getIpeTemplate(), 10); TreeTemplates.kapokA = new TreeMutation(Allele.treeJungle, Allele.treeTeak, TreeTemplates.getKapokTemplate(), 10); - TreeTemplates.ebonyA = new TreeMutation(Allele.treeKapok, Allele.treeTeak, + TreeTemplates.ebonyA = new TreeMutation(Allele.treeDarkOak, Allele.treeKapok, TreeTemplates.getEbonyTemplate(), 10); + TreeTemplates.zebrawoodA = new TreeMutation(Allele.treeEbony, Allele.treePoplar, + TreeTemplates.getZebrawoodTemplate(), 5); TreeTemplates.mahoganyA = new TreeMutation(Allele.treeKapok, Allele.treeEbony, TreeTemplates.getMahoganyTemplate(), 10); @@ -1056,15 +1130,19 @@ public class PluginArboriculture extends ForestryPlugin { TreeTemplates.getDateTemplate(), 5); // Malva - TreeTemplates.balsaA = new TreeMutation(Allele.treeTeak, Allele.treeLime, + TreeTemplates.balsaA = new TreeMutation(Allele.treeTeak, Allele.treeAcacia, TreeTemplates.getBalsaTemplate(), 10); TreeTemplates.acaciaA = new TreeMutation(Allele.treeTeak, Allele.treeBalsa, TreeTemplates.getDesertAcaciaTemplate(), 10); - TreeTemplates.wengeA = new TreeMutation(Allele.treeDesertAcacia, Allele.treeBalsa, + TreeTemplates.padaukA = new TreeMutation(Allele.treeAcacia, Allele.treeJungle, + TreeTemplates.getPadaukTemplate(), 10); + TreeTemplates.cocoboloA = new TreeMutation(Allele.treeDesertAcacia, Allele.treeDarkOak, + TreeTemplates.getCocoboloTemplate(), 10); + TreeTemplates.wengeA = new TreeMutation(Allele.treeCocobolo, Allele.treeBalsa, TreeTemplates.getWengeTemplate(), 10); TreeTemplates.baobabA = new TreeMutation(Allele.treeBalsa, Allele.treeWenge, TreeTemplates.getBaobabTemplate(), 10); - TreeTemplates.mahoeA = new TreeMutation(Allele.treeBirch, Allele.treeDesertAcacia, + TreeTemplates.mahoeA = new TreeMutation(Allele.treeBalsa, Allele.treeDesertAcacia, TreeTemplates.getMahoeTemplate(), 5); TreeTemplates.willowA = new TreeMutation(Allele.treeOak, Allele.treeBirch, @@ -1095,12 +1173,6 @@ public class PluginArboriculture extends ForestryPlugin { return new GuiHandlerArboriculture(); } - @Override - public ICommand[] getConsoleCommands() { - return new ICommand[]{new CommandSpawnTree(), new CommandSpawnForest(), - new CommandTreekeepingMode()}; - } - @Override public IFuelHandler getFuelHandler() { return new IFuelHandler() { diff --git a/src/main/java/forestry/plugins/PluginBuildCraftFuels.java b/src/main/java/forestry/plugins/PluginBuildCraftFuels.java index 79ce9b58f..e8c159d0b 100644 --- a/src/main/java/forestry/plugins/PluginBuildCraftFuels.java +++ b/src/main/java/forestry/plugins/PluginBuildCraftFuels.java @@ -10,21 +10,23 @@ ******************************************************************************/ package forestry.plugins; -import buildcraft.api.fuels.BuildcraftFuelRegistry; +import net.minecraftforge.fluids.Fluid; + import cpw.mods.fml.common.Optional; + import forestry.core.GameMode; import forestry.core.config.Defaults; -import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; -import net.minecraftforge.fluids.Fluid; + +import buildcraft.api.fuels.BuildcraftFuelRegistry; @Plugin(pluginID = "BC6|Fuels", name = "BuildCraft 6 Fuels", author = "mezz", url = Defaults.URL, unlocalizedDescription = "for.plugin.buildcraft6.description") public class PluginBuildCraftFuels extends ForestryPlugin { @Override public boolean isAvailable() { - return Proxies.common.isAPILoaded("buildcraft.api.fuels", "[2.0, 2.1)"); + return Proxies.common.isAPILoaded("buildcraft.api.fuels", "[2.0, 3.0)"); } @Override @@ -35,19 +37,14 @@ public class PluginBuildCraftFuels extends ForestryPlugin { @Optional.Method(modid = "BuildCraftAPI|fuels") @Override public void doInit() { - BuildcraftFuelRegistry.coolant.addCoolant(LiquidHelper.getFluid(Defaults.LIQUID_ICE), 10.0f); + BuildcraftFuelRegistry.coolant.addCoolant(Fluids.ICE.getFluid(), 10.0f); - Fluid ethanol = LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, 1).getFluid(); - int ethanolPower = 40; - int ethanolBurnTime = Math.round(Defaults.ENGINE_CYCLE_DURATION_ETHANOL * GameMode.getGameMode().getFloatSetting("fuel.ethanol.combustion")); - BuildcraftFuelRegistry.fuel.addFuel(ethanol, ethanolPower, ethanolBurnTime); - - LiquidHelper.injectWaxContainer(Defaults.LIQUID_OIL, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleOil.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectWaxContainer(Defaults.LIQUID_FUEL, Defaults.BUCKET_VOLUME, ForestryItem.waxCapsuleFuel.getItemStack(), ForestryItem.waxCapsule.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_OIL, Defaults.BUCKET_VOLUME, ForestryItem.refractoryOil.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - LiquidHelper.injectRefractoryContainer(Defaults.LIQUID_FUEL, Defaults.BUCKET_VOLUME, ForestryItem.refractoryFuel.getItemStack(), ForestryItem.refractoryEmpty.getItemStack()); - LiquidHelper.injectTinContainer(Defaults.LIQUID_OIL, Defaults.BUCKET_VOLUME, ForestryItem.canOil.getItemStack(), ForestryItem.canEmpty.getItemStack()); - LiquidHelper.injectTinContainer(Defaults.LIQUID_FUEL, Defaults.BUCKET_VOLUME, ForestryItem.canFuel.getItemStack(), ForestryItem.canEmpty.getItemStack()); + Fluid ethanol = Fluids.ETHANOL.getFluid(); + if (ethanol != null) { + int ethanolPower = 40; + int ethanolBurnTime = Math.round(Defaults.ENGINE_CYCLE_DURATION_ETHANOL * GameMode.getGameMode().getFloatSetting("fuel.ethanol.combustion")); + BuildcraftFuelRegistry.fuel.addFuel(ethanol, ethanolPower, ethanolBurnTime); + } } } diff --git a/src/main/java/forestry/plugins/PluginBuildCraftRecipes.java b/src/main/java/forestry/plugins/PluginBuildCraftRecipes.java index 632880e42..52b94edbc 100644 --- a/src/main/java/forestry/plugins/PluginBuildCraftRecipes.java +++ b/src/main/java/forestry/plugins/PluginBuildCraftRecipes.java @@ -13,16 +13,15 @@ package forestry.plugins; import buildcraft.api.recipes.BuildcraftRecipeRegistry; import cpw.mods.fml.common.Optional; import forestry.core.config.Defaults; +import forestry.core.fluids.Fluids; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; -import net.minecraftforge.fluids.FluidStack; @Plugin(pluginID = "BC6|Recipes", name = "BuildCraft 6 Recipes", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.buildcraft6.description") public class PluginBuildCraftRecipes extends ForestryPlugin { @Override public boolean isAvailable() { - return Proxies.common.isAPILoaded("buildcraft.api.recipes", "[2.0, 2.1)"); + return Proxies.common.isAPILoaded("buildcraft.api.recipes", "[2.0, 3.0)"); } @Override @@ -34,8 +33,6 @@ public class PluginBuildCraftRecipes extends ForestryPlugin { @Override protected void registerRecipes() { // Add recipe for ethanol - FluidStack input = LiquidHelper.getLiquid(Defaults.LIQUID_BIOMASS, 4); - FluidStack output = LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, 1); - BuildcraftRecipeRegistry.refinery.addRecipe("forestry:BiomassToEthanol", input, output, 100, 1); + BuildcraftRecipeRegistry.refinery.addRecipe("forestry:BiomassToEthanol", Fluids.BIOMASS.getFluid(4), Fluids.ETHANOL.getFluid(1), 100, 1); } } diff --git a/src/main/java/forestry/plugins/PluginBuildCraftStatements.java b/src/main/java/forestry/plugins/PluginBuildCraftStatements.java index 61c9ed4f3..b93b073a3 100644 --- a/src/main/java/forestry/plugins/PluginBuildCraftStatements.java +++ b/src/main/java/forestry/plugins/PluginBuildCraftStatements.java @@ -18,18 +18,17 @@ import buildcraft.api.statements.StatementManager; import cpw.mods.fml.common.Optional; import forestry.core.config.Defaults; import forestry.core.proxy.Proxies; +import java.util.Collection; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -import java.util.Collection; - @Plugin(pluginID = "BC6|Statements", name = "BuildCraft 6 Statements", author = "mezz", url = Defaults.URL, unlocalizedDescription = "for.plugin.buildcraft6.description") -@Optional.Interface(iface = "ITriggerProvider", modid = "BuildCraftAPI|statements") +@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements") public class PluginBuildCraftStatements extends ForestryPlugin implements ITriggerProvider { @Override public boolean isAvailable() { - return Proxies.common.isAPILoaded("buildcraft.api.statements", "[1.0, 1.1)"); + return Proxies.common.isAPILoaded("buildcraft.api.statements", "[1.0, 2.0)"); } @Override diff --git a/src/main/java/forestry/plugins/PluginBuildCraftTransport.java b/src/main/java/forestry/plugins/PluginBuildCraftTransport.java index 6d9b6d3d9..e717bc066 100644 --- a/src/main/java/forestry/plugins/PluginBuildCraftTransport.java +++ b/src/main/java/forestry/plugins/PluginBuildCraftTransport.java @@ -22,7 +22,7 @@ public class PluginBuildCraftTransport extends ForestryPlugin { @Override public boolean isAvailable() { - return Proxies.common.isModLoaded("BuildCraft|Transport"); + return Proxies.common.isAPILoaded("buildcraft.api.transport", "[2.0, 4.0)"); } @Override diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index 411514819..d338d5e4d 100755 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -10,19 +10,26 @@ ******************************************************************************/ package forestry.plugins; +import java.util.ArrayList; + import net.minecraft.block.material.Material; import net.minecraft.command.ICommand; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; + import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.RecipeSorter; + import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.network.IGuiHandler; + import forestry.api.circuits.ChipsetManager; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; +import forestry.api.storage.ICrateRegistry; +import forestry.api.storage.StorageManager; import forestry.core.CreativeTabForestry; import forestry.core.GameMode; import forestry.core.PickupHandlerCore; @@ -52,14 +59,11 @@ import forestry.core.interfaces.IPickupHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemArmorNaturalist; import forestry.core.items.ItemAssemblyKit; -import forestry.core.items.ItemCrated; import forestry.core.items.ItemForestry; import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemForestryPickaxe; import forestry.core.items.ItemForestryShovel; import forestry.core.items.ItemFruit; -import forestry.core.items.ItemLiquidContainer; -import forestry.core.items.ItemLiquidContainer.EnumContainerType; import forestry.core.items.ItemMisc; import forestry.core.items.ItemOverlay; import forestry.core.items.ItemOverlay.OverlayInfo; @@ -70,8 +74,6 @@ import forestry.core.proxy.Proxies; import forestry.core.utils.ForestryModEnvWarningCallable; import forestry.core.utils.ShapedRecipeCustom; -import java.util.ArrayList; - @Plugin(pluginID = "Core", name = "Core", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.core.description") public class PluginCore extends ForestryPlugin { @@ -110,19 +112,14 @@ public class PluginCore extends ForestryPlugin { ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1); ForestryBlock.resources.registerBlock(new BlockResource(), ItemForestryBlock.class, "resources"); - ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1, 0); - ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1, 1); - ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1, 2); + ForestryBlock.resources.block().setHarvestLevel("pickaxe", 1); OreDictionary.registerOre("oreApatite", ForestryBlock.resources.getItemStack(1, 0)); OreDictionary.registerOre("oreCopper", ForestryBlock.resources.getItemStack(1, 1)); OreDictionary.registerOre("oreTin", ForestryBlock.resources.getItemStack(1, 2)); ForestryBlock.resourceStorage.registerBlock(new BlockResourceStorageBlock(), ItemForestryBlock.class, "resourceStorage"); - ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 0); - ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 1); - ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 2); - ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 3); + ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0); OreDictionary.registerOre("blockApatite", ForestryBlock.resourceStorage.getItemStack(1, 0)); OreDictionary.registerOre("blockCopper", ForestryBlock.resourceStorage.getItemStack(1, 1)); @@ -159,7 +156,6 @@ public class PluginCore extends ForestryPlugin { @Override protected void registerItems() { - // / FERTILIZERS ForestryItem.fertilizerBio.registerItem((new ItemForestry()), "fertilizerBio"); ForestryItem.fertilizerCompound.registerItem((new ItemForestry()).setBonemeal(true), "fertilizerCompound"); @@ -193,13 +189,6 @@ public class PluginCore extends ForestryPlugin { /* ARMOR */ ForestryItem.naturalistHat.registerItem(new ItemArmorNaturalist(0), "naturalistHelmet"); - // / DISCONTINUED - // ForestryItem.vialEmpty = (new - // ItemForestry(Config.getOrCreateIntProperty("vialEmpty", - // Config.CATEGORY_ITEM, Defaults.ID_ITEM_VIAL_EMPTY))) - // .setItemName("vialEmpty").setIconIndex(10); - ForestryItem.vialCatalyst.registerItem((new ItemForestry()), "vialCatalyst"); - // / PEAT PRODUCTION ForestryItem.peat.registerItem((new ItemForestry()), "peat"); OreDictionary.registerOre("brickPeat", ForestryItem.peat.getItemStack()); @@ -270,51 +259,10 @@ public class PluginCore extends ForestryPlugin { // FRUITS ForestryItem.fruits.registerItem(new ItemFruit(), "fruits"); + } - // / EMPTY LIQUID CONTAINERS - ForestryItem.waxCapsule.registerItem(new ItemLiquidContainer(EnumContainerType.CAPSULE, -1).setMaxStackSize(64), "waxCapsule"); - ForestryItem.canEmpty.registerItem(new ItemLiquidContainer(EnumContainerType.CAN, -1).setMaxStackSize(64), "canEmpty"); - ForestryItem.refractoryEmpty.registerItem(new ItemLiquidContainer(EnumContainerType.REFRACTORY, -1).setMaxStackSize(64), "refractoryEmpty"); - - // / BUCKETS - ForestryItem.bucketBiomass.registerItem(new ItemForestry().setContainerItem(Items.bucket).setMaxStackSize(1), "bucketBiomass"); - ForestryItem.bucketBiofuel.registerItem(new ItemForestry().setContainerItem(Items.bucket).setMaxStackSize(1), "bucketBiofuel"); - - // / WAX CAPSULES - ForestryItem.waxCapsuleWater.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0x2432ec)), "waxCapsuleWater"); - ForestryItem.waxCapsuleBiomass.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0x83d41c)), "waxCapsuleBiomass"); - ForestryItem.waxCapsuleBiofuel.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0xff7909)), "waxCapsuleBiofuel"); - ForestryItem.waxCapsuleOil.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0x404040)), "waxCapsuleOil"); - ForestryItem.waxCapsuleFuel.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0xffff00)), "waxCapsuleFuel"); - ForestryItem.waxCapsuleSeedOil.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0xffffa9)), "waxCapsuleSeedOil"); - ForestryItem.waxCapsuleHoney.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0xffda47)).setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION), "waxCapsuleHoney"); - ForestryItem.waxCapsuleJuice.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0x99d04e)).setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION), "waxCapsuleJuice"); - ForestryItem.waxCapsuleIce.registerItem((new ItemLiquidContainer(EnumContainerType.CAPSULE, 0xdcffff)), "waxCapsuleIce"); - - // / CANS - ForestryItem.canWater.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0x2432ec)), "waterCan"); - ForestryItem.canBiomass.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0x83d41c)), "biomassCan"); - ForestryItem.canBiofuel.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xff7909)), "biofuelCan"); - ForestryItem.canOil.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0x404040)), "canOil"); - ForestryItem.canFuel.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xffff00)), "canFuel"); - ForestryItem.canLava.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xfd461f)), "canLava"); - ForestryItem.canSeedOil.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xffffa9)), "canSeedOil"); - ForestryItem.canHoney.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xffda47)).setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION), "canHoney"); - ForestryItem.canJuice.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0x99d04e)).setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION), "canJuice"); - ForestryItem.canIce.registerItem((new ItemLiquidContainer(EnumContainerType.CAN, 0xdcffff)), "canIce"); - - // / REFRACTORY CAPSULES - ForestryItem.refractoryWater.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0x2432ec)), "refractoryWater"); - ForestryItem.refractoryBiomass.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0x83d41c)), "refractoryBiomass"); - ForestryItem.refractoryBiofuel.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xff7909)), "refractoryBiofuel"); - ForestryItem.refractoryOil.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0x404040)), "refractoryOil"); - ForestryItem.refractoryFuel.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xffff00)), "refractoryFuel"); - ForestryItem.refractoryLava.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xfd461f)), "refractoryLava"); - ForestryItem.refractorySeedOil.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xffffa9)), "refractorySeedOil"); - ForestryItem.refractoryHoney.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xffda47)).setDrink(Defaults.FOOD_HONEY_HEAL, Defaults.FOOD_HONEY_SATURATION), "refractoryHoney"); - ForestryItem.refractoryJuice.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0x99d04e)).setDrink(Defaults.FOOD_JUICE_HEAL, Defaults.FOOD_JUICE_SATURATION), "refractoryJuice"); - ForestryItem.refractoryIce.registerItem((new ItemLiquidContainer(EnumContainerType.REFRACTORY, 0xdcffff)), "refractoryIce"); - + @Override + public void postInit() { } @Override @@ -323,45 +271,48 @@ public class PluginCore extends ForestryPlugin { @Override protected void registerCrates() { - // / CRATES - ForestryItem.cratedWood.registerItem(new ItemCrated(new ItemStack(Blocks.log)), "cratedWood"); - ForestryItem.cratedCobblestone.registerItem(new ItemCrated(new ItemStack(Blocks.cobblestone)), "cratedCobblestone"); - ForestryItem.cratedDirt.registerItem(new ItemCrated(new ItemStack(Blocks.dirt)), "cratedDirt"); - ForestryItem.cratedStone.registerItem(new ItemCrated(new ItemStack(Blocks.stone)), "cratedStone"); - ForestryItem.cratedBrick.registerItem(new ItemCrated(new ItemStack(Blocks.brick_block)), "cratedBrick"); - ForestryItem.cratedCacti.registerItem(new ItemCrated(new ItemStack(Blocks.cactus)), "cratedCacti"); - ForestryItem.cratedSand.registerItem(new ItemCrated(new ItemStack(Blocks.sand)), "cratedSand"); - ForestryItem.cratedObsidian.registerItem(new ItemCrated(new ItemStack(Blocks.obsidian)), "cratedObsidian"); - ForestryItem.cratedNetherrack.registerItem(new ItemCrated(new ItemStack(Blocks.netherrack)), "cratedNetherrack"); - ForestryItem.cratedSoulsand.registerItem(new ItemCrated(new ItemStack(Blocks.soul_sand)), "cratedSoulsand"); - ForestryItem.cratedSandstone.registerItem(new ItemCrated(new ItemStack(Blocks.sandstone)), "cratedSandstone"); - ForestryItem.cratedBogearth.registerItem(new ItemCrated(ForestryBlock.soil.getItemStack(1, 1)), "cratedBogearth"); - ForestryItem.cratedHumus.registerItem(new ItemCrated(ForestryBlock.soil.getItemStack(1, 0)), "cratedHumus"); - ForestryItem.cratedNetherbrick.registerItem(new ItemCrated(new ItemStack(Blocks.nether_brick)), "cratedNetherbrick"); - ForestryItem.cratedPeat.registerItem(new ItemCrated(ForestryItem.peat.getItemStack()), "cratedPeat"); - ForestryItem.cratedApatite.registerItem(new ItemCrated(ForestryItem.apatite.getItemStack()), "cratedApatite"); - ForestryItem.cratedFertilizer.registerItem(new ItemCrated(ForestryItem.fertilizerCompound.getItemStack()), "cratedFertilizer"); - ForestryItem.cratedTin.registerItem(new ItemCrated(ForestryItem.ingotTin.getItemStack()), "cratedTin"); - ForestryItem.cratedCopper.registerItem(new ItemCrated(ForestryItem.ingotCopper.getItemStack()), "cratedCopper"); - ForestryItem.cratedBronze.registerItem(new ItemCrated(ForestryItem.ingotBronze.getItemStack()), "cratedBronze"); - ForestryItem.cratedWheat.registerItem(new ItemCrated(new ItemStack(Items.wheat)), "cratedWheat"); - ForestryItem.cratedMycelium.registerItem(new ItemCrated(new ItemStack(Blocks.mycelium)), "cratedMycelium"); - ForestryItem.cratedMulch.registerItem(new ItemCrated(ForestryItem.mulch.getItemStack()), "cratedMulch"); - ForestryItem.cratedCookies.registerItem(new ItemCrated(new ItemStack(Items.cookie)), "cratedCookies"); - ForestryItem.cratedRedstone.registerItem(new ItemCrated(new ItemStack(Items.redstone)), "cratedRedstone"); - ForestryItem.cratedLapis.registerItem(new ItemCrated(new ItemStack(Items.dye, 1, 4)), "cratedLapis"); - ForestryItem.cratedReeds.registerItem(new ItemCrated(new ItemStack(Items.reeds)), "cratedReeds"); - ForestryItem.cratedClay.registerItem(new ItemCrated(new ItemStack(Items.clay_ball)), "cratedClay"); - ForestryItem.cratedGlowstone.registerItem(new ItemCrated(new ItemStack(Items.glowstone_dust)), "cratedGlowstone"); - ForestryItem.cratedApples.registerItem(new ItemCrated(new ItemStack(Items.apple)), "cratedApples"); - ForestryItem.cratedNetherwart.registerItem(new ItemCrated(new ItemStack(Items.nether_wart)), "cratedNetherwart"); - ForestryItem.cratedPhosphor.registerItem(new ItemCrated(ForestryItem.phosphor.getItemStack()), "cratedPhosphor"); - ForestryItem.cratedAsh.registerItem(new ItemCrated(ForestryItem.ash.getItemStack()), "cratedAsh"); - ForestryItem.cratedCharcoal.registerItem(new ItemCrated(new ItemStack(Items.coal, 1, 1)), "cratedCharcoal"); - ForestryItem.cratedGravel.registerItem(new ItemCrated(new ItemStack(Blocks.gravel)), "cratedGravel"); - ForestryItem.cratedCoal.registerItem(new ItemCrated(new ItemStack(Items.coal, 1, 0)), "cratedCoal"); - ForestryItem.cratedSeeds.registerItem(new ItemCrated(new ItemStack(Items.wheat_seeds)), "cratedSeeds"); - ForestryItem.cratedSaplings.registerItem(new ItemCrated(new ItemStack(Blocks.sapling)), "cratedSaplings"); + ICrateRegistry crateRegistry = StorageManager.crateRegistry; + crateRegistry.registerCrate(Blocks.log, "cratedWood"); + crateRegistry.registerCrate(Blocks.cobblestone, "cratedCobblestone"); + crateRegistry.registerCrate(Blocks.dirt, "cratedDirt"); + crateRegistry.registerCrate(Blocks.stone, "cratedStone"); + crateRegistry.registerCrate(Blocks.brick_block, "cratedBrick"); + crateRegistry.registerCrate(Blocks.cactus, "cratedCacti"); + crateRegistry.registerCrate(Blocks.sand, "cratedSand"); + crateRegistry.registerCrate(Blocks.obsidian, "cratedObsidian"); + crateRegistry.registerCrate(Blocks.netherrack, "cratedNetherrack"); + crateRegistry.registerCrate(Blocks.soul_sand, "cratedSoulsand"); + crateRegistry.registerCrate(Blocks.sandstone, "cratedSandstone"); + crateRegistry.registerCrate(ForestryBlock.soil.getItemStack(1, 0), "cratedHumus"); + crateRegistry.registerCrate(ForestryBlock.soil.getItemStack(1, 1), "cratedBogearth"); + crateRegistry.registerCrate(Blocks.nether_brick, "cratedNetherbrick"); + crateRegistry.registerCrate(ForestryItem.peat.item(), "cratedPeat"); + crateRegistry.registerCrate(ForestryItem.apatite.item(), "cratedApatite"); + crateRegistry.registerCrate(ForestryItem.fertilizerCompound.item(), "cratedFertilizer"); + crateRegistry.registerCrate(Items.wheat, "cratedWheat"); + crateRegistry.registerCrate(Blocks.mycelium, "cratedMycelium"); + crateRegistry.registerCrate(ForestryItem.mulch.item(), "cratedMulch"); + crateRegistry.registerCrate(Items.cookie, "cratedCookies"); + crateRegistry.registerCrate(Items.redstone, "cratedRedstone"); + crateRegistry.registerCrate(new ItemStack(Items.dye, 1, 4), "cratedLapis"); + crateRegistry.registerCrate(Items.reeds, "cratedReeds"); + crateRegistry.registerCrate(Items.clay_ball, "cratedClay"); + crateRegistry.registerCrate(Items.glowstone_dust, "cratedGlowstone"); + crateRegistry.registerCrate(Items.apple, "cratedApples"); + crateRegistry.registerCrate(new ItemStack(Items.nether_wart), "cratedNetherwart"); + crateRegistry.registerCrate(ForestryItem.phosphor.item(), "cratedPhosphor"); + crateRegistry.registerCrate(ForestryItem.ash.item(), "cratedAsh"); + crateRegistry.registerCrate(new ItemStack(Items.coal, 1, 1), "cratedCharcoal"); + crateRegistry.registerCrate(new ItemStack(Items.coal, 1, 0), "cratedCoal"); + crateRegistry.registerCrate(Blocks.gravel, "cratedGravel"); + crateRegistry.registerCrate(Items.wheat_seeds, "cratedSeeds"); + crateRegistry.registerCrate(Blocks.sapling, "cratedSaplings"); + crateRegistry.registerCrate(Items.potato, "cratedPotatoes"); + crateRegistry.registerCrate(Items.carrot, "cratedCarrots"); + + crateRegistry.registerCrateUsingOreDict(ForestryItem.ingotTin.item(), "cratedTin"); + crateRegistry.registerCrateUsingOreDict(ForestryItem.ingotCopper.item(), "cratedCopper"); + crateRegistry.registerCrateUsingOreDict(ForestryItem.ingotBronze.item(), "cratedBronze"); } @Override @@ -373,7 +324,7 @@ public class PluginCore extends ForestryPlugin { Proxies.common.addSmelting(ForestryBlock.resources.getItemStack(1, 2), ForestryItem.ingotTin.getItemStack(), 0.5f); /* BRONZE INGOTS */ - if (Config.getCraftingBronzeEnabled()) + if (Config.isCraftingBronzeEnabled()) Proxies.common.addShapelessRecipe(ForestryItem.ingotBronze.getItemStack(4), "ingotTin", "ingotCopper", "ingotCopper", "ingotCopper"); /* STURDY MACHINE */ @@ -432,10 +383,6 @@ public class PluginCore extends ForestryPlugin { Proxies.common.addRecipe(GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"), "#Y#", "YXY", "#Y#", '#', Blocks.dirt, 'X', ForestryItem.refractoryWater, 'Y', Blocks.sand); } - // Vials and catalyst - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(3), "###", "YXY", '#', ForestryItem.waxCapsule.item(), 'X', Items.bone, 'Y', ForestryItem.fertilizerCompound); - Proxies.common.addRecipe(ForestryItem.vialCatalyst.getItemStack(3), "###", "YXY", '#', ForestryItem.canEmpty.item(), 'X', Items.bone, 'Y', ForestryItem.fertilizerCompound); - // Crafting Material Proxies.common.addRecipe(new ItemStack(Items.string), "#", "#", "#", '#', ForestryItem.craftingMaterial.getItemStack(1, 2)); diff --git a/src/main/java/forestry/plugins/PluginEE.java b/src/main/java/forestry/plugins/PluginEE.java index c684ce36f..d68e343f0 100755 --- a/src/main/java/forestry/plugins/PluginEE.java +++ b/src/main/java/forestry/plugins/PluginEE.java @@ -10,13 +10,6 @@ ******************************************************************************/ package forestry.plugins; -import java.lang.reflect.Field; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - -import net.minecraftforge.common.BiomeDictionary; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IMutation; import forestry.apiculture.genetics.AlleleBeeSpecies; @@ -27,6 +20,10 @@ import forestry.apiculture.genetics.MutationEMC; import forestry.core.config.Defaults; import forestry.core.genetics.Allele; import forestry.core.proxy.Proxies; +import java.lang.reflect.Field; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.BiomeDictionary; @Plugin(pluginID = "EqEx2", name = "Equivalent Exchange 2", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.ee2.description") public class PluginEE extends ForestryPlugin { diff --git a/src/main/java/forestry/plugins/PluginEnergy.java b/src/main/java/forestry/plugins/PluginEnergy.java index 443578996..a9679a6d7 100755 --- a/src/main/java/forestry/plugins/PluginEnergy.java +++ b/src/main/java/forestry/plugins/PluginEnergy.java @@ -10,23 +10,9 @@ ******************************************************************************/ package forestry.plugins; -import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; - -import net.minecraftforge.fluids.FluidStack; - import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.IGuiHandler; - -import forestry.api.circuits.ChipsetManager; -import forestry.api.circuits.ICircuitLayout; -import forestry.api.fuels.FuelManager; -import forestry.api.fuels.GeneratorFuel; import forestry.core.GameMode; -import forestry.core.circuits.Circuit; -import forestry.core.circuits.CircuitId; -import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; @@ -35,21 +21,16 @@ import forestry.core.gadgets.MachineDefinition; import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemForestryBlock; -import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; import forestry.energy.GuiHandlerEnergy; -import forestry.energy.circuits.CircuitElectricBoost; -import forestry.energy.circuits.CircuitElectricChoke; -import forestry.energy.circuits.CircuitElectricEfficiency; -import forestry.energy.circuits.CircuitFireDampener; import forestry.energy.gadgets.EngineBronze; import forestry.energy.gadgets.EngineClockwork; import forestry.energy.gadgets.EngineCopper; import forestry.energy.gadgets.EngineDefinition; -import forestry.energy.gadgets.EngineTin; -import forestry.energy.gadgets.MachineGenerator; import forestry.energy.proxy.ProxyEnergy; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; @Plugin(pluginID = "Energy", name = "Energy", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.energy.description") public class PluginEnergy extends ForestryPlugin { diff --git a/src/main/java/forestry/plugins/PluginFactory.java b/src/main/java/forestry/plugins/PluginFactory.java old mode 100755 new mode 100644 index 05eec8e43..0ea4b22a0 --- a/src/main/java/forestry/plugins/PluginFactory.java +++ b/src/main/java/forestry/plugins/PluginFactory.java @@ -10,22 +10,29 @@ ******************************************************************************/ package forestry.plugins; +import java.util.Arrays; + +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + import cpw.mods.fml.common.network.IGuiHandler; -import forestry.api.recipes.ICraftingProvider; + import forestry.api.recipes.RecipeManagers; import forestry.core.GameMode; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; import forestry.core.gadgets.MachineNBTDefinition; -import forestry.core.interfaces.IOreDictionaryHandler; -import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemForestryBlock; import forestry.core.items.ItemNBTTile; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.RecipeUtil; import forestry.core.utils.ShapedRecipeCustom; import forestry.factory.GuiHandlerFactory; @@ -42,12 +49,7 @@ import forestry.factory.gadgets.MillRainmaker; import forestry.factory.gadgets.TileWorktable; import forestry.factory.recipes.CraftGuideIntegration; import forestry.factory.triggers.FactoryTriggers; -import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import java.util.ArrayList; @Plugin(pluginID = "Factory", name = "Factory", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.factory.description") public class PluginFactory extends ForestryPlugin { @@ -68,21 +70,15 @@ public class PluginFactory extends ForestryPlugin { public void preInit() { super.preInit(); - RecipeManagers.craftingProviders = new ArrayList(); - // Init carpenter manager - RecipeManagers.craftingProviders.add(RecipeManagers.carpenterManager = new MachineCarpenter.RecipeManager()); - // Init centrifuge manager - RecipeManagers.craftingProviders.add(RecipeManagers.centrifugeManager = new MachineCentrifuge.RecipeManager()); - // Init fabricator manager - RecipeManagers.craftingProviders.add(RecipeManagers.fabricatorManager = new MachineFabricator.RecipeManager()); - // Init fermenter manager - RecipeManagers.craftingProviders.add(RecipeManagers.fermenterManager = new MachineFermenter.RecipeManager()); - // Init moistener manager - RecipeManagers.craftingProviders.add(RecipeManagers.moistenerManager = new MachineMoistener.RecipeManager()); - // Init squeezer manager - RecipeManagers.craftingProviders.add(RecipeManagers.squeezerManager = new MachineSqueezer.RecipeManager()); - // Init still manager - RecipeManagers.craftingProviders.add(RecipeManagers.stillManager = new MachineStill.RecipeManager()); + RecipeManagers.craftingProviders = Arrays.asList( + RecipeManagers.carpenterManager = new MachineCarpenter.RecipeManager(), + RecipeManagers.centrifugeManager = new MachineCentrifuge.RecipeManager(), + RecipeManagers.fabricatorManager = new MachineFabricator.RecipeManager(), + RecipeManagers.fermenterManager = new MachineFermenter.RecipeManager(), + RecipeManagers.moistenerManager = new MachineMoistener.RecipeManager(), + RecipeManagers.squeezerManager = new MachineSqueezer.RecipeManager(), + RecipeManagers.stillManager = new MachineStill.RecipeManager() + ); ForestryBlock.factoryTESR.registerBlock(new BlockBase(Material.iron, true), ItemForestryBlock.class, "factory"); @@ -250,56 +246,61 @@ public class PluginFactory extends ForestryPlugin { protected void registerRecipes() { // / FABRICATOR - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 0), new Object[]{ + + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 0), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', "ingotCopper"}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 1), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 1), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', "ingotTin"}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 2), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 2), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', "ingotBronze"}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 3), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 3), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.iron_ingot}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 4), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 4), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.gold_ingot}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 5), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 5), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.diamond}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 6), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 6), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Blocks.obsidian}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 7), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 7), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.blaze_powder}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 9), new Object[]{ + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 9), new Object[]{ " X ", "#X#", "XXX", '#', Items.redstone, 'X', Items.emerald}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 10), + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 10), new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', "gemApatite"}); - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 11), + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 11), new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', new ItemStack(Items.dye, 1, 4)}); String[] dyes = {"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite"}; - if (PluginManager.Module.APICULTURE.isEnabled()) + if (PluginManager.Module.APICULTURE.isEnabled()) { + FluidStack liquidGlass = Fluids.GLASS.getFluid(Defaults.BUCKET_VOLUME); for (int i = 0; i < 16; i++) - RecipeManagers.fabricatorManager.addRecipe(ForestryItem.waxCast.getItemStack(1, Defaults.WILDCARD), LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, - Defaults.BUCKET_VOLUME), ForestryBlock.glass.getItemStack(1, 15 - i), new Object[]{"#", "X", '#', dyes[i], - 'X', ForestryItem.propolis.getItemStack(1, Defaults.WILDCARD)}); + RecipeManagers.fabricatorManager.addRecipe(ForestryItem.waxCast.getItemStack(1, Defaults.WILDCARD), liquidGlass, ForestryBlock.glass.getItemStack(1, 15 - i), new Object[]{"#", "X", '#', dyes[i], + 'X', ForestryItem.propolis.getItemStack(1, Defaults.WILDCARD)}); + } // / SQUEEZER - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.apple)}, LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple")), - ForestryItem.mulch.getItemStack(), GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple")); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.wheat_seeds)}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, GameMode - .getGameMode().getIntegerSetting("squeezer.liquid.seed"))); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.pumpkin_seeds)}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, GameMode - .getGameMode().getIntegerSetting("squeezer.liquid.seed"))); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.melon_seeds)}, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, GameMode - .getGameMode().getIntegerSetting("squeezer.liquid.seed"))); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.cobblestone)}, - LiquidHelper.getLiquid(Defaults.LIQUID_LAVA, 1600)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Blocks.cactus)}, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 500)); - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.snowball), ForestryItem.craftingMaterial.getItemStack(4, 5)}, - LiquidHelper.getLiquid(Defaults.LIQUID_ICE, 4000)); + int appleMulchAmount = GameMode.getGameMode().getIntegerSetting("squeezer.mulch.apple"); + int appleJuiceAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple"); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.apple)}, Fluids.JUICE.getFluid(appleJuiceAmount), + ForestryItem.mulch.getItemStack(), appleMulchAmount); + + int seedOilAmount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); + FluidStack seedOil = Fluids.SEEDOIL.getFluid(seedOilAmount); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.wheat_seeds)}, seedOil); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.pumpkin_seeds)}, seedOil); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.melon_seeds)}, seedOil); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{ForestryItem.phosphor.getItemStack(2), new ItemStack(Blocks.cobblestone)}, Fluids.LAVA.getFluid(1600)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Blocks.cactus)}, Fluids.WATER.getFluid(500)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(Items.snowball), ForestryItem.craftingMaterial.getItemStack(4, 5)}, Fluids.ICE.getFluid(4000)); // STILL - RecipeManagers.stillManager.addRecipe(Defaults.STILL_DESTILLATION_DURATION, LiquidHelper.getLiquid(Defaults.LIQUID_BIOMASS, - Defaults.STILL_DESTILLATION_INPUT), LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, Defaults.STILL_DESTILLATION_OUTPUT)); + RecipeManagers.stillManager.addRecipe(Defaults.STILL_DESTILLATION_DURATION, Fluids.BIOMASS.getFluid(Defaults.STILL_DESTILLATION_INPUT), + Fluids.ETHANOL.getFluid(Defaults.STILL_DESTILLATION_OUTPUT)); + + // convert old honey to new honey + RecipeManagers.stillManager.addRecipe(1, Fluids.LEGACY_HONEY.getFluid(1000), Fluids.HONEY.getFluid(1000)); // MOISTENER RecipeManagers.moistenerManager.addRecipe(new ItemStack(Items.wheat_seeds), new ItemStack(Blocks.mycelium), 5000); @@ -307,29 +308,28 @@ public class PluginFactory extends ForestryPlugin { RecipeManagers.moistenerManager.addRecipe(new ItemStack(Blocks.stonebrick), new ItemStack(Blocks.stonebrick, 1, 1), 20000); // FERMENTER - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.sapling, 1, 0), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.sapling, 1, 1), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.sapling, 1, 2), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.sapling, 1, 3), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + for (int i = 0; i < 4; i++) + RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.sapling, 1, i), GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.cactus), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cactus"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Items.wheat), GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Items.reeds), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cane"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.brown_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.red_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Defaults.LIQUID_BIOMASS); + RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.cactus), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS); + RecipeUtil.injectLeveledRecipe(new ItemStack(Items.wheat), GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); + RecipeUtil.injectLeveledRecipe(new ItemStack(Items.reeds), GameMode.getGameMode().getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS); + RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.brown_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); + RecipeUtil.injectLeveledRecipe(new ItemStack(Blocks.red_mushroom), GameMode.getGameMode().getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS); // FABRICATOR - RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.glass), LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 1000), 1000); - RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.glass_pane), LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 375), 1000); - RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.sand), LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 1000), 3000); + + RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.glass), Fluids.GLASS.getFluid(1000), 1000); + RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.glass_pane), Fluids.GLASS.getFluid(375), 1000); + RecipeManagers.fabricatorManager.addSmelting(new ItemStack(Blocks.sand), Fluids.GLASS.getFluid(1000), 3000); // / CARPENTER - RecipeManagers.carpenterManager.addRecipe(50, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 250), null, ForestryItem.impregnatedCasing.getItemStack(), + RecipeManagers.carpenterManager.addRecipe(50, Fluids.SEEDOIL.getFluid(250), null, ForestryItem.impregnatedCasing.getItemStack(), "###", "# #", "###", '#', "logWood"); - RecipeManagers.carpenterManager.addRecipe(50, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 500), null, + RecipeManagers.carpenterManager.addRecipe(50, Fluids.SEEDOIL.getFluid(500), null, ForestryBlock.core.getItemStack(1, Defaults.DEFINITION_ESCRITOIRE_META), "# ", "###", @@ -337,35 +337,35 @@ public class PluginFactory extends ForestryPlugin { '#', "plankWood"); // RESOURCES - RecipeManagers.carpenterManager.addRecipe(10, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 100), null, + RecipeManagers.carpenterManager.addRecipe(10, Fluids.SEEDOIL.getFluid(100), null, ForestryItem.stickImpregnated.getItemStack(2), "#", "#", '#', "logWood"); - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 250), null, + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(250), null, ForestryItem.woodPulp.getItemStack(4), "#", '#', "logWood"); - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 250), null, + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(250), null, new ItemStack(Items.paper, 1), "#", "#", '#', "pulpWood"); - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryBlock.soil.getItemStack(9), "###", "#X#", "###", '#', Blocks.dirt, 'X', ForestryItem.mulch); - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryBlock.soil.getItemStack(8, 1), "#X#", "XYX", "#X#", '#', Blocks.dirt, 'X', Blocks.sand, 'Y', ForestryItem.mulch); - RecipeManagers.carpenterManager.addRecipe(75, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 5000), null, ForestryItem.hardenedCasing.getItemStack(), + RecipeManagers.carpenterManager.addRecipe(75, Fluids.WATER.getFluid(5000), null, ForestryItem.hardenedCasing.getItemStack(), "# #", " Y ", "# #", @@ -373,21 +373,21 @@ public class PluginFactory extends ForestryPlugin { 'Y', ForestryItem.sturdyCasing); // / CHIPSETS - RecipeManagers.carpenterManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.circuitboards.getItemStack(1, 0), + RecipeManagers.carpenterManager.addRecipe(20, Fluids.WATER.getFluid(1000), null, ForestryItem.circuitboards.getItemStack(1, 0), "R R", "R#R", "R R", '#', "ingotTin", 'R', Items.redstone); - RecipeManagers.carpenterManager.addRecipe(40, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.circuitboards.getItemStack(1, 1), + RecipeManagers.carpenterManager.addRecipe(40, Fluids.WATER.getFluid(1000), null, ForestryItem.circuitboards.getItemStack(1, 1), "R#R", "R#R", "R#R", '#', "ingotBronze", 'R', Items.redstone); - RecipeManagers.carpenterManager.addRecipe(80, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.circuitboards.getItemStack(1, 2), + RecipeManagers.carpenterManager.addRecipe(80, Fluids.WATER.getFluid(1000), null, ForestryItem.circuitboards.getItemStack(1, 2), "R#R", "R#R", "R#R", '#', Items.iron_ingot, 'R', Items.redstone); - RecipeManagers.carpenterManager.addRecipe(80, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.circuitboards.getItemStack(1, 3), + RecipeManagers.carpenterManager.addRecipe(80, Fluids.WATER.getFluid(1000), null, ForestryItem.circuitboards.getItemStack(1, 3), "R#R", "R#R", "R#R", '#', Items.gold_ingot, 'R', Items.redstone); - RecipeManagers.carpenterManager.addRecipe(40, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.solderingIron.getItemStack(), + RecipeManagers.carpenterManager.addRecipe(40, Fluids.WATER.getFluid(1000), null, ForestryItem.solderingIron.getItemStack(), " # ", "# #", " B", '#', Items.iron_ingot, 'B', "ingotBronze"); // ForestryCore.oreHandler.registerCarpenterRecipe(solderingIron); // RAIN SUBSTRATES if (PluginManager.Module.APICULTURE.isEnabled()) { - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.iodineCharge.getItemStack(), + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryItem.iodineCharge.getItemStack(), "Z#Z", "#Y#", "X#X", @@ -396,7 +396,7 @@ public class PluginFactory extends ForestryPlugin { 'Y', ForestryItem.canEmpty, 'Z', ForestryItem.honeyDrop); // ForestryCore.oreHandler.registerCarpenterRecipe(iodineCapsule); - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.craftingMaterial.getItemStack(1, 4), + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryItem.craftingMaterial.getItemStack(1, 4), "Z#Z", "#Y#", "X#X", @@ -411,13 +411,13 @@ public class PluginFactory extends ForestryPlugin { RecipeManagers.carpenterManager.addRecipe(100, null, new ItemStack(Items.ender_pearl, 1), " # ", "###", " # ", '#', ForestryItem.craftingMaterial.getItemStack(1, 1)); // Woven Silk - RecipeManagers.carpenterManager.addRecipe(10, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 500), null, ForestryItem.craftingMaterial.getItemStack(1, 3), + RecipeManagers.carpenterManager.addRecipe(10, Fluids.WATER.getFluid(500), null, ForestryItem.craftingMaterial.getItemStack(1, 3), "###", "###", "###", '#', ForestryItem.craftingMaterial.getItemStack(1, 2)); // Boxes - RecipeManagers.carpenterManager.addRecipe(5, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.carton.getItemStack(2), + RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null, ForestryItem.carton.getItemStack(2), " # ", "# #", " # ", '#', "pulpWood"); - RecipeManagers.carpenterManager.addRecipe(20, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.crate.getItemStack(24), + RecipeManagers.carpenterManager.addRecipe(20, Fluids.WATER.getFluid(1000), null, ForestryItem.crate.getItemStack(24), " # ", "# #", " # ", '#', "logWood"); // Assembly Kits @@ -436,83 +436,15 @@ public class PluginFactory extends ForestryPlugin { "#", '#', ForestryItem.brokenBronzePickaxe); RecipeManagers.carpenterManager.addRecipe(null, ForestryItem.ingotBronze.getItemStack(), "#", '#', ForestryItem.brokenBronzeShovel); - // Crating and uncrating condensed + // Crating and uncrating if (PluginManager.Module.STORAGE.isEnabled()) { - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedWood.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCobblestone.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedDirt.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedStone.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedBrick.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCacti.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSand.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedObsidian.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedNetherrack.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSoulsand.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSandstone.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedBogearth.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedHumus.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedNetherbrick.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedPeat.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedApatite.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedFertilizer.getItemStack()); - RecipeManagers.carpenterManager.addCrating("ingotTin", ForestryItem.ingotTin.getItemStack(), ForestryItem.cratedTin.getItemStack()); - RecipeManagers.carpenterManager.addCrating("ingotCopper", ForestryItem.ingotCopper.getItemStack(), ForestryItem.cratedCopper.getItemStack()); - RecipeManagers.carpenterManager.addCrating("ingotBronze", ForestryItem.ingotBronze.getItemStack(), ForestryItem.cratedBronze.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedWheat.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedMycelium.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedMulch.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCookies.getItemStack()); - - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedRedstone.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedLapis.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedReeds.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedClay.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedGlowstone.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedApples.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedNetherwart.getItemStack()); - - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedPhosphor.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedAsh.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCharcoal.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedGravel.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCoal.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSeeds.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSaplings.getItemStack()); - - if (PluginManager.Module.APICULTURE.isEnabled()) { - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedHoneycombs.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedBeeswax.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedPollen.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedPropolis.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedHoneydew.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedRoyalJelly.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedCocoaComb.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedSimmeringCombs.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedStringyCombs.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedFrozenCombs.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedDrippingCombs.getItemStack()); - RecipeManagers.carpenterManager.addCrating(ForestryItem.cratedRefractoryWax.getItemStack()); - } + PluginStorage.createCrateRecipes(); } } - @Override - protected void registerCrates() { - // TODO Auto-generated method stub - } - @Override public IGuiHandler getGuiHandler() { return new GuiHandlerFactory(); } - @Override - public ISaveEventHandler getSaveEventHandler() { - return null; - } - - @Override - public IOreDictionaryHandler getDictionaryHandler() { - return null; - } } diff --git a/src/main/java/forestry/plugins/PluginFarmCraftory.java b/src/main/java/forestry/plugins/PluginFarmCraftory.java index 5a785612d..ba527c9e1 100755 --- a/src/main/java/forestry/plugins/PluginFarmCraftory.java +++ b/src/main/java/forestry/plugins/PluginFarmCraftory.java @@ -10,19 +10,16 @@ ******************************************************************************/ package forestry.plugins; -import java.lang.reflect.Method; -import java.util.HashMap; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - - import forestry.api.farming.Farmables; import forestry.core.config.Defaults; import forestry.core.proxy.Proxies; import forestry.farming.logic.FarmableFarmCraftory; +import java.lang.reflect.Method; +import java.util.HashMap; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; @Plugin(pluginID = "FarmCraftory", name = "FarmCraftory", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.farmcraftory.description") public class PluginFarmCraftory extends ForestryPlugin { diff --git a/src/main/java/forestry/plugins/PluginFarming.java b/src/main/java/forestry/plugins/PluginFarming.java index 0c9187319..885eedc0b 100755 --- a/src/main/java/forestry/plugins/PluginFarming.java +++ b/src/main/java/forestry/plugins/PluginFarming.java @@ -10,11 +10,23 @@ ******************************************************************************/ package forestry.plugins; +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import net.minecraftforge.common.MinecraftForge; + import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; + import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuitLayout; import forestry.api.farming.Farmables; @@ -35,8 +47,8 @@ import forestry.farming.GuiHandlerFarming; import forestry.farming.circuits.CircuitFarmLogic; import forestry.farming.gadgets.BlockFarm; import forestry.farming.gadgets.BlockMushroom; +import forestry.farming.gadgets.EnumFarmBlock; import forestry.farming.gadgets.TileControl; -import forestry.farming.gadgets.TileFarm.EnumFarmBlock; import forestry.farming.gadgets.TileFarmPlain; import forestry.farming.gadgets.TileGearbox; import forestry.farming.gadgets.TileHatch; @@ -62,15 +74,6 @@ import forestry.farming.logic.FarmableVanillaSapling; import forestry.farming.logic.FarmableVanillaShroom; import forestry.farming.proxy.ProxyFarming; import forestry.farming.triggers.FarmingTriggers; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.MinecraftForge; - -import java.util.ArrayList; @Plugin(pluginID = "Farming", name = "Farming", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.farming.description") public class PluginFarming extends ForestryPlugin { @@ -295,8 +298,7 @@ public class PluginFarming extends ForestryPlugin { block.saveToCompound(compound); basic.setTagCompound((NBTTagCompound) compound.copy()); - ShapedRecipeCustom.buildRecipe(basic.copy(), "I#I", "WCW", '#', block.getCraftingIngredient(), 'W', "slabWood", 'C', ForestryItem.tubes.getItemStack(1, 1), 'I', "ingotCopper"); - + ShapedRecipeCustom.buildRecipe(basic.copy(), "I#I", "WCW", '#', block.getBase(), 'W', "slabWood", 'C', ForestryItem.tubes.getItemStack(1, 1), 'I', "ingotCopper"); } ItemStack gearbox = ForestryBlock.farm.getItemStack(1, 2); diff --git a/src/main/java/forestry/plugins/PluginFluids.java b/src/main/java/forestry/plugins/PluginFluids.java new file mode 100644 index 000000000..a523853ce --- /dev/null +++ b/src/main/java/forestry/plugins/PluginFluids.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * 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.plugins; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; + +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.config.ForestryItem; +import forestry.core.fluids.BlockForestryFluid; +import forestry.core.fluids.Fluids; +import forestry.core.items.ItemLiquidContainer; +import forestry.core.proxy.Proxies; +import forestry.core.utils.LiquidHelper; + +import static forestry.core.items.ItemLiquidContainer.EnumContainerType; + +@Plugin(pluginID = "Fluids", name = "Fluids", author = "mezz", url = Defaults.URL, unlocalizedDescription = "for.plugin.fluids.description") +public class PluginFluids extends ForestryPlugin { + + private static final List forestryFluidsWithBlocks = new ArrayList(); + + private static void createFluid(Fluids forestryFluid) { + if (forestryFluid.getFluid() == null && Config.isFluidEnabled(forestryFluid)) { + String fluidName = forestryFluid.getTag(); + if (!FluidRegistry.isFluidRegistered(fluidName)) { + Fluid fluid = new Fluid(fluidName).setDensity(forestryFluid.getDensity()).setViscosity(forestryFluid.getViscosity()).setTemperature(forestryFluid.getTemperature()); + FluidRegistry.registerFluid(fluid); + createBlock(forestryFluid); + } + } + } + + private static void createBlock(Fluids forestryFluid) { + Fluid fluid = forestryFluid.getFluid(); + Block fluidBlock = fluid.getBlock(); + + if (Config.isBlockEnabled(forestryFluid.getTag())) { + if (fluidBlock == null) { + fluidBlock = forestryFluid.makeBlock(); + if (fluidBlock != null) { + fluidBlock.setBlockName("forestry.fluid." + forestryFluid.getTag()); + Proxies.common.registerBlock(fluidBlock, ItemBlock.class); + forestryFluidsWithBlocks.add(forestryFluid); + } + } else { + GameRegistry.UniqueIdentifier blockID = GameRegistry.findUniqueIdentifierFor(fluidBlock); + Proxies.log.severe("Pre-existing {0} fluid block detected, deferring to {1}:{2}, " + + "this may cause issues if the server/client have different mod load orders, " + + "recommended that you disable all but one instance of {0} fluid blocks via your configs.", fluid.getName(), blockID.modId, blockID.name); + } + } + } + + @Override + public void preInit() { + for (Fluids fluidType : Fluids.forestryFluids) { + createFluid(fluidType); + } + MinecraftForge.EVENT_BUS.register(getTextureHook()); + MinecraftForge.EVENT_BUS.register(getFillBucketHook()); + } + + @Override + public void registerItems() { + for (EnumContainerType type : EnumContainerType.values()) { + Item emptyContainer = new ItemLiquidContainer(type, Blocks.air, null); + switch (type) { + case CAN: + ForestryItem.canEmpty.registerItem(emptyContainer, "canEmpty"); + break; + case CAPSULE: + ForestryItem.waxCapsule.registerItem(emptyContainer, "waxCapsule"); + break; + case REFRACTORY: + ForestryItem.refractoryEmpty.registerItem(emptyContainer, "refractoryEmpty"); + break; + } + + for (Fluids fluidType : Fluids.values()) { + ForestryItem container = fluidType.getContainerForType(type); + if (container == null) + continue; + + ItemLiquidContainer liquidContainer = new ItemLiquidContainer(type, fluidType.getBlock(), fluidType.getColor()); + fluidType.setProperties(liquidContainer); + container.registerItem(liquidContainer, container.toString()); + } + } + } + + @Override + public void doInit() { + for (Fluids fluidType : Fluids.values()) { + if (fluidType.getFluid() == null) + continue; + + for (EnumContainerType type : EnumContainerType.values()) { + ForestryItem container = fluidType.getContainerForType(type); + if (container == null) + continue; + + LiquidHelper.injectLiquidContainer(fluidType, container.getItemStack()); + } + + for (ItemStack filledContainer : fluidType.getOtherContainers()) { + LiquidHelper.injectLiquidContainer(fluidType, filledContainer); + } + } + } + + public static class MissingFluidException extends RuntimeException { + public MissingFluidException(String tag) { + super("Fluid '" + tag + "' was not found. Please check your configs."); + } + } + + @Override + public void postInit() { + for (Fluids fluidType : Fluids.forestryFluids) { + if (fluidType.getFluid() == null) + throw new MissingFluidException(fluidType.getTag()); + } + } + + public static class TextureHook { + @SubscribeEvent + @SideOnly(Side.CLIENT) + public void textureHook(TextureStitchEvent.Post event) { + if (event.map.getTextureType() == 0) { + for (Fluids fluidType : forestryFluidsWithBlocks) { + Fluid fluid = fluidType.getFluid(); + Block fluidBlock = fluidType.getBlock(); + if (fluid != null && fluidBlock != null) + fluid.setIcons(fluidBlock.getBlockTextureFromSide(1), fluidBlock.getBlockTextureFromSide(2)); + } + } + } + } + + private static Object getTextureHook() { + return new TextureHook(); + } + + public static class FillBucketHook { + @SubscribeEvent + public void fillBucket(FillBucketEvent event) { + MovingObjectPosition movingObjectPosition = event.target; + int x = movingObjectPosition.blockX; + int y = movingObjectPosition.blockY; + int z = movingObjectPosition.blockZ; + Block targetedBlock = event.world.getBlock(x, y, z); + if (targetedBlock instanceof BlockForestryFluid) { + Item filledBucket = ItemLiquidContainer.getExistingBucket(targetedBlock); + if (filledBucket != null) { + event.result = new ItemStack(filledBucket); + event.setResult(Event.Result.ALLOW); + } + } + } + } + + private static Object getFillBucketHook() { + return new FillBucketHook(); + } +} diff --git a/src/main/java/forestry/plugins/PluginFood.java b/src/main/java/forestry/plugins/PluginFood.java index 3e68bed5d..dc4cd9a21 100755 --- a/src/main/java/forestry/plugins/PluginFood.java +++ b/src/main/java/forestry/plugins/PluginFood.java @@ -10,16 +10,12 @@ ******************************************************************************/ package forestry.plugins; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - import cpw.mods.fml.common.network.IGuiHandler; - import forestry.api.food.BeverageManager; import forestry.api.food.IBeverageEffect; -import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemForestryFood; @@ -31,6 +27,8 @@ import forestry.food.items.ItemAmbrosia; import forestry.food.items.ItemBeverage; import forestry.food.items.ItemBeverage.BeverageInfo; import forestry.food.items.ItemInfuser; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; @Plugin(pluginID = "Food", name = "Food", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.food.description") public class PluginFood extends ForestryPlugin { @@ -69,8 +67,7 @@ public class PluginFood extends ForestryPlugin { ItemStack meadBottle = ForestryItem.beverage.getItemStack(); ((ItemBeverage) ForestryItem.beverage.item()).beverages[0].saveEffects(meadBottle, new IBeverageEffect[] { BeverageEffect.weakAlcoholic }); - LiquidHelper.getOrCreateLiquid(Defaults.LIQUID_MEAD); - LiquidHelper.injectLiquidContainer(Defaults.LIQUID_MEAD, Defaults.BUCKET_VOLUME, meadBottle, new ItemStack(Items.glass_bottle)); + LiquidHelper.injectLiquidContainer(Fluids.SHORT_MEAD, Defaults.BUCKET_VOLUME, meadBottle, new ItemStack(Items.glass_bottle)); } @Override diff --git a/src/main/java/forestry/plugins/PluginIC2.java b/src/main/java/forestry/plugins/PluginIC2.java index 227192bcc..95a228f25 100644 --- a/src/main/java/forestry/plugins/PluginIC2.java +++ b/src/main/java/forestry/plugins/PluginIC2.java @@ -10,15 +10,26 @@ ******************************************************************************/ package forestry.plugins; +import java.util.EnumSet; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.GameData; + import forestry.api.circuits.ChipsetManager; import forestry.api.circuits.ICircuitLayout; import forestry.api.fuels.FuelManager; import forestry.api.fuels.GeneratorFuel; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; +import forestry.api.storage.ICrateRegistry; +import forestry.api.storage.StorageManager; import forestry.core.GameMode; import forestry.core.circuits.Circuit; import forestry.core.circuits.CircuitId; @@ -28,9 +39,9 @@ import forestry.core.config.Configuration; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; -import forestry.core.items.ItemCrated; import forestry.core.proxy.Proxies; import forestry.core.utils.LiquidHelper; import forestry.core.utils.RecipeUtil; @@ -45,15 +56,10 @@ import forestry.energy.gadgets.EngineTin; import forestry.energy.gadgets.MachineGenerator; import forestry.farming.circuits.CircuitFarmLogic; import forestry.farming.logic.FarmLogicRubber; + import ic2.api.item.IC2Items; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.Recipes; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import java.util.EnumSet; @Plugin(pluginID = "IC2", name = "IndustrialCraft2", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.ic2.description") public class PluginIC2 extends ForestryPlugin { @@ -195,11 +201,11 @@ public class PluginIC2 extends ForestryPlugin { definitionEngineTin.register(); definitionGenerator.register(); - FluidStack ethanol = LiquidHelper.getLiquid(Defaults.LIQUID_ETHANOL, 1); + FluidStack ethanol = Fluids.ETHANOL.getFluid(1); GeneratorFuel ethanolFuel = new GeneratorFuel(ethanol, (int) (32 * GameMode.getGameMode().getFloatSetting("fuel.ethanol.generator")), 4); FuelManager.generatorFuel.put(ethanol.getFluid(), ethanolFuel); - FluidStack biomass = LiquidHelper.getLiquid(Defaults.LIQUID_BIOMASS, 1); + FluidStack biomass = Fluids.BIOMASS.getFluid(1); GeneratorFuel biomassFuel = new GeneratorFuel(biomass, (int) (8 * GameMode.getGameMode().getFloatSetting("fuel.biomass.generator")), 1); FuelManager.generatorFuel.put(biomass.getFluid(), biomassFuel); @@ -229,47 +235,45 @@ public class PluginIC2 extends ForestryPlugin { @Override @Optional.Method(modid = "IC2") protected void registerCrates() { + ICrateRegistry crateRegistry = StorageManager.crateRegistry; if (resin != null) { - ForestryItem.cratedResin.registerItem(new ItemCrated(), "cratedResin"); - ((ItemCrated) ForestryItem.cratedResin.item()).setContained(ForestryItem.cratedResin.getItemStack(), resin); + crateRegistry.registerCrate(resin, "cratedResin"); } if (rubber != null) { - ForestryItem.cratedRubber.registerItem(new ItemCrated(), "cratedRubber"); - ((ItemCrated) ForestryItem.cratedRubber.item()).setContained(ForestryItem.cratedRubber.getItemStack(), rubber); + crateRegistry.registerCrate(rubber, "cratedRubber"); } if (scrap != null) { - ForestryItem.cratedScrap.registerItem(new ItemCrated(), "cratedScrap"); - ((ItemCrated) ForestryItem.cratedScrap.item()).setContained(ForestryItem.cratedScrap.getItemStack(), scrap); + crateRegistry.registerCrate(scrap, "cratedScrap"); } if (uuMatter != null) { - ForestryItem.cratedUUM.registerItem(new ItemCrated(), "cratedUUM"); - ((ItemCrated) ForestryItem.cratedUUM.item()).setContained(ForestryItem.cratedUUM.getItemStack(), uuMatter); + crateRegistry.registerCrate(uuMatter, "cratedUUM"); } if (silver != null) { - ForestryItem.cratedSilver.registerItem(new ItemCrated(), "cratedSilver"); - ((ItemCrated) ForestryItem.cratedSilver.item()).setContained(ForestryItem.cratedSilver.getItemStack(), silver); + crateRegistry.registerCrateUsingOreDict(silver, "cratedSilver"); } if (brass != null) { - ForestryItem.cratedBrass.registerItem(new ItemCrated(), "cratedBrass"); - ((ItemCrated) ForestryItem.cratedBrass.item()).setContained(ForestryItem.cratedBrass.getItemStack(), brass); + crateRegistry.registerCrateUsingOreDict(brass, "cratedBrass"); } } @Optional.Method(modid = "IC2") protected void registerRecipes() { - if (rubber != null) - RecipeManagers.fabricatorManager.addRecipe(null, LiquidHelper.getLiquid(Defaults.LIQUID_GLASS, 500), ForestryItem.tubes.getItemStack(4, 8), - new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', PluginIC2.rubber}); + if (rubber != null) { + for (Object rubberOreDict : RecipeUtil.getOreDictRecipeEquivalents(rubber)) { + RecipeManagers.fabricatorManager.addRecipe(null, Fluids.GLASS.getFluid(500), ForestryItem.tubes.getItemStack(4, 8), + new Object[]{" X ", "#X#", "XXX", '#', Items.redstone, 'X', rubberOreDict}); + } + } if (plantBall != null && compressedPlantBall != null) { - RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 4, Defaults.LIQUID_BIOMASS); - RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 5, Defaults.LIQUID_BIOMASS); + RecipeUtil.injectLeveledRecipe(plantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 4, Fluids.BIOMASS); + RecipeUtil.injectLeveledRecipe(compressedPlantBall, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat") * 5, Fluids.BIOMASS); } else { Proxies.log.fine("No IC2 plantballs found."); } @@ -280,7 +284,7 @@ public class PluginIC2 extends ForestryPlugin { Proxies.log.fine("Missing IC2 resin, skipping centrifuge recipe for propolis to resin."); if (rubbersapling != null) { - RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Defaults.LIQUID_BIOMASS); + RecipeUtil.injectLeveledRecipe(rubbersapling, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); } else Proxies.log.fine("Missing IC2 rubber sapling, skipping fermenter recipe for converting rubber sapling to biomass."); @@ -295,10 +299,10 @@ public class PluginIC2 extends ForestryPlugin { } if (lavaCell != null) - LiquidHelper.injectTinContainer(Defaults.LIQUID_LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); + LiquidHelper.injectTinContainer(Fluids.LAVA, Defaults.BUCKET_VOLUME, lavaCell, emptyCell); if (waterCell != null) { - LiquidHelper.injectTinContainer(Defaults.LIQUID_WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); + LiquidHelper.injectTinContainer(Fluids.WATER, Defaults.BUCKET_VOLUME, waterCell, emptyCell); ItemStack bogEarthCan = GameMode.getGameMode().getStackSetting("recipe.output.bogearth.can"); if (bogEarthCan.stackSize > 0) diff --git a/src/main/java/forestry/plugins/PluginLepidopterology.java b/src/main/java/forestry/plugins/PluginLepidopterology.java index 1630ac097..f8a2d5988 100755 --- a/src/main/java/forestry/plugins/PluginLepidopterology.java +++ b/src/main/java/forestry/plugins/PluginLepidopterology.java @@ -10,18 +10,8 @@ ******************************************************************************/ package forestry.plugins; -import java.util.EnumSet; -import java.util.Locale; - -import net.minecraft.block.material.Material; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraftforge.oredict.RecipeSorter; - import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.IGuiHandler; - import forestry.api.arboriculture.ITreeRoot; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; @@ -37,12 +27,12 @@ import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.config.Property; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; import forestry.core.genetics.Allele; import forestry.core.genetics.Branch; import forestry.core.items.ItemForestryBlock; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; import forestry.core.utils.Utils; import forestry.lepidopterology.ButterflySpawner; @@ -58,6 +48,13 @@ import forestry.lepidopterology.genetics.ButterflyTemplates; import forestry.lepidopterology.items.ItemButterflyGE; import forestry.lepidopterology.items.ItemFlutterlyzer; import forestry.lepidopterology.proxy.ProxyLepidopterology; +import java.util.EnumSet; +import java.util.Locale; +import net.minecraft.block.material.Material; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraftforge.oredict.RecipeSorter; @Plugin(pluginID = "Lepidopterology", name = "Lepidopterology", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.lepidopterology.description") public class PluginLepidopterology extends ForestryPlugin { @@ -102,12 +99,12 @@ public class PluginLepidopterology extends ForestryPlugin { config = new Configuration(); Property property = config.get("entities.spawn.limit", CONFIG_CATEGORY, spawnConstraint); - property.Comment = "determines the global butterfly entity count above which natural spawning of butterflies ceases."; - spawnConstraint = Integer.parseInt(property.Value); + property.comment = "determines the global butterfly entity count above which natural spawning of butterflies ceases."; + spawnConstraint = Integer.parseInt(property.value); property = config.get("entities.maximum.allowed", CONFIG_CATEGORY, entityConstraint); - property.Comment = "determines the global butterfly entity count above which butterflies will stay in item form and will not take flight anymore."; - entityConstraint = Integer.parseInt(property.Value); + property.comment = "determines the global butterfly entity count above which butterflies will stay in item form and will not take flight anymore."; + entityConstraint = Integer.parseInt(property.value); config.save(); @@ -148,9 +145,9 @@ public class PluginLepidopterology extends ForestryPlugin { protected void registerRecipes() { CraftingManager.getInstance().getRecipeList().add(new MatingRecipe()); - RecipeManagers.carpenterManager.addRecipe(100, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 2000), null, ForestryItem.flutterlyzer.getItemStack(), - "X#X", "X#X", "RDR", Character.valueOf('#'), Blocks.glass_pane, Character.valueOf('X'), "ingotBronze", Character.valueOf('R'), - Items.redstone, Character.valueOf('D'), Items.diamond); + RecipeManagers.carpenterManager.addRecipe(100, Fluids.WATER.getFluid(2000), null, ForestryItem.flutterlyzer.getItemStack(), + "X#X", "X#X", "RDR", '#', Blocks.glass_pane, 'X', "ingotBronze", 'R', + Items.redstone, 'D', Items.diamond); } private void createAlleles() { diff --git a/src/main/java/forestry/plugins/PluginMail.java b/src/main/java/forestry/plugins/PluginMail.java index b98c89c30..ce8fc0548 100755 --- a/src/main/java/forestry/plugins/PluginMail.java +++ b/src/main/java/forestry/plugins/PluginMail.java @@ -19,6 +19,7 @@ import net.minecraft.item.ItemStack; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.network.IGuiHandler; +import forestry.api.mail.EnumAddressee; import forestry.api.mail.EnumPostage; import forestry.api.mail.PostManager; import forestry.api.recipes.RecipeManagers; @@ -26,6 +27,7 @@ import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.gadgets.BlockBase; import forestry.core.gadgets.MachineDefinition; import forestry.core.interfaces.IOreDictionaryHandler; @@ -33,10 +35,7 @@ import forestry.core.interfaces.IPacketHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.items.ItemForestryBlock; import forestry.core.proxy.Proxies; -import forestry.core.triggers.Trigger; -import forestry.core.utils.LiquidHelper; import forestry.core.utils.ShapedRecipeCustom; -import forestry.api.mail.EnumAddressee; import forestry.mail.GuiHandlerMail; import forestry.mail.PacketHandlerMail; import forestry.mail.PostRegistry; @@ -52,26 +51,13 @@ import forestry.mail.items.ItemLetter; import forestry.mail.items.ItemStamps; import forestry.mail.items.ItemStamps.StampInfo; import forestry.mail.proxy.ProxyMail; -import forestry.mail.triggers.TriggerBuffer; -import forestry.mail.triggers.TriggerHasMail; -import forestry.mail.triggers.TriggerLowInput; -import forestry.mail.triggers.TriggerLowPaper; -import forestry.mail.triggers.TriggerLowStamps; +import forestry.mail.triggers.MailTriggers; @Plugin(pluginID = "Mail", name = "Mail", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.mail.description") public class PluginMail extends ForestryPlugin { @SidedProxy(clientSide = "forestry.mail.proxy.ClientProxyMail", serverSide = "forestry.mail.proxy.ProxyMail") public static ProxyMail proxy; - public static Trigger triggerHasMail; - public static Trigger lowPaper64; - public static Trigger lowPaper32; - public static Trigger lowPostage40; - public static Trigger lowPostage20; - public static Trigger lowInput25; - public static Trigger lowInput10; - public static Trigger highBuffer75; - public static Trigger highBuffer90; public static MachineDefinition definitionMailbox; public static MachineDefinition definitionTradestation; public static MachineDefinition definitionPhilatelist; @@ -85,15 +71,10 @@ public class PluginMail extends ForestryPlugin { new TickHandlerMailClient(); - triggerHasMail = new TriggerHasMail(); - lowPaper64 = new TriggerLowPaper("mail.lowPaper.64", 64); - lowPaper32 = new TriggerLowPaper("mail.lowPaper.32", 32); - lowPostage40 = new TriggerLowStamps("mail.lowStamps.40", 40); - lowPostage20 = new TriggerLowStamps("mail.lowStamps.20", 20); - lowInput25 = new TriggerLowInput("mail.lowInput.25", 0.25f); - lowInput10 = new TriggerLowInput("mail.lowInput.10", 0.1f); - highBuffer75 = new TriggerBuffer("mail.lowBuffer.75", 0.75f); - highBuffer90 = new TriggerBuffer("mail.lowBuffer.90", 0.90f); + // Triggers + if (PluginManager.Module.BUILDCRAFT_STATEMENTS.isEnabled()) { + MailTriggers.initialize(); + } ForestryBlock.mail.registerBlock(new BlockBase(Material.iron), ItemForestryBlock.class, "mail"); @@ -201,7 +182,7 @@ public class PluginMail extends ForestryPlugin { 'X', stampDefinitions[i].getCraftingIngredient(), '#', Items.paper, 'Z', stampGlue); - RecipeManagers.carpenterManager.addRecipe(10, LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, 300), null, ForestryItem.stamps.getItemStack(9, i), + RecipeManagers.carpenterManager.addRecipe(10, Fluids.SEEDOIL.getFluid(300), null, ForestryItem.stamps.getItemStack(9, i), "XXX", "###", 'X', stampDefinitions[i].getCraftingIngredient(), '#', Items.paper); @@ -211,7 +192,7 @@ public class PluginMail extends ForestryPlugin { Proxies.common.addRecipe(new ItemStack(Items.paper), "###", '#', ForestryItem.letters.getItemStack(1, Defaults.WILDCARD)); // Carpenter - RecipeManagers.carpenterManager.addRecipe(10, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 250), null, ForestryItem.letters.getItemStack(), "###", "###", '#', ForestryItem.woodPulp); + RecipeManagers.carpenterManager.addRecipe(10, Fluids.WATER.getFluid(250), null, ForestryItem.letters.getItemStack(), "###", "###", '#', ForestryItem.woodPulp); Proxies.common.addShapelessRecipe(ForestryItem.catalogue.getItemStack(), ForestryItem.stamps.getItemStack(1, Defaults.WILDCARD), new ItemStack(Items.book)); } diff --git a/src/main/java/forestry/plugins/PluginManager.java b/src/main/java/forestry/plugins/PluginManager.java index cc5628a8f..e521a671c 100755 --- a/src/main/java/forestry/plugins/PluginManager.java +++ b/src/main/java/forestry/plugins/PluginManager.java @@ -11,16 +11,12 @@ package forestry.plugins; import com.google.common.collect.ImmutableList; -import java.util.ArrayList; - import com.google.common.collect.Lists; - import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameRegistry; import forestry.Forestry; - import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.IPacketHandler; import forestry.core.interfaces.IPickupHandler; @@ -28,6 +24,7 @@ import forestry.core.interfaces.IResupplyHandler; import forestry.core.interfaces.ISaveEventHandler; import forestry.core.proxy.Proxies; import java.io.File; +import java.util.ArrayList; import java.util.EnumSet; import java.util.Iterator; import java.util.Locale; @@ -38,6 +35,8 @@ import net.minecraft.command.ICommand; import net.minecraft.server.MinecraftServer; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; + import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; @@ -64,7 +63,8 @@ public class PluginManager { public enum Module { - CORE(new PluginCore()), + CORE(new PluginCore(), false), + FLUIDS(new PluginFluids(), false), APICULTURE(new PluginApiculture()), ARBORICULTURE(new PluginArboriculture()), ENERGY(new PluginEnergy()), @@ -85,9 +85,15 @@ public class PluginManager { NATURA(new PluginNatura()),; private final ForestryPlugin instance; + private final boolean canBeDisabled; private Module(ForestryPlugin plugin) { + this(plugin, true); + } + + private Module(ForestryPlugin plugin, boolean canBeDisabled) { this.instance = plugin; + this.canBeDisabled = canBeDisabled; } public ForestryPlugin instance() { @@ -98,8 +104,18 @@ public class PluginManager { return isModuleLoaded(this); } + public boolean canBeDisabled() { + return canBeDisabled; + } + + public String configName() { + return toString().toLowerCase(Locale.ENGLISH).replace('_', '.'); + } + } + public static final EnumSet configDisabledModules = EnumSet.noneOf(Module.class); + public static Stage getStage() { return stage; } @@ -131,7 +147,7 @@ public class PluginManager { Iterator it = toLoad.iterator(); while (it.hasNext()) { Module m = it.next(); - if (m == Module.CORE) + if (!m.canBeDisabled()) continue; if (!isEnabled(config, m)) { it.remove(); @@ -155,7 +171,7 @@ public class PluginManager { if (!toLoad.containsAll(deps)) { it.remove(); changed = true; - Proxies.log.warning("Module {0} is missing dependancies: {1}", m, deps); + Proxies.log.warning("Module {0} is missing dependencies: {1}", m, deps); continue; } } @@ -274,18 +290,30 @@ public class PluginManager { } } - public static void generateSurface(World world, Random rand, int chunkX, int chunkZ) { + public static void populateChunk(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) { for (Module m : loadedModules) { ForestryPlugin plugin = m.instance; - plugin.generateSurface(world, rand, chunkX, chunkZ); + plugin.populateChunk(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated); + } + } + + public static void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) { + for (Module m : loadedModules) { + ForestryPlugin plugin = m.instance; + plugin.populateChunkRetroGen(world, rand, chunkX, chunkZ); } } private static boolean isEnabled(Configuration config, Module m) { Plugin info = m.instance().getClass().getAnnotation(Plugin.class); - Property prop = config.get(CATEGORY_MODULES, m.toString().toLowerCase(Locale.ENGLISH).replace('_', '.'), true); - prop.comment = StatCollector.translateToLocal(info.unlocalizedDescription()); - return prop.getBoolean(true); + String comment = StatCollector.translateToLocal(info.unlocalizedDescription()); + Property prop = config.get(CATEGORY_MODULES, m.configName(), true, comment); + boolean enabled = prop.getBoolean(); + + if (!enabled) + configDisabledModules.add(m); + + return enabled; } } diff --git a/src/main/java/forestry/plugins/PluginNatura.java b/src/main/java/forestry/plugins/PluginNatura.java index 8611c3700..70d47da8d 100755 --- a/src/main/java/forestry/plugins/PluginNatura.java +++ b/src/main/java/forestry/plugins/PluginNatura.java @@ -10,21 +10,19 @@ ******************************************************************************/ package forestry.plugins; -import java.util.ArrayList; - -import cpw.mods.fml.common.registry.GameData; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - import cpw.mods.fml.common.event.FMLInterModComms; +import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; - import forestry.api.recipes.RecipeManagers; import forestry.core.GameMode; import forestry.core.config.Defaults; +import forestry.core.fluids.Fluids; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; +import forestry.core.utils.RecipeUtil; +import java.util.ArrayList; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; @Plugin(pluginID = "Natura", name = "Natura", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.natura.description") public class PluginNatura extends ForestryPlugin { @@ -67,6 +65,10 @@ public class PluginNatura extends ForestryPlugin { for (String key : saplingItemKeys) { Item saplingItem = GameRegistry.findItem(NATURA, key); + + ItemStack saplingWild = new ItemStack(saplingItem, 1, Defaults.WILDCARD); + RecipeUtil.injectLeveledRecipe(saplingWild, GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS); + String saplingName = GameData.getItemRegistry().getNameForObject(saplingItem); FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); } @@ -85,8 +87,7 @@ public class PluginNatura extends ForestryPlugin { int amount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.seed"); for (ItemStack aSeedList : seedList) - RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{aSeedList}, - LiquidHelper.getLiquid(Defaults.LIQUID_SEEDOIL, amount)); + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{aSeedList}, Fluids.SEEDOIL.getFluid(amount)); ItemStack berryBlight = GameRegistry.findItemStack(NATURA, "berryBlight", 1); ItemStack berryDusk = GameRegistry.findItemStack(NATURA, "berryDusk", 1); @@ -118,8 +119,11 @@ public class PluginNatura extends ForestryPlugin { amount = GameMode.getGameMode().getIntegerSetting("squeezer.liquid.apple") / 25; amount = (amount > 1) ? amount : 1; // Produce at least 1 mb of juice. for (ItemStack berry : berries) - RecipeManagers.squeezerManager.addRecipe(3, new ItemStack[]{berry}, - LiquidHelper.getLiquid(Defaults.LIQUID_JUICE, amount)); + RecipeManagers.squeezerManager.addRecipe(3, new ItemStack[]{berry}, Fluids.JUICE.getFluid(amount)); + + ItemStack itemBarley = GameRegistry.findItemStack(NATURA, "barleyFood", 1); + if (itemBarley != null) + RecipeUtil.injectLeveledRecipe(itemBarley, GameMode.getGameMode().getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); } } diff --git a/src/main/java/forestry/plugins/PluginPropolisPipe.java b/src/main/java/forestry/plugins/PluginPropolisPipe.java index 5e3f45715..13fe70503 100755 --- a/src/main/java/forestry/plugins/PluginPropolisPipe.java +++ b/src/main/java/forestry/plugins/PluginPropolisPipe.java @@ -16,9 +16,8 @@ import forestry.core.proxy.Proxies; import forestry.pipes.GuiHandlerPipes; import forestry.pipes.network.PacketHandlerPipes; import forestry.pipes.proxy.ProxyPipes; -import net.minecraft.item.Item; - import java.util.EnumSet; +import net.minecraft.item.Item; @Plugin(pluginID = "Pipes", name = "Pipes", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.pipes.description") public class PluginPropolisPipe extends ForestryPlugin { diff --git a/src/main/java/forestry/plugins/PluginStorage.java b/src/main/java/forestry/plugins/PluginStorage.java index c8bfb475d..3a5c9b503 100755 --- a/src/main/java/forestry/plugins/PluginStorage.java +++ b/src/main/java/forestry/plugins/PluginStorage.java @@ -13,6 +13,7 @@ package forestry.plugins; import java.text.NumberFormat; import java.text.ParseException; import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,52 +42,60 @@ import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; -import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; -import cpw.mods.fml.common.network.IGuiHandler; -import cpw.mods.fml.common.registry.GameData; - import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IShearable; import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.common.registry.GameData; + import forestry.api.core.Tabs; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; import forestry.api.storage.EnumBackpackType; import forestry.api.storage.IBackpackDefinition; +import forestry.api.storage.StorageManager; import forestry.core.config.Configuration; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; import forestry.core.config.ForestryItem; import forestry.core.config.Property; +import forestry.core.fluids.Fluids; import forestry.core.interfaces.IOreDictionaryHandler; import forestry.core.interfaces.IPickupHandler; import forestry.core.interfaces.IResupplyHandler; import forestry.core.interfaces.ISaveEventHandler; -import forestry.core.items.ItemForestry; +import forestry.core.items.ItemCrated; import forestry.core.network.GuiId; import forestry.core.proxy.Proxies; -import forestry.core.utils.LiquidHelper; import forestry.storage.BackpackDefinition; import forestry.storage.BackpackHelper; +import forestry.storage.CrateRegistry; import forestry.storage.GuiHandlerStorage; import forestry.storage.PickupHandlerStorage; import forestry.storage.ResupplyHandler; import forestry.storage.items.ItemNaturalistBackpack; import forestry.storage.items.ItemNaturalistBackpack.BackpackDefinitionApiarist; import forestry.storage.items.ItemNaturalistBackpack.BackpackDefinitionLepidopterist; +import forestry.storage.proxy.ProxyStorage; @Plugin(pluginID = "Storage", name = "Storage", author = "SirSengir", url = Defaults.URL, unlocalizedDescription = "for.plugin.storage.description") public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandler { + private static final List crates = new ArrayList(); + private static final String CONFIG_CATEGORY = "backpacks"; + + @SidedProxy(clientSide = "forestry.storage.proxy.ClientProxyStorage", serverSide = "forestry.storage.proxy.ProxyStorage") + public static ProxyStorage proxy; private final ArrayList minerItems = new ArrayList(); private final ArrayList diggerItems = new ArrayList(); private final ArrayList foresterItems = new ArrayList(); private final ArrayList hunterItems = new ArrayList(); private final ArrayList adventurerItems = new ArrayList(); private final ArrayList builderItems = new ArrayList(); - private final static String CONFIG_CATEGORY = "backpacks"; - Configuration config; + private Configuration config; @Override @SuppressWarnings({"unchecked","rawtypes"}) @@ -101,6 +110,8 @@ public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandl BackpackManager.backpackItems[3] = hunterItems; BackpackManager.backpackItems[4] = adventurerItems; BackpackManager.backpackItems[5] = builderItems; + + StorageManager.crateRegistry = new CrateRegistry(); } @Override @@ -110,23 +121,23 @@ public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandl config = new Configuration(); Property backpackConf = config.get("backpacks.miner.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add additional blocks and items for the miner's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Miner's Backpack", backpackConf.Value, BackpackManager.definitions.get("miner")); + backpackConf.comment = "add additional blocks and items for the miner's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Miner's Backpack", backpackConf.value, BackpackManager.definitions.get("miner")); backpackConf = config.get("backpacks.digger.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add additional blocks and items for the digger's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Digger's Backpack", backpackConf.Value, BackpackManager.definitions.get("digger")); + backpackConf.comment = "add additional blocks and items for the digger's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Digger's Backpack", backpackConf.value, BackpackManager.definitions.get("digger")); backpackConf = config.get("backpacks.forester.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add additional blocks and items for the forester's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Forester's Backpack", backpackConf.Value, BackpackManager.definitions.get("forester")); + backpackConf.comment = "add additional blocks and items for the forester's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Forester's Backpack", backpackConf.value, BackpackManager.definitions.get("forester")); backpackConf = config.get("backpacks.hunter.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add additional blocks and items for the hunter's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Hunter's Backpack", backpackConf.Value, BackpackManager.definitions.get("hunter")); + backpackConf.comment = "add additional blocks and items for the hunter's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Hunter's Backpack", backpackConf.value, BackpackManager.definitions.get("hunter")); backpackConf = config.get("backpacks.adventurer.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add blocks and items for the adventurer's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Adventurer's Backpack", backpackConf.Value, BackpackManager.definitions.get("adventurer")); + backpackConf.comment = "add blocks and items for the adventurer's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Adventurer's Backpack", backpackConf.value, BackpackManager.definitions.get("adventurer")); backpackConf = config.get("backpacks.builder.items", CONFIG_CATEGORY, ""); - backpackConf.Comment = "add blocks and items for the builder's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; - parseBackpackItems("Builder's Backpack", backpackConf.Value, BackpackManager.definitions.get("builder")); + backpackConf.comment = "add blocks and items for the builder's backpack here in the format id:meta. separate blocks and items using ';'. wildcard for metadata: '*'"; + parseBackpackItems("Builder's Backpack", backpackConf.value, BackpackManager.definitions.get("builder")); config.save(); @@ -138,6 +149,22 @@ public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandl BackpackManager.definitions.get("builder").addValidItems(builderItems); } + public static void registerCrate(ItemCrated crate) { + proxy.registerCrate(crate); + crates.add(crate); + } + + public static void createCrateRecipes() { + for (ItemCrated crate : crates) { + ItemStack itemStack = new ItemStack(crate); + if (crate.usesOreDict()) { + RecipeManagers.carpenterManager.addCratingWithOreDict(itemStack); + } else { + RecipeManagers.carpenterManager.addCrating(itemStack); + } + } + } + public static void addBackpackItem(String pack, ItemStack stack) { if (stack == null) return; @@ -241,7 +268,7 @@ public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandl @Override protected void registerItems() { // CRATE - ForestryItem.crate.registerItem((new ItemForestry()), "crate"); + ForestryItem.crate.registerItem((new ItemCrated(null, false)), "crate"); // BACKPACKS BackpackDefinition definition; @@ -502,27 +529,28 @@ public class PluginStorage extends ForestryPlugin implements IOreDictionaryHandl Proxies.common.addRecipe(ForestryItem.builderBackpack.getItemStack(), "X#X", "VYV", "X#X", '#', Blocks.wool, 'X', Items.string, 'V', Items.clay_ball, 'Y', Blocks.chest); - // / CARPENTER - // / BACKPACKS T2 - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.minerBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.minerBackpack); - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.diggerBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.diggerBackpack); - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.foresterBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.foresterBackpack); - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.hunterBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.hunterBackpack); - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.adventurerBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.adventurerBackpack); - RecipeManagers.carpenterManager.addRecipe(200, LiquidHelper.getLiquid(Defaults.LIQUID_WATER, 1000), null, ForestryItem.builderBackpackT2.getItemStack(), - "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', - ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.builderBackpack); - + if (PluginManager.Module.FACTORY.isEnabled()) { + // / CARPENTER + // / BACKPACKS T2 + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.minerBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.minerBackpack); + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.diggerBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.diggerBackpack); + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.foresterBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.foresterBackpack); + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.hunterBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.hunterBackpack); + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.adventurerBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.adventurerBackpack); + RecipeManagers.carpenterManager.addRecipe(200, Fluids.WATER.getFluid(1000), null, ForestryItem.builderBackpackT2.getItemStack(), + "WXW", "WTW", "WWW", 'X', Items.diamond, 'W', + ForestryItem.craftingMaterial.getItemStack(1, 3), 'T', ForestryItem.builderBackpack); + } } @Override diff --git a/src/main/java/forestry/storage/BackpackDefinition.java b/src/main/java/forestry/storage/BackpackDefinition.java index a17d205e1..fc37a28f8 100755 --- a/src/main/java/forestry/storage/BackpackDefinition.java +++ b/src/main/java/forestry/storage/BackpackDefinition.java @@ -10,15 +10,13 @@ ******************************************************************************/ package forestry.storage; +import forestry.api.storage.IBackpackDefinition; +import forestry.core.utils.StackUtils; import java.util.ArrayList; import java.util.List; - -import forestry.core.utils.StackUtils; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -import forestry.api.storage.IBackpackDefinition; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; @@ -87,17 +85,21 @@ public class BackpackDefinition implements IBackpackDefinition { addValidItem(validItem); } - public ArrayList getValidItems(EntityPlayer player) { + public ArrayList getValidItems() { return validItems; } @Override public boolean isValidItem(EntityPlayer player, ItemStack itemstack) { - for (ItemStack stack : getValidItems(player)) + return isValidItem(itemstack); + } + + @Override + public boolean isValidItem(ItemStack itemstack) { + for (ItemStack stack : getValidItems()) if (StackUtils.isCraftingEquivalent(stack, itemstack, true, false)) return true; return false; } - } diff --git a/src/main/java/forestry/storage/BackpackHelper.java b/src/main/java/forestry/storage/BackpackHelper.java index 6fdb5b07c..19573b5d7 100755 --- a/src/main/java/forestry/storage/BackpackHelper.java +++ b/src/main/java/forestry/storage/BackpackHelper.java @@ -10,13 +10,12 @@ ******************************************************************************/ package forestry.storage; -import net.minecraft.item.Item; - import forestry.api.storage.BackpackManager; import forestry.api.storage.EnumBackpackType; import forestry.api.storage.IBackpackDefinition; import forestry.api.storage.IBackpackInterface; import forestry.storage.items.ItemBackpack; +import net.minecraft.item.Item; public class BackpackHelper implements IBackpackInterface { diff --git a/src/main/java/forestry/storage/CrateRegistry.java b/src/main/java/forestry/storage/CrateRegistry.java new file mode 100644 index 000000000..504025ffc --- /dev/null +++ b/src/main/java/forestry/storage/CrateRegistry.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.storage; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +import forestry.api.storage.ICrateRegistry; +import forestry.core.items.ItemCrated; +import forestry.core.proxy.Proxies; +import forestry.plugins.PluginManager; +import forestry.plugins.PluginStorage; + +public class CrateRegistry implements ICrateRegistry { + + private void registerCrate(ItemStack stack, String uid, boolean useOreDict) { + if (PluginManager.getStage() != PluginManager.Stage.INIT) + throw new RuntimeException("Tried to make a crate outside of Init"); + + if (stack == null || stack.getItem() == null) + throw new RuntimeException("Tried to make a crate without an item"); + + if (uid == null) + throw new RuntimeException("Tried to make a crate without a uid"); + + ItemCrated crate = new ItemCrated(stack, useOreDict); + crate.setUnlocalizedName(uid); + Proxies.common.registerItem(crate); + PluginStorage.registerCrate(crate); + } + + @Override + public void registerCrate(Item item, String uid) { + registerCrate(new ItemStack(item), uid, false); + } + + @Override + public void registerCrateUsingOreDict(Item item, String uid) { + registerCrate(new ItemStack(item), uid, true); + } + + @Override + public void registerCrate(Block block, String uid) { + registerCrate(new ItemStack(block), uid, false); + } + + @Override + public void registerCrateUsingOreDict(Block block, String uid) { + registerCrate(new ItemStack(block), uid, true); + } + + @Override + public void registerCrate(ItemStack stack, String uid) { + registerCrate(stack, uid, false); + } + + @Override + public void registerCrateUsingOreDict(ItemStack stack, String uid) { + registerCrate(stack, uid, true); + } +} diff --git a/src/main/java/forestry/storage/GuiHandlerStorage.java b/src/main/java/forestry/storage/GuiHandlerStorage.java index 330452d45..34692d6a4 100755 --- a/src/main/java/forestry/storage/GuiHandlerStorage.java +++ b/src/main/java/forestry/storage/GuiHandlerStorage.java @@ -22,8 +22,9 @@ import forestry.core.GuiHandlerBase; import forestry.core.config.Defaults; import forestry.core.gui.GuiNaturalistInventory; import forestry.core.gui.IPagedInventory; +import forestry.core.inventory.ItemInventory; +import forestry.core.inventory.ItemInventoryBackpack; import forestry.core.network.GuiId; -import forestry.core.utils.ItemInventory; import forestry.storage.gui.ContainerBackpack; import forestry.storage.gui.ContainerNaturalistBackpack; import forestry.storage.gui.GuiBackpack; @@ -32,12 +33,12 @@ import forestry.storage.items.ItemBackpack; public class GuiHandlerStorage extends GuiHandlerBase { - public static class PagedInventory extends ItemInventory implements IPagedInventory { + public static class PagedBackpackInventory extends ItemInventoryBackpack implements IPagedInventory { //private final int x, y, z; private final int guiId; - public PagedInventory(Class itemClass, int size, ItemStack itemstack, int x, int y, int z, int guiId) { + public PagedBackpackInventory(Class itemClass, int size, ItemStack itemstack, int x, int y, int z, int guiId) { super(itemClass, size, itemstack); /*this.x = x; this.y = y; @@ -68,28 +69,28 @@ public class GuiHandlerStorage extends GuiHandlerBase { if (equipped == null) return null; ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); - PagedInventory inventory = new PagedInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(speciesRoot, player.inventory, inventory, guiData, 25), inventory, guiData, 5); + PagedBackpackInventory inventory = new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId); + return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player.inventory, inventory, guiData, 25), inventory, guiData, 5); case BackpackGUI: equipped = getBackpackItem(player); if (equipped == null) return null; - return new GuiBackpack(new ContainerBackpack(player, new ItemInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped))); + return new GuiBackpack(new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped))); case BackpackT2GUI: equipped = getBackpackItem(player); if (equipped == null) return null; - return new GuiBackpackT2(new ContainerBackpack(player, new ItemInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped))); + return new GuiBackpackT2(new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped))); case LepidopteristBackpackGUI: equipped = getBackpackItem(player); if (equipped == null) return null; speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); - inventory = new PagedInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, id); - return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(speciesRoot, player.inventory, inventory, guiData, 25), inventory, guiData, 5); + inventory = new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, id); + return new GuiNaturalistInventory(speciesRoot, player, new ContainerNaturalistBackpack(player.inventory, inventory, guiData, 25), inventory, guiData, 5); default: return null; @@ -98,7 +99,7 @@ public class GuiHandlerStorage extends GuiHandlerBase { } private ItemStack getBackpackItem(EntityPlayer player) { - ItemStack equipped = getEquippedItem(player); + ItemStack equipped = player.getCurrentEquippedItem(); if (equipped == null) return null; if (equipped.getItem() instanceof ItemBackpack) @@ -122,32 +123,28 @@ public class GuiHandlerStorage extends GuiHandlerBase { if (equipped == null) return null; - ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); - speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); - return new ContainerNaturalistBackpack(speciesRoot, player.inventory, new PagedInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); + return new ContainerNaturalistBackpack(player.inventory, new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); case BackpackGUI: equipped = getBackpackItem(player); if (equipped == null) return null; - return new ContainerBackpack(player, new ItemInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped)); + return new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_DEFAULT, equipped)); case BackpackT2GUI: equipped = getBackpackItem(player); if (equipped == null) return null; - return new ContainerBackpack(player, new ItemInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped)); + return new ContainerBackpack(player, new ItemInventoryBackpack(ItemBackpack.class, Defaults.SLOTS_BACKPACK_T2, equipped)); case LepidopteristBackpackGUI: equipped = getBackpackItem(player); if (equipped == null) return null; - speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); - speciesRoot.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player); - return new ContainerNaturalistBackpack(speciesRoot, player.inventory, new PagedInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); + return new ContainerNaturalistBackpack(player.inventory, new PagedBackpackInventory(ItemBackpack.class, Defaults.SLOTS_BACKPACK_APIARIST, equipped, x, y, z, cleanId), guiData, 25); default: return null; diff --git a/src/main/java/forestry/storage/PickupHandlerStorage.java b/src/main/java/forestry/storage/PickupHandlerStorage.java index 766f9ae4d..e45ef050e 100755 --- a/src/main/java/forestry/storage/PickupHandlerStorage.java +++ b/src/main/java/forestry/storage/PickupHandlerStorage.java @@ -14,9 +14,9 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import forestry.storage.gui.ContainerNaturalistBackpack; import forestry.core.interfaces.IPickupHandler; import forestry.storage.gui.ContainerBackpack; +import forestry.storage.gui.ContainerNaturalistBackpack; import forestry.storage.items.ItemBackpack; public class PickupHandlerStorage implements IPickupHandler { @@ -28,13 +28,11 @@ public class PickupHandlerStorage implements IPickupHandler { if (itemstack == null || itemstack.stackSize <= 0) return false; - // Do not pick up if a backpack is open // FIXME: Must not contain - // anything from apiculture + // Do not pick up if a backpack is open if (player.openContainer instanceof ContainerBackpack || player.openContainer instanceof ContainerNaturalistBackpack) return true; - // Make sure to top off manually placed itemstacks in player - // inventory first + // Make sure to top off manually placed itemstacks in player inventory first topOffPlayerInventory(player, itemstack); for (ItemStack pack : player.inventory.mainInventory) { @@ -53,18 +51,12 @@ public class PickupHandlerStorage implements IPickupHandler { backpack.tryStowing(player, pack, itemstack); } - if (itemstack.stackSize <= 0) - return false; - else - return true; + return itemstack.stackSize > 0; } /** * This tops off existing stacks in the player's inventory. That way you can keep f.e. a stack of dirt or cobblestone in your inventory which gets refreshed * constantly by picked up items. - * - * @param player - * @param itemstack */ private void topOffPlayerInventory(EntityPlayer player, ItemStack itemstack) { @@ -87,7 +79,6 @@ public class PickupHandlerStorage implements IPickupHandler { if (space > itemstack.stackSize) { inventoryStack.stackSize += itemstack.stackSize; itemstack.stackSize = 0; - itemstack = null; break; // Only part can be added } else { diff --git a/src/main/java/forestry/storage/ResupplyHandler.java b/src/main/java/forestry/storage/ResupplyHandler.java index 54be8eb05..52d26fb77 100755 --- a/src/main/java/forestry/storage/ResupplyHandler.java +++ b/src/main/java/forestry/storage/ResupplyHandler.java @@ -10,20 +10,18 @@ ******************************************************************************/ package forestry.storage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ContainerPlayer; -import net.minecraft.item.ItemStack; - import cpw.mods.fml.common.eventhandler.Event; - -import net.minecraftforge.common.MinecraftForge; - import forestry.api.storage.BackpackManager; import forestry.api.storage.BackpackResupplyEvent; import forestry.api.storage.IBackpackDefinition; import forestry.core.interfaces.IResupplyHandler; -import forestry.core.utils.ItemInventory; +import forestry.core.inventory.ItemInventory; +import forestry.core.inventory.ItemInventoryBackpack; import forestry.storage.items.ItemBackpack; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ContainerPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; public class ResupplyHandler implements IResupplyHandler { @@ -62,7 +60,7 @@ public class ResupplyHandler implements IResupplyHandler { // Load their inventory ItemBackpack packItem = ((ItemBackpack) backpack.getItem()); - ItemInventory backpackinventory = new ItemInventory(ItemBackpack.class, packItem.getBackpackSize(), backpack); + ItemInventory backpackinventory = new ItemInventoryBackpack(ItemBackpack.class, packItem.getBackpackSize(), backpack); Event event = new BackpackResupplyEvent(player, packItem.getDefinition(), backpackinventory); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) @@ -96,9 +94,6 @@ public class ResupplyHandler implements IResupplyHandler { /** * This tops off existing stacks in the player's inventory. - * - * @param player - * @param itemstack */ private boolean topOffPlayerInventory(EntityPlayer player, ItemStack itemstack) { @@ -115,11 +110,8 @@ public class ResupplyHandler implements IResupplyHandler { continue; if (inventoryStack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(inventoryStack, itemstack)) { - inventoryStack.stackSize++; itemstack.stackSize--; - if (itemstack.stackSize <= 0) - itemstack = null; return true; } } diff --git a/src/main/java/forestry/storage/gui/ContainerBackpack.java b/src/main/java/forestry/storage/gui/ContainerBackpack.java index 63d4ce780..a456b4886 100755 --- a/src/main/java/forestry/storage/gui/ContainerBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerBackpack.java @@ -11,17 +11,15 @@ package forestry.storage.gui; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import forestry.core.config.Defaults; import forestry.core.gui.ContainerItemInventory; -import forestry.core.gui.slots.SlotForestry; -import forestry.core.utils.ItemInventory; -import forestry.storage.items.ItemBackpack; +import forestry.core.gui.slots.SlotFiltered; +import forestry.core.inventory.ItemInventoryBackpack; public class ContainerBackpack extends ContainerItemInventory { - public ContainerBackpack(final EntityPlayer player, ItemInventory inventory) { + public ContainerBackpack(final EntityPlayer player, ItemInventoryBackpack inventory) { super(inventory, player); int lines = 0; @@ -41,18 +39,12 @@ public class ContainerBackpack extends ContainerItemInventory { } // Inventory - for (int j = 0; j < lines; j++) + for (int j = 0; j < lines; j++) { for (int k = 0; k < columns; k++) { int slot = k + j * columns; - addSlot(new SlotForestry(inventory, slot, startX + k * 18, startY + j * 18) { - - @Override - public boolean isItemValid(ItemStack stack) { - return isAcceptedItem(player, stack); - } - - }); + addSlotToContainer(new SlotFiltered(inventory, slot, startX + k * 18, startY + j * 18)); } + } // Player inventory for (int i = 0; i < 3; i++) @@ -63,21 +55,4 @@ public class ContainerBackpack extends ContainerItemInventory { addSecuredSlot(player.inventory, i, 8 + i * 18, 11 + startY + lines * 18 + 58); } - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - // FIXME: This is incorrect. - // However, if we return false here, even valid items will be dropped - // while being kept inside the backpack, leading to duping. - // inventory.parent will turn null with the current implementation if - // something is put inside a backpack and the backpack is then - // moved from the action bar into the player's inventory. - if (inventory.parent == null) - return true; - - if (!(inventory.parent.getItem() instanceof ItemBackpack)) - return false; - - return ((ItemBackpack) inventory.parent.getItem()).getDefinition().isValidItem(player, stack); - } - } diff --git a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java index d0322062d..f5e6c7b19 100755 --- a/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java +++ b/src/main/java/forestry/storage/gui/ContainerNaturalistBackpack.java @@ -12,31 +12,26 @@ package forestry.storage.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import forestry.api.genetics.ISpeciesRoot; import forestry.core.gui.ContainerItemInventory; import forestry.core.gui.IGuiSelectable; -import forestry.core.gui.slots.SlotCustom; +import forestry.core.gui.slots.SlotFiltered; import forestry.core.network.PacketUpdate; -import forestry.core.proxy.Proxies; -import forestry.storage.GuiHandlerStorage.PagedInventory; +import forestry.storage.GuiHandlerStorage.PagedBackpackInventory; public class ContainerNaturalistBackpack extends ContainerItemInventory implements IGuiSelectable { - private final PagedInventory inv; - private ISpeciesRoot speciesRoot; + private final PagedBackpackInventory inv; - public ContainerNaturalistBackpack(ISpeciesRoot speciesRoot, InventoryPlayer player, PagedInventory inventory, int page, int pageSize) { + public ContainerNaturalistBackpack(InventoryPlayer player, PagedBackpackInventory inventory, int page, int pageSize) { super(inventory, player.player); this.inv = inventory; - this.speciesRoot = speciesRoot; // Inventory for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { - addSlot(new SlotCustom(inventory, y + page * pageSize + x * 5, 100 + y * 18, 21 + x * 18, speciesRoot)); + addSlotToContainer(new SlotFiltered(inventory, y + page * pageSize + x * 5, 100 + y * 18, 21 + x * 18)); } } @@ -52,27 +47,6 @@ public class ContainerNaturalistBackpack extends ContainerItemInventory implemen } } - @Override - public void purgeBag(EntityPlayer player) { - for (int i = 0; i < inventory.getSizeInventory(); i++) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack == null) - continue; - - if (speciesRoot.isMember(stack)) - continue; - - Proxies.common.dropItemPlayer(player, stack); - inventory.setInventorySlotContents(i, null); - } - } - - @Override - protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) { - // TODO Auto-generated method stub - return false; - } - @Override public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) { inv.flipPage(player, packet.payload.intPayload[0]); diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index e3bb49819..9fbba383f 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -10,9 +10,28 @@ ******************************************************************************/ package forestry.storage.items; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.core.ForestryAPI; +import forestry.api.storage.BackpackStowEvent; +import forestry.api.storage.EnumBackpackType; +import forestry.api.storage.IBackpackDefinition; +import forestry.core.config.Config; +import forestry.core.config.Defaults; +import forestry.core.inventory.InvTools; +import forestry.core.inventory.ItemInventory; +import forestry.core.inventory.ItemInventoryBackpack; +import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryIterator; +import forestry.core.items.ItemInventoried; +import forestry.core.network.GuiId; +import forestry.core.proxy.Proxies; +import forestry.core.render.TextureManager; +import forestry.core.utils.StringUtil; +import forestry.storage.BackpackMode; import java.util.List; import java.util.Locale; - import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -20,30 +39,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; - -import cpw.mods.fml.common.eventhandler.Event; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; -import forestry.api.core.ForestryAPI; -import forestry.api.storage.BackpackStowEvent; -import forestry.api.storage.EnumBackpackType; -import forestry.api.storage.IBackpackDefinition; -import forestry.core.config.Defaults; -import forestry.core.inventory.InvTools; -import forestry.core.inventory.wrappers.IInvSlot; -import forestry.core.inventory.wrappers.InventoryIterator; -import forestry.core.items.ItemInventoried; -import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; -import forestry.core.render.TextureManager; -import forestry.core.utils.ItemInventory; -import forestry.core.utils.StringUtil; -import forestry.storage.BackpackMode; - public class ItemBackpack extends ItemInventoried { private final IBackpackDefinition info; @@ -85,10 +83,7 @@ public class ItemBackpack extends ItemInventoried { @Override public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - if (getInventoryHit(world, x, y, z, side) != null) - return true; - else - return false; + return getInventoryHit(world, x, y, z, side) != null; } @Override @@ -107,7 +102,7 @@ public class ItemBackpack extends ItemInventoried { public ItemStack tryStowing(EntityPlayer player, ItemStack backpackStack, ItemStack stack) { ItemBackpack backpack = ((ItemBackpack) backpackStack.getItem()); - ItemInventory inventory = new ItemInventory(ItemBackpack.class, backpack.getBackpackSize(), backpackStack); + ItemInventory inventory = new ItemInventoryBackpack(ItemBackpack.class, backpack.getBackpackSize(), backpackStack); if (backpackStack.getItemDamage() == 1) return stack; @@ -127,14 +122,12 @@ public class ItemBackpack extends ItemInventoried { private void switchMode(ItemStack itemstack) { BackpackMode mode = getMode(itemstack); - if (mode == BackpackMode.RESUPPLY) - itemstack.setItemDamage(0); - else if (mode == BackpackMode.RECEIVE) - itemstack.setItemDamage(3); - else if (mode == BackpackMode.LOCKED) - itemstack.setItemDamage(2); - else - itemstack.setItemDamage(1); + int nextMode = mode.ordinal() + 1; + if (!Config.enableBackpackResupply && nextMode == BackpackMode.RESUPPLY.ordinal()) { + nextMode++; + } + nextMode %= BackpackMode.values().length; + itemstack.setItemDamage(nextMode); } private IInventory getInventoryHit(World world, int x, int y, int z, int side) { @@ -155,7 +148,7 @@ public class ItemBackpack extends ItemInventoried { return true; // Create our own backpack inventory - ItemInventory backpackInventory = new ItemInventory(ItemBackpack.class, getBackpackSize(), stack); + ItemInventoryBackpack backpackInventory = new ItemInventoryBackpack(ItemBackpack.class, getBackpackSize(), stack); BackpackMode mode = getMode(stack); if (mode == BackpackMode.RECEIVE) @@ -171,7 +164,7 @@ public class ItemBackpack extends ItemInventoried { return false; } - private void tryChestTransfer(ItemInventory backpackInventory, IInventory target) { + private void tryChestTransfer(ItemInventoryBackpack backpackInventory, IInventory target) { for (IInvSlot slot : InventoryIterator.getIterable(backpackInventory)) { ItemStack packStack = slot.getStackInSlot(); @@ -183,7 +176,7 @@ public class ItemBackpack extends ItemInventoried { } } - private void tryChestReceive(EntityPlayer player, ItemInventory backpackInventory, IInventory target) { + private void tryChestReceive(EntityPlayer player, ItemInventoryBackpack backpackInventory, IInventory target) { for (IInvSlot slot : InventoryIterator.getIterable(target)) { ItemStack targetStack = slot.getStackInSlot(); diff --git a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java b/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java index 281e7a4d2..edd69ccdd 100755 --- a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java +++ b/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java @@ -10,14 +10,13 @@ ******************************************************************************/ package forestry.storage.items; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - import forestry.api.core.ForestryAPI; import forestry.api.storage.EnumBackpackType; import forestry.plugins.PluginApiculture; import forestry.plugins.PluginLepidopterology; import forestry.storage.BackpackDefinition; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; public class ItemNaturalistBackpack extends ItemBackpack { @@ -28,7 +27,7 @@ public class ItemNaturalistBackpack extends ItemBackpack { } @Override - public boolean isValidItem(EntityPlayer player, ItemStack stack) { + public boolean isValidItem(ItemStack stack) { return PluginApiculture.beeInterface.isMember(stack); } } @@ -40,7 +39,7 @@ public class ItemNaturalistBackpack extends ItemBackpack { } @Override - public boolean isValidItem(EntityPlayer player, ItemStack stack) { + public boolean isValidItem(ItemStack stack) { return PluginLepidopterology.butterflyInterface.isMember(stack); } } diff --git a/src/main/java/forestry/storage/proxy/ClientProxyStorage.java b/src/main/java/forestry/storage/proxy/ClientProxyStorage.java new file mode 100644 index 000000000..ecfd3d9f7 --- /dev/null +++ b/src/main/java/forestry/storage/proxy/ClientProxyStorage.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.storage.proxy; + +import net.minecraftforge.client.MinecraftForgeClient; + +import forestry.core.items.ItemCrated; +import forestry.core.render.CrateRenderingHandler; + +public class ClientProxyStorage extends ProxyStorage{ + + private static final CrateRenderingHandler crateRenderer = new CrateRenderingHandler(); + + @Override + public void registerCrate(ItemCrated crate) { + MinecraftForgeClient.registerItemRenderer(crate, crateRenderer); + } +} diff --git a/src/main/java/forestry/core/circuits/CircuitBoardManager.java b/src/main/java/forestry/storage/proxy/ProxyStorage.java old mode 100755 new mode 100644 similarity index 76% rename from src/main/java/forestry/core/circuits/CircuitBoardManager.java rename to src/main/java/forestry/storage/proxy/ProxyStorage.java index 7de2ccfdd..a2043a210 --- a/src/main/java/forestry/core/circuits/CircuitBoardManager.java +++ b/src/main/java/forestry/storage/proxy/ProxyStorage.java @@ -1,14 +1,20 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.circuits; - -public class CircuitBoardManager { -} +/******************************************************************************* + * 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.storage.proxy; + +import forestry.core.items.ItemCrated; + +public class ProxyStorage { + + public void registerCrate(ItemCrated crate) { + } + +} diff --git a/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeCocobolo.png b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeCocobolo.png new file mode 100644 index 000000000..f017d5b9a Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeCocobolo.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeIpe.png b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeIpe.png new file mode 100644 index 000000000..cf789a332 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeIpe.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treePadauk.png b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treePadauk.png new file mode 100644 index 000000000..4d4bb412f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treePadauk.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeZebrawood.png b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeZebrawood.png new file mode 100644 index 000000000..5c681b97f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/germlings/sapling.treeZebrawood.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol.png b/src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol_still.png old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol.png rename to src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol_still.png diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/bioethanol_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/biomass.png b/src/main/resources/assets/forestry/textures/blocks/liquid/biomass.png deleted file mode 100755 index 3f226d8c5..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/liquid/biomass.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/biomass_still.png b/src/main/resources/assets/forestry/textures/blocks/liquid/biomass_still.png new file mode 100644 index 000000000..79660a1b6 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/liquid/biomass_still.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/biomass.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/biomass_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/biomass.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/biomass_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/for.honey_still.png b/src/main/resources/assets/forestry/textures/blocks/liquid/for.honey_still.png new file mode 100644 index 000000000..c9a6ab622 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/liquid/for.honey_still.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/glass.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/for.honey_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/glass.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/for.honey_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/glass.png b/src/main/resources/assets/forestry/textures/blocks/liquid/glass_still.png old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/glass.png rename to src/main/resources/assets/forestry/textures/blocks/liquid/glass_still.png diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/honey.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/glass_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/honey.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/glass_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/honey.png b/src/main/resources/assets/forestry/textures/blocks/liquid/honey.png deleted file mode 100755 index 6c7973aa5..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/liquid/honey.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/ice.png b/src/main/resources/assets/forestry/textures/blocks/liquid/ice.png deleted file mode 100755 index 96470cd62..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/liquid/ice.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/ice_still.png b/src/main/resources/assets/forestry/textures/blocks/liquid/ice_still.png new file mode 100644 index 000000000..cbb2d11a2 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/liquid/ice_still.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/ice.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/ice_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/ice.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/ice_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/juice.png b/src/main/resources/assets/forestry/textures/blocks/liquid/juice.png deleted file mode 100755 index 1ccbd8b94..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/liquid/juice.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/juice_still.png b/src/main/resources/assets/forestry/textures/blocks/liquid/juice_still.png new file mode 100644 index 000000000..853306a2f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/liquid/juice_still.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/juice.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/juice_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/juice.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/juice_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/milk.png b/src/main/resources/assets/forestry/textures/blocks/liquid/milk_still.png old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/milk.png rename to src/main/resources/assets/forestry/textures/blocks/liquid/milk_still.png diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/seedoil.png b/src/main/resources/assets/forestry/textures/blocks/liquid/seedoil_still.png old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/seedoil.png rename to src/main/resources/assets/forestry/textures/blocks/liquid/seedoil_still.png diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/seedoil.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/seedoil_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/seedoil.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/seedoil_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead.png b/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead.png deleted file mode 100755 index 49cdec0cf..000000000 Binary files a/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead_still.png b/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead_still.png new file mode 100644 index 000000000..f4c802672 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead_still.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead.png.mcmeta b/src/main/resources/assets/forestry/textures/blocks/liquid/short.mead_still.png.mcmeta old mode 100755 new mode 100644 similarity index 100% rename from src/main/resources/assets/forestry/textures/blocks/liquid/short.mead.png.mcmeta rename to src/main/resources/assets/forestry/textures/blocks/liquid/short.mead_still.png.mcmeta diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/bark.cocobolo.png b/src/main/resources/assets/forestry/textures/blocks/wood/bark.cocobolo.png new file mode 100644 index 000000000..23c727615 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/bark.cocobolo.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/bark.ipe.png b/src/main/resources/assets/forestry/textures/blocks/wood/bark.ipe.png new file mode 100644 index 000000000..dcc0e33ae Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/bark.ipe.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/bark.padauk.png b/src/main/resources/assets/forestry/textures/blocks/wood/bark.padauk.png new file mode 100644 index 000000000..e281270db Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/bark.padauk.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/bark.zebrawood.png b/src/main/resources/assets/forestry/textures/blocks/wood/bark.zebrawood.png new file mode 100644 index 000000000..1cad97551 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/bark.zebrawood.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/heart.cocobolo.png b/src/main/resources/assets/forestry/textures/blocks/wood/heart.cocobolo.png new file mode 100644 index 000000000..ff21f9ab3 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/heart.cocobolo.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/heart.ipe.png b/src/main/resources/assets/forestry/textures/blocks/wood/heart.ipe.png new file mode 100644 index 000000000..8672a2d73 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/heart.ipe.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/heart.padauk.png b/src/main/resources/assets/forestry/textures/blocks/wood/heart.padauk.png new file mode 100644 index 000000000..02f58edb6 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/heart.padauk.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/heart.zebrawood.png b/src/main/resources/assets/forestry/textures/blocks/wood/heart.zebrawood.png new file mode 100644 index 000000000..f6a7bef4f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/heart.zebrawood.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/planks.cocobolo.png b/src/main/resources/assets/forestry/textures/blocks/wood/planks.cocobolo.png new file mode 100644 index 000000000..e6ae46dac Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/planks.cocobolo.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/planks.giganteum.png b/src/main/resources/assets/forestry/textures/blocks/wood/planks.giganteum.png new file mode 100644 index 000000000..9d37011c9 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/planks.giganteum.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/planks.ipe.png b/src/main/resources/assets/forestry/textures/blocks/wood/planks.ipe.png new file mode 100644 index 000000000..5069aac83 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/planks.ipe.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/planks.padauk.png b/src/main/resources/assets/forestry/textures/blocks/wood/planks.padauk.png new file mode 100644 index 000000000..050fa9ad6 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/planks.padauk.png differ diff --git a/src/main/resources/assets/forestry/textures/blocks/wood/planks.zebrawood.png b/src/main/resources/assets/forestry/textures/blocks/wood/planks.zebrawood.png new file mode 100644 index 000000000..dd0b140e5 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/blocks/wood/planks.zebrawood.png differ diff --git a/src/main/resources/assets/forestry/textures/items/crate-filled.png b/src/main/resources/assets/forestry/textures/items/crate-filled.png new file mode 100644 index 000000000..08cb41c64 Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/crate-filled.png differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/apatite.png b/src/main/resources/assets/forestry/textures/items/crates/apatite.png deleted file mode 100755 index f24613f07..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/apatite.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/apples.png b/src/main/resources/assets/forestry/textures/items/crates/apples.png deleted file mode 100755 index 2f882f326..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/apples.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/ash.png b/src/main/resources/assets/forestry/textures/items/crates/ash.png deleted file mode 100755 index ff4bbcb36..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/ash.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/beeswax.png b/src/main/resources/assets/forestry/textures/items/crates/beeswax.png deleted file mode 100755 index 12039ea9d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/beeswax.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/bogearth.png b/src/main/resources/assets/forestry/textures/items/crates/bogearth.png deleted file mode 100755 index de7aecf81..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/bogearth.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/brass.png b/src/main/resources/assets/forestry/textures/items/crates/brass.png deleted file mode 100755 index 07e6e8760..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/brass.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/brick.png b/src/main/resources/assets/forestry/textures/items/crates/brick.png deleted file mode 100755 index 131e39669..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/brick.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/bronze.png b/src/main/resources/assets/forestry/textures/items/crates/bronze.png deleted file mode 100755 index f1946a4ec..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/bronze.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/cacti.png b/src/main/resources/assets/forestry/textures/items/crates/cacti.png deleted file mode 100755 index 117b255be..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/cacti.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/charcoal.png b/src/main/resources/assets/forestry/textures/items/crates/charcoal.png deleted file mode 100755 index b3bfcf15e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/charcoal.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/clay.png b/src/main/resources/assets/forestry/textures/items/crates/clay.png deleted file mode 100755 index 0fce69962..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/clay.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/coal.png b/src/main/resources/assets/forestry/textures/items/crates/coal.png deleted file mode 100755 index b3bfcf15e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/coal.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/cobblestone.png b/src/main/resources/assets/forestry/textures/items/crates/cobblestone.png deleted file mode 100755 index 7a6ca7f6b..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/cobblestone.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/cocoacomb.png b/src/main/resources/assets/forestry/textures/items/crates/cocoacomb.png deleted file mode 100755 index 81a41222a..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/cocoacomb.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/cookies.png b/src/main/resources/assets/forestry/textures/items/crates/cookies.png deleted file mode 100755 index 48174ee7f..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/cookies.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/copper.png b/src/main/resources/assets/forestry/textures/items/crates/copper.png deleted file mode 100755 index 8a95f4830..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/copper.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/dirt.png b/src/main/resources/assets/forestry/textures/items/crates/dirt.png deleted file mode 100755 index 9aae11ae5..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/dirt.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/drippingcombs.png b/src/main/resources/assets/forestry/textures/items/crates/drippingcombs.png deleted file mode 100755 index 804a9eb7a..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/drippingcombs.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/fertilizer.png b/src/main/resources/assets/forestry/textures/items/crates/fertilizer.png deleted file mode 100755 index f1e2bc592..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/fertilizer.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/frozencombs.png b/src/main/resources/assets/forestry/textures/items/crates/frozencombs.png deleted file mode 100755 index 3fcf0962a..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/frozencombs.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/glowstone.png b/src/main/resources/assets/forestry/textures/items/crates/glowstone.png deleted file mode 100755 index b9b68e858..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/glowstone.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/gravel.png b/src/main/resources/assets/forestry/textures/items/crates/gravel.png deleted file mode 100755 index d24c83cc6..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/gravel.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/honeycombs.png b/src/main/resources/assets/forestry/textures/items/crates/honeycombs.png deleted file mode 100755 index 59199951b..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/honeycombs.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/honeydew.png b/src/main/resources/assets/forestry/textures/items/crates/honeydew.png deleted file mode 100755 index d9636a50a..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/honeydew.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/honeydrop.png b/src/main/resources/assets/forestry/textures/items/crates/honeydrop.png deleted file mode 100755 index fd1ba3628..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/honeydrop.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/humus.png b/src/main/resources/assets/forestry/textures/items/crates/humus.png deleted file mode 100755 index 5a9fdd5c0..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/humus.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/iron.png b/src/main/resources/assets/forestry/textures/items/crates/iron.png deleted file mode 100755 index cb9a75e11..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/iron.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/lapis.png b/src/main/resources/assets/forestry/textures/items/crates/lapis.png deleted file mode 100755 index 255c35ab5..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/lapis.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/mulch.png b/src/main/resources/assets/forestry/textures/items/crates/mulch.png deleted file mode 100755 index dcae6f9c0..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/mulch.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/mycelium.png b/src/main/resources/assets/forestry/textures/items/crates/mycelium.png deleted file mode 100755 index 6860834a7..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/mycelium.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/netherbrick.png b/src/main/resources/assets/forestry/textures/items/crates/netherbrick.png deleted file mode 100755 index 087302b20..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/netherbrick.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/netherrack.png b/src/main/resources/assets/forestry/textures/items/crates/netherrack.png deleted file mode 100755 index a506651a5..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/netherrack.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/netherwart.png b/src/main/resources/assets/forestry/textures/items/crates/netherwart.png deleted file mode 100755 index 306a81446..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/netherwart.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/nikolite.png b/src/main/resources/assets/forestry/textures/items/crates/nikolite.png deleted file mode 100755 index c8d522ef6..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/nikolite.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/obsidian.png b/src/main/resources/assets/forestry/textures/items/crates/obsidian.png deleted file mode 100755 index a6cf7b677..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/obsidian.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/peat.png b/src/main/resources/assets/forestry/textures/items/crates/peat.png deleted file mode 100755 index 18e307926..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/peat.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/phosphor.png b/src/main/resources/assets/forestry/textures/items/crates/phosphor.png deleted file mode 100755 index fee61a3c1..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/phosphor.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/pollen.png b/src/main/resources/assets/forestry/textures/items/crates/pollen.png deleted file mode 100755 index f807d2842..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/pollen.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/propolis.png b/src/main/resources/assets/forestry/textures/items/crates/propolis.png deleted file mode 100755 index f680be088..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/propolis.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/redstone.png b/src/main/resources/assets/forestry/textures/items/crates/redstone.png deleted file mode 100755 index d15529c89..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/redstone.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/reeds.png b/src/main/resources/assets/forestry/textures/items/crates/reeds.png deleted file mode 100755 index eb34cd95e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/reeds.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/refractorywax.png b/src/main/resources/assets/forestry/textures/items/crates/refractorywax.png deleted file mode 100755 index 347374558..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/refractorywax.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/resin.png b/src/main/resources/assets/forestry/textures/items/crates/resin.png deleted file mode 100755 index 74ad76402..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/resin.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/royaljelly.png b/src/main/resources/assets/forestry/textures/items/crates/royaljelly.png deleted file mode 100644 index 9949cbd6e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/royaljelly.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/rubber.png b/src/main/resources/assets/forestry/textures/items/crates/rubber.png deleted file mode 100755 index ceca55287..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/rubber.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/sand.png b/src/main/resources/assets/forestry/textures/items/crates/sand.png deleted file mode 100755 index 39481d26d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/sand.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/sandstone.png b/src/main/resources/assets/forestry/textures/items/crates/sandstone.png deleted file mode 100755 index aa3fb342d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/sandstone.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/saplings.png b/src/main/resources/assets/forestry/textures/items/crates/saplings.png deleted file mode 100755 index 4462a4af2..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/saplings.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/scrap.png b/src/main/resources/assets/forestry/textures/items/crates/scrap.png deleted file mode 100755 index 019d876f8..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/scrap.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/seeds.png b/src/main/resources/assets/forestry/textures/items/crates/seeds.png deleted file mode 100755 index 74920f38e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/seeds.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/silver.png b/src/main/resources/assets/forestry/textures/items/crates/silver.png deleted file mode 100644 index 7de7391af..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/silver.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/simmeringcombs.png b/src/main/resources/assets/forestry/textures/items/crates/simmeringcombs.png deleted file mode 100755 index 4fd50ba1d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/simmeringcombs.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/soulsand.png b/src/main/resources/assets/forestry/textures/items/crates/soulsand.png deleted file mode 100755 index ab2882eac..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/soulsand.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/stone.png b/src/main/resources/assets/forestry/textures/items/crates/stone.png deleted file mode 100755 index 54afd48d3..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/stone.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/stringycombs.png b/src/main/resources/assets/forestry/textures/items/crates/stringycombs.png deleted file mode 100755 index 0994fb72e..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/stringycombs.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/tile]-16.png b/src/main/resources/assets/forestry/textures/items/crates/tile]-16.png deleted file mode 100755 index 93f68cbe7..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/tile]-16.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/tin.png b/src/main/resources/assets/forestry/textures/items/crates/tin.png deleted file mode 100755 index 0e0510424..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/tin.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/uum.png b/src/main/resources/assets/forestry/textures/items/crates/uum.png deleted file mode 100755 index 24e3bca3d..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/uum.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/wheat.png b/src/main/resources/assets/forestry/textures/items/crates/wheat.png deleted file mode 100755 index a57576767..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/wheat.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/crates/wood.png b/src/main/resources/assets/forestry/textures/items/crates/wood.png deleted file mode 100755 index 938c9f069..000000000 Binary files a/src/main/resources/assets/forestry/textures/items/crates/wood.png and /dev/null differ diff --git a/src/main/resources/assets/forestry/textures/items/errors/noCircuitLayout.png b/src/main/resources/assets/forestry/textures/items/errors/noCircuitLayout.png new file mode 100644 index 000000000..3c458744f Binary files /dev/null and b/src/main/resources/assets/forestry/textures/items/errors/noCircuitLayout.png differ