Jump to content

[1.9] Smelting item only with certain item


grossik

Recommended Posts

I need to BottleFW smelting only FermentedWine and KegForBeer only BeerBucket. How to do it?  :( :'(

 

public class SlotBottlingFuel extends Slot
{
public static boolean wine = false;
public static boolean beer = false;

    public SlotBottlingFuel(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
    {
        super(inventoryIn, slotIndex, xPosition, yPosition);
    }

    public boolean isItemValid(ItemStack stack)
    {   
     	if(stack.getItem() == ItemHandler.FermentedWine)
     	{
     		beer = false;
     		wine = true; 
     	} 
     	if(stack.getItem() == ItemHandler.BeerBucket)
     	{
     		wine = false;
     		beer = true;
     	}
     	
        return TileEntityBottling.isItemFuel(stack) || isBucket(stack);
    }

    public int getItemStackLimit(ItemStack stack)
    {
        return isBucket(stack) ? 1 : super.getItemStackLimit(stack);
    }

    public static boolean isBucket(ItemStack stack)
    {
        return stack != null && stack.getItem() != null && stack.getItem() == Items.bucket;
    }
}

 

public class BottlingRecipes
{
private static final BottlingRecipes smeltingBase = new BottlingRecipes();
private Map<ItemStack, ItemStack> smeltingList = Maps.<ItemStack, ItemStack>newHashMap();
private Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();

public static BottlingRecipes instance()
{
return smeltingBase;
}

private BottlingRecipes()
{
if(SlotBottlingFuel.wine == true)
{
this.addSmelting(ItemHandler.BottleFW, new ItemStack(ItemHandler.BottleSW), 0.0F);
}
if(SlotBottlingFuel.beer == true)
{
this.addSmelting(ItemHandler.KegForBeer, new ItemStack(ItemHandler.KegOfBeer), 0.0F);
}
}

public void addSmeltingRecipeForBlock(Block input, ItemStack stack, float experience)
{
this.addSmelting(Item.getItemFromBlock(input), stack, experience);
}

public void addSmelting(Item input, ItemStack stack, float experience)
{
this.addSmeltingRecipe(new ItemStack(input, 1, 32767), stack, experience);
}

public void addSmeltingRecipe(ItemStack input, ItemStack stack, float experience)
{
if (getSmeltingResult(input) != null) { net.minecraftforge.fml.common.FMLLog.info("Ignored smelting recipe with conflicting input: " + input + " = " + stack); return; }
this.smeltingList.put(input, stack);
this.experienceList.put(stack, Float.valueOf(experience));
}

public ItemStack getSmeltingResult(ItemStack stack)
{
for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
{
if (this.compareItemStacks(stack, (ItemStack)entry.getKey()))
{
return (ItemStack)entry.getValue();
}
}

return null;
}

private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
{
return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
}

public Map<ItemStack, ItemStack> getSmeltingList()
{
return this.smeltingList;
}

public float getSmeltingExperience(ItemStack stack)
{
float ret = stack.getItem().getSmeltingExperience(stack);
if (ret != -1) return ret;

for (Entry<ItemStack, Float> entry : this.experienceList.entrySet())
{
if (this.compareItemStacks(stack, (ItemStack)entry.getKey()))
{
return ((Float)entry.getValue()).floatValue();
}
}

return 0.0F;
}
}

 

 

 

Block_Bottling:

public class Block_Bottling extends BlockContainer
{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
private final boolean isBurning;
private static boolean keepInventory;

public Block_Bottling(boolean isBurning)
{
super(Material.rock);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
this.isBurning = isBurning;
}

/**
* Get the Item that this Block should drop when harvested.
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(BlockHandler.BottlingOff);
}

public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.setDefaultFacing(worldIn, pos, state);
}

private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}

worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}

@SideOnly(Side.CLIENT)
@SuppressWarnings("incomplete-switch")
public void randomDisplayTick(IBlockState worldIn, World pos, BlockPos state, Random rand)
{
if (this.isBurning)
{
EnumFacing enumfacing = (EnumFacing)worldIn.getValue(FACING);
double d0 = (double)state.getX() + 0.5D;
double d1 = (double)state.getY() + rand.nextDouble() * 6.0D / 16.0D;
double d2 = (double)state.getZ() + 0.5D;
double d3 = 0.52D;
double d4 = rand.nextDouble() * 0.6D - 0.3D;

if (rand.nextDouble() < 0.1D)
{
pos.playSound((double)state.getX() + 0.5D, (double)state.getY(), (double)state.getZ() + 0.5D, SoundEvents.block_furnace_fire_crackle, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
}
}

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (!worldIn.isRemote){
playerIn.openGui(Main.MODID, FC2_GuiHandler.BOTTLING_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}

public static void setState(boolean active, World worldIn, BlockPos pos)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;

if (active)
{
worldIn.setBlockState(pos, BlockHandler.BottlingOn.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockHandler.BottlingOn.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}
else
{
worldIn.setBlockState(pos, BlockHandler.BottlingOff.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockHandler.BottlingOff.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
}

keepInventory = false;

if (tileentity != null)
{
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}

/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileEntityBottling();
}

/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

/**
* Called by ItemBlocks after a block is set in the world, to allow post-place logic
*/
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);

if (stack.hasDisplayName())
{
TileEntity tileentity = worldIn.getTileEntity(pos);

if (tileentity instanceof TileEntityBottling)
{
((TileEntityBottling)tileentity).setCustomInventoryName(stack.getDisplayName());
}
}
}

public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!keepInventory)
{
TileEntity tileentity = worldIn.getTileEntity(pos);

if (tileentity instanceof TileEntityBottling)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityBottling)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
}

