Jump to content

[1.19.4] New furnace block


JoasJSD

Recommended Posts

So I've been trying to make a custom furnace block for my mod, but whenever I go into Minecraft, the menu doesn't pop up when right clicking on the block

This is my code:

Knakworst Oven Entity Class:

package net.iegeliers.themakkersmod.block.custom.entity;

import net.iegeliers.themakkersmod.menu.MenuKnakworstOven;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;

public class BlockEntityKnakworstOven extends AbstractFurnaceBlockEntity {

    public BlockEntityKnakworstOven(BlockPos blockPos, BlockState blockState) {
        super(TMMBlockEntity.KNAKWORST_OVEN.get(), blockPos, blockState, RecipeType.SMELTING);
    }

    protected @NotNull Component getDefaultName() {
        return Component.translatable("block.themakkersmod.knakworst_oven");
    }

    protected @NotNull AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory) {
        return new MenuKnakworstOven(id, inventory, this, this.dataAccess);
    }

    @Override
    protected int getBurnDuration(@NotNull ItemStack itemStack) {
        return (super.getBurnDuration(itemStack) * 3) / 2;
    }
}

Block Entities Class:

package net.iegeliers.themakkersmod.block.custom.entity;

import net.iegeliers.themakkersmod.TheMakkersMod;
import net.iegeliers.themakkersmod.block.TMMBlocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class TMMBlockEntity {

    public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, TheMakkersMod.MODID);

    public static final RegistryObject<BlockEntityType<BlockEntityKnakworstOven>> KNAKWORST_OVEN =
            BLOCK_ENTITIES.register("knakworst_oven", () -> BlockEntityType.Builder.of
                    (BlockEntityKnakworstOven::new, TMMBlocks.KNAKWORST_OVEN.get()).build(null)
    );

    public static void register(IEventBus eventBus) {
        BLOCK_ENTITIES.register(eventBus);
    }
}

Menu Types Class:

package net.iegeliers.themakkersmod.block.custom.entity;

import net.iegeliers.themakkersmod.TheMakkersMod;
import net.iegeliers.themakkersmod.menu.MenuKnakworstOven;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.network.IContainerFactory;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class TMMMenuType {

    public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(ForgeRegistries.MENU_TYPES, TheMakkersMod.MODID);

    public static final RegistryObject<MenuType<MenuKnakworstOven>> KNAKWORST_OVEN_MENU = registerMenuType(
            (ID, inventory, extraData) -> new MenuKnakworstOven(ID, inventory), "knakworst_oven_menu");

    private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(IContainerFactory<T> factory, String name) {
        return MENUS.register(name, () -> IForgeMenuType.create(factory));
    }

    public static void register(IEventBus eventBus) {
        MENUS.register(eventBus);
    }

}

Knakworst Oven Block Class:

package net.iegeliers.themakkersmod.block.custom;

import net.iegeliers.themakkersmod.block.custom.entity.BlockEntityKnakworstOven;
import net.iegeliers.themakkersmod.block.custom.entity.TMMBlockEntity;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractFurnaceBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

public class BlockKnakworstOven extends AbstractFurnaceBlock {

    public BlockKnakworstOven(BlockBehaviour.Properties properties) {
        super(properties);
    }

    public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
        return new BlockEntityKnakworstOven(pos, state);
    }

    @Nullable
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level level, @NotNull BlockState blockState, @NotNull BlockEntityType<T> blockEntityType) {
        return createFurnaceTicker(level, blockEntityType, TMMBlockEntity.KNAKWORST_OVEN.get());
    }

    protected void openContainer(Level level, @NotNull BlockPos blockPos, @NotNull Player player) {
        BlockEntity blockentity = level.getBlockEntity(blockPos);
        if (blockentity instanceof BlockEntityKnakworstOven) {
            player.openMenu((MenuProvider) blockentity);
            player.awardStat(Stats.INTERACT_WITH_FURNACE);
        }
    }

    public void animateTick(BlockState blockState, @NotNull Level level, @NotNull BlockPos blockPos, @NotNull RandomSource randomSource) {
        if (blockState.getValue(LIT)) {
            double d0 = (double) blockPos.getX() + 0.5D;
            double d1 = blockPos.getY();
            double d2 = (double) blockPos.getZ() + 0.5D;
            if (randomSource.nextDouble() < 0.1D) {
                level.playLocalSound(d0, d1, d2, SoundEvents.FURNACE_FIRE_CRACKLE, SoundSource.BLOCKS, 1.0F, 1.0F, false);
            }

            Direction direction = blockState.getValue(FACING);
            Direction.Axis direction$axis = direction.getAxis();
            double d4 = randomSource.nextDouble() * 0.6D - 0.3D;
            double d5 = direction$axis == Direction.Axis.X ? (double) direction.getStepX() * 0.52D : d4;
            double d6 = randomSource.nextDouble() * 6.0D / 16.0D;
            double d7 = direction$axis == Direction.Axis.Z ? (double) direction.getStepZ() * 0.52D : d4;
            level.addParticle(ParticleTypes.SMOKE, d0 + d5, d1 + d6, d2 + d7, 0.0D, 0.0D, 0.0D);
            level.addParticle(ParticleTypes.FLAME, d0 + d5, d1 + d6, d2 + d7, 0.0D, 0.0D, 0.0D);
        }
    }
}

Knakworst Oven Menu Class:

package net.iegeliers.themakkersmod.menu;

import net.iegeliers.themakkersmod.block.custom.entity.TMMMenuType;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.crafting.RecipeType;

public class MenuKnakworstOven extends AbstractFurnaceMenu {

    public MenuKnakworstOven(int p_39532_, Inventory p_39533_) {
        super(TMMMenuType.KNAKWORST_OVEN_MENU.get(), RecipeType.SMELTING, RecipeBookType.FURNACE, p_39532_, p_39533_);
    }

    public MenuKnakworstOven(int p_39535_, Inventory p_39536_, Container p_39537_, ContainerData p_39538_) {
        super(TMMMenuType.KNAKWORST_OVEN_MENU.get(), RecipeType.SMELTING, RecipeBookType.FURNACE, p_39535_, p_39536_, p_39537_, p_39538_);
    }
}

Knakworst Oven Screen Class:

package net.iegeliers.themakkersmod.screen;

import net.iegeliers.themakkersmod.menu.MenuKnakworstOven;
import net.minecraft.client.gui.screens.inventory.AbstractFurnaceScreen;
import net.minecraft.client.gui.screens.recipebook.SmeltingRecipeBookComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class ScreenKnakworstOven extends AbstractFurnaceScreen<MenuKnakworstOven> {
    private static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/container/furnace.png");

    public ScreenKnakworstOven(MenuKnakworstOven menu, Inventory inventory, Component component) {
        super(menu, new SmeltingRecipeBookComponent(), inventory, component, TEXTURE);
    }

    @Override
    public void init() {
        super.init();
    }
}

I registered both the Block Entities and Menu Types classes and I also registered the menuscreens in my mod's main class and yet the menu still isn't showing. Can anyone help?

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.



×
×
  • Create New...

Important Information

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