Jump to content

[1.12.2] Custom Furnace Issue (no error)


ShadowVappy

Recommended Posts

I'm trying to make a forge (basically a custom furnace) which has selectable results (the input item is the same, with the count being different per result). Everything seems to work, but when forging starts, the effects of it are immediately reverted (or I suppose never existed in the first place) ie. the input count is not changed, and when the forging finishes, it outputs a fake item which disappears when you interact with it, with no error in the log.

 

Block Class

public class BlockAdamantineForge extends Block {
    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    public static final PropertyBool BURNING = PropertyBool.create("burning");
    private static final int HARVEST_LEVEL = ModConfig.addMineLevels ? 4 : 2;

    public BlockAdamantineForge(String name) {
        super(Material.IRON);
        setRegistryName(name);
        setUnlocalizedName(Objects.requireNonNull(getRegistryName()).toString());
        setCreativeTab(Main.TAB_GENERAL);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));

        setSoundType(SoundType.METAL);
        setHardness(6.0F);
        setResistance(6.0F);
        setHarvestLevel("pickaxe", HARVEST_LEVEL);

        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }

    @Override
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
        if(!worldIn.isRemote) {
            IBlockState north = worldIn.getBlockState(pos.north());
            IBlockState south = worldIn.getBlockState(pos.south());
            IBlockState east = worldIn.getBlockState(pos.east());
            IBlockState west = worldIn.getBlockState(pos.west());
            EnumFacing face = state.getValue(FACING);

            if(face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock())
                face = EnumFacing.SOUTH;
            else if(face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock())
                face = EnumFacing.NORTH;
            else if(face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock())
                face = EnumFacing.WEST;
            else if(face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock())
                face = EnumFacing.EAST;
            worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
        }
    }

    @Override
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
        IItemHandler capability = Objects.requireNonNull(worldIn.getTileEntity(pos)).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        for(int i = 0; i< Objects.requireNonNull(capability).getSlots(); i++) {
            ItemStack stack = capability.getStackInSlot(i);
            if(!stack.isEmpty())
                InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
        }
        super.breakBlock(worldIn, pos, state);
    }

    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        if(!worldIn.isRemote)
            playerIn.openGui(Main.instance, Reference.GUI_ADAMANTINE_FORGE, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }

    @Override
    public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, BURNING, FACING);
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        EnumFacing facing = EnumFacing.getFront(meta);
        if(facing.getAxis() == EnumFacing.Axis.Y)
            facing = EnumFacing.NORTH;
        return this.getDefaultState().withProperty(FACING, facing);
    }

    @Override
    public int getMetaFromState(IBlockState state) {
        return (state.getValue(FACING)).getIndex();
    }

    @Override
    public boolean hasTileEntity(IBlockState state) {
        return true;
    }

    @Override
    public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityAdamantineForge(); }
}

 

Tile Entity Class

public class TileEntityAdamantineForge extends TileEntity implements ITickable {
    private final ItemStackHandler handler = new ItemStackHandler(3);

    public ItemStack result = ItemStack.EMPTY;
    public int burnTime, currentBurnTime, cookTime, totalCookTime = 200;
    private boolean isCurrentlyActive = false;

    private final String TAG_BURN_TIME = "BurnTime", TAG_CURRENT_BURN_TIME = "CurrentBurnTime", TAG_COOK_TIME = "CookTime", TAG_TOTAL_COOK_TIME = "TotalCookTime";
    private final String INVENTORY_KEY = "Inventory";
    private final String TAG_RESULT = "CurrentResult";
    private final String TAG_ACTIVE = "IsActive";

