Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Getting Furnace Smelting Recipes [1.16.5]


Recommended Posts

Hi!
I'm trying to create a custom tileentity that automatically cooks the item inside, but I don't know how to see if the inserted item has a smelting recipe or not.
How can i see the recipes? I tried to copy from the FurnaceTileEntity, but the IRecipe result aslways null.

 

@Override
    public void setItem(int index, ItemStack stack) {
        assert this.level != null : "Can't happend";
        IRecipe<?> iRecipe = this.level.getRecipeManager().getRecipeFor(IRecipeType.SMELTING, this, this.level).orElse(null);
        ItemStack toInsert;
        if (iRecipe != null) {
            ItemStack resultItem = iRecipe.getResultItem();
            if (resultItem.equals(ItemStack.EMPTY)) {
                toInsert = stack;
            } else {
                toInsert = resultItem;
            }
        } else {
            toInsert = stack;
        }
        this.items.set(index, toInsert);
    }

 

Link to post
Share on other sites
public class SmeltingChestTileEntity extends TileEntity implements IInventory, INamedContainerProvider {
    private NonNullList<ItemStack> items = NonNullList.withSize(27, ItemStack.EMPTY);


    public SmeltingChestTileEntity() {
        super(Blocks.smeltingChestType);
    }

    @Override
    public CompoundNBT save(CompoundNBT nbt) {
        super.save(nbt);
        ItemStackHelper.saveAllItems(nbt, this.items);
        return nbt;
    }

    @Override
    public void load(BlockState state, CompoundNBT nbt) {
        super.load(state, nbt);
        this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
        ItemStackHelper.loadAllItems(nbt, this.items);
    }

    @Override
    public int getContainerSize() {
        return 27;
    }

    @Override
    public boolean isEmpty() {
        return items.isEmpty();
    }

    @Override
    public ItemStack getItem(int index) {
        return items.get(index);
    }

    @Override
    public ItemStack removeItem(int index, int quantity) {
        ItemStack itemStack = items.get(index);
        if (itemStack.getCount() <= quantity) {
            items.set(index, ItemStack.EMPTY);
            return itemStack;
        } else {
            int count = itemStack.getCount() - quantity;
            itemStack.setCount(count);
            items.set(index, itemStack);
            return new ItemStack(itemStack.getItem(), count);
        }
    }

    @Override
    public ItemStack removeItemNoUpdate(int index) {
        return items.remove(index);
    }

    @Override
    public void setItem(int index, ItemStack stack) {
        assert this.level != null : "Can't happend";
        IRecipe<?> iRecipe = this.level.getRecipeManager().getRecipeFor(IRecipeType.SMELTING, this, this.level).orElse(null);
        ItemStack toInsert;
        hasFuel();
        if (iRecipe != null && hasFuel()) {
            ItemStack resultItem = iRecipe.getResultItem();
            if (resultItem.equals(ItemStack.EMPTY)) {
                toInsert = stack;
            } else {
                toInsert = resultItem;
            }
        } else {
            toInsert = stack;
        }
        this.items.set(index, toInsert);
    }

    private boolean hasFuel() {
        BlockPos blockPos = this.getBlockPos().below();
        assert this.level != null;
        BlockState blockState = this.level.getBlockState(blockPos);
        BlockState lavaState = net.minecraft.block.Blocks.LAVA.defaultBlockState();
        BlockState fireState = net.minecraft.block.Blocks.FIRE.defaultBlockState();
        System.out.println(blockState);
        boolean b = blockState.equals(lavaState) || blockState.equals(fireState);
        System.out.println("Has fuel? " + b);
        return b;
    }

    @Override
    public boolean stillValid(PlayerEntity entity) {
        return true;
    }

    @Override
    public void clearContent() {
        items.clear();
    }

    @Override
    public ITextComponent getDisplayName() {
        return new TranslationTextComponent("smelting_chest");
    }

    @Nullable
    @Override
    public Container createMenu(int id, PlayerInventory inventory, PlayerEntity entity) {
        return ChestContainer.threeRows(id, inventory, this);
    }
}

This is the TileEntity class.

public class SmeltingChestBlock extends ContainerBlock {
    public static final DirectionProperty FACING = HorizontalBlock.FACING;

    public SmeltingChestBlock(Properties p_i48446_1_) {
        super(p_i48446_1_);
        this.setRegistryName(TenChest.MODID, "smelting_chest");
        Blocks.BLOCKS.add(this);
        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
    }

    /*public static Direction getConnectedDirection(BlockState p_196311_0_) {
        Direction direction = p_196311_0_.getValue(FACING);
        return direction.getClockWise();
    }*/

