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

Tieso2001

Members
  • Posts

    73
  • Joined

  • Last visited

Posts posted by Tieso2001

  1. 2 minutes ago, Animefan8888 said:

    When I said this I was talking about RecipeManager#getRecipe(the method you are having a problem with).

    Okay let me explain what I have and what I don't understand.

     

    You say that I need to add RecipeWrapper field to my TileEntity.

    private RecipeWrapper recipeWrapper() {
    
        }

    This needs to return RecipeWrapper.

     

    I understand that I need RecipeWrapper in my TileEntity, because I can use that to pass the inventory to RecipeManager#getRecipe.

     

    But I don't understand how to get RecipeWrapper into my TileEntity

  2. 12 hours ago, Draco18s said:

    Very helpful, Tieso2001, I probably won't end up using it (we'll see; a bunch of my machines shouldn't have exposed recipes, as it markedly impacts the intended balance). 

    Well the reason I want to be able to add recipes through jsons is for modpack makers to easily customise my mod and balance it themself.

  3. I got everything working after I changed the IFactory interface in SteepingRecipeSerializer to public.

    Now I try to add the recipes to my TileEntity but I get the following error: "Wrong 1st argument type. Found: 'crafting.IRecipeType<SteepingRecipe>', required: 'crafting.IRecipeType<T>'"

    I tried changing it IRecipeType<T> but that doesn't work.

     

    Spoiler
    
    SteepingRecipe recipe = world.getRecipeManager().getRecipe(SteepingRecipe.steeping, this.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY), world).orElse(null);

     

     

  4. 2 hours ago, Yanny7 said:

    Just implement own IRecipe<IInventory>,

    Spoiler
    
    package mod.tieso2001.boneappletea.recipe;
    
    import mod.tieso2001.boneappletea.init.ModBlocks;
    import mod.tieso2001.boneappletea.init.ModRecipeSerializers;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.crafting.IRecipe;
    import net.minecraft.item.crafting.IRecipeSerializer;
    import net.minecraft.item.crafting.IRecipeType;
    import net.minecraft.item.crafting.Ingredient;
    import net.minecraft.util.NonNullList;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.world.World;
    
    import javax.annotation.Nonnull;
    
    public class SteepingRecipe implements IRecipe<IInventory> {
    
        public static final IRecipeType<SteepingRecipe> steeping = IRecipeType.register("steeping");
    
        private final IRecipeType<?> type;
        private final ResourceLocation id;
        final String group;
        final Ingredient ingredient;
        final ItemStack result;
        final int steepTime;
    
        SteepingRecipe(ResourceLocation resourceLocation, String group, Ingredient ingredient, ItemStack result, int steepTime) {
            type = steeping;
            id = resourceLocation;
            this.group = group;
            this.ingredient = ingredient;
            this.result = result;
            this.steepTime = steepTime;
        }
    
        @Override
        public boolean matches(IInventory inv, @Nonnull World worldIn) {
            return this.ingredient.test(inv.getStackInSlot(0));
        }
    
        @Override
        @Nonnull
        public ItemStack getCraftingResult(@Nonnull IInventory inv) {
            return this.result.copy();
        }
    
        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    
        @Override
        @Nonnull
        public ItemStack getRecipeOutput() {
            return result;
        }
    
        @Override
        @Nonnull
        public ResourceLocation getId() {
            return id;
        }
    
        @Override
        @Nonnull
        public IRecipeSerializer<?> getSerializer() {
            return ModRecipeSerializers.STEEPING;
        }
    
        @Override
        @Nonnull
        public IRecipeType<?> getType() {
            return type;
        }
    
        @Override
        @Nonnull
        public NonNullList<Ingredient> getIngredients() {
            NonNullList<Ingredient> nonnulllist = NonNullList.create();
            nonnulllist.add(this.ingredient);
            return nonnulllist;
        }
    
        @Override
        @Nonnull
        public ItemStack getIcon() {
            return new ItemStack(ModBlocks.OAK_CASK);
        }
    
        public int getSteepTime() {
            return steepTime;
        }
    }

     

     

    2 hours ago, Yanny7 said:

    then extend recipe serializer,

    Spoiler
    
    package mod.tieso2001.boneappletea.recipe;
    
    import com.google.gson.JsonElement;
    import com.google.gson.JsonObject;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.crafting.IRecipeSerializer;
    import net.minecraft.item.crafting.Ingredient;
    import net.minecraft.item.crafting.ShapedRecipe;
    import net.minecraft.network.PacketBuffer;
    import net.minecraft.util.JSONUtils;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.registry.Registry;
    
    import javax.annotation.Nonnull;
    import javax.annotation.Nullable;
    
    public class SteepingRecipeSerializer<T extends SteepingRecipe> extends net.minecraftforge.registries.ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<T> {
    
        private final SteepingRecipeSerializer.IFactory<T> factory;
    
        SteepingRecipeSerializer(SteepingRecipeSerializer.IFactory<T> factory) {
            this.factory = factory;
        }
    
        @Override
        @Nonnull
        public T read(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
            String s = JSONUtils.getString(json, "group", "");
            JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient") ? JSONUtils.getJsonArray(json, "ingredient") : JSONUtils.getJsonObject(json, "ingredient");
            Ingredient ingredient = Ingredient.deserialize(jsonelement);
            ItemStack itemstack;
    
            if (!json.has("result")) {
                throw new com.google.gson.JsonSyntaxException("Missing result, expected to find a string or object");
            }
    
            if (json.get("result").isJsonObject()) {
                itemstack = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result"));
            } else {
                String s1 = JSONUtils.getString(json, "result");
                ResourceLocation resourcelocation = new ResourceLocation(s1);
                itemstack = new ItemStack(Registry.ITEM.getValue(resourcelocation).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist")));
            }
    
            int i = JSONUtils.getInt(json, "steepTime", 200);
    
            return this.factory.create(recipeId, s, ingredient, itemstack, i);
        }
    
        @Nullable
        @Override
        public T read(@Nonnull ResourceLocation recipeId, PacketBuffer buffer) {
            String s = buffer.readString(32767);
            Ingredient ingredient = Ingredient.read(buffer);
            ItemStack itemstack = buffer.readItemStack();
            int i = buffer.readVarInt();
    
            return this.factory.create(recipeId, s, ingredient, itemstack, i);
        }
    
        @Override
        public void write(PacketBuffer buffer, T recipe) {
            buffer.writeString(recipe.group);
            recipe.ingredient.write(buffer);
            buffer.writeItemStack(recipe.result);
            buffer.writeVarInt(recipe.steepTime);
        }
    
        interface IFactory<T extends SteepingRecipe> {
            T create(ResourceLocation resourceLocation, String group, Ingredient ingredient, ItemStack result, int steepTime);
        }
    }

     

     

    2 hours ago, Yanny7 said:

    dont forget to register it,

    Spoiler
    
    @ObjectHolder(BoneAppleTea.MOD_ID)
    public class ModRecipeSerializers {
    
        public static final SteepingRecipeSerializer<SteepingRecipe> STEEPING = Null();
    }
    
    @SubscribeEvent
        public static void onRegisterRecipeSerializers(final RegistryEvent.Register<IRecipeSerializer<?>> event) {
            event.getRegistry().registerAll(
                    new SteepingRecipeSerializer<>(SteepingRecipe::new).setRegistryName(BoneAppleTea.MOD_ID, "steeping")
            );
        }

     

    • Thanks 1
  5. I have a machine that has an input fluidstack, an input itemstack and an output itemstack. Currently I can add recipes with the following code:

    RecipeRegistrySteeping.addRecipe("recipe_name", new FluidStack(Fluids.WATER, 1000), new ItemStack(Items.STICK), new ItemStack(Items.DIAMOND));

    Where water is the input fluid, the stick the input item and the diamond the output item.

     

    I would like to be able to add and remove recipes like vanilla does this with crafting recipes and furnace recipes, through jsons. How can I implement this for my own machine? I want players to add their own recipes through data packs like how it is done in vanilla right now.

     

    I took a look at the CookingRecipeSerializer class but I have no idea how to do it myself.

  6. 18 hours ago, diesieben07 said:

    Show the ModContainerTypes class.

    Spoiler
    
    @SubscribeEvent
        public static void onRegisterContainerTypes(final RegistryEvent.Register<ContainerType<?>> event) {
            event.getRegistry().registerAll(
                    IForgeContainerType.create(((windowId, inv, data) -> {
                        BlockPos pos = data.readBlockPos();
                        return new CaskContainer(windowId, BoneAppleTea.proxy.getClientWorld(), pos, inv, BoneAppleTea.proxy.getClientPlayer());
                    })).setRegistryName("cask")
            );
        }

     

    Spoiler
    
    @ObjectHolder(BoneAppleTea.MOD_ID)
    public class ModContainerTypes {
    
        public static final ContainerType<?> CASK_CONTAINER = Null();
    }

     

     

  7. I followed this tutorial from McJty: https://wiki.mcjty.eu/modding/index.php?title=Tut14_Ep4.

    to create a container for my TileEntity. I got everything worked except the screen part.

     

    I have this:

    Spoiler
    
    public class ClientProxy implements IProxy {
    
        @Override
        public void init() {
            ScreenManager.registerFactory(ModContainerTypes.CASK_CONTAINER, CaskScreen::new);
        }
    
        @Override
        public World getClientWorld() {
            return Minecraft.getInstance().world;
        }
    
        @Override
        public PlayerEntity getClientPlayer() {
            return Minecraft.getInstance().player;
        }
    }

     

    The problem is CaskScreen::new says it is a bad return type and that it cannot convert CaskScreen to U. What did I do wrong?

     

    CaskScreen.class:

    Spoiler
    
    public class CaskScreen extends ContainerScreen<CaskContainer> {
    
        private ResourceLocation GUI = new ResourceLocation(BoneAppleTea.MOD_ID, "textures/gui/cask_gui.png");
    
        public CaskScreen(CaskContainer container, PlayerInventory inventory, ITextComponent name) {
            super(container, inventory, name);
        }
    
        @Override
        public void render(int mouseX, int mouseY, float partialTicks) {
            this.renderBackground();
            super.render(mouseX, mouseY, partialTicks);
            this.renderHoveredToolTip(mouseX, mouseY);
        }
    
        @Override
        protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
            super.drawGuiContainerForegroundLayer(mouseX, mouseY);
        }
    
        @Override
        protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
            GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.minecraft.getTextureManager().bindTexture(GUI);
            int relX = (this.width - this.xSize) / 2;
            int relY = (this.height - this.ySize) / 2;
            this.blit(relX, relY, 0, 0, this.xSize, this.ySize);
        }
    }

     

     

  8. 48 minutes ago, Draco18s said:

    Thanks, now it works.

     

    51 minutes ago, Draco18s said:

    Also, show where you create and register your blocks

    Here:

    Spoiler
    
    @ObjectHolder(BoneAppleTea.MOD_ID)
    public class ModBlocks {
    
        public static final Block BARLEY = Null();
        public static final Block QUERN = Null();
    
        public static final Block OAK_CASK = Null();
        public static final Block SPRUCE_CASK = Null();
        public static final Block BIRCH_CASK = Null();
        public static final Block JUNGLE_CASK = Null();
        public static final Block ACACIA_CASK = Null();
        public static final Block DARK_OAK_CASK = Null();
    }

     

    Spoiler
    
    @SubscribeEvent
        public static void onRegisterBlocks(final RegistryEvent.Register<Block> event) {
            event.getRegistry().registerAll(
                    setup(new BarleyBlock(Block.Properties.create(Material.PLANTS).doesNotBlockMovement().tickRandomly().hardnessAndResistance(0.0F).sound(SoundType.CROP)), "barley"),
                    setup(new QuernBlock(Block.Properties.create(Material.ROCK).hardnessAndResistance(2.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE).harvestLevel(1)), "quern"),
    
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "oak_cask"),
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "spruce_cask"),
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "birch_cask"),
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "jungle_cask"),
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "acacia_cask"),
                    setup(new CaskBlock(Block.Properties.create(Material.WOOD).hardnessAndResistance(2.0F).sound(SoundType.WOOD).harvestTool(ToolType.AXE).harvestLevel(0)), "dark_oak_cask")
            );
        }

     

     

  9. I have created a TileEntity block that places like a normal block. Now I wanted to make it rotate-able like the dispenser so I looked into the dispenser code and created this.

    Spoiler
    
    public class CaskBlock extends Block {
    
        public static final DirectionProperty FACING = DirectionalBlock.FACING;
    
        public CaskBlock(Block.Properties properties) {
            super(properties);
            this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.UP));
        }
    
        @Override
        public BlockRenderLayer getRenderLayer() {
            return BlockRenderLayer.CUTOUT;
        }
    
        @Nullable
        @Override
        public BlockState getStateForPlacement(BlockItemUseContext context) {
            return this.getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite());
        }
    
        @Override
        public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) {
            return state.with(FACING, direction.rotate(state.get(FACING)));
        }
    
        @Override
        public BlockState mirror(BlockState state, Mirror mirrorIn) {
            return state.rotate(mirrorIn.toRotation(state.get(FACING)));
        }
    
        @Override
        public boolean hasTileEntity(BlockState state) {
            return true;
        }
    
        @Nullable
        @Override
        public TileEntity createTileEntity(BlockState state, IBlockReader world) {
            return ModTileEntityTypes.CASK.create();
        }
    
        @Override
        public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
    
            if (worldIn.isRemote) return true;
            if (!(worldIn.getTileEntity(pos) instanceof CaskTileEntity)) return false;
    
            LazyOptional<IFluidHandler> handler = worldIn.getTileEntity(pos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, hit.getFace());
            handler.ifPresent(tank -> {
                FluidUtil.interactWithFluidHandler(player, handIn, worldIn, pos, hit.getFace());
            });
    
            return true;
        }
    }

     

    When I try to load the game I get the following error:

    Spoiler
    
    java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.util.Direction, values=[north, east, south, west, up, down]} as it does not exist in Block{null}
    	at net.minecraft.state.StateHolder.with(StateHolder.java:105)
    	at mod.tieso2001.boneappletea.block.CaskBlock.<init>(CaskBlock.java:31)
    	at mod.tieso2001.boneappletea.ModEventSubscriber.onRegisterBlocks(ModEventSubscriber.java:36)
    	at net.minecraftforge.eventbus.ASMEventHandler_1_ModEventSubscriber_onRegisterBlocks_Register.invoke(.dynamic)
    	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
    	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
    	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
    	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
    	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
    	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
    	at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$5(ModList.java:124)
    	at java.util.ArrayList.forEach(ArrayList.java:1257)
    	at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:124)
    	at net.minecraftforge.fml.ModList.lambda$static$1(ModList.java:95)
    	at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71)
    	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:194)
    	at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$24(ModLoader.java:186)
    	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:969)
    	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:186)
    	at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$2(ClientModLoader.java:79)
    	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:95)
    	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:79)
    	at net.minecraft.client.Minecraft.init(Minecraft.java:456)
    	at net.minecraft.client.Minecraft.run(Minecraft.java:365)
    	at net.minecraft.client.main.Main.main(Main.java:128)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
    	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
    	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:50)
    	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68)
    	at cpw.mods.modlauncher.Launcher.run(Launcher.java:80)
    	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
    	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101)

     

    I understand that "java.lang.IllegalArgumentException: Cannot set property DirectionProperty{name=facing, clazz=class net.minecraft.util.Direction, values=[north, east, south, west, up, down]} as it does not exist in Block{null}" this says what is wrong and that it cannot set the property because it doesn't exist, but I don't know how to fix this. Help would be appreciated.

  10. I have a tileEntity with 1 inventory slot with a max stacksize of 1. I'm trying to make it so that, when rightclicked, the item in your hand will be inserted into the slot or when already full, the item in the slot will be extracted into your inventory. I've got it working for the most part, but when I test it sometimes it works and sometimes not. I tried debugging it and it turns out that onBlockActivated sometimes fires 2 times, so it inserts and then extracts immediately. How do I fix this / stop this from happening?

     

    Spoiler
    
    @Override
        public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
    
            if (worldIn.isRemote) return true;
            if (!(worldIn.getTileEntity(pos) instanceof QuernTileEntity)) return false;
    
            LazyOptional<IItemHandler> handler = worldIn.getTileEntity(pos).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, hit.getFace());
            handler.ifPresent(inv -> {
    
                ItemStack heldItem = player.getHeldItem(handIn).copy();
                heldItem.setCount(1);
    
                if (inv.insertItem(0, heldItem, true).isEmpty() && !heldItem.isEmpty()) {
                    player.getHeldItem(handIn).shrink(1);
                    inv.insertItem(0, heldItem, false);
                }
                else if (!inv.extractItem(0, 1, true).isEmpty()) {
                    ItemStack extractedItem = inv.extractItem(0, 1, true);
                    ItemHandlerHelper.giveItemToPlayer(player, extractedItem);
                    inv.extractItem(0, 1, false);
                }
            });
    
            return true;
        }

     

     

×
×
  • Create New...

Important Information

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