super.breakBlock(worldIn, pos, state);
}

public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}

public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
{
return Container.calcRedstone(worldIn.getTileEntity(pos));
}

public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
{
return new ItemStack(BlockHandler.BottlingOff);
}

/**
* The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
*/
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.MODEL;
}

/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
EnumFacing enumfacing = EnumFacing.getFront(meta);

if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}

return this.getDefaultState().withProperty(FACING, enumfacing);
}

/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing)state.getValue(FACING)).getIndex();
}

/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}

/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}

protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
}

 

ContainerBottling:

public class ContainerBottling extends Container
{
private final IInventory tileFurnace;
private int cookTime;
private int totalCookTime;
private int furnaceBurnTime;
private int currentItemBurnTime;

public ContainerBottling(InventoryPlayer playerInventory, TileEntityBottling te)
{
this.tileFurnace = te;
this.addSlotToContainer(new SlotBottling(te, 0, 56, 17));
this.addSlotToContainer(new SlotBottlingFuel(te, 1, 56, 53));
this.addSlotToContainer(new SlotBottlingOutput(playerInventory.player, te, 2, 116, 35));

for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}

for (int k = 0; k < 9; ++k)
{
this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
}
}

public void onCraftGuiOpened(ICrafting listener)
{
super.onCraftGuiOpened(listener);
listener.sendAllWindowProperties(this, this.tileFurnace);
}

/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges()
{
super.detectAndSendChanges();

for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);

if (this.cookTime != this.tileFurnace.getField(0))
{
icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.getField(0));
}

if (this.furnaceBurnTime != this.tileFurnace.getField(1))
{
icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.getField(1));
}

if (this.currentItemBurnTime != this.tileFurnace.getField(2))
{
icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.getField(2));
}

if (this.totalCookTime != this.tileFurnace.getField(3))
{
icrafting.sendProgressBarUpdate(this, 3, this.tileFurnace.getField(3));
}
}

this.cookTime = this.tileFurnace.getField(2);
this.furnaceBurnTime = this.tileFurnace.getField(0);
this.currentItemBurnTime = this.tileFurnace.getField(1);
this.totalCookTime = this.tileFurnace.getField(3);
}

@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{
this.tileFurnace.setField(id, data);
}

public boolean canInteractWith(EntityPlayer playerIn)
{
return this.tileFurnace.isUseableByPlayer(playerIn);
}

/**
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(index);

if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();

if (index == 2)
{
if (!this.mergeItemStack(itemstack1, 3, 39, true))
{
return null;
}

slot.onSlotChange(itemstack1, itemstack);
}
else if (index != 1 && index != 0)
{
if (BottlingRecipes.instance().getSmeltingResult(itemstack1) != null)
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return null;
}
}
else if (TileEntityBottling.isItemFuel(itemstack1))
{
if (!this.mergeItemStack(itemstack1, 1, 2, false))
{
return null;
}
}
else if (index >= 3 && index < 30)
{
if (!this.mergeItemStack(itemstack1, 30, 39, false))
{
return null;
}
}
else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 3, 39, false))
{
return null;
}

if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}

if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}

slot.onPickupFromSlot(playerIn, itemstack1);
}

return itemstack;
}
}

 

GuiBottling:

@SideOnly(Side.CLIENT)
public class GuiBottling extends GuiContainer
{
private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("farmcraft2:textures/gui/container/bottling.png");
/** The player inventory bound to this GUI. */
private final InventoryPlayer playerInventory;
private IInventory tileFurnace;

