Jump to content

Changing block texture based on Tile entity variable


brady131313

Recommended Posts

I want to change my machines face to an active texture when It is active but how would I access that variable in the tile entity, This is what I've tried

Block

package com.brady131313.steamreborn.block.machines;

import com.brady131313.steamreborn.block.BlockSR;
import com.brady131313.steamreborn.init.ModBlocks;
import com.brady131313.steamreborn.init.ModItems;
import com.brady131313.steamreborn.reference.GuiId;
import com.brady131313.steamreborn.steamreborn;
import com.brady131313.steamreborn.tileentity.TileEntityAlloyCompressor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.Random;

public class MachineAlloyCompressor extends BlockSR implements ITileEntityProvider {

    @SideOnly(Side.CLIENT)
    private static IIcon frontIcon;
    @SideOnly(Side.CLIENT)
    private static IIcon sideIcon;
    @SideOnly(Side.CLIENT)
    private static IIcon topbotIcon;

    TileEntityAlloyCompressor alloyCompressor;

    public MachineAlloyCompressor() {

        super(Material.iron);
        this.setBlockName("machineAlloyCompressor");
        this.setHardness(3.0f);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister) {

        this.frontIcon = iconRegister.registerIcon(TileEntityAlloyCompressor.isActive ? "steamreborn:AlloyCompressorActive" : "steamreborn:alloyCompressorFront1");
        this.sideIcon = iconRegister.registerIcon("steamreborn:steamMachineSide");
        this.topbotIcon = iconRegister.registerIcon("steamreborn:steamMachineTop");
    }

    @Override
    public IIcon getIcon(int side, int meta) {

        if (side == 3 && meta == 0) {
            return frontIcon;
        } else {
            if (side == 0 || side == 1) {
                return topbotIcon;
            } else if (side != meta) {
                return sideIcon;
            } else {
                return frontIcon;
            }
        }
    }

    @Override
    public void onBlockAdded(World world, int x, int y, int z) {

        super.onBlockAdded(world, x, y, z);
        setDefaultDirection(world, x, y, z);
    }

    @Override
    public TileEntity createNewTileEntity(World world, int metaData) {

        return new TileEntityAlloyCompressor();
    }

    @Override
    public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {

        TileEntityAlloyCompressor tileEntityAlloyCompressor = (TileEntityAlloyCompressor) world.getTileEntity(x, y, z);
        super.onNeighborBlockChange(world, x, y, z, block);
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int facehit, float par7, float par8, float par9) {

        TileEntityAlloyCompressor tileEntity = (TileEntityAlloyCompressor) world.getTileEntity(x, y, z);
        ItemStack playerItem = player.getCurrentEquippedItem();

        if (tileEntity == null || player.isSneaking()) {
            return false;
        } else {
            if (!world.isRemote) {
                if (world.getTileEntity(x, y, z) instanceof TileEntityAlloyCompressor) {
                    player.openGui(steamreborn.instance, GuiId.ALLOY_COMPRESSOR.ordinal(), world, x, y, z);
                }
            }
        }
        return true;
    }

    @Override
    public boolean onBlockEventReceived(World world, int x, int y, int z, int eventId, int eventData) {

        super.onBlockEventReceived(world, x, y, z, eventId, eventData);
        TileEntity tileEntity = world.getTileEntity(x, y, z);
        return tileEntity != null && tileEntity.receiveClientEvent(eventId, eventData);
    }

    @Override
    public void breakBlock(World world, int x, int y, int z, Block block, int meta) {

        super.breakBlock(world, x, y, z, block, meta);
    }

