Jump to content

Recommended Posts

Posted

Hello I am a first time mod maker and I am trying to make a custom model that get placed like a Dispenser, where the front of model faces the player when the block is placed.

 

The model I am trying to orientable is fairly complicated with multiple elements at 45 degree angels, I have found a thread where someone has had the same problem as I am having now (http://www.minecraftforge.net/forum/index.php?topic=34695.0) and I have followed it's advice as best as possible but all I accomplished was make my block no longer render properly replacing it with black and purple. If anyone can show me what I am doing wrong I would appreciate it.

 

Here is a link to my github page with the code before I tried to make my blocks orientable, the block you are looking for is called Underwater_Art_Deco.

https://github.com/DarkbutGood/BetterWindows

 

Posted

Step 1: use metadata to encode facing.  Look at any vanilla block to see how this is done.

Step 2: in your blockstate file provide rotation based on block state.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/resources/assets/harderores/blockstates/axel.json#L31-L43

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

Sorry Draco18s but that hasn't helped me, I've tried to use the example code you gave me and the code in the reference library but nothing has worked. However after having another look in the reference library I'm starting to think that it is my model that is to blame as I noticed that the dispenser has a separate model for rendering the block up and down. I may be worng about this but I think that the rotated elements in my model doesn't like to be orientated like a normal block, is this something that can happen or I'm still missing something?

Posted

Do you want to rotate your block as a dispense (1 model for the 4 sides, 1 for up/down) or like a piston (1 model for each orientation)? That you should look at those classes for reference.

 

Also, you should update to 1.10.2.

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

Do you want to rotate your block as a dispense (1 model for the 4 sides, 1 for up/down) or like a piston (1 model for each orientation)? That you should look at those classes for reference.

 

Also, you should update to 1.10.2.

 

I hope to rotate my block like a piston but frankly I will take what ever will work because I have tried to use the piston code and it hasn't worked.

 

I don't want to update to 1.10.2 because I use mods that haven't updated yet and I want to play my mod to test it before I publish it.

Posted

Hi

 

You might find this example  project useful, it has a block you can orient in four directions.

https://github.com/TheGreyGhost/MinecraftByExample

see MBE03

In particular have a look at

 

BlockVariants.onBlockPlaced(), getStateFromMeta(), and getMetaFromState()

 

-TGG

 

I have added what I think is the necessary code but when I get eclipse to run client minecraft no longer load's, I feel like I'm missing something but don't know what I have updated my git hub it you want to have a look the update is under a new branch called patch-1.

Posted

1) In your model file, round those numbers with a lot of decimals to 1 decimal, like

4.499999992549419

to

4.5

and

11.50000000745058

to

11.5

. You won't notice a difference.

 

2) Define "no longer works".

 

Not updating to 1.10.2 is the reason other mods won't update, because other mods won't update, because other mods won't update... See what happens? There are plenty of mods available, and you have to get over the fact that some mods won't get updated anymore, or not updated yet.

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

1) In your model file, round those numbers with a lot of decimals to 1 decimal, like

4.499999992549419

to

4.5

and

11.50000000745058

to

11.5

. You won't notice a difference.

 

2) Define "no longer works".

 

Not updating to 1.10.2 is the reason other mods won't update, because other mods won't update, because other mods won't update... See what happens? There are plenty of mods available, and you have to get over the fact that some mods won't get updated anymore, or not updated yet.

 

1) I will look into removing the long decimals after I can 2 to stop happening.

 

2) Minecraft no longer loads, I should have been more clear sorry about that.

 

3) I will make the mod in 1.10 but I want to get the basic features of my down first before I start porting to new versions, this means play testing with other mods and the version that I play right now is 1.8.9 because haven't had the time to go though what mods I need to have and update.

Posted

1) In your model file, round those numbers with a lot of decimals to 1 decimal, like

4.499999992549419

to

4.5

and

11.50000000745058

to

11.5

. You won't notice a difference.

 

2) Define "no longer works".

 

