Jump to content

[SOLVED][1.11.2] Making a Double Plant (2 Block High Flower)


Recommended Posts

Posted (edited)

So, I'm trying to implement a flower block that is a Double Plant, and after taking a look at the double plant class to try and figure out how this is done, it's left me with my head spinning. I'm usually able to reverse-engineer classes, but with the amount of variants that are used, I just can't figure out where the specific things I need are implemented. The latest info I can find is for 1.7.10 and I have verified that it doesn't translate over well.

 

Would anyone be willing to help simplify the process of going about this?

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

Well the BlockDoublePlant has a property HALF that tells you if the block represents the UPPER or LOWER block of the 2 block group.  This property is stored in the blockstate.  So when you do a IBlockState state= world.getBlockState(BlockPos);  you can get the  value by  state.getValue(BlockDoublePlant.HALF);

 

The BlockDoublePlant then traps events such as getItemDropped, etc to determine which blockstate is present (UPPER or LOWER) and do appropriate action. i.e. upper should turn to air if the bottom block is destroyed/harvested

 

If you create a new class MyBlockDoublePlant and copy all the code over from BlockDoublePlant (extending BlockBush, implements IGrowable, net.minecraftforge.common.IShearable) then get rid of the variants you don't want, create your own EnumPlantTypes and tweak as needed. Should get you were you want to be. The json file for the blockstate would be similar to the double_rose.json, double_fern.json, etc taking note of the variants 'half=lower', 'half=upper'.

 

In your modblocks, create each variant appropriately with the MyBlockDoublePlant (or whatever you call the class).

 

You would also have to deal with generation in the biomes that you want, but that is next step if you were wanting auto generating plant.

 

  • Like 1
Posted (edited)
3 hours ago, aw_wolfe said:

If you create a new class MyBlockDoublePlant and copy all the code over from BlockDoublePlant (extending BlockBush, implements IGrowable, net.minecraftforge.common.IShearable) then get rid of the variants you don't want, create your own EnumPlantTypes and tweak as needed. Should get you were you want to be. The json file for the blockstate would be similar to the double_rose.json, double_fern.json, etc taking note of the variants 'half=lower', 'half=upper'.

 

Would it also be possible to get all of these variables directly from BlockDoublePlant and just reference them in my own mod? Or would I actually need to implement everything in the individual class for my own double plant?

ie. 

public class BlockAplant extends BlockDoublePlant

 

Edited by ModMCdl
  • Like 1

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 can absolutely use the IProperties already defined in another class. In fact, it increases inter-mod compatibility!  As any mod that looks at a block and wants to fiddle around with the HALF property only needs to know about the vanilla HALF property and it can fiddle with your plant the same way it fiddles with a vanilla plant.

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)
54 minutes ago, Draco18s said:

You can absolutely use the IProperties already defined in another class. In fact, it increases inter-mod compatibility!  As any mod that looks at a block and wants to fiddle around with the HALF property only needs to know about the vanilla HALF property and it can fiddle with your plant the same way it fiddles with a vanilla plant.

Alright. So, please, bear with me for a minute here...

I've made my class extend BlockDoublePlant, and everything seems to be working fine. I've got everything working except for the actual model itself. I've 99% verified that it isn't a problem in my .json files, so I must be missing something to override in the class itself, I'm thinking something along the lines of the variants. 

 

BlockClass.java

Blockstates.json

 

Let me know if you need something else.

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

{ "model": "asphodelplant_bottom" }

 

Unable to load model asphodelplant_bottom in domain minecraft.

 

You're missing your mod ID.

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)
1 minute ago, Draco18s said:

{ "model": "asphodelplant_bottom" }

 

Unable to load model asphodelplant_bottom in domain minecraft.

 

You're missing your mod ID.

Oh. I did fix that and it still isn't working. I didn't realize that I uploaded the errored .json. (Updated to fix).

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

You'll also need to have the model json files. (not sure if you do or not). So block/asphodelplant_bottom would be located...assets/modmt/models/block/asphodelplant_bottom.json

 

 

 

 

Posted

Yes, I have those. I've been digging around for a while in between editing and adding other parts of the code. I've verified that the .json are set up correctly. Everything is working except the model render. Originally, it was because I was calling on BlockDoubleClass and not defining what variant (sunflower, fern, etc). my new plant was. So. I've gone as far as to recreate my own DoubleBlock class named BlockTwoPlant, and calling upon that instead, only defining one variant (my plant), but for some reason, its still registering the variant I added as undefined. Source below:

 

BlockTwoPlant.java (My version of BlockDoublePlant, almost c+p)

BlockAsphodelPlant.java (My 2-high plant)

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

Can you explain what exactly isn't working? 

1) plants not showing up in creativeTabs for you to place during creative?

2) plants not being created during biome creation?

3) plants showing up in creativeTabs, but without proper texture? pink/black squares?

etc...

 

  • Like 1
Posted (edited)
2 hours ago, aw_wolfe said:

Can you explain what exactly isn't working? 

That's the problem, everything is working, the .json, the class file, but in the console, its trying to implement variants that are (to the best of my, and my comrades' knowledge), defined. 

 

I ended up writing my own class to handle a two-high plant (see BlockTwoPlant.java) above, and that runs fine, but for some reason, Minecraft/Forge are trying to call upon variants that I didn't implement.

 

The Error:

Spoiler