public GuiBottling(InventoryPlayer playerInv, TileEntityBottling furnaceInv)
{
super(new ContainerBottling(playerInv, furnaceInv));
this.playerInventory = playerInv;
this.tileFurnace = furnaceInv;
}

/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
* 
* @param mouseX Mouse x coordinate
* @param mouseY Mouse y coordinate
*/
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileFurnace.getDisplayName().getUnformattedText();
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
}

/**
* Draws the background layer of this container (behind the items).
* 
* @param partialTicks How far into the current tick the game is, with 0.0 being the start of the tick and 1.0 being
* the end.
* @param mouseX Mouse x coordinate
* @param mouseY Mouse y coordinate
*/
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);

if (TileEntityBottling.isBurning(this.tileFurnace))
{
int k = this.getBurnLeftScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}

int l = this.getCookProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}

private int getCookProgressScaled(int pixels)
{
int i = this.tileFurnace.getField(2);
int j = this.tileFurnace.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}

private int getBurnLeftScaled(int pixels)
{
int i = this.tileFurnace.getField(1);

if (i == 0)
{
i = 200;
}

return this.tileFurnace.getField(0) * pixels / i;
}
}

 

SlotBottling:

public class SlotBottling extends Slot
{
private int slotIndex;

public SlotBottling(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
}

/**
* if par2 has more items than par1, onCrafting(item,countIncrease) is called
*/
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
{
if (p_75220_1_ != null && p_75220_2_ != null)
{
if (p_75220_1_.getItem() == p_75220_2_.getItem())
{
int i = p_75220_2_.stackSize - p_75220_1_.stackSize;

if (i > 0)
{
this.onCrafting(p_75220_1_, i);
}
}
}
}

/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
}

/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
}

public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
{
this.onSlotChanged();
}

/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
public boolean isItemValid(ItemStack stack)
{
return true;
}

/**
* Helper fnct to get the stack in the slot.
*/
public ItemStack getStack()
{
return this.inventory.getStackInSlot(this.slotIndex);
}

/**
* Returns if this slot contains a stack.
*/
public boolean getHasStack()
{
return this.getStack() != null;
}

/**
* Helper method to put a stack in the slot.
*/
public void putStack(ItemStack stack)
{
this.inventory.setInventorySlotContents(this.slotIndex, stack);
this.onSlotChanged();
}

/**
* Called when the stack in a Slot changes
*/
public void onSlotChanged()
{
this.inventory.markDirty();
}

/**
* Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1 in the case
* of armor slots)
*/
public int getSlotStackLimit()
{
return this.inventory.getInventoryStackLimit();
}

public int getItemStackLimit(ItemStack stack)
{
return this.getSlotStackLimit();
}

@SideOnly(Side.CLIENT)
public String getSlotTexture()
{
return backgroundName;
}

/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
return this.inventory.decrStackSize(this.slotIndex, amount);
}

/**
* returns true if the slot exists in the given inventory and location
*/
public boolean isHere(IInventory inv, int slotIn)
{
return inv == this.inventory && slotIn == this.slotIndex;
}

/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean canTakeStack(EntityPlayer playerIn)
{
return true;
}

/**
* Actualy only call when we want to render the white square effect over the slots. Return always True, except for
* the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses)
*/
@SideOnly(Side.CLIENT)
public boolean canBeHovered()
{
return true;
}

/*========================================= FORGE START =====================================*/
protected String backgroundName = null;
protected net.minecraft.util.ResourceLocation backgroundLocation = null;
protected Object backgroundMap;
/**
* Gets the path of the texture file to use for the background image of this slot when drawing the GUI.
* @return The resource location for the background image
*/
@SideOnly(Side.CLIENT)
public net.minecraft.util.ResourceLocation getBackgroundLocation()
{
return (backgroundLocation == null ? net.minecraft.client.renderer.texture.TextureMap.locationBlocksTexture : backgroundLocation);
}

/**
* Sets the texture file to use for the background image of the slot when it's empty.
* @param texture the resourcelocation for the texture
*/
@SideOnly(Side.CLIENT)
public void setBackgroundLocation(net.minecraft.util.ResourceLocation texture)
{
this.backgroundLocation = texture;
}

/**
* Sets which icon index to use as the background image of the slot when it's empty.
* @param name The icon to use, null for none
*/
public void setBackgroundName(String name)
{
this.backgroundName = name;
}