Not updating to 1.10.2 is the reason other mods won't update, because other mods won't update, because other mods won't update... See what happens? There are plenty of mods available, and you have to get over the fact that some mods won't get updated anymore, or not updated yet.

 

1) I will look into removing the long decimals after I can 2 to stop happening.

 

2) Minecraft no longer loads, I should have been more clear sorry about that.

 

3) I will make the mod in 1.10 but I want to get the basic features of my down first before I start porting to new versions, this means play testing with other mods and the version that I play right now is 1.8.9 because haven't had the time to go though what mods I need to have and update.

Minecraft no longer starts...how do we help if we do not have the crash report?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Sorry Draco18s but that hasn't helped me, I've tried to use the example code you gave me and the code in the reference library but nothing has worked. However after having another look in the reference library I'm starting to think that it is my model that is to blame as I noticed that the dispenser has a separate model for rendering the block up and down. I may be worng about this but I think that the rotated elements in my model doesn't like to be orientated like a normal block, is this something that can happen or I'm still missing something?

i think dyspenser has separte model for up and dowt because it has other texture when you will place it up/down side facing
Posted

1) In your model file, round those numbers with a lot of decimals to 1 decimal, like

4.499999992549419

to

4.5

and

11.50000000745058

to

11.5

. You won't notice a difference.

 

2) Define "no longer works".

 

Not updating to 1.10.2 is the reason other mods won't update, because other mods won't update, because other mods won't update... See what happens? There are plenty of mods available, and you have to get over the fact that some mods won't get updated anymore, or not updated yet.

 

1) I will look into removing the long decimals after I can 2 to stop happening.

 

2) Minecraft no longer loads, I should have been more clear sorry about that.

 

3) I will make the mod in 1.10 but I want to get the basic features of my down first before I start porting to new versions, this means play testing with other mods and the version that I play right now is 1.8.9 because haven't had the time to go though what mods I need to have and update.

Minecraft no longer starts...how do we help if we do not have the crash report?

When you run minecraft though eclipse when it stops working you don't get a crash report like when you fail to run minecraft though the launcher. I will try to find away around this.

Posted

When you run minecraft though eclipse when it stops working you don't get a crash report like when you fail to run minecraft though the launcher. I will try to find away around this.

Yes, you get one in the console or in your eclipse working directory.

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

When you run minecraft though eclipse when it stops working you don't get a crash report like when you fail to run minecraft though the launcher. I will try to find away around this.

Yes, you get one in the console or in your eclipse working directory.

Ah that's how you get it, I had no idea, thanks for letting me know.

 

 

 

Crash report

Time: 9/28/16 5:49 PM

Description: There was a severe problem during mod loading that has caused the game to fail

 

net.minecraftforge.fml.common.LoaderException: java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} as it does not exist in BlockState{block=bw:Underwater_Art_Deco, properties=[]}

at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:231)

at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:188)

at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:177)

at com.Dark_but_Good.BetterWindows.blocks.ModBlocks.createBlocks(ModBlocks.java:15)

at com.Dark_but_Good.BetterWindows.CommonProxy.preInit(CommonProxy.java:13)

at com.Dark_but_Good.BetterWindows.ClientProxy.preInit(ClientProxy.java:14)

at com.Dark_but_Good.BetterWindows.Main.preInit(Main.java:25)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:553)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)

at com.google.common.eventbus.EventBus.post(EventBus.java:275)

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)

at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:550)

at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)

at net.minecraft.client.Minecraft.run(Minecraft.java:356)

at net.minecraft.client.main.Main.main(Main.java:117)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

Caused by: java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} as it does not exist in BlockState{block=bw:Underwater_Art_Deco, properties=[]}

at net.minecraft.block.state.BlockState$StateImplementation.getValue(BlockState.java:174)

at com.Dark_but_Good.BetterWindows.blocks.BasicBlock.getMetaFromState(BasicBlock.java:82)

at net.minecraftforge.fml.common.registry.GameData.registerBlock(GameData.java:843)

at net.minecraftforge.fml.common.registry.GameData.registerBlock(GameData.java:805)

at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:220)

... 49 more

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.8

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_101, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 811037872 bytes (773 MB) / 1047592960 bytes (999 MB) up to 1047592960 bytes (999 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.4.1577 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCH mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)

UCH FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.4.1577.jar)

UCH Forge{11.14.4.1577} [Minecraft Forge] (forgeSrc-1.8-11.14.4.1577.jar)

UCE bw{1.8.9 1.0} [better Windows] (bin)

Loaded coremods (and transformers):

GL info: ' Vendor: 'ATI Technologies Inc.' Version: '3.3.11672 Compatibility Profile Context' Renderer: 'ATI Radeon HD 2400 XT'

[17:49:12] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\Ben Scogings\Desktop\My Mods\Better Windows\run\.\crash-reports\crash-2016-09-28_17.49.11-client.txt

 

 

 

Posted
net.minecraftforge.fml.common.LoaderException: java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} as it does not exist in BlockState{block=bw:Underwater_Art_Deco, properties=[]}

 

You never set the default state. To do so, use this line in your

Block

constructor:

setDefaultState(getBlockState().getBaseState().withProperty(PROPERTY, defaultValue));

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

net.minecraftforge.fml.common.LoaderException: java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} as it does not exist in BlockState{block=bw:Underwater_Art_Deco, properties=[]}

 

You never set the default state. To do so, use this line in your

Block

constructor:

setDefaultState(getBlockState().getBaseState().withProperty(PROPERTY, defaultValue));

 

Do I add it in the block constructor in a particular place or will any where do? Also do I need to have a preface in front of it such as a public boolean?

Posted

It can go anywhere in the constuctor, you just have to put it after the

super

call. And no, you don't have to save the return value as it simply returns

this

for chaining.

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

It can go anywhere in the constuctor, you just have to put it after the

super

call. And no, you don't have to save the return value as it simply returns

this

for chaining.

Strange because whats me to among other things add a void to it. I work on it a bit

Posted

It can go anywhere in the constuctor, you just have to put it after the

super

call. And no, you don't have to save the return value as it simply returns

this

for chaining.

Strange because whats me to among other things add a void to it. I work on it a bit

Never mind solved that problem but a new problem has a risen, eclipse wants me to change PROPERTY and defaultValue. I assume that this needs to be changed to facing and the direction I want default respectively.

Posted

Yes, they were just placeholders.

Ok I think I am right in saying that PROPERTY needs to be PROPERTYFACING but I can't seem to figure out what defaultValue needs to be changed to, I have tried to copy the facings from the blockstates and name it HORIZONTAL and NORTH none of them work.

Posted

In your case, it has to be an

EnumFacing

, and you only allow

EnumFacing.HORIZONTALS

, so you have to use

EnumFacing.NORTH

,

EnumFacing.EAST

,

EnumFacing.SOUTH

or

EnumFacing.WEST

.

 

I am getting the idea you don't actually know Java very well, in which I suggest you learn that first, and not via modding, as that generally doesn't end well.

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

In your case, it has to be an

EnumFacing

, and you only allow

EnumFacing.HORIZONTALS

, so you have to use

EnumFacing.NORTH

,

EnumFacing.EAST

,

EnumFacing.SOUTH

or

EnumFacing.WEST

.

 

I am getting the idea you don't actually know Java very well, in which I suggest you learn that first, and not via modding, as that generally doesn't end well.

 

Thanks for you help I should be able to figure the rest out now, to be honest some errors I make are me just being dumb but a lot is due to being inexperienced with Java, I am learning slowly but not as much as I would have thought I would. Most of the time I learn things like mathematics  better if I learn it though application, I like to see the practical out come of something as usually I get lost in the abstract without it. For example learning about graphs made more sense to me with a goal in mind as in lets me associate the skills with something concrete. Java has not been such a case, I'm just failing my way though it at this point instead of learning anything, the only thing left to do at this point is to be honest, admit defeat for now and learn another way.

 

It hurts to say it like that but it's true and as Adam Savage says failure is always an option, lessons have been learned and it's time to back away form this project. Thanks for helping me see this, you shouldn't have to help me for awhile.

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

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • 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.