[21:05:55] [Client thread/ERROR] [FML]: Exception loading model for variant modmt:blockasphodelplant#facing=north,half=upper,variant=asphodelplant for blockstate "modmt:blockasphodelplant[facing=north,half=upper,variant=asphodelplant]"
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model modmt:blockasphodelplant#facing=north,half=upper,variant=asphodelplant with loader VariantLoader.INSTANCE, skipping
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
    at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:264) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:153) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:252) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:159) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:541) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:387) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:78) ~[ModelBlockDefinition.class:?]
    at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1257) ~[ModelLoader$VariantLoader.class:?]
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
    ... 21 more
[21:05:55] [Client thread/FA

 

Edited by ModMCdl
Posted wrong error message

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)

Your block has 3 properties:

Horizontal Facing (4 values)

HALF (2 values)

PlantType (1 value)

All of this is encodable in 4 bits (you have 8 possible variations: 4 * 2 * 1)

 

Looking at your getMetaFromState method, if the top half of the block is set, the metadata is (8 + Facing). Otherwise it's (plant type).

However if we look at your getStateFromMeta method, we check if the metadata is >= 8, if it is, set HALF to true. Otherwise we decompose the other three bits into a Plant Type.

 

These two methods are not inverse of each other. Your getStateFromMeta discards the FACING property entirely.

 

THEN, ON TOP OF THAT, your json file ignores both the plant type and facing value:

{
    "variants": {
        "half=lower": { "model": "modmt:block/asphodelplant_bottom" },
        "half=upper":    { "model": "modmt:block/asphodelplant_top" }
    }
}

Those are not your only two variants! What about "facing=north,half=upper,variant=asphodelplant"?

Edited by Draco18s

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:

Those are not your only two variants! What about "facing=north,half=upper,variant=asphodelplant"?

Considering that the .json and the BlockTwoPlant.class were most stripped from the minecraft source, and neither included all of the variants, I didn't think they were necessary. 

 

Note: I did try implementing everything the console spat out at one point, but it didn't help, could you possible just example one for me? .json is still relatively new to me. I had just listed all of the respected variants that were listed but it didn't help.

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)
6 minutes ago, ModMCdl said:

Considering that the .json and the BlockTwoPlant.class were most stripped from the minecraft source, and neither included all of the variants, I didn't think they were necessary. 

Vanilla might (and probably does) use a custom IStateMapper object to strip some properties from needing to be present in the json file.

"It throws an error" is a far cry from "its not needed." If it throws an error either its needed or you did something wrong.

Quote

Note: I did try implementing everything the console spat out at one point, but it didn't help, could you possible just example one for me? .json is still relatively new to me. I had just listed all of the respected variants that were listed but it didn't help.

Take a look at

http://mcforge.readthedocs.io/en/latest/blockstates/forgeBlockstates/#forges-blockstates

Edited by Draco18s

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
5 minutes ago, Draco18s said:

Take a look at

Oh, that's a nifty little page there... thanks! You, draco, are a lifesaver.

 

 

2017-10-06_21.39.20.png

  • Like 2

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

Alright, so now, I've gotten the models to work. But, I've encountered yet another problem: my flower now longer drops itself (when destroyed or clicked with bonemeal).

 

It was working earlier, and I do not know what I changed to make it not work.

 

BlockTwoPlant.java (my doubleblock class)

BlockAsphodelPlant.java (my flower)

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

return blockasphodelplant$enumplanttype == BlockTwoPlant.EnumPlantType.ASPHODELPLANT ? Items.AIR

"If the current block's plant type is Asphodel, then return air."

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)
45 minutes ago, Draco18s said:

return blockasphodelplant$enumplanttype == BlockTwoPlant.EnumPlantType.ASPHODELPLANT ? Items.AIR

"If the current block's plant type is Asphodel, then return air."

Lol, jeez. Alright. I didn't realize that. Thanks.

 

However, that doesn't fix the bonemeal issue.

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

what are you looking for the bonemeal to do?  If you want growing plants, your have to incorporate an age property.

Your cangrow..

 

 return blockasphodelplant$enumplanttype != BlockTwoPlant.EnumPlantType.ASPHODELPLANT && blockasphodelplant$enumplanttype != BlockTwoPlant.EnumPlantType.ASPHODELPLANT;

 

looks like it would always return false if plant type is ASPHODELPLANT, which in your case it would be, so cangrow always returns false, so grow is never called.

 

I haven't had my coffee yet, but that's how I'm reading it.

  • Like 1
Posted
4 hours ago, aw_wolfe said:

what are you looking for the bonemeal to do?

I just want it to act like a normal DoublePlant, and drop itself when bonemeal is used. It was working properly before, and I cannot figure out what I did to mess it up.

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
4 hours ago, aw_wolfe said:

looks like it would always return false if plant type is ASPHODELPLANT, which in your case it would be, so cangrow always returns false, so grow is never called.

This was it. By removing that line and setting return true;it now works. Thanks!

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
On 10/8/2017 at 1:35 AM, ModMCdl said:

This was it. By removing that line and setting return true;it now works. Thanks!

Also as a suggestion, kindly please edit your first post to change the title so you can have a some sort of mark that this has been solved, like (SOLVED) or [SOLVED] so people have this same problem can tell if this is solved THANKS! ;)

Posted
1 hour ago, TheRPGAdventurer said:

kindly please edit your first post to change the title so you can have a some sort of mark that this has been solved, like (SOLVED) or [SOLVED]

Done ^_^

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

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

    • 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?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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