    @Override
    public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
        if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            return true;
        return super.hasCapability(capability, facing);
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
        if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            return (T)this.handler;
        return super.getCapability(capability, facing);
    }

    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        this.handler.deserializeNBT(compound.getCompoundTag(INVENTORY_KEY));
        this.burnTime = compound.getInteger(TAG_BURN_TIME);
        this.cookTime = compound.getInteger(TAG_COOK_TIME);
        this.totalCookTime = compound.getInteger(TAG_TOTAL_COOK_TIME);
        this.currentBurnTime = compound.getInteger(TAG_CURRENT_BURN_TIME);
        this.isCurrentlyActive = compound.getBoolean(TAG_ACTIVE);
        NBTTagCompound compoundStack = compound.getCompoundTag(TAG_RESULT);
        this.result = new ItemStack(compoundStack);
    }
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);
        compound.setInteger(TAG_BURN_TIME, this.burnTime);
        compound.setInteger(TAG_COOK_TIME, this.cookTime);
        compound.setInteger(TAG_TOTAL_COOK_TIME, this.totalCookTime);
        compound.setInteger(TAG_CURRENT_BURN_TIME, this.currentBurnTime);
        compound.setTag(INVENTORY_KEY, this.handler.serializeNBT());
        compound.setBoolean(TAG_ACTIVE, this.isCurrentlyActive);
        NBTTagCompound compoundStack = this.result.writeToNBT(new NBTTagCompound());
        compound.setTag(TAG_RESULT, compoundStack);

        return compound;
    }

    @Override
    public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
        return oldState.getBlock() != newState.getBlock();
    }

    @Override
    public ITextComponent getDisplayName() {
        return new TextComponentTranslation("container.adamantine_forge");
    }

    /**
     * Checks if the player can use the tile entity
     * @param player The player to check.
     * @return True if the player is within range to use the tile entity, else false.
     */
    public boolean isUsableByPlayer(EntityPlayer player) {
        return this.world.getTileEntity(this.pos) == this && player.getDistanceSq((double) this.pos.getX() + 0.5D, (double) this.pos.getY() + 0.5D, (double) this.pos.getZ() + 0.5D) <= 64.0D;
    }

    public void setState(boolean active, World world, BlockPos pos) {
        IBlockState state = world.getBlockState(pos);
        TileEntity tileEntity = world.getTileEntity(pos);

        if(active != state.getValue(BlockAdamantineForge.BURNING)) {
            if(active)
                world.setBlockState(pos, state.withProperty(BlockAdamantineForge.BURNING, true));
            else
                world.setBlockState(pos, state.withProperty(BlockAdamantineForge.BURNING, false));
        }

        if(tileEntity != null)
            tileEntity.validate();
    }

    public void update() {
        ItemStack input = this.handler.getStackInSlot(0); //Gets an item stack containing the stack in the input slot
        ItemStack fuel = this.handler.getStackInSlot(1); //Gets an item stack containing the stack in the fuel slot

        if(!this.isBurning())
            setState(false, this.getWorld(), this.getPos()); //Sets the state of the adamantine forge to not burning when it isn't burning
        if(this.isCurrentlyActive && !(this.getCookTime()>0)){
            int inputCount = AdamantineForgeRecipes.getInstance().getInputCount(this.result); //Get the item count of the recipe
            if(input.getCount() >= inputCount && input.getItem() == AdamantineForgeRecipes.getInstance().getForgingInput(this.result).getItem()) {
                this.cookTime++; //Increment cook time
                this.setTotalCookTime(this.getCookTime(this.result)); //Set the total cook time to the cook time of the recipe
                this.handler.getStackInSlot(0).shrink(inputCount); //Shrink the input stack by the recipe input count
            }
        }
        if(this.getCookTime()>0 && (this.isBurning() || !fuel.isEmpty())) {
            this.burnTime--; //Reduces the burn time by one if the forge is burning or fuel is empty, and is forging (reduces the time left fueled by one tick)
            this.cookTime++; //Increment cook time if the forge is forging
            if(!this.isBurning()) { //If the forge is active and is not burning
                this.setBurnTime(TileEntityFurnace.getItemBurnTime(fuel)); //Set the burn time to the burn time of the fuel
                this.setCurrentBurnTime(this.getBurnTime()); //Set the current burn time to the burn time
                setState(true, this.getWorld(), this.getPos()); //Sets the state of the adamantine forge to burning when it first starts burning

                if(this.isBurning() && !fuel.isEmpty()) { //If the adamantine forge is active and fuel isn't empty
                    if(fuel.getItem() != Items.LAVA_BUCKET) //If fuel isn't a lava bucket
                        fuel.shrink(1); //Reduce the fuel stack by one
                    else
                        this.handler.setStackInSlot(1, new ItemStack(Items.BUCKET)); //Sets the stack in the fuel slot to an empty bucket

                    if(fuel.isEmpty()) //If the fuel stack is empty
                        this.handler.setStackInSlot(1, ItemStack.EMPTY); //Sets the stack in the fuel slot to the empty item stack
                }
            }
            if(this.getCookTime() == this.getTotalCookTime()) { //If cook time is total cook time
                if(this.handler.getStackInSlot(2).getCount() == 0) //If the output slot is empty
                    this.handler.insertItem(2, this.result, false); //Insert the recipe result into the output slot
                this.setTotalCookTime(0); //Set the total cook time to 0
                this.setCookTime(0); //Set the cook time to 0
                this.setCurrentlyActive(false); //Set inactive
            }
        }
    }

    /**
     * Sets currently active if forge button is clicked, and sets result based on result button selected.
     * @param guiLeft The left side of the gui.
     * @param guiTop The top of the gui.
     * @param mouseX The x position of the mouse.
     * @param mouseY The y position of the mouse.
     */
    public void onClick(int guiLeft, int guiTop, int mouseX, int mouseY) {
        //If mouse clicked the forge button
        if(mouseX>(guiLeft+61) && mouseX<(guiLeft+84)){
            if(mouseY>(guiTop+50) && mouseY<(guiTop+61)) {
                if(!this.isCurrentlyActive() && this.canSmelt())
                    this.setCurrentlyActive(true); //Set the forge to be active
            }
        }else if(mouseX>(guiLeft+93) && mouseX<(guiLeft+129)) { //If mouse clicked a left column result button
            if(mouseY > (guiTop+10) && mouseY < (guiTop+22)) { //If mouse clicked sword button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_SWORD)); //Set the result to corresponding button
            }else if (mouseY > (guiTop+23) && mouseY < (guiTop+35)) { //If mouse clicked pickaxe button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_PICKAXE)); //Set the result to corresponding button
            }else if(mouseY>(guiTop+36) && mouseY<(guiTop+48)) { //If mouse clicked axe button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_AXE)); //Set the result to corresponding button
            }else if(mouseY>(guiTop+49) && mouseY<(guiTop+61)) { //If mouse clicked shovel button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_SHOVEL)); //Set the result to corresponding button
            }else if(mouseY>(guiTop+62) && mouseY<(guiTop+74)) { //If mouse clicked hoe button
                if (!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_HOE)); //Set the result to corresponding button
            }
        }else if(mouseX>(guiLeft+131) && mouseX<(guiLeft+167)) { //If mouse clicked a right column result button
            if(mouseY > (guiTop+17) && mouseY < (guiTop+29)) { //If mouse clicked helmet button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_HELMET)); //Set the result to corresponding button
            }else if (mouseY > (guiTop+30) && mouseY < (guiTop+42)) { //If mouse clicked chestplate button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_CHESTPLATE)); //Set the result to corresponding button
            }else if (mouseY > (guiTop+43) && mouseY < (guiTop+55)) { //If mouse clicked leggings button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_LEGGINGS)); //Set the result to corresponding button
            }else if (mouseY > (guiTop+56) && mouseY < (guiTop+68)) { //If mouse clicked boots button
                if(!this.isCurrentlyActive())
                    this.setResult(new ItemStack(ModItems.ADAMANTINE_BOOTS)); //Set the result to corresponding button
            }
        }
    }

    /**
     * Checks whether the tile entity is active.
     * @return True if the burn time is greater than 0, else false.
     */
    public boolean isBurning() {
        return this.burnTime > 0;
    }

    /**
     * Checks whether the tile entity is active.
     * @param te The tile entity.
     * @return True if the burnTime field of the tile entity is greater than 0, else false.
     */
    @SideOnly(Side.CLIENT)
    public static boolean isBurning(TileEntityAdamantineForge te) {
        return te.burnTime > 0;
    }

    /**
     * Gets the cook time for the recipe with the given input
     * @param result The result of the recipe.
     * @return The cook time for the recipe.
     */
    private int getCookTime(ItemStack result) {
        return AdamantineForgeRecipes.getInstance().getForgingTime(result);
    }

    /**
     * Checks whether the recipe is valid and the output slot can fit the result.
     * @return True if the recipe is valid and the output slot is not full, else false.
     */
    public boolean canSmelt() {
        if(!(this.handler.getStackInSlot(0).isEmpty()) && this.handler.getStackInSlot(2).isEmpty()) {
            if(this.handler.getStackInSlot(0).getCount() >= AdamantineForgeRecipes.getInstance().getInputCount(this.result))
                return AdamantineForgeRecipes.getInstance().getForgingInput(this.result) != ItemStack.EMPTY;
        }
        return false;
    }

    public int getBurnTime() {
        return this.burnTime;
    }
    public void setBurnTime(int burnTime) {
        this.burnTime = burnTime;
    }
    public int getCurrentBurnTime() {
        return this.currentBurnTime;
    }
    public void setCurrentBurnTime(int currentBurnTime) {
        this.currentBurnTime = currentBurnTime;
    }

    public int getCookTime() {
        return this.cookTime;
    }
    public void setCookTime(int cookTime) {
        this.cookTime = cookTime;
    }
    public int getTotalCookTime() {
        return this.totalCookTime;
    }
    public void setTotalCookTime(int totalCookTime) {
        this.totalCookTime = totalCookTime;
    }

    public ItemStack getResult() {
        return this.result;
    }
    public void setResult(ItemStack result) {
        this.result = result;
    }

    public void setCurrentlyActive(boolean isActive) {
        this.isCurrentlyActive = isActive;
    }
    public boolean isCurrentlyActive() {
        return this.isCurrentlyActive;
    }
}

 