@SideOnly(Side.CLIENT)
public net.minecraft.client.renderer.texture.TextureAtlasSprite getBackgroundSprite()
{
String name = getSlotTexture();
return name == null ? null : getBackgroundMap().getAtlasSprite(name);
}

@SideOnly(Side.CLIENT)
protected net.minecraft.client.renderer.texture.TextureMap getBackgroundMap()
{
if (backgroundMap == null) backgroundMap = net.minecraft.client.Minecraft.getMinecraft().getTextureMapBlocks();
return (net.minecraft.client.renderer.texture.TextureMap)backgroundMap;
}

/**
* Retrieves the index in the inventory for this slot, this value should typically not
* be used, but can be useful for some occasions.
*
* @return Index in associated inventory for this slot.
*/
public int getSlotIndex()
{
/** The index of the slot in the inventory. */
return slotIndex;
}
}

 

SlotBottlingOutput:

public class SlotBottlingOutput extends Slot
{
private EntityPlayer thePlayer;
private int field_75228_b;

public SlotBottlingOutput(EntityPlayer player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
{
super(inventoryIn, slotIndex, xPosition, yPosition);
this.thePlayer = player;
}

public boolean isItemValid(ItemStack stack)
{
return false;
}

public ItemStack decrStackSize(int amount)
{
if (this.getHasStack())
{
this.field_75228_b += Math.min(amount, this.getStack().stackSize);
}

return super.decrStackSize(amount);
}

public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
{
this.onCrafting(stack);
super.onPickupFromSlot(playerIn, stack);
}

protected void onCrafting(ItemStack stack, int amount)
{
this.field_75228_b += amount;
this.onCrafting(stack);
}

protected void onCrafting(ItemStack stack)
{
stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b);

if (!this.thePlayer.worldObj.isRemote)
{
int i = this.field_75228_b;
float f = BottlingRecipes.instance().getSmeltingExperience(stack);

if (f == 0.0F)
{
i = 0;
}
else if (f < 1.0F)
{
int j = MathHelper.floor_float((float)i * f);

if (j < MathHelper.ceiling_float_int((float)i * f) && Math.random() < (double)((float)i * f - (float)j))
{
++j;
}

i = j;
}

while (i > 0)
{
int k = EntityXPOrb.getXPSplit(i);
i -= k;
this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, k));
}
}

this.field_75228_b = 0;

net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(thePlayer, stack);

if (stack.getItem() == Items.iron_ingot)
{
this.thePlayer.addStat(AchievementList.acquireIron);
}

if (stack.getItem() == Items.cooked_fish)
{
this.thePlayer.addStat(AchievementList.cookFish);
}
}
}

 

TileEntityBottling:

public class TileEntityBottling extends TileEntityLockable implements ITickable, ISidedInventory
{
    private static final int[] slotsTop = new int[] {0};
    private static final int[] slotsBottom = new int[] {2, 1};
    private static final int[] slotsSides = new int[] {1};
    /** The ItemStacks that hold the items currently being used in the furnace */
    private ItemStack[] furnaceItemStacks = new ItemStack[3];
    /** The number of ticks that the furnace will keep burning */
    private int furnaceBurnTime;
    /** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */
    private int currentItemBurnTime;
    private int cookTime;
    private int totalCookTime;
    private String furnaceCustomName;

    /**
     * Returns the number of slots in the inventory.
     */
    public int getSizeInventory()
    {
        return this.furnaceItemStacks.length;
    }

    /**
     * Returns the stack in the given slot.
     */
    public ItemStack getStackInSlot(int index)
    {
        return this.furnaceItemStacks[index];
    }

    /**
     * Removes up to a specified number of items from an inventory slot and returns them in a new stack.
     */
    public ItemStack decrStackSize(int index, int count)
    {
        return ItemStackHelper.func_188382_a(this.furnaceItemStacks, index, count);
    }

    /**
     * Removes a stack from the given slot and returns it.
     */
    public ItemStack removeStackFromSlot(int index)
    {
        return ItemStackHelper.func_188383_a(this.furnaceItemStacks, index);
    }

    /**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     */
    public void setInventorySlotContents(int index, ItemStack stack)
    {
        boolean flag = stack != null && stack.isItemEqual(this.furnaceItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.furnaceItemStacks[index]);
        this.furnaceItemStacks[index] = stack;

        if (stack != null && stack.stackSize > this.getInventoryStackLimit())
        {
            stack.stackSize = this.getInventoryStackLimit();
        }

        if (index == 0 && !flag)
        {
            this.totalCookTime = 100;
            this.cookTime = 0;
            this.markDirty();
        }
    }

