Jump to content

Recommended Posts

Posted (edited)

Is there a method to add your own custom brewing stand recipes? It has nothing to do with adding custom potions and their effects. Let's say I just want to brew ITEM_A from ITEM_B as the ingredient and water bottles inside.

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted (edited)

Well, I really tried. I looked at BrewingRecipeRegistry, I found 

BrewingRecipeRegistry.addRecipe(Ingredient, Ingredient, ItemStack);

and I put it here:

@SubscribeEvent
    public void registerItems(final RegistryEvent.Register<Item> event) {

        event.getRegistry().registerAll(ItemList.getItems());

        BrewingRecipeRegistry.addRecipe( ... );
    }

but I have no idea how to use Ingredient... I really miss any examples on the internet. I learn the best with examples. My question is:

BrewingRecipeRegistry.addRecipe(
  /* Ingredient input - what to write here? (for example: water bottle*) */,
  /* Ingredient ingredient - what to write here? (for example: ItemList.ITEM_A) */,
  new ItemStack(ItemList.ITEM_B, 1)
);

// * BTW, I'd like to know how to implement water bottle, since it's not an item, but a Potion

 

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted (edited)

Alright.
I created a class SoySauceRecipe which looks like this:

package ...

import ...

public class SoySauceRecipe implements IBrewingRecipe {

    private ItemStack output = new ItemStack(ItemList.soy_sauce);

    SoySauceRecipe() {
    }

    @Override
    public boolean isInput(ItemStack input2) {
        return input2.getItem().equals(Items.POTION) && PotionUtils.getEffectsFromStack(input2).isEmpty();
    }

    @Override
    public boolean isIngredient(ItemStack ingredient2) {
        return ingredient2.getItem() == ItemList.soybean;
    }

    @Override
    public ItemStack getOutput(ItemStack input2, ItemStack ingredient2) {
        return output;
    }
}

and registered the recipe here, in main mod file:

package ...

import ...

@Mod("...")
public class SushiMod {

    ...

    public SushiMod() {
        ...
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
    }

    private void setup(final FMLCommonSetupEvent event) {
        DeferredWorkQueue.runLater(this::registerPotions);
    }

    private void registerPotions() {
        BrewingRecipeRegistry.addRecipe(new SoySauceRecipe());
    }
}

Works fine... but not entirely.
There are two problems:

  1. According to you, from Topic #64031: Recipes with Water Bottle ItemStack:
    Quote

    Yes, PotionUtils.getEffectsFromStack will give you all potions in a potion stack. If there are none, it's a water bottle.

    a potion with no effect is exclusively a water bottle. But so are potions such as an Awkward Potion as well. Therefore they get accepted as the input for the recipe, too. How to make the recipe only accept pure water bottle?

  2. After the soy sauce is brewed and there's still remaining soybean in the ingredient slot, the soy sauce gets brewed again with itself as the input. Why is that happening despite the fact that isInput method returns true only when there's a POTION input slot?

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted

diesieben07, I really appreciate that you answer people's question in such way that you make them do some research in their own. I even like that. Learning is more efficient when you put some effort into it. But sometimes this method fails :/. As I said, I learn the best with examples. I'm really tired after sieben hours of trying to do such relatively simple thing as adding a working brewing recipe with my mod items to the game... (yeah, I started this topic 7 hours ago and I've been doing nothing but trying to get this working).

My SoySauceRecipe class looks like this now:

package ...

import ,,,

public class SoySauceRecipe implements IBrewingRecipe {

    private ItemStack input = new ItemStack(Items.POTION);
    private ItemStack ingredient = new ItemStack(ItemList.soybean);
    private ItemStack output = new ItemStack(ItemList.soy_sauce);

    public SoySauceRecipe() {
    }

    @Override
    public boolean isInput(ItemStack input2) {
        return PotionUtils.getPotionFromItem(input2) == Potions.WATER;
    }


    @Override
    public boolean isIngredient(ItemStack ingredient2) {
        return ingredient2.getItem() == ingredient.getItem();
    }

    @Override
    public ItemStack getOutput(ItemStack input2, ItemStack ingredient2) {
        if (ingredient2 != null && input2 != null && isIngredient(ingredient2)) {
            ItemStack output2 = this.output.copy();
            if (input2 != output2) return output2;
            else return null;
        } else return null;
    }
}

(with the line return PotionUtils.getPotionFromItem(input2) == Potions.WATER; from you plus the IBrewingRecipe#getOutput method found somewhere on this forum), and it all works the same way. Both Awkward Potion and Soy Sauce is still acceptable as the input. Moreover, I just found out that when I don't fill all of the 3 brewing stand output slots with bottles and there is Blaze Powder in its upper-left slot.., it gets replaced with soy sauce after brewing is done. -,-
All this mess is shown on the screenshot.

So... yeah.. Sorry, but could you please write for me a properly working class SoySauceRecipe that implements IBrewingRecipe with Water Bottle as the only acceptable input, Items.soybean as the ingredient, and Items.soy_sauce as the output..? I believe that this impossible challenge for a beginner modder like me is a piece of cake for somebody like you.

 

2019-11-25_00.28.53.png

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted (edited)

Well... Although debugging did illuminate some things that are going on when operating the brewing stand, one thing remains a mistery. As for now, the recipe works perfectly as intended... but only once. After one brewing, no further can be performed.

My SoySauceRecipe class now:

package ...

import ...

public class SoySauceRecipe implements IBrewingRecipe {

    private static final ItemStack INGREDIENT = new ItemStack(ItemList.soybean);
    private static final ItemStack OUTPUT = new ItemStack(ItemList.soy_sauce);

    SoySauceRecipe() {
    }

    @Override
    public boolean isInput(@Nonnull ItemStack stack) {
        LOGGER.info("IBrewingRecipe#isInput: return " + PotionUtils.getPotionFromItem(stack) + " == " + Potions.WATER);
        return PotionUtils.getPotionFromItem(stack) == Potions.WATER;
    }

    @Override
    public boolean isIngredient(@Nonnull ItemStack ingredient) {
        LOGGER.info("IBrewingRecipe#isIngredient: return " + INGREDIENT.getItem() + " == " + ItemList.soybean);
        return INGREDIENT.getItem() == ItemList.soybean;
    }

    @Nonnull
    @Override
    public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient) {
        LOGGER.info("IBrewingRecipe#getOutput: isInput(input) = " + isInput(input)
                + " isIngredient(ingredient) = " + isIngredient(ingredient)
                + " -> return " + ((isInput(input) && isIngredient(ingredient))
                ? "OUTPUT (=" + OUTPUT + ")" : "ItemStack.EMPTY"));
        LOGGER.info("Target output: " + OUTPUT);
        if (isInput(input) && isIngredient(ingredient))
            return OUTPUT;
        return ItemStack.EMPTY;
    }
}

Now, when I put Soybean to the ingredient slot, but leave the bottles slots empty, the log shows:

[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@7f70e244 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#getOutput: isInput(input) = false isIngredient(ingredient) = true -> return ItemStack.EMPTY
[...] Target output: 1 soy_sauce
  1. First line - shows what is compared in isIngredient method.
  2. Second line - shows what is compared in isInput method.
  3. Third line - shows results of isIngredient and isInput methods and resulting ItemStack that is returned as the output.
  4. Fourth line - shows what should be the output of the recipe (it's the item declared in the OUTPUT field.

Looks good for now. After adding water bottles:

[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@fd14789 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#getOutput: isInput(input) = true isIngredient(ingredient) = true -> return OUTPUT (=1 soy_sauce)
[...] Target output: 1 soy_sauce

As you can see, both isInput and isIngredient are returning true, thus getOutput returns ItemStack with Soy Sauce now, and the brewing begins. Target output is still 1 soy sauce.

But after it finishes:

[...] IBrewingRecipe#isInput: return net.minecraft.potion.Potion@7f70e244 == net.minecraft.potion.Potion@fd14789
[...] IBrewingRecipe#isIngredient: return soybean == soybean
[...] IBrewingRecipe#getOutput: isInput(input) = false isIngredient(ingredient) = true -> return ItemStack.EMPTY
[...] Target output: 0 air

Despite the fact that the ingredient slot hasn't changed (which even the console output agrees with - as shows the second line), the target output somehow has changed to 0 air... Firstly, this state remains the same regardless of the bottles slots contents. Why is that? It should change when I put a water bottle inside, like at the first brewing. And secondly, how on earth is it possible that target output changed if the console reads content of the OUTPUT field which not only isn't changed anywhere in the code, but also is declared as final?? This looks like a Forge bug to me.., but I don't feel suitable to judge such things. Am I missing something..?

---

Here's the GitHub repository: [LINK EXPIRED]

Edited by Xander402

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

Posted

Well, I'm happy to say that this fixed the error. ? Thank you for all your help on this topic!

A few bytes about me:

public class Xander402 extends Modder implements IForumMember {
    int javaExperience, moddingExperience;
    LearningWay preferredLearningWay;
    public Xander402() {
        this.javaExperience = BIG;
        this.moddingExperience = NOT_SO_BIG;
        this.preferredLearningWay = LearningWay.through("exampes");
      	super(/*displayName*/"Xander402", /*moddingSince*/"1.9", preferredLearningWay);
    }
    @Override
    public Goal getReasonOfJoining(Forum forum) { return new Goal(() -> { while (true) moddingExperience++; }); }
}

 

  • 1 year later...
Posted
2 hours ago, eggpasta said:

Can you please share your finished code as i am having the same issues

don't necropost on a thread from 2 year ago
and his solution possibly wouldn't work for you since it was for 1.14
just make a new topic and explain your issues further

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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