    public BlockState getStateForPlacement(BlockItemUseContext p_196258_1_) {
        Direction direction = p_196258_1_.getHorizontalDirection().getOpposite();

        return this.defaultBlockState().setValue(FACING, direction);
    }

    public BlockRenderType getRenderShape(BlockState p_149645_1_) {
        return BlockRenderType.MODEL;
    }

    public VoxelShape getShape(BlockState p_220053_1_, IBlockReader p_220053_2_, BlockPos p_220053_3_, ISelectionContext p_220053_4_) {
        return Block.box(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
    }

    /*@Nullable
    private Direction candidatePartnerFacing(BlockItemUseContext p_196312_1_, Direction p_196312_2_) {
        BlockState blockstate = p_196312_1_.getLevel().getBlockState(p_196312_1_.getClickedPos().relative(p_196312_2_));
        return blockstate.is(this)? blockstate.getValue(FACING) : null;
    }*/

    protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> p_206840_1_) {
        p_206840_1_.add(FACING);
    }

    @Override
    public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult rayTrace) {
        if (world.isClientSide)
            return ActionResultType.SUCCESS;
        INamedContainerProvider menuProvider = getMenuProvider(state, world, pos);
        if (menuProvider != null) {
            player.openMenu(menuProvider);
            player.awardStat(Stats.CUSTOM.get(Stats.OPEN_CHEST));
            PiglinTasks.angerNearbyPiglins(player, true);
        }
        return ActionResultType.CONSUME;
    }

    @Nullable
    @Override
    public TileEntity newBlockEntity(IBlockReader p_196283_1_) {
        return new SmeltingChestTileEntity();
    }

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

    @Nullable
    @Override
    public TileEntity createTileEntity(BlockState state, IBlockReader world) {
        return new SmeltingChestTileEntity();
    }
}

This is the block class

Link to post
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.

Guest
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

    • I have made a custom armor piece and have given it a texture for when you hold it. I have also made a custom armor material but I dont know how to make it so that when you where the armor you see a custom texture.
    • Probably only the main block should hold all the data, that way you don't have things spread out.
    • It hasn't been changed in a long time and should be updated.  But no, it's not overly aggressive. People don't read it. Look at all the support threads. 90% of them are "okay i have this issue", no debug.log in sight.
    • I solved it by copying the .gradle folder from another laptop where it works to run the client!
    • I am currently drawing a compass to my ingame gui as follows: private static void renderCompass(MatrixStack matrixStack, int width, int height) { TextureDrawer.drawGuiTexture(matrixStack, width / 2 - 110, 10, 0, 37, 221, 14); int rot; boolean f0 = mc.player.yRot < 0.0f; if(f0) rot = -MathHelper.floor(mc.player.yRot % 360); else rot = MathHelper.floor(mc.player.yRot % 360); boolean f1 = rot > 0 && rot < 180; boolean f2 = rot <= 270 && rot >= 90; boolean f3 = rot <= 180 && rot >= 0; AtomicInteger targetAngle = new AtomicInteger(-1); mc.player.getCapability(ISkyrimPlayerDataProvider.SKYRIM_PLAYER_DATA_CAPABILITY).ifPresent(cap -> { if(cap.getCurrentTarget() != null && cap.getCurrentTarget().isAlive()) { Vector3d playerPos = mc.player.getLookAngle(); Vector3d targetPos = cap.getCurrentTarget().position(); Vector3d norm = playerPos.subtract(targetPos); double angleDir = (Math.atan2(norm.z, norm.x) / 2 / Math.PI * 360 + 360) % 360; double angleLook = (Math.atan2(playerPos.z, playerPos.x) / 2 / Math.PI * 360 + 360) % 360; targetAngle.set((int)(angleDir - angleLook + 360) % 360); } else targetAngle.set(-1); }); int targetEntityAngle = targetAngle.get(); if(targetEntityAngle > 0 && targetEntityAngle <= 90) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle, 14, 105, 52, 6, 6); else if(targetEntityAngle > 90 && targetEntityAngle <= 180) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle + 90, 14, 105, 52, 6, 6); if (rot == 0) { drawCenteredString(matrixStack, fontRenderer, "S", width / 2, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "E", (width / 2) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "W", (width / 2) + 90, 13, 16777215); } else if (!f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 - rot) + 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 - rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "E" : "", (width / 2 - rot) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "W" : "", (width / 2 - rot) + 90, 13, 16777215); } else if(f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 + rot) - 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 + rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "W" : "", (width / 2 + rot) + 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "E" : "", (width / 2 + rot) - 90, 13, 16777215); } } What I'm trying to do is only render the entity texture (the calls including targetEntityAngle) when it is in compass view.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.