    /**
     * Get the name of this object. For players this returns their username
     */
    public String getName()
    {
        return this.hasCustomName() ? this.furnaceCustomName : "Bottling";
    }

    /**
     * Returns true if this thing is named
     */
    public boolean hasCustomName()
    {
        return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty();
    }

    public void setCustomInventoryName(String p_145951_1_)
    {
        this.furnaceCustomName = p_145951_1_;
    }

    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);
        NBTTagList nbttaglist = compound.getTagList("Items", 10);
        this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound.getByte("Slot");

            if (j >= 0 && j < this.furnaceItemStacks.length)
            {
                this.furnaceItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
            }
        }

        this.furnaceBurnTime = compound.getInteger("BurnTime");
        this.cookTime = compound.getInteger("CookTime");
        this.totalCookTime = compound.getInteger("CookTimeTotal");
        this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);

        if (compound.hasKey("CustomName", )
        {
            this.furnaceCustomName = compound.getString("CustomName");
        }
    }

    public void writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);
        compound.setInteger("BurnTime", this.furnaceBurnTime);
        compound.setInteger("CookTime", this.cookTime);
        compound.setInteger("CookTimeTotal", this.totalCookTime);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.furnaceItemStacks.length; ++i)
        {
            if (this.furnaceItemStacks<em> != null)
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.setByte("Slot", (byte)i);
                this.furnaceItemStacks<em>.writeToNBT(nbttagcompound);
                nbttaglist.appendTag(nbttagcompound);
            }
        }

        compound.setTag("Items", nbttaglist);

        if (this.hasCustomName())
        {
            compound.setString("CustomName", this.furnaceCustomName);
        }
    }

    /**
     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
     */
    public int getInventoryStackLimit()
    {
        return 64;
    }

    /**
     * Furnace isBurning
     */
    public boolean isBurning()
    {
        return this.furnaceBurnTime > 0;
    }

    @SideOnly(Side.CLIENT)
    public static boolean isBurning(IInventory p_174903_0_)
    {
        return p_174903_0_.getField(0) > 0;
    }

    /**
     * Like the old updateEntity(), except more generic.
     */
    public void update()
    {
        boolean flag = this.isBurning();
        boolean flag1 = false;

        if (this.isBurning())
        {
            --this.furnaceBurnTime;
        }

        if (!this.worldObj.isRemote)
        {
            if (this.isBurning() || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
            {
                if (!this.isBurning() && this.canSmelt())
                {
                    this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);

                    if (this.isBurning())
                    {
                        flag1 = true;

                        if (this.furnaceItemStacks[1] != null)
                        {
                            --this.furnaceItemStacks[1].stackSize;

                            if (this.furnaceItemStacks[1].stackSize == 0)
                            {
                                this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(furnaceItemStacks[1]);
                            }
                        }
                    }
                }

                if (this.isBurning() && this.canSmelt())
                {
                    ++this.cookTime;

                    if (this.cookTime == this.totalCookTime)
                    {
                        this.cookTime = 0;
                        this.totalCookTime = this.getCookTime(this.furnaceItemStacks[0]);
                        this.smeltItem();
                        flag1 = true;
                    }
                }
                else
                {
                    this.cookTime = 0;
                }
            }
            else if (!this.isBurning() && this.cookTime > 0)
            {
                this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);
            }

            if (flag != this.isBurning())
            {
                flag1 = true;
                Block_Bottling.setState(this.isBurning(), this.worldObj, this.pos);
            }
        }

        if (flag1)
        {
            this.markDirty();
        }
    }

    public int getCookTime(ItemStack stack)
    {
        return 100;
    }

    /**
     * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
     */
    private boolean canSmelt()
    {
        if (this.furnaceItemStacks[0] == null)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = BottlingRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);
            if (itemstack == null) return false;
            if (this.furnaceItemStacks[2] == null) return true;
            if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
            int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
            return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
        }
    }

    /**
     * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
     */
    public void smeltItem()
    {
        if (this.canSmelt())
        {
            ItemStack itemstack = BottlingRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);

            if (this.furnaceItemStacks[2] == null)
            {
                this.furnaceItemStacks[2] = itemstack.copy();
            }
            else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
            {
                this.furnaceItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
            }

            if (this.furnaceItemStacks[0].getItem() == Item.getItemFromBlock(Blocks.sponge) && this.furnaceItemStacks[0].getMetadata() == 1 && this.furnaceItemStacks[1] != null && this.furnaceItemStacks[1].getItem() == Items.bucket)
            {
                this.furnaceItemStacks[1] = new ItemStack(Items.water_bucket);
            }

            --this.furnaceItemStacks[0].stackSize;

            if (this.furnaceItemStacks[0].stackSize <= 0)
            {
                this.furnaceItemStacks[0] = null;
            }
        }
    }

    /**
     * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
     * fuel
     */
    public static int getItemBurnTime(ItemStack p_145952_0_)
    {
        if (p_145952_0_ == null)
        {
            return 0;
        }
        else
        {
            Item item = p_145952_0_.getItem();
        	
            if (item == ItemHandler.FermentedWine) return 100;
            if (item == ItemHandler.BeerBucket) return 100;

            return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(p_145952_0_);
        }
    }

    public static boolean isItemFuel(ItemStack p_145954_0_)
    {
        return getItemBurnTime(p_145954_0_) > 0;
    }

    /**
     * Do not make give this method the name canInteractWith because it clashes with Container
     */
    public boolean isUseableByPlayer(EntityPlayer player)
    {
        return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }

    public void openInventory(EntityPlayer player)
    {
    }

    public void closeInventory(EntityPlayer player)
    {
    }

    /**
     * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
     */
    public boolean isItemValidForSlot(int index, ItemStack stack)
    {
        if (index == 2)
        {
            return false;
        }
        else if (index != 1)
        {
            return true;
        }
        else
        {
            ItemStack itemstack = this.furnaceItemStacks[1];
            return isItemFuel(stack) || SlotBottlingFuel.isBucket(stack) && (itemstack == null || itemstack.getItem() != Items.bucket);
        }
    }

    public int[] getSlotsForFace(EnumFacing side)
    {
        return side == EnumFacing.DOWN ? slotsBottom : (side == EnumFacing.UP ? slotsTop : slotsSides);
    }

    /**
     * Returns true if automation can insert the given item in the given slot from the given side.
     *  
     * @param index The slot index to test insertion into
     * @param itemStackIn The item to test insertion of
     * @param direction The direction to test insertion from
     */
    public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
    {
        return this.isItemValidForSlot(index, itemStackIn);
    }

    /**
     * Returns true if automation can extract the given item in the given slot from the given side.
     *  
     * @param index The slot index to test extraction from
     * @param stack The item to try to extract
     * @param direction The direction to extract from
     */
    public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
    {
        if (direction == EnumFacing.DOWN && index == 1)
        {
            Item item = stack.getItem();

            if (item != Items.water_bucket && item != Items.bucket)
            {
                return false;
            }
        }

        return true;
    }

    public String getGuiID()
    {
        return "0";
    }

    public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
    {
        return new ContainerBottling(playerInventory, this);
    }

    public int getField(int id)
    {
        switch (id)
        {
            case 0:
                return this.furnaceBurnTime;
            case 1:
                return this.currentItemBurnTime;
            case 2:
                return this.cookTime;
            case 3:
                return this.totalCookTime;
            default:
                return 0;
        }
    }

    public void setField(int id, int value)
    {
        switch (id)
        {
            case 0:
                this.furnaceBurnTime = value;
                break;
            case 1:
                this.currentItemBurnTime = value;
                break;
            case 2:
                this.cookTime = value;
                break;
            case 3:
                this.totalCookTime = value;
        }
    }

    public int getFieldCount()
    {
        return 4;
    }

    public void clear()
    {
        for (int i = 0; i < this.furnaceItemStacks.length; ++i)
        {
            this.furnaceItemStacks<em> = null;
        }
    }

    net.minecraftforge.items.IItemHandler handlerTop = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP);
    net.minecraftforge.items.IItemHandler handlerBottom = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN);
    net.minecraftforge.items.IItemHandler handlerSide = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.WEST);

    @SuppressWarnings("unchecked")
    @Override
    public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
    {
        if (facing != null && capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            if (facing == EnumFacing.DOWN)
                return (T) handlerBottom;
            else if (facing == EnumFacing.UP)
                return (T) handlerTop;
            else
                return (T) handlerSide;
        return super.getCapability(capability, facing);
    }
}

 

 

 

Link to comment
Share on other sites

if(A == Foo && B == Bar) {

}

 

Modder Support

 

This is the support section for those modding with Forge. Help with modding goes in here, however, please keep in mind that this is not a Java school. You are expected to have basic knowledge of Java before posting here.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.