Container Class

public class ContainerAdamantineForge extends Container {
    private final TileEntityAdamantineForge tileEntity;
    private int cookTime, totalCookTime, burnTime, currentBurnTime;

    /**
     * Creates the slots in the container.
     * @param player The player to create player inventory slots.
     * @param tileEntity The tile entity to create item handler for tile entity slots.
     */
    public ContainerAdamantineForge(InventoryPlayer player, TileEntityAdamantineForge tileEntity) {
        this.tileEntity = tileEntity;
        IItemHandler handler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

        this.addSlotToContainer(new SlotItemHandler(handler, 0, 10, 23));
        this.addSlotToContainer(new SlotForgeFuel(handler, 1, 10, 48));
        this.addSlotToContainer(new SlotOutput(handler, 2, 65, 24));

        for(int y=0; y<3; y++) {
            for(int x=0; x<9; x++) {
                this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 84 + y*18));
            }
        }
        for(int x=0; x<9; x++) {
            this.addSlotToContainer(new Slot(player, x, 8 + x*18, 142));
        }
    }

    @Override
    public void detectAndSendChanges() {
        super.detectAndSendChanges();

        for(IContainerListener iContainerListener : this.listeners) {
            if(this.cookTime != this.tileEntity.getCookTime())
                iContainerListener.sendWindowProperty(this, 2, this.tileEntity.getCookTime());
            if(this.burnTime != this.tileEntity.getBurnTime())
                iContainerListener.sendWindowProperty(this, 0, this.tileEntity.getBurnTime());
            if(this.currentBurnTime != this.tileEntity.getCurrentBurnTime())
                iContainerListener.sendWindowProperty(this, 1, this.tileEntity.getCurrentBurnTime());
            if(this.totalCookTime != this.tileEntity.getTotalCookTime())
                iContainerListener.sendWindowProperty(this, 3, this.tileEntity.getTotalCookTime());
        }

        this.cookTime = this.tileEntity.getCookTime();
        this.burnTime = this.tileEntity.getBurnTime();
        this.currentBurnTime = this.tileEntity.getCurrentBurnTime();
        this.totalCookTime = this.tileEntity.getTotalCookTime();
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int data) {
        switch(id) {
            case 0:
                this.tileEntity.setBurnTime(data);
                break;
            case 1:
                this.tileEntity.setCurrentBurnTime(data);
                break;
            case 2:
                this.tileEntity.setCookTime(data);
                break;
            case 3:
                this.tileEntity.setTotalCookTime(data);
        }
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn) {
        return this.tileEntity.isUsableByPlayer(playerIn);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
        ItemStack stack = ItemStack.EMPTY;
        Slot slot = this.inventorySlots.get(index);

        if(slot != null && slot.getHasStack()) {
            ItemStack stack1 = slot.getStack();
            stack = stack1.copy();

            if(index == 2) {
                if(!this.mergeItemStack(stack1, 4, 39, true)) return ItemStack.EMPTY;
                slot.onSlotChange(stack1, stack);
            }else if(index != 1 && index != 0) {
                if(stack1.getItem() == ModItems.ADAMANTINE_WAFER) {
                    if(!this.mergeItemStack(stack1, 0, 1, false))
                        return ItemStack.EMPTY;
                }
                if(TileEntityFurnace.isItemFuel(stack1)) {
                    if(!this.mergeItemStack(stack1, 1, 2, false))
                        return ItemStack.EMPTY;
                }else if(index >= 4 && index < 31) {
                    if(!this.mergeItemStack(stack1, 31, 39, false))
                        return ItemStack.EMPTY;
                }else if(index >= 31 && index < 39 && !this.mergeItemStack(stack1, 4, 31, false)) {
                    return ItemStack.EMPTY;
                }
            }else if(!this.mergeItemStack(stack1, 4, 39, false))
                return ItemStack.EMPTY;
            if(stack1.isEmpty())
                slot.putStack(ItemStack.EMPTY);
            else
                slot.onSlotChanged();
            if(stack1.getCount() == stack.getCount())
                return ItemStack.EMPTY;
            slot.onTake(playerIn, stack1);
        }
        return stack;
    }
}

 

