Jump to content

[1.11.2][UNSOLVED] Custom Crafting Block Not Crafting


Recommended Posts

Posted (edited)

So this is a bit tricky. I know I've been spamming up the forums lately, but here's yet another problem I can't solve.

 

I have successfully created a block and a GUI with container, however, I cannot get the custom crafting methods right. Essentially, I want to take two items and be able to combine them into one, but they don't craft. Nothing appears in the "result" slot, index 2. Image of GUI below for reference.

 

My custom crafting class:

https://github.com/ModMCdl/Magitech/blob/master/src/main/java/com/modmcdl/magitech/recipe/PestleRecipe.java

My Tile Entity:

https://github.com/ModMCdl/Magitech/blob/master/src/main/java/com/modmcdl/magitech/tileenitity/TileEntityPestle.java

My Container:

https://github.com/ModMCdl/Magitech/blob/master/src/main/java/com/modmcdl/magitech/gui/ContainerPestle.java

My Block:

https://github.com/ModMCdl/Magitech/blob/master/src/main/java/com/modmcdl/magitech/blocks/BlockPestle.java

 

If another class is needed, they're all in the github there.

 

 

2017-11-03_15.04.56.png

Edited by ModMCdl
Still not solved...

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted

1) Don't useIInventory. Use an IItemhandler (ItemStackHandler for most use-cases).

2) You never call TileEntityPestle#craftItem.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
21 minutes ago, loordgek said:

i dont think you can use a HashBasedTable here because the hashcode from the itemstacks are different 

FurnaceRecipes uses a HashMap themselves so that's not the issue, because you never actually compare the hashcodes of the ItemStacks (HashMap#contains*()), just the ItemStacks themselves (going through the entry Set and compare them yourself).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
2 hours ago, loordgek said:

The ItemStack is referring to the two input slots in my TileEntity, and I pretty much frankensteined the code from the furnace, which uses the HasBasedTable. The reason I used this instead of the workbench was because I was a bit more familiar with TileEntities, and I could not find an example relating to the workbench that was newer than 1.7.10. (and I hate having to scour the web to find named versions of all the various unnamed funcs and fields).

2 hours ago, larsgerrits said:

1) Don't useIInventory. Use an IItemhandler (ItemStackHandler for most use-cases).

2) You never call TileEntityPestle#craftItem.

I'll be honest, I'm confused. I can understand most of the reason behind using IItemHandler, but I don't understand where I need to call that TileEntity reference. This is a relatively new thing for me here, so I'm probably asking a stupid question.

You reference that I never compare the hashcodes of my two ItemStacks. I'm confused as by how to exactly implement that. Could you possibly provide an example of where and when?

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted
1 minute ago, ModMCdl said:

I don't understand where I need to call that TileEntity reference.

Everywhere you want to trigger the crafting of the Item. If you want pestle to check for a crafting recipe every tick implement the ITickable interface on your TileEntityPestle and call it in the ITickable#update method.

 

5 minutes ago, ModMCdl said:

You reference that I never compare the hashcodes of my two ItemStacks. I'm confused as by how to exactly implement that. Could you possibly provide an example of where and when?

That was in response to @loordgek for suggesting the recipe class is at fault because of a hash-based solution. I told him that most likely wasn't the issue, as you aren't using the HashMap#contains*() functions to check for recipes, and so you never check based on the hash of the ItemStack.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
14 minutes ago, larsgerrits said:

Everywhere you want to trigger the crafting of the Item. If you want pestle to check for a crafting recipe every tick implement the ITickable interface on your TileEntityPestle and call it in the ITickable#update method.

 

That was in response to @loordgek for suggesting the recipe class is at fault because of a hash-based solution. I told him that most likely wasn't the issue, as you aren't using the HashMap#contains*() functions to check for recipes, and so you never check based on the hash of the ItemStack.

I tried overriding update, but It wouldn't let me. I'll check again, maybe I'm just an idiot. 

Was typing that when I decided to read the first part and implement ITickable. That's probably my issue here. I thought it wasn't necessary, because I wouldn't be using methods for smelting time and such. Also, are you saying I need to call my TileEntity in my custom crafting class, or call it through ITickable to check for new crafting items.

(I know some of these questions are probably really stupid, but I'm just trying to learn here. This is new, and I couldn't find a decent tutorial or coherent example).

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)
1 hour ago, larsgerrits said:

If you want pestle to check for a crafting recipe every tick implement the ITickable interface on your TileEntityPestle and call it in the ITickable#update method.

Alright, after a lot of experimentation and fails, I can't quite figure out how this update thing works, or more precisely, how to make it work in my case. Could you please give an example?(Not asking for you to do it for me, more of like a brief rundown of how one would do it).

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted
17 minutes ago, ModMCdl said:

Alright, after a lot of experimentation and fails, I can't quite figure out how this update thing works, or more precisely, how to make it work in my case. Could you please give an example?(Not asking for you to do it for me, more of like a brief rundown of how one would do it).

At the top of your class add "implements ITickable"

Let your IDE underline it in red.

Pick the only suggested solution that makes any sense "implement the interface")

One of the methods added automatically will be one called Update

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
4 minutes ago, Draco18s said:

At the top of your class add "implements ITickable"

Let your IDE underline it in red.

Pick the only suggested solution that makes any sense "implement the interface")

One of the methods added automatically will be one called Update

Yeah I got that. I'm just unsure what to do with it now. (As in what to call to specifically only update the recipes)

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted

Look at the furnace.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

Look at the furnace.

I did, and I had omitted all of the "tickable" methods, because I didn't think they were needed unless I was doing some form of cooking? Would all I need from the furnace be the isRemote statement regarding the furnaceItemStacks, instead using that with my Pestle Recipes? Most of my code is frankensteined from the furnace, but I really have no idea what to do here.

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted

If you're not cooking it over time, then you don't need ITickable.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, Draco18s said:

If you're not cooking it over time, then you don't need ITickable.

That's what I thought, but now I'm lost. If you look above, I was informed I needed the update method to check the crafting recipe list each time I wanted to craft something. The only way to do this was through ITickable. Now, you're saying I don't need it, which puts me back to square one. Since you have never failed me before, Draco, (and if you haven't already), take a look at my original post and git and see if you can tell where I'm going wrong?

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted

You don't need to check for a result every tick. You only need to do it when the inventory changes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
2 minutes ago, Draco18s said:

You don't need to check for a result every tick. You only need to do it when the inventory changes.

...so what method would I call upon to do that, if not ITickableSorry, I feel stupid. :|

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)
23 minutes ago, ModMCdl said:

I was informed I needed the update method to check the crafting recipe list each time I wanted to craft something. The only way to do this was through ITickable

I told you this: 

2 hours ago, larsgerrits said:

If you want pestle to check for a crafting recipe every tick implement the ITickable interface

 

If you don't want to check every tick, don't implement ITickable.

 

9 minutes ago, ModMCdl said:

so what method would I call upon to do that

 

If you use an ItemStackHandler (again, use it instead of IInventory), you can make an anonymous subclass (is that what you call it?) or a normal subclass and override the ItemStackHandler#onContentsChanged method to call the TileEntityPestle#craftItem method.

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
Just now, larsgerrits said:

I told you this: 

If you don't want to check every tick, don't implement ITickable.

 

If you use an ItemStackHandler (again, use it instead of IInventory), you can make an anonymous subclass (is that what you call it?) or a normal subclass and override the ItemStackHandler#onContentsChanged method to call the TileEntityPestle#craftItem.

So I have to re-write my old code with IItemHandler, which doesn't implement the same methods? Damn, that's gonna be a pain.

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)
5 minutes ago, ModMCdl said:

So I have to re-write my old code with IItemHandler, which doesn't implement the same methods? Damn, that's gonna be a pain.

Not really. It's way easier actually.

 

Remove everything related to IInventory, and make a single instance of ItemStackHandler:

public ItemStackHandler inventory = new ItemStackHandler(INVENTORY_SIZE);

Everything related to the inventory is now inside that, and you can call various methods to interact with it.

 

If you want other machines to be able to manipulate your inventory, look at the docs to see how to expose your capability.

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
2 minutes ago, larsgerrits said:

Remove everything related to IInventory, and make a single instance of ItemStackHandler:

Se essentially replace my NonNullList with that? If I'm not mistaken, that's what would change my inventory instance? Because doing that errors almost every instance of inventory I use...

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)
9 minutes ago, ModMCdl said:

Se essentially replace my NonNullList with that?

Yes.

 

9 minutes ago, ModMCdl said:

Because doing that errors almost every instance of inventory I use...

Not only remove the "implements IInventory", but also every method you have to override from that. The only issues you'll have are in your TileEntityPestle#craftItem method and the ContainerPestle class.

 

Take a look at my TileEntity class, it has an ItemStackHandler with anonymous subclass: https://gist.github.com/Larsg310/0bafea64ccac7280f32158dc52ead2a2

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted (edited)
11 minutes ago, larsgerrits said:

Yes.

 

Not only remove the "implements IInventory", but also every method you have to override from that. The only issues you'll have are in your TileEntityPestle#craftItem method and the ContainerPestle class.

Oh, I see. So I'm no longer overriding IInventory, but instead solely using ItemStackHandler

 

But now what do I do with the canCraft and craftItem methods? You mentioned issues, but wouldn't that completely error them out because they rely on all the methods from IInventory?  Would I just replace .get with.getStackInSlot? And creategetInventoryStackLimit as my own method rather than an override?

 

Then I could just cast all of the methods in my other classes to IInventory?

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted (edited)

You call ItemStackHandler#getStackInSlot instead of NonNullIList#get to get stuff out of your inventory.

 

Instead of using the IInventory#getInventoryStackLimit method, you should override ItemStackHandler#getSlotLimit inside of an (anonymous) subclass of ItemStackHandler. Take a look at my previous edit for a link in which I do the same.

Edited by larsgerrits

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted (edited)
14 minutes ago, larsgerrits said:

Instead of using the IInventory#getInventoryStackLimit method, you should override ItemStackHandler#getSlotLimit inside of an (anonymous) subclass of ItemStackHandler. Take a look at my previous edit for a link in which I do the same.

Alright, but what do I do about all of my other classes? My Container, GUI, and Block were all built around the original version. Am I casting those toIInventory? And what about my block'scanInteractWith?

Edited by ModMCdl

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Posted
46 minutes ago, ModMCdl said:

Alright, but what do I do about all of my other classes? My Container, GUI, and Block were all built around the original version. Am I casting those toIInventory? And what about my block'scanInteractWith?

Instead of using Slot you use SlotItemHandler and instead of casting to IInventory you use getCapability().

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
  • Topics

×
×
  • Create New...

Important Information

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