    public static void setDefaultDirection(World world, int x, int y, int z) {

        if (!world.isRemote) {

            Block zNeg = world.getBlock(x, y, z - 1);
            Block zPos = world.getBlock(x, y, z + 1);
            Block xNeg = world.getBlock(x - 1, y, z);
            Block xPos = world.getBlock(x + 1, y, z);

            byte meta = 3;

            if (xNeg.func_149730_j() && !xPos.func_149730_j()) {
                meta = 5;
            }

            if (xPos.func_149730_j() && !xNeg.func_149730_j()) {
                meta = 4;
            }

            if (zNeg.func_149730_j() && !zPos.func_149730_j()) {
                meta = 3;
            }

            if (zPos.func_149730_j() && !zNeg.func_149730_j()) {
                meta = 2;
            }

            world.setBlockMetadataWithNotify(x, y, z, meta, 2);
        }
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {

        int rotation = MathHelper.floor_double((double) (entity.rotationYaw * 4F / 360F) + 0.5D) & 3;

        if (rotation == 0) {
            world.setBlockMetadataWithNotify(x, y, z, 2, 2);
        }

        if (rotation == 1) {
            world.setBlockMetadataWithNotify(x, y, z, 5, 2);
        }

        if (rotation == 2) {
            world.setBlockMetadataWithNotify(x, y, z, 3, 2);
        }

        if (rotation == 3) {
            world.setBlockMetadataWithNotify(x, y, z, 4, 2);
        }
    }

}

 

Tile Entity

package com.brady131313.steamreborn.tileentity;

import com.brady131313.steamreborn.init.ModFluids;
import com.brady131313.steamreborn.inventory.ContainerSR;
import com.brady131313.steamreborn.item.crafting.RecipeAlloyCompressor;
import com.brady131313.steamreborn.network.PacketHandler;
import com.brady131313.steamreborn.network.message.MessageTileEntityAlloyCompressor;
import com.brady131313.steamreborn.recipe.RecipesAlloyCompressor;
import com.brady131313.steamreborn.reference.Names;
import com.brady131313.steamreborn.tileentity.base.TileMachineTank;
import com.brady131313.steamreborn.utility.Tank;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

/**
* Created by brady on 8/6/2014.
*/
public class TileEntityAlloyCompressor extends TileMachineTank {

    public static final int INVENTORY_SIZE = 3;
    public static final int ITEM1_INVENTORY_INDEX = 0;
    public static final int ITEM2_INVENTORY_INDEX = 1;
    public static final int OUTPUT_INVENTORY_INDEX = 2;
    private int tankSize;

    public int itemCookTime; //How long the current item has been cooking
    public int deviceCookTime; //How long the smelter will cook

    public static boolean isActive = false;

    public ItemStack outputItemStack;

    public TileEntityAlloyCompressor() {
        tank = new Tank(new FluidStack(ModFluids.steamFluid, 0), 10000);
        inventory = new ItemStack[iNVENTORY_SIZE];
    }

    public void alloyItem() {

        if (this.canAlloy()) {
            RecipeAlloyCompressor recipe = RecipesAlloyCompressor.getInstance().getRecipe(inventory[iTEM1_INVENTORY_INDEX], inventory[iTEM2_INVENTORY_INDEX]);

            if (this.inventory[OUTPUT_INVENTORY_INDEX] == null) {
                this.inventory[OUTPUT_INVENTORY_INDEX] = recipe.getRecipeOutput().copy();
            } else if (this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(recipe.getRecipeOutput())) {
                inventory[OUTPUT_INVENTORY_INDEX].stackSize += recipe.getRecipeOutput().stackSize;
            }

            decrStackSize(ITEM1_INVENTORY_INDEX, recipe.getRecipeInputs()[0].getStackSize());
            decrStackSize(ITEM2_INVENTORY_INDEX, recipe.getRecipeInputs()[1].getStackSize());
            this.tank.drain(100, true);
        }
    }

    @Override
    public void updateEntity() {

        boolean isBurning = this.deviceCookTime > 0;
        boolean sendUpdate = false;
        isActive = isBurning;

        //If the smelter still has burn time, decrement it
        if (this.deviceCookTime > 0) {
            this.deviceCookTime--;
         }

        if (!this.worldObj.isRemote) {
            //Start cooking new item if we can
            if (this.deviceCookTime == 0 && this.canAlloy()) {
                if (this.tank.getFluidAmount() >= 100) {
                    this.deviceCookTime += 1;
                    //Implement fluid decrement
                }
            }

            //Continue cooking the same item if we can
            if (this.deviceCookTime > 0 && this.canAlloy()) {
                this.itemCookTime++;

                if (this.itemCookTime == 200) {
                    this.itemCookTime = 0;
                    this.alloyItem();
                    sendUpdate = true;
                }
            } else {
                this.itemCookTime = 0;
            }

            // If the state has changed catch something has changed
            if (isBurning != this.deviceCookTime > 0) {
                sendUpdate = true;
            }
        }

        if (sendUpdate) {
            this.markDirty();
            this.state = this.deviceCookTime > 0 ? (byte) 1 : (byte) 0;
            this.worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), 1, this.state);
            PacketHandler.INSTANCE.sendToAllAround(new MessageTileEntityAlloyCompressor(this, inventory[OUTPUT_INVENTORY_INDEX]), new NetworkRegistry.TargetPoint(this.worldObj.provider.dimensionId, (double) this.xCoord, (double) this.yCoord, (double) this.zCoord, 128d));
            this.worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, this.getBlockType());
        }
    }

    private boolean canAlloy() {

        if (inventory[iTEM1_INVENTORY_INDEX] == null || inventory[iTEM2_INVENTORY_INDEX] == null) {

            return false;
        } else {
            ItemStack alloyedItemStack = RecipesAlloyCompressor.getInstance().getResult(inventory[iTEM1_INVENTORY_INDEX], inventory[iTEM2_INVENTORY_INDEX]);

            if (alloyedItemStack == null) {
                return false;
            }

            if (inventory[OUTPUT_INVENTORY_INDEX] == null) {
                return true;
            } else {
                boolean outputEquals = this.inventory[OUTPUT_INVENTORY_INDEX].isItemEqual(alloyedItemStack);
                int mergedOutputStackSize = this.inventory[OUTPUT_INVENTORY_INDEX].stackSize + alloyedItemStack.stackSize;

                if (outputEquals) {
                    return mergedOutputStackSize <= getInventoryStackLimit() && mergedOutputStackSize <= alloyedItemStack.getMaxStackSize();
                }
            }
        }

        return false;
    }

    @Override
    public void markDirty() {

        PacketHandler.INSTANCE.sendToAllAround(new MessageTileEntityAlloyCompressor(this, inventory[OUTPUT_INVENTORY_INDEX]), new NetworkRegistry.TargetPoint(this.worldObj.provider.dimensionId, (double) this.xCoord, (double) this.yCoord, (double) this.zCoord, 128d));
        worldObj.func_147451_t(xCoord, yCoord, zCoord);
    }

    @Override
    public int[] getAccessibleSlotsFromSide(int side) {

        return side == ForgeDirection.DOWN.ordinal() ? new int[]{OUTPUT_INVENTORY_INDEX} : new int[]{ITEM1_INVENTORY_INDEX, ITEM2_INVENTORY_INDEX, OUTPUT_INVENTORY_INDEX};
    }

    @Override
    public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) {

        if (worldObj.getTileEntity(xCoord, yCoord, zCoord) instanceof TileEntityAlloyCompressor) {
            return isItemValidForSlot(slotIndex, itemStack);
        } else {
            return false;
        }
    }

    @Override
    public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) {

        return slotIndex == OUTPUT_INVENTORY_INDEX;
    }

    @Override
    public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) {

        switch (slotIndex) {

            case ITEM1_INVENTORY_INDEX: {
                return true;
            }
            case ITEM2_INVENTORY_INDEX: {
                return true;
            }
            default: {
                return false;
            }
        }
    }

    @Override
    public String getInventoryName() {

        return this.hasCustomName() ? this.getCustomName() : Names.Containers.ALLOY_COMPRESSOR;
    }

    @Override
    public boolean hasCustomInventoryName() {

        return this.hasCustomName();
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer player) {

        return true;
    }

    @SideOnly(Side.CLIENT)
    public int getCookProgressScaled(int scale) {

        return this.itemCookTime * scale / 200;
    }

    public int getScaledSteamLevel(int scale) {

        final double steamLevel = tank.getFluid() == null ? 0 : this.tank.getFluidAmount();

        return (int) (steamLevel * scale / this.tank.getCapacity());
    }

    public FluidStack getSteam() {

        return tank.getFluid();
    }

    @Override
    public void process() {


    }

    public void getGUINetworkData(int id, int value) {

        if (id == 6) tankSize = value;
        if (id == 7) itemCookTime = value;
        else super.getGuiNetworkData(id, value);
    }

    public void sendGUINetworkData(ContainerSR container, ICrafting crafting) {

        super.sendGuiNetworkData(container, crafting);
        crafting.sendProgressBarUpdate(container, 6, tankSize);
        crafting.sendProgressBarUpdate(container, 7, itemCookTime);
    }

    @Override
    public Packet getDescriptionPacket() {

        return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityAlloyCompressor(this, inventory[OUTPUT_INVENTORY_INDEX]));
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt) {

        super.readFromNBT(nbt);

        NBTTagList tagList = nbt.getTagList(Names.NBT.ITEMS, 10);
        inventory = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < tagList.tagCount(); ++i) {
            NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
            byte slotIndex = tagCompound.getByte("Slot");
            if (slotIndex >= 0 && slotIndex < inventory.length) {
                inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
            }
        }

        tank.readFromNBT(nbt.getCompoundTag("steamTank"));
        deviceCookTime = nbt.getInteger("deviceCookTime");
        itemCookTime = nbt.getInteger("itemCookTime");
    }

    @Override
    public void writeToNBT(NBTTagCompound nbt) {

        super.writeToNBT(nbt);

        NBTTagList tagList = new NBTTagList();
        for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
            if (inventory[currentIndex] != null) {
                NBTTagCompound tagCompound = new NBTTagCompound();
                tagCompound.setByte("Slot", (byte) currentIndex);
                inventory[currentIndex].writeToNBT(tagCompound);
                tagList.appendTag(tagCompound);
            }
        }

        nbt.setTag("steamTank", tank.writeToNBT(new NBTTagCompound()));
        nbt.setTag(Names.NBT.ITEMS, tagList);
        nbt.setInteger("deviceCookTime", deviceCookTime);
        nbt.setInteger("itemCookTime", itemCookTime);
    }

    public void sendChatInfoToPlayer(EntityPlayer player) {

        player.addChatMessage(new ChatComponentText("Tanks Fluid Amount: " + tank.getFluidAmount()));
        player.addChatMessage(new ChatComponentText("Tanks Capacity: " + tank.getCapacity()));
    }
}

Link to comment
Share on other sites

Look at how they have done this for the vanilla furnace.

 

The isActive variable goes in the block class, not the tileentity class

 

above your constructor in the block class, add this:

public final boolean isActive;

then make your constructor look something like this:

public MachineAlloyCompressor(Material mat, boolean isActive) {
        super(mat) 
        this.isActive = isActive;
}

then when you are registering the icons, change TileEntityAlloyCompressor.isActive to this.isActive

Also, where you are registering your blocks, you need to put true inside the brackets where you normally set the material on the active version of your block, and false on the idle version. This is because you have a boolean (isActive) in the constructor

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Okay, nevermind then, this is how i do it, and this is how the vanilla furnace does it though

blockRegistry.addObject(61, "furnace", (new BlockFurnace(false)).setHardness(3.5F).setStepSound(soundTypePiston).setBlockName("furnace").setCreativeTab(CreativeTabs.tabDecorations));
blockRegistry.addObject(62, "lit_furnace", (new BlockFurnace(true)).setHardness(3.5F).setStepSound(soundTypePiston).setLightLevel(0.875F).setBlockName("furnace"));

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
    • No dice. Unfortunately this fix didn't work, thank you though.
  • Topics

×
×
  • Create New...

Important Information

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