Gui Class

public class GuiAdamantineForge extends GuiContainer {
    private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MODID + ":textures/gui/gui_adamantine_forge.png");
    private final InventoryPlayer player;
    private final TileEntityAdamantineForge tileEntity;

    public GuiAdamantineForge(InventoryPlayer player, TileEntityAdamantineForge tileEntity) {
        super(new ContainerAdamantineForge(player, tileEntity));
        this.player = player;
        this.tileEntity = tileEntity;
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        this.drawDefaultBackground();
        super.drawScreen(mouseX, mouseY, partialTicks);
        this.renderHoveredToolTip(mouseX, mouseY);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        super.drawGuiContainerForegroundLayer(mouseX, mouseY);
        String tileName = Objects.requireNonNull(this.tileEntity.getDisplayName()).getUnformattedText();
        int inputCount = AdamantineForgeRecipes.getInstance().getInputCount(this.tileEntity.result);
        this.fontRenderer.drawString(tileName, 4, 6, 4210752);
        this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
        this.fontRenderer.drawString("x" + inputCount, inputCount<10 ? 67: 65, 62, 16777215);
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(TEXTURES);
        this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);

        if(TileEntityAdamantineForge.isBurning(tileEntity)) {
            int k = this.getBurnLeftScaled();
            this.drawTexturedModalRect(this.guiLeft+36, this.guiTop+49+12-k, 176, 12-k, 14, k+1);
        }

        int l = this.getCookProgressScaled();
        this.drawTexturedModalRect(this.guiLeft+31, this.guiTop+23, 176, 14, l+1, 16);

        mouseHover(mouseX, mouseY);
        drawCurrentSelected();
    }

    /**
     * Gets the number of pixels of the fire animation to show.
     * @return The number of pixels height to render.
     */
    private int getBurnLeftScaled() {
        int i = this.tileEntity.getCurrentBurnTime();
        if(i == 0) i = 200;
        return this.tileEntity.getBurnTime()*13/i;
    }

    /**
     * Gets the number of pixels of the arrow animation to show.
     * @return The number of pixels width to render.
     */
    private int getCookProgressScaled() {
        int i = this.tileEntity.getCookTime();
        int j = this.tileEntity.getTotalCookTime();
        return j != 0 && i != 0 ? i*24/j : 0;
    }

    @Override
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
        super.mouseClicked(mouseX, mouseY, mouseButton);

        if(Minecraft.getMinecraft().currentScreen instanceof GuiAdamantineForge) {
            if(mouseButton == 0)
                this.tileEntity.onClick(this.guiLeft, this.guiTop, mouseX, mouseY);
        }
    }

    private void mouseHover(int mouseX, int mouseY) {
        if(mouseX>(this.guiLeft+61) && mouseX<(this.guiLeft+84)){
            if(mouseY>(this.guiTop+50) && mouseY<(this.guiTop+61))
                this.drawTexturedModalRect(this.guiLeft+62, this.guiTop+50, 198, 131, 22, 10);
        }else if(mouseX>(this.guiLeft+93) && mouseX<(this.guiLeft+129)){
            if(mouseY>(this.guiTop+10) && mouseY<(this.guiTop+22))
                this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+10, 211, 31, 35, 11);
            else if(mouseY>(this.guiTop+23) && mouseY<(this.guiTop+35))
                this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+23, 211, 42, 35, 11);
            else if(mouseY>(this.guiTop+36) && mouseY<(this.guiTop+48))
                this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+36, 211, 53, 35, 11);
            else if(mouseY>(this.guiTop+49) && mouseY<(this.guiTop+61))
                this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+49, 211, 64, 35, 11);
            else if(mouseY>(this.guiTop+62) && mouseY<(this.guiTop+74))
                this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+62, 211, 75, 35, 11);
        }else if(mouseX>(this.guiLeft+131) && mouseX<(this.guiLeft+167)){
            if(mouseY>(this.guiTop+17) && mouseY<(this.guiTop+29))
                this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+17, 211, 86, 35, 11);
            else if(mouseY>(this.guiTop+30) && mouseY<(this.guiTop+42))
                this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+30, 211, 97, 35, 11);
            else if(mouseY>(this.guiTop+43) && mouseY<(this.guiTop+55))
                this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+43, 211, 108, 35, 11);
            else if(mouseY>(this.guiTop+56) && mouseY<(this.guiTop+68))
                this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+56, 211, 119, 35, 11);
        }
    }

    private void drawCurrentSelected() {
        if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_SWORD)
            this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+10, 176, 31, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_PICKAXE)
            this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+23, 176, 42, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_AXE)
            this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+36, 176, 53, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_SHOVEL)
            this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+49, 176, 64, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_HOE)
            this.drawTexturedModalRect(this.guiLeft+94, this.guiTop+62, 176, 75, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_HELMET)
            this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+17, 176, 86, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_CHESTPLATE)
            this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+30, 176, 97, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_LEGGINGS)
            this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+43, 176, 108, 35, 11);
        else if(this.tileEntity.getResult().getItem() == ModItems.ADAMANTINE_BOOTS)
            this.drawTexturedModalRect(this.guiLeft+132, this.guiTop+56, 176, 119, 35, 11);

        if(this.tileEntity.isCurrentlyActive())
            this.drawTexturedModalRect(this.guiLeft+62, this.guiTop+50, 176, 131, 22, 10);
    }
}

 

Recipes Class

public class AdamantineForgeRecipes {
    private static final AdamantineForgeRecipes INSTANCE = new AdamantineForgeRecipes();
    private final Map<ItemStack, ItemStack> smeltingList = Maps.newHashMap();
    private final Map<ItemStack, Integer> smeltingTime = Maps.newHashMap();
    private final Map<ItemStack, Float> experienceList = Maps.newHashMap();

    public static AdamantineForgeRecipes getInstance() {
        return INSTANCE;
    }

    private AdamantineForgeRecipes() {
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_SWORD), new ItemStack(ModItems.ADAMANTINE_WAFER, 7), 8.0F, 1500);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_PICKAXE), new ItemStack(ModItems.ADAMANTINE_WAFER, 11), 8.0F, 2100);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_AXE), new ItemStack(ModItems.ADAMANTINE_WAFER, 11), 8.0F, 1800);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_SHOVEL), new ItemStack(ModItems.ADAMANTINE_WAFER, 5), 8.0F, 1200);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_HOE), new ItemStack(ModItems.ADAMANTINE_WAFER, 8), 8.0F, 1900);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_HELMET), new ItemStack(ModItems.ADAMANTINE_WAFER, 15), 8.0F, 2400);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_CHESTPLATE), new ItemStack(ModItems.ADAMANTINE_WAFER, 24), 8.0F, 3300);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_LEGGINGS), new ItemStack(ModItems.ADAMANTINE_WAFER, 21), 8.0F, 3000);
        addForgingRecipe(new ItemStack(ModItems.ADAMANTINE_BOOTS), new ItemStack(ModItems.ADAMANTINE_WAFER, 12), 8.0F, 3600);
    }

    /**
     * Adds a forging recipe if the recipe does not already exist
     * @param input The input of the recipe.
     * @param result The result of the recipe.
     * @param experience The chance for the recipe to drop an experience.
     * @param time The time taken for the recipe to complete.
     */
    public void addForgingRecipe(ItemStack result, ItemStack input, float experience, int time) {
        if(getForgingInput(result) != ItemStack.EMPTY) return;
        this.smeltingList.put(result, input);
        this.smeltingTime.put(result, time);
        this.experienceList.put(result, experience);
    }

    /**
     * Gets the input of the forging recipe with the given result.
     * @param result The result of the recipe.
     * @return The input of the recipe.
     */
    public ItemStack getForgingInput(ItemStack result) {
        for(Map.Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet()) {
            if(this.compareItemStacks(result, entry.getKey())) {
                return entry.getValue();
            }
        }
        return ItemStack.EMPTY;
    }

    /**
     * Gets the input count of the forging recipe with the given input.
     * @param result The result of the recipe.
     * @return The number of items the recipe requires.
     */
    public int getInputCount(ItemStack result) {
        for(Map.Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet()) {
            if(this.compareItemStacks(result, entry.getKey())) {
                return entry.getValue().getCount();
            }
        }
        return 0;
    }

    /**
     * Gets the time taken for the forging recipe with the given input to complete.
     * @param result The result of the recipe.
     * @return The time taken for the recipe to complete, if it exists.
     */
    public int getForgingTime(ItemStack result) {
        for(Map.Entry<ItemStack, Integer> entry : this.smeltingTime.entrySet()) {
            if(this.compareItemStacks(result, entry.getKey())) {
                return entry.getValue();
            }
        }
        return 0;
    }

    /**
     * Gets the experience given by the recipe with the given result.
     * @param result The result of the recipe.
     * @return The experience given by the recipe, if it exists.
     */
    public float getForgingExperience(ItemStack result) {
        for(Map.Entry<ItemStack, Float> entry : this.experienceList.entrySet()) {
            if(this.compareItemStacks(result, entry.getKey()))
                return entry.getValue();
        }
        return 0.0F;
    }

    /**
     * Compares two item stacks to check if they are the same.
     * @param stack1 The item stack to compare.
     * @param stack2 The item stack to compare to.
     * @return True if the item stacks are identical, else false.
     */
    private boolean compareItemStacks(ItemStack stack1, ItemStack stack2) {
        return stack2.getItem() == stack1.getItem() && stack2.getMetadata() == stack1.getMetadata();
    }
}

 

As a side-note, how do you get a recipe to drop experience? I have the method to get experience in the recipes class, but I don't know what to do with it.

Edited by ShadowVappy
Spoiler tags not working
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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