mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Merge remote-tracking branch 'upstream/master' into redstoneflux
This commit is contained in:
commit
b9dfdef20c
31 files changed
+359
-316
No files matched your search
@@ -243,6 +243,9 @@ public class GuiBeealyzer extends GuiAlyzer {
|
||||
|
||||
private void drawAnalyticsPage3(IBee bee, EnumBeeType type) {
|
||||
|
||||
float factor = this.factor;
|
||||
this.setFactor(1.0f);
|
||||
|
||||
tempProductList = bee.getProduceList();
|
||||
|
||||
startPage(COLUMN_0, COLUMN_1, COLUMN_2);
|
||||
@@ -253,8 +256,8 @@ public class GuiBeealyzer extends GuiAlyzer {
|
||||
|
||||
int x = COLUMN_0;
|
||||
for (ItemStack stack : tempProductList) {
|
||||
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, stack, (int) ((guiLeft + x) * (1 / factor)),
|
||||
(int) ((guiTop + getLineY()) * (1 / factor)));
|
||||
widgetManager.add(new ItemStackWidget(adjustToFactor(x), adjustToFactor(getLineY()), stack));
|
||||
|
||||
x += 18;
|
||||
if (x > adjustToFactor(148)) {
|
||||
x = COLUMN_0;
|
||||
@@ -262,16 +265,16 @@ public class GuiBeealyzer extends GuiAlyzer {
|
||||
}
|
||||
}
|
||||
|
||||
newLine();
|
||||
newLine();
|
||||
newLine();
|
||||
|
||||
drawLine(StringUtil.localize("gui.beealyzer.specialty") + ":", COLUMN_0);
|
||||
newLine();
|
||||
|
||||
x = COLUMN_0;
|
||||
for (ItemStack stack : bee.getSpecialtyList()) {
|
||||
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, stack, (int) ((guiLeft + x) * (1 / factor)),
|
||||
(int) ((guiTop + getLineY()) * (1 / factor)));
|
||||
widgetManager.add(new ItemStackWidget(adjustToFactor(x), adjustToFactor(getLineY()), stack));
|
||||
|
||||
x += 18;
|
||||
if (x > adjustToFactor(148)) {
|
||||
x = COLUMN_0;
|
||||
@@ -280,6 +283,8 @@ public class GuiBeealyzer extends GuiAlyzer {
|
||||
}
|
||||
|
||||
endPage();
|
||||
|
||||
this.setFactor(factor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,10 @@ import net.minecraft.block.material.Material;
|
||||
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.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.ColorizerFoliage;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
@@ -35,6 +37,8 @@ import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.core.IToolScoop;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.arboriculture.items.ItemLeavesBlock;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
@@ -147,6 +151,20 @@ public class BlockLeaves extends BlockTreeContainer {
|
||||
return prod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
|
||||
TileLeaves leaves = getLeafTile(world, x, y, z);
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
leaves.getTree().writeToNBT(nbttagcompound);
|
||||
|
||||
ItemLeavesBlock leavesItem = (ItemLeavesBlock)ForestryBlock.leaves.item();
|
||||
ItemStack leavesStack = new ItemStack(leavesItem);
|
||||
leavesStack.setTagCompound(nbttagcompound);
|
||||
|
||||
return leavesStack;
|
||||
}
|
||||
|
||||
/* RENDERING */
|
||||
@Override
|
||||
public boolean isOpaqueCube() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -145,6 +146,12 @@ public class BlockSapling extends BlockTreeContainer {
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
|
||||
TileSapling sapling = getSaplingTile(world, x, y, z);
|
||||
return PluginArboriculture.treeInterface.getMemberStack(sapling.getTree(), EnumGermlingType.SAPLING.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||
if (Proxies.common.isSimulating(world) && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
||||
|
||||
@@ -277,16 +277,16 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketLeafUpdate(xCoord, yCoord, zCoord, this).getPacket();
|
||||
return new PacketLeafUpdate(this).getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(xCoord, yCoord, zCoord, this), xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(this), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
private void sendNetworkUpdateRipening() {
|
||||
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(xCoord, yCoord, zCoord, determineFruitColour()), xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketLeafUpdate(this, determineFruitColour()), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -296,6 +296,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
if(packet.isRipeningUpdate()) {
|
||||
colourFruits = packet.colourFruits;
|
||||
} else {
|
||||
readFromNBT(packet.getTagCompound());
|
||||
isFruitLeaf = packet.isFruitLeaf();
|
||||
isPollinatedState = packet.isPollinated();
|
||||
textureIndexFancy = packet.textureIndexFancy;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package forestry.arboriculture.items;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.arboriculture.genetics.Tree;
|
||||
import forestry.core.items.ItemForestryBlock;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class ItemLeavesBlock extends ItemForestryBlock {
|
||||
|
||||
public ItemLeavesBlock(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack itemstack) {
|
||||
String type = StringUtil.localize("trees.grammar.leaves.type");
|
||||
if (!itemstack.hasTagCompound())
|
||||
return type;
|
||||
ITree tree = getTree(itemstack);
|
||||
String customTreeKey = "trees.custom.leaves." + tree.getGenome().getPrimary().getUnlocalizedName().replace("trees.species.","");
|
||||
if(StatCollector.canTranslate("for." + customTreeKey)){
|
||||
return StringUtil.localize(customTreeKey);
|
||||
}
|
||||
String grammar = StringUtil.localize("trees.grammar.leaves");
|
||||
|
||||
return grammar.replaceAll("%SPECIES", tree.getDisplayName()).replaceAll("%TYPE", type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorFromItemStack(ItemStack itemstack, int renderPass) {
|
||||
ITree tree = getTree(itemstack);
|
||||
return tree.getGenome().getPrimary().getLeafColour(tree);
|
||||
}
|
||||
|
||||
private ITree getTree(ItemStack itemStack) {
|
||||
return new Tree(itemStack.getTagCompound());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,10 +15,10 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.arboriculture.gadgets.TileLeaves;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketTileNBT;
|
||||
|
||||
public class PacketLeafUpdate extends PacketCoordinates {
|
||||
public class PacketLeafUpdate extends PacketTileNBT {
|
||||
|
||||
public byte isRipeningUpdate = 0;
|
||||
|
||||
@@ -33,8 +33,8 @@ public class PacketLeafUpdate extends PacketCoordinates {
|
||||
public PacketLeafUpdate() {
|
||||
}
|
||||
|
||||
public PacketLeafUpdate(int posX, int posY, int posZ, TileLeaves leaves) {
|
||||
super(PacketIds.LEAF_UPDATE, posX, posY, posZ);
|
||||
public PacketLeafUpdate(TileLeaves leaves) {
|
||||
super(PacketIds.LEAF_UPDATE, leaves);
|
||||
|
||||
leafState = 0;
|
||||
if(leaves.hasFruit())
|
||||
@@ -48,8 +48,8 @@ public class PacketLeafUpdate extends PacketCoordinates {
|
||||
colourFruits = leaves.determineFruitColour();
|
||||
}
|
||||
|
||||
public PacketLeafUpdate(int posX, int posY, int posZ, int fruitColour) {
|
||||
super(PacketIds.LEAF_UPDATE, posX, posY, posZ);
|
||||
public PacketLeafUpdate(TileLeaves leaves, int fruitColour) {
|
||||
super(PacketIds.LEAF_UPDATE, leaves);
|
||||
|
||||
isRipeningUpdate = 1;
|
||||
colourFruits = fruitColour;
|
||||
|
||||
@@ -130,6 +130,12 @@ public abstract class GuiAlyzer extends GuiForestry<TileForestry> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
widgetManager.clear();
|
||||
}
|
||||
|
||||
protected void drawAnalyticsOverview() {
|
||||
|
||||
startPage();
|
||||
@@ -235,10 +241,12 @@ public abstract class GuiAlyzer extends GuiForestry<TileForestry> {
|
||||
|
||||
protected void drawAnalyticsPage4(IIndividual individual) {
|
||||
|
||||
float factor = this.factor;
|
||||
this.setFactor(1.0f);
|
||||
|
||||
startPage(COLUMN_0, COLUMN_1, COLUMN_2);
|
||||
drawLine(StringUtil.localize("gui.beealyzer.mutations") + ":", COLUMN_0);
|
||||
newLine();
|
||||
newLine();
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
@@ -266,7 +274,7 @@ public abstract class GuiAlyzer extends GuiForestry<TileForestry> {
|
||||
}
|
||||
|
||||
x += columnWidth;
|
||||
if (x > columnWidth * 4) {
|
||||
if (x >= columnWidth * 4) {
|
||||
x = 0;
|
||||
newLine();
|
||||
newLine();
|
||||
@@ -274,73 +282,40 @@ public abstract class GuiAlyzer extends GuiForestry<TileForestry> {
|
||||
}
|
||||
|
||||
endPage();
|
||||
|
||||
this.setFactor(factor);
|
||||
}
|
||||
|
||||
protected void drawMutationInfo(IMutation combination, IAllele species, int x) {
|
||||
|
||||
drawItemStack(iconStacks.get(combination.getPartner(species).getUID()),
|
||||
adjustToFactor(guiLeft) + x, adjustToFactor(guiTop) + getLineY());
|
||||
/*
|
||||
itemRenderer.renderItemIntoGUI(fontRendererObj, mc.renderEngine, iconStacks.get(combination.getPartner(species).getUID()), adjustToFactor(guiLeft) + x,
|
||||
adjustToFactor(guiTop) + getLineY());
|
||||
itemRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, iconStacks.get(combination.getPartner(species).getUID()), adjustToFactor(guiLeft)
|
||||
+ x, adjustToFactor(guiTop) + getLineY());
|
||||
*/
|
||||
ItemStack partnerBee = iconStacks.get(combination.getPartner(species).getUID());
|
||||
widgetManager.add(new ItemStackWidget(x, getLineY(), partnerBee));
|
||||
|
||||
drawProbabilityArrow(combination.getBaseChance(), adjustToFactor(guiLeft) + x + 18, adjustToFactor(guiTop) + getLineY() + 4);
|
||||
|
||||
IAllele result = combination.getTemplate()[EnumBeeChromosome.SPECIES.ordinal()];
|
||||
|
||||
drawItemStack(iconStacks.get(result.getUID()),
|
||||
adjustToFactor(guiLeft) + x + 33, adjustToFactor(guiTop) + getLineY());
|
||||
/*
|
||||
itemRenderer.renderItemIntoGUI(fontRendererObj, mc.renderEngine, iconStacks.get(result.getUID()), adjustToFactor(guiLeft) + x + 33, adjustToFactor(guiTop)
|
||||
+ getLineY());
|
||||
itemRenderer.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, iconStacks.get(result.getUID()), adjustToFactor(guiLeft) + x + 33,
|
||||
adjustToFactor(guiTop) + getLineY());
|
||||
*/
|
||||
|
||||
int line = 247;
|
||||
int column = 100;
|
||||
|
||||
switch (EnumMutateChance.rateChance(combination.getBaseChance())) {
|
||||
case HIGHEST:
|
||||
column = 100;
|
||||
break;
|
||||
case HIGHER:
|
||||
column = 100 + 15;
|
||||
break;
|
||||
case HIGH:
|
||||
column = 100 + 15 * 2;
|
||||
break;
|
||||
case NORMAL:
|
||||
column = 100 + 15 * 3;
|
||||
break;
|
||||
case LOW:
|
||||
column = 100 + 15 * 4;
|
||||
break;
|
||||
case LOWEST:
|
||||
column = 100 + 15 * 5;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Proxies.common.bindTexture(textureFile);
|
||||
drawTexturedModalRect(adjustToFactor(guiLeft) + x + 18, adjustToFactor(guiTop) + getLineY() + 4, column, line, 15, 9);
|
||||
|
||||
ItemStack resultBee = iconStacks.get(result.getUID());
|
||||
widgetManager.add(new ItemStackWidget(x + 33, getLineY(), resultBee));
|
||||
}
|
||||
|
||||
protected void drawUnknownMutation(IMutation combination, IAllele species, int x) {
|
||||
|
||||
// Question marks
|
||||
Proxies.common.bindTexture(textureFile);
|
||||
drawTexturedModalRect(adjustToFactor(guiLeft) + x, adjustToFactor(guiTop) + getLineY(), 78, 240, 16, 16);
|
||||
drawQuestionMark(adjustToFactor(guiLeft) + x, adjustToFactor(guiTop) + getLineY());
|
||||
|
||||
Proxies.common.bindTexture(textureFile);
|
||||
drawTexturedModalRect(adjustToFactor(guiLeft) + x + 32, adjustToFactor(guiTop) + getLineY(), 78, 240, 16, 16);
|
||||
drawProbabilityArrow(combination.getBaseChance(), adjustToFactor(guiLeft) + x + 18, adjustToFactor(guiTop) + getLineY() + 4);
|
||||
|
||||
drawQuestionMark(adjustToFactor(guiLeft) + x + 32, adjustToFactor(guiTop) + getLineY());
|
||||
}
|
||||
|
||||
protected void drawQuestionMark(int x, int y) {
|
||||
Proxies.common.bindTexture(textureFile);
|
||||
drawTexturedModalRect(x, y, 78, 240, 16, 16);
|
||||
}
|
||||
|
||||
protected void drawProbabilityArrow(float chance, int x, int y) {
|
||||
int line = 247;
|
||||
int column = 100;
|
||||
|
||||
switch (EnumMutateChance.rateChance(combination.getBaseChance())) {
|
||||
switch (EnumMutateChance.rateChance(chance)) {
|
||||
case HIGHEST:
|
||||
column = 100;
|
||||
break;
|
||||
@@ -364,8 +339,7 @@ public abstract class GuiAlyzer extends GuiForestry<TileForestry> {
|
||||
|
||||
// Probability arrow
|
||||
Proxies.common.bindTexture(textureFile);
|
||||
drawTexturedModalRect(adjustToFactor(guiLeft) + x + 18, adjustToFactor(guiTop) + getLineY() + 4, column, line, 15, 9);
|
||||
|
||||
drawTexturedModalRect(x, y, column, line, 15, 9);
|
||||
}
|
||||
|
||||
protected void drawToleranceInfo(EnumTolerance tolerance, int x, int textColor) {
|
||||
|
||||
@@ -35,6 +35,7 @@ import forestry.core.gui.slots.SlotForestry;
|
||||
import forestry.core.gui.tooltips.IToolTipProvider;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.tooltips.ToolTipLine;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.interfaces.IErrorSource;
|
||||
import forestry.core.interfaces.IHintSource;
|
||||
@@ -541,4 +542,31 @@ public abstract class GuiForestry<T extends TileForestry> extends GuiContainer {
|
||||
this.zLevel = 0.0F;
|
||||
itemRender.zLevel = 0.0F;
|
||||
}
|
||||
|
||||
protected class ItemStackWidget extends Widget {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip() {
|
||||
ToolTip tip = new ToolTip();
|
||||
tip.add(itemStack.getDisplayName());
|
||||
return tip;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,11 @@ import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.common.versioning.VersionRange;
|
||||
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
@@ -237,9 +242,28 @@ public class ProxyCommon {
|
||||
return Loader.isModLoaded(modname);
|
||||
}
|
||||
|
||||
public Object instantiateIfModLoaded(String modname, String className) {
|
||||
public boolean isModLoaded(String modname, String versionRangeString) {
|
||||
if (versionRangeString != null) {
|
||||
ModContainer mod = Loader.instance().getIndexedModList().get(modname);
|
||||
ArtifactVersion modVersion = mod.getProcessedVersion();
|
||||
|
||||
if (isModLoaded(modname))
|
||||
VersionRange versionRange = VersionParser.parseRange(versionRangeString);
|
||||
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(modname, versionRange);
|
||||
|
||||
if (!requiredVersion.containsVersion(modVersion))
|
||||
return false;
|
||||
}
|
||||
|
||||
return isModLoaded(modname);
|
||||
}
|
||||
|
||||
public Object instantiateIfModLoaded(String modname, String className) {
|
||||
return instantiateIfModLoaded(modname, null, className);
|
||||
}
|
||||
|
||||
public Object instantiateIfModLoaded(String modname, String versionRangeString, String className) {
|
||||
|
||||
if (isModLoaded(modname, versionRangeString))
|
||||
try {
|
||||
Class<?> clas = Class.forName(className, true, Loader.instance().getModClassLoader());
|
||||
return clas.newInstance();
|
||||
|
||||
@@ -191,68 +191,60 @@ public class InventoryAdapter implements IInventory, INBTTagable {
|
||||
|
||||
/* CONTAINS */
|
||||
public boolean contains(ItemStack[] query, int startSlot, int slots) {
|
||||
for (ItemStack queried : query) {
|
||||
|
||||
int itemCount = 0;
|
||||
for (int i = startSlot; i < startSlot + slots; i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
|
||||
if (stack == null)
|
||||
continue;
|
||||
|
||||
if (StackUtils.equals(Blocks.bedrock, queried)) {
|
||||
itemCount += stack.stackSize;
|
||||
continue;
|
||||
}
|
||||
if (queried.getItemDamage() < 0) {
|
||||
|
||||
if (stack.getItem() == queried.getItem())
|
||||
itemCount += stack.stackSize;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stack.isItemEqual(queried) && ItemStack.areItemStackTagsEqual(stack, queried))
|
||||
itemCount += stack.stackSize;
|
||||
}
|
||||
|
||||
if (itemCount < queried.stackSize)
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
ItemStack[] stock = getStacks(startSlot, slots);
|
||||
return StackUtils.containsSets(query, stock) > 0;
|
||||
}
|
||||
|
||||
/* REMOVAL */
|
||||
public void removeResources(ItemStack[] query, int startSlot, int slots) {
|
||||
for (ItemStack queried : query) {
|
||||
/**
|
||||
* 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 boolean removeSets(int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
|
||||
ItemStack remain = queried.copy();
|
||||
ItemStack[] condensedSet = StackUtils.condenseStacks(set, -1, false);
|
||||
|
||||
for (int i = startSlot; i < startSlot + slots; i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
ItemStack[] stock = getStacks(firstSlotIndex, slotCount);
|
||||
if (StackUtils.containsSets(condensedSet, stock, null, oreDictionary, craftingTools) < count)
|
||||
return false;
|
||||
|
||||
if (stack == null)
|
||||
continue;
|
||||
for (ItemStack stackToRemove : condensedSet) {
|
||||
stackToRemove.stackSize *= count;
|
||||
|
||||
if (queried.getItemDamage() < 0) {
|
||||
|
||||
if (stack.getItem() == queried.getItem()) {
|
||||
ItemStack removed = decrStackSize(i, remain.stackSize);
|
||||
remain.stackSize -= removed.stackSize;
|
||||
}
|
||||
|
||||
} else if (stack.isItemEqual(remain) && ItemStack.areItemStackTagsEqual(stack, remain)) {
|
||||
ItemStack removed = decrStackSize(i, remain.stackSize);
|
||||
remain.stackSize -= removed.stackSize;
|
||||
}
|
||||
|
||||
if (remain.stackSize <= 0)
|
||||
break;
|
||||
}
|
||||
// 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 */
|
||||
|
||||
@@ -267,7 +267,7 @@ public class StackUtils {
|
||||
public static int containsSets(ItemStack[] set, ItemStack[] stock, ItemStack exclude, boolean oreDictionary, boolean craftingTools) {
|
||||
int count = 0;
|
||||
|
||||
ItemStack[] condensedRequired = StackUtils.condenseStacks(set);
|
||||
ItemStack[] condensedRequired = StackUtils.condenseStacks(set, -1, oreDictionary);
|
||||
ItemStack[] condensedOffered = StackUtils.condenseStacks(stock, -1, oreDictionary);
|
||||
|
||||
for (ItemStack req : condensedRequired) {
|
||||
@@ -297,6 +297,27 @@ public class StackUtils {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two item stacks for crafting equivalency without oreDictionary or craftingTools
|
||||
*/
|
||||
public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison) {
|
||||
if (base == null || comparison == null)
|
||||
return false;
|
||||
|
||||
if (base.getItem() != comparison.getItem())
|
||||
return false;
|
||||
|
||||
if (base.getItemDamage() != Defaults.WILDCARD)
|
||||
if (base.getItemDamage() != comparison.getItemDamage())
|
||||
return false;
|
||||
|
||||
// When the base stackTagCompound is null or empty, treat it as a wildcard for crafting
|
||||
if (base.stackTagCompound == null || base.stackTagCompound.hasNoTags())
|
||||
return true;
|
||||
else
|
||||
return ItemStack.areItemStackTagsEqual(base, comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two item stacks for crafting equivalency.
|
||||
*
|
||||
@@ -306,7 +327,7 @@ public class StackUtils {
|
||||
* @return
|
||||
*/
|
||||
public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison, boolean oreDictionary, boolean craftingTools) {
|
||||
if (isIdenticalItem(base, comparison))
|
||||
if (isCraftingEquivalent(base, comparison))
|
||||
return true;
|
||||
|
||||
if (base == null || comparison == null)
|
||||
|
||||
@@ -51,7 +51,7 @@ public class Vect {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%sx%sx%s;", x, y, z);
|
||||
return String.format("%sx%sx%s", x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -386,7 +386,8 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
totalTime = 0;
|
||||
|
||||
// Remove resources
|
||||
removeResources(currentRecipe);
|
||||
if (!removeResources(currentRecipe))
|
||||
return false;
|
||||
|
||||
// Update product display
|
||||
if (activeContainer != null)
|
||||
@@ -434,37 +435,29 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
return StackUtils.containsSets(craftingInventory.getStacks(SLOT_CRAFTING_1, 9), accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT), null, true, false) > 0;
|
||||
}
|
||||
|
||||
private void removeResources(Recipe recipe) {
|
||||
private boolean removeResources(Recipe recipe) {
|
||||
|
||||
// Remove resources
|
||||
if (recipe.liquid != null)
|
||||
resourceTank.drain(recipe.liquid.amount, true);
|
||||
if (recipe.liquid != null) {
|
||||
FluidStack amountDrained = resourceTank.drain(recipe.liquid.amount, false);
|
||||
if (amountDrained != null && amountDrained.amount == recipe.liquid.amount)
|
||||
resourceTank.drain(recipe.liquid.amount, true);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
// Remove boxes
|
||||
if (recipe.box != null)
|
||||
accessibleInventory.decrStackSize(SLOT_BOX, 1);
|
||||
|
||||
removeSets(1, craftingInventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
|
||||
}
|
||||
|
||||
private void removeSets(int count, ItemStack[] set) {
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ItemStack[] condensedSet = StackUtils.condenseStacks(set);
|
||||
for (ItemStack req : condensedSet) {
|
||||
for (int j = SLOT_INVENTORY_1; j < SLOT_INVENTORY_1 + SLOT_INVENTORY_COUNT; j++) {
|
||||
ItemStack pol = accessibleInventory.getStackInSlot(j);
|
||||
if (pol == null)
|
||||
continue;
|
||||
if (!StackUtils.isCraftingEquivalent(pol, req, true, false))
|
||||
continue;
|
||||
|
||||
ItemStack removed = accessibleInventory.decrStackSize(j, req.stackSize);
|
||||
req.stackSize -= removed.stackSize;
|
||||
}
|
||||
}
|
||||
if (recipe.box != null) {
|
||||
ItemStack removed = accessibleInventory.decrStackSize(SLOT_BOX, 1);
|
||||
if (removed == null || removed.stackSize == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return removeSets(1, craftingInventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
}
|
||||
|
||||
private boolean removeSets(int count, ItemStack[] set) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
return accessibleInventory.removeSets(count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
}
|
||||
|
||||
private boolean tryAddPending() {
|
||||
|
||||
@@ -399,8 +399,8 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
FluidStack liquid = myRecipe.molten;
|
||||
|
||||
// Remove resources
|
||||
if (removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), false)) {
|
||||
removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), true);
|
||||
if (removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, false)) {
|
||||
removeFromInventory(1, inventory.getStacks(SLOT_CRAFTING_1, 9), player, true);
|
||||
moltenTank.drain(liquid.amount, true);
|
||||
} else if (consumeRecipe) {
|
||||
removeFromCraftMatrix(myRecipe);
|
||||
@@ -430,39 +430,13 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
}
|
||||
|
||||
private boolean removeFromInventory(int count, ItemStack[] set, boolean doRemove) {
|
||||
|
||||
boolean hasRemoved = true;
|
||||
for (int i = 0; i < count; i++) {
|
||||
ItemStack[] condensedSet = StackUtils.condenseStacks(set, 1, true);
|
||||
for (ItemStack req : condensedSet)
|
||||
for (int j = SLOT_INVENTORY_1; j < SLOT_INVENTORY_1 + SLOT_INVENTORY_COUNT; j++) {
|
||||
ItemStack pol = inventory.getStackInSlot(j);
|
||||
if (pol == null)
|
||||
continue;
|
||||
if (!StackUtils.isCraftingEquivalent(pol, req, true, false))
|
||||
continue;
|
||||
|
||||
int available = pol.stackSize;
|
||||
if (doRemove) {
|
||||
inventory.decrStackSize(j, req.stackSize);
|
||||
}
|
||||
req.stackSize -= available;
|
||||
|
||||
if(req.stackSize <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
boolean hasLeft = false;
|
||||
for (ItemStack req : condensedSet)
|
||||
if (req != null && req.stackSize > 0)
|
||||
hasLeft = true;
|
||||
if (hasLeft)
|
||||
hasRemoved = false;
|
||||
|
||||
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);
|
||||
return StackUtils.containsSets(set, stock) >= count;
|
||||
}
|
||||
|
||||
return hasRemoved;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -529,10 +503,12 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
@Override
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack taken;
|
||||
if (doRemove)
|
||||
taken = this.takenFromSlot(SLOT_RESULT, false, null);
|
||||
else
|
||||
if (doRemove) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
taken = this.takenFromSlot(SLOT_RESULT, false, player);
|
||||
} else {
|
||||
taken = this.getResult();
|
||||
}
|
||||
|
||||
if (taken != null)
|
||||
return new ItemStack[] { taken };
|
||||
|
||||
@@ -77,29 +77,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack[] res) {
|
||||
// No recipe without resource!
|
||||
if (res == null || res.length <= 0)
|
||||
return false;
|
||||
|
||||
boolean matchedAll = true;
|
||||
|
||||
for (ItemStack stack : resources) {
|
||||
boolean matched = false;
|
||||
for (ItemStack matchStack : res) {
|
||||
if (matchStack == null)
|
||||
continue;
|
||||
|
||||
// If the item matches, we need enough items
|
||||
if (matchStack.isItemEqual(stack))
|
||||
if (matchStack.stackSize >= stack.stackSize) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matched)
|
||||
matchedAll = false;
|
||||
}
|
||||
return matchedAll;
|
||||
return StackUtils.containsSets(resources, res, null, true, true) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,13 +270,14 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
return true;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
removeResources(currentRecipe.resources);
|
||||
|
||||
checkRecipe();
|
||||
resetRecipe();
|
||||
|
||||
@@ -367,8 +346,9 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
return inventory.tryAddStack(stack, SLOT_REMNANT, 1, true);
|
||||
}
|
||||
|
||||
private void removeResources(ItemStack[] stacks) {
|
||||
inventory.removeResources(stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT);
|
||||
private boolean removeResources(ItemStack[] stacks) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
return inventory.removeSets(1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -462,43 +462,14 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
}
|
||||
|
||||
private boolean validateResources() {
|
||||
// Need at least one matched set
|
||||
if (currentRecipe == null)
|
||||
return false;
|
||||
|
||||
ItemStack[] set = currentRecipe.getMatrix().getStacks();
|
||||
ItemStack[] stock = accessibleInventory.getStacks();
|
||||
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
|
||||
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
|
||||
return StackUtils.containsSets(set, stock, currentRecipe.getRecipeOutput(), true, true) > 0;
|
||||
}
|
||||
|
||||
private void removeResources(EntityPlayer player) {
|
||||
removeSets(1, craftingInventory.getStacks(SLOT_CRAFTING_1, 9), player);
|
||||
}
|
||||
|
||||
private void removeSets(int count, ItemStack[] set, EntityPlayer player) {
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ItemStack[] condensedSet = StackUtils.condenseStacks(set);
|
||||
for (ItemStack req : condensedSet) {
|
||||
for (int j = SLOT_INVENTORY_1; j < SLOT_INVENTORY_1 + SLOT_INVENTORY_COUNT; j++) {
|
||||
ItemStack pol = accessibleInventory.getStackInSlot(j);
|
||||
if (pol == null)
|
||||
continue;
|
||||
|
||||
if (!StackUtils.isCraftingEquivalent(pol, req, true, true))
|
||||
continue;
|
||||
|
||||
ItemStack removed = accessibleInventory.decrStackSize(j, req.stackSize);
|
||||
req.stackSize -= removed.stackSize;
|
||||
|
||||
if (req.getItem().hasContainerItem(req))
|
||||
StackUtils.stowContainerItem(removed, accessibleInventory, j, player);
|
||||
if (req.stackSize <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -508,12 +479,12 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
|
||||
@Override
|
||||
public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) {
|
||||
if (!validateResources())
|
||||
if (!removeResources(player))
|
||||
return null;
|
||||
|
||||
if (Proxies.common.isSimulating(worldObj))
|
||||
memorized.memorizeRecipe(worldObj, currentRecipe, currentCrafting);
|
||||
removeResources(player);
|
||||
|
||||
updateCraftResult(currentCrafting);
|
||||
return currentRecipe.getRecipeOutput().copy();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -757,7 +758,8 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
inventory.removeResources(resources, SLOT_RESOURCES_1, SLOT_COUNT_RESERVOIRS);
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
inventory.removeSets(1, resources, SLOT_RESOURCES_1, SLOT_RESOURCES_1, player, false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,11 +32,11 @@ public class MailAddress implements INBTTagable, IMailAddress {
|
||||
@EntityNetData
|
||||
private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
|
||||
private static final MailAddress invalidAddress = new MailAddress();
|
||||
private static final GameProfile invalidGameProfile = new GameProfile(new UUID(0,0), "");
|
||||
|
||||
public MailAddress() {
|
||||
this.type = EnumAddressee.INVALID;
|
||||
this.gameProfile = new GameProfile(new UUID(0,0), "");
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = invalidGameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(GameProfile gameProfile) {
|
||||
@@ -101,20 +101,25 @@ public class MailAddress implements INBTTagable, IMailAddress {
|
||||
return type == EnumAddressee.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isTrader() {
|
||||
return type == EnumAddressee.TRADER;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return type != EnumAddressee.INVALID;
|
||||
return !gameProfile.equals(invalidGameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
type = EnumAddressee.INVALID;
|
||||
type = null;
|
||||
if(nbttagcompound.hasKey("TP")) {
|
||||
String typeName = nbttagcompound.getString("TP");
|
||||
type = EnumAddressee.fromString(typeName);
|
||||
}
|
||||
|
||||
if (!isValid()) {
|
||||
gameProfile = invalidAddress.gameProfile;
|
||||
if (type == null) {
|
||||
type = EnumAddressee.PLAYER;
|
||||
gameProfile = invalidGameProfile;
|
||||
} else if(nbttagcompound.hasKey("profile")) {
|
||||
NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile");
|
||||
gameProfile = NBTUtil.func_152459_a(profileTag);
|
||||
|
||||
@@ -159,20 +159,13 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
|
||||
IPostalState state = EnumDeliveryState.NOT_MAILABLE;
|
||||
for (IMailAddress address : letter.getRecipients()) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType().toString());
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
|
||||
if (carrier == null)
|
||||
continue;
|
||||
state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
|
||||
if (!state.isOk())
|
||||
break;
|
||||
}
|
||||
/*
|
||||
for (MailAddress address : letter.getRecipients())
|
||||
if (address.isPlayer())
|
||||
state = storeInPOBox(world, address, itemstack, doLodge);
|
||||
else if (address.getType().equals(EnumAddressee.TRADER.toString()))
|
||||
state = handleTradeLetter(world, address, itemstack, doLodge);
|
||||
*/
|
||||
|
||||
if (!state.isOk())
|
||||
return state;
|
||||
|
||||
@@ -27,6 +27,7 @@ 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;
|
||||
@@ -79,7 +80,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeAddress(World world, IMailAddress address) {
|
||||
return !address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
return address.isTrader() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,21 +169,21 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
/* CARRIER */
|
||||
private final HashMap<String, IPostalCarrier> carriers = new HashMap<String, IPostalCarrier>();
|
||||
private final HashMap<EnumAddressee, IPostalCarrier> carriers = new HashMap<EnumAddressee, IPostalCarrier>();
|
||||
|
||||
@Override
|
||||
public Map<String, IPostalCarrier> getRegisteredCarriers() {
|
||||
public Map<EnumAddressee, IPostalCarrier> getRegisteredCarriers() {
|
||||
return carriers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCarrier(IPostalCarrier carrier) {
|
||||
carriers.put(carrier.getUID(), carrier);
|
||||
carriers.put(carrier.getType(), carrier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPostalCarrier getCarrier(String uid) {
|
||||
return carriers.get(uid);
|
||||
public IPostalCarrier getCarrier(EnumAddressee type) {
|
||||
return carriers.get(type);
|
||||
}
|
||||
|
||||
/* LETTERS */
|
||||
|
||||
@@ -26,24 +26,22 @@ import forestry.plugins.PluginMail;
|
||||
|
||||
public class PostalCarrier implements IPostalCarrier {
|
||||
|
||||
private final String uid;
|
||||
private final String iconID;
|
||||
private final EnumAddressee type;
|
||||
|
||||
public PostalCarrier(EnumAddressee type) {
|
||||
uid = type.toString().toLowerCase(Locale.ENGLISH);
|
||||
iconID = "mail/carrier." + uid;
|
||||
iconID = "mail/carrier." + type;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUID() {
|
||||
return uid;
|
||||
public EnumAddressee getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return StringUtil.localize("gui.addressee." + uid);
|
||||
return StringUtil.localize("gui.addressee." + type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,8 +64,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
// / CONSTRUCTORS
|
||||
public TradeStation(GameProfile owner, IMailAddress address) {
|
||||
super(SAVE_NAME + address);
|
||||
if (address.isPlayer()) {
|
||||
throw new IllegalArgumentException("TradeStation address must not be a player");
|
||||
if (!address.isTrader()) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
this.owner = owner;
|
||||
this.address = address;
|
||||
|
||||
@@ -44,7 +44,7 @@ import forestry.mail.network.PacketLetterInfo;
|
||||
public class ContainerLetter extends ContainerItemInventory {
|
||||
|
||||
private final LetterInventory letterInventory;
|
||||
private EnumAddressee carrier = EnumAddressee.PLAYER;
|
||||
private EnumAddressee carrierType = EnumAddressee.PLAYER;
|
||||
private TradeStationInfo tradeInfo = null;
|
||||
|
||||
public ContainerLetter(EntityPlayer player, LetterInventory inventory) {
|
||||
@@ -88,7 +88,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
if (letterInventory.getLetter() != null)
|
||||
if (letterInventory.getLetter().getRecipients() != null)
|
||||
if (letterInventory.getLetter().getRecipients().length > 0)
|
||||
this.carrier = letterInventory.getLetter().getRecipients()[0].getType();
|
||||
this.carrierType = letterInventory.getLetter().getRecipients()[0].getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,17 +115,17 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
public void setCarrierType(EnumAddressee type) {
|
||||
this.carrier = type;
|
||||
this.carrierType = type;
|
||||
}
|
||||
|
||||
public EnumAddressee getCarrierType() {
|
||||
return this.carrier;
|
||||
return this.carrierType;
|
||||
}
|
||||
|
||||
public void advanceCarrierType() {
|
||||
Iterator<IPostalCarrier> it = PostManager.postRegistry.getRegisteredCarriers().values().iterator();
|
||||
while(it.hasNext()) {
|
||||
if(it.next().getUID().equals(carrier))
|
||||
if(it.next().getType().equals(carrierType))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -135,12 +135,11 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
else
|
||||
postal = PostManager.postRegistry.getRegisteredCarriers().values().iterator().next();
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(postal.getUID());
|
||||
setCarrierType(type);
|
||||
setCarrierType(postal.getType());
|
||||
}
|
||||
|
||||
public void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (StringUtils.isBlank(recipientName) || type == EnumAddressee.INVALID)
|
||||
if (StringUtils.isBlank(recipientName) || type == null)
|
||||
return;
|
||||
|
||||
// / Send to server
|
||||
@@ -222,7 +221,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
public void handleLetterInfoUpdate(PacketLetterInfo packet) {
|
||||
carrier = packet.type;
|
||||
carrierType = packet.type;
|
||||
if (packet.type == EnumAddressee.PLAYER) {
|
||||
getLetter().setRecipient(packet.address);
|
||||
} else if (packet.type == EnumAddressee.TRADER) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -48,7 +48,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
//mc.renderEngine.bindTexture(Defaults.TEXTURE_PATH_GUI + "/letter.png");
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType().toString());
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType());
|
||||
if(carrier != null)
|
||||
drawTexturedModelRectFromIcon(startX + xPos, startY + yPos - 5, carrier.getIcon(), 26, 26);
|
||||
|
||||
@@ -76,6 +76,8 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
boolean addressFocus;
|
||||
boolean textFocus;
|
||||
|
||||
protected ArrayList<Widget> tradeInfoWidgets;
|
||||
|
||||
private final ContainerLetter container;
|
||||
|
||||
public GuiLetter(EntityPlayer player, LetterInventory inventory) {
|
||||
@@ -86,6 +88,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
this.container = (ContainerLetter) inventorySlots;
|
||||
this.isProcessedLetter = container.getLetter().isProcessed();
|
||||
this.widgetManager.add(new AddresseeSlot(16, 12));
|
||||
this.tradeInfoWidgets = new ArrayList<Widget>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,9 +175,10 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
fontRendererObj.drawString(address.getText(), guiLeft + 49, guiTop + 16, fontColor.get("gui.mail.lettertext"));
|
||||
fontRendererObj.drawSplitString(text.getText(), guiLeft + 20, guiTop + 34, 119, fontColor.get("gui.mail.lettertext"));
|
||||
} else {
|
||||
clearTradeInfoWidgets();
|
||||
address.drawTextBox();
|
||||
if (container.getCarrierType() == EnumAddressee.TRADER)
|
||||
drawTradePreview(guiLeft + 18, guiTop + 32);
|
||||
drawTradePreview(18, 32);
|
||||
else
|
||||
text.drawTextBox();
|
||||
}
|
||||
@@ -191,25 +195,30 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
infoString = "chat.mail." + container.getTradeInfo().state.getIdentifier();
|
||||
|
||||
if (infoString != null) {
|
||||
fontRendererObj.drawSplitString(StringUtil.localize(infoString), x, y, 119, fontColor.get("gui.mail.lettertext"));
|
||||
fontRendererObj.drawSplitString(StringUtil.localize(infoString), guiLeft + x, guiTop + y, 119, fontColor.get("gui.mail.lettertext"));
|
||||
return;
|
||||
}
|
||||
|
||||
fontRendererObj.drawString(StringUtil.localize("gui.mail.pleasesend"), x, y, fontColor.get("gui.mail.lettertext"));
|
||||
fontRendererObj.drawString(StringUtil.localize("gui.mail.pleasesend"), guiLeft + x, guiTop + y, fontColor.get("gui.mail.lettertext"));
|
||||
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, container.getTradeInfo().tradegood, x, y + 10);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, container.getTradeInfo().tradegood, x, y + 10);
|
||||
addTradeInfoWidget(new ItemStackWidget(x, y + 10, container.getTradeInfo().tradegood));
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
fontRendererObj.drawString(StringUtil.localize("gui.mail.foreveryattached"), x, y + 28, fontColor.get("gui.mail.lettertext"));
|
||||
fontRendererObj.drawString(StringUtil.localize("gui.mail.foreveryattached"), guiLeft + x, guiTop + y + 28, fontColor.get("gui.mail.lettertext"));
|
||||
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, container.getTradeInfo().required[i], x + i * 18, y + 38);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, container.getTradeInfo().required[i], x + i * 18, y + 38);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
addTradeInfoWidget(new ItemStackWidget(x + i * 18, y + 38, container.getTradeInfo().required[i]));
|
||||
}
|
||||
}
|
||||
|
||||
private void addTradeInfoWidget(Widget widget) {
|
||||
tradeInfoWidgets.add(widget);
|
||||
widgetManager.add(widget);
|
||||
}
|
||||
|
||||
private void clearTradeInfoWidgets() {
|
||||
for (Widget widget : tradeInfoWidgets)
|
||||
widgetManager.remove(widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,7 +255,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
}
|
||||
|
||||
private void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (this.isProcessedLetter || StringUtils.isBlank(recipientName) || type == null || type == EnumAddressee.INVALID)
|
||||
if (this.isProcessedLetter || StringUtils.isBlank(recipientName) || type == null)
|
||||
return;
|
||||
|
||||
container.setRecipient(recipientName, type);
|
||||
|
||||
@@ -46,11 +46,10 @@ public class PacketLetterInfo extends ForestryPacket {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
if (type == null || type == EnumAddressee.INVALID) {
|
||||
if (type == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(type.toString());
|
||||
|
||||
@@ -89,6 +89,7 @@ import forestry.arboriculture.genetics.TreeTemplates;
|
||||
import forestry.arboriculture.genetics.TreekeepingMode;
|
||||
import forestry.arboriculture.items.ItemGermlingGE;
|
||||
import forestry.arboriculture.items.ItemGrafter;
|
||||
import forestry.arboriculture.items.ItemLeavesBlock;
|
||||
import forestry.arboriculture.items.ItemStairs;
|
||||
import forestry.arboriculture.items.ItemTreealyzer;
|
||||
import forestry.arboriculture.items.ItemWoodBlock;
|
||||
@@ -233,7 +234,7 @@ public class PluginArboriculture extends NativePlugin implements IFuelHandler {
|
||||
ForestryBlock.saplingGE.registerBlock(new BlockSapling(), ItemForestryBlock.class, "saplingGE");
|
||||
|
||||
// Leaves
|
||||
ForestryBlock.leaves.registerBlock(new BlockLeaves(), ItemForestryBlock.class, "leaves");
|
||||
ForestryBlock.leaves.registerBlock(new BlockLeaves(), ItemLeavesBlock.class, "leaves");
|
||||
|
||||
// Pods
|
||||
ForestryBlock.pods.registerBlock(new BlockFruitPod(), ItemForestryBlock.class, "pods");
|
||||
|
||||
@@ -53,6 +53,7 @@ public class PluginBuildCraft implements IPlugin, ITriggerProvider {
|
||||
public static Item wrench;
|
||||
public static Item stoneGear;
|
||||
public static Item pipeWaterproof;
|
||||
public static final String validVersionRange = "[6.0.0,6.1.0)";
|
||||
|
||||
public PluginBuildCraft() {
|
||||
if (PluginBuildCraft.instance == null)
|
||||
@@ -64,7 +65,7 @@ public class PluginBuildCraft implements IPlugin, ITriggerProvider {
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return (Proxies.common.isModLoaded("BuildCraft|Core") && Proxies.common.isModLoaded("BuildCraft|Transport"));
|
||||
return (Proxies.common.isModLoaded("BuildCraft|Core", validVersionRange) && Proxies.common.isModLoaded("BuildCraft|Transport", validVersionRange));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PluginPropolisPipe extends NativePlugin {
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return Proxies.common.isModLoaded("BuildCraft|Transport");
|
||||
return Proxies.common.isModLoaded("BuildCraft|Transport", PluginBuildCraft.validVersionRange);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +62,7 @@ public class PluginPropolisPipe extends NativePlugin {
|
||||
if (FMLCommonHandler.instance().getSide().isClient())
|
||||
proxyClass = "forestry.pipes.proxy.ClientProxyPipes";
|
||||
|
||||
proxy = (ProxyPipes) Proxies.common.instantiateIfModLoaded("BuildCraft|Transport", proxyClass);
|
||||
proxy = (ProxyPipes) Proxies.common.instantiateIfModLoaded("BuildCraft|Transport", PluginBuildCraft.validVersionRange, proxyClass);
|
||||
|
||||
if (proxy == null)
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user