Jump to content

Recommended Posts

Posted

Ok, here is my question, is it possible to have the texture of a custom modeled block change based on an event, like if it's right clicked with an item... I have an idea on how I could do it, but I don't know where to place the code.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Well I was planning on making my custom block to change it's texture when it is rightclicked with a certain item, like a stick makes it's texture be texture 2, while on default it would be texture 1. I would assume I could use either a switch to set texture based on metadata of the block, but I don't know how to impliment it.

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Well, all you really have to do is think logical. Let us analyse what you want:

- change texture

- right click

- change metadata

- stick

 

The block class has a convenient right click method which we can simply override

 

    @Override
    public boolean onBlockActivated(World parWorld, int parXCoordinate, ...)
    {	
return false;
    }

 

The metadata as well can easily be set in this method by calling:

 

parWorld.setBlockMetadataWithNotify(parXCoordinate, parYCoordinate, ...);

 

If it is just two texture you can toggle inbetween them by putting an if statement as a parameter: ParWorld.getBlockMetaData(x, y, z) == 0 ? 1 : 0

 

Selecting what to hold can also be achieved here, simply use the player parameter

 

player.getHeldItem().getItem().equals(Items.stick)

 

And rendering, well, you allready know a switch and then it is a simple matter of finding the correct method, as there are several that do just about the same things so I won't post any and leave it up to you, have a look in the Block.class and simply get the metadata and return the correct texture.

 

Not that hard is it? All you have to do is think logical, have a look in the base classes what is allready there, what you can use and you're good to go.

Posted

Ok, so in my attempt to see if I could get it to start to work, I now get a null point exception when I right click it, here is the crash:

 

[13:08:03] [server thread/ERROR] [FML]: A TileEntity type com.AutonMatrix.tileentity.TileEntityAIBeacon has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class com.AutonMatrix.tileentity.TileEntityAIBeacon is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:100) ~[TileEntity.class:?]
at com.AutonMatrix.tileentity.TileEntityAIBeacon.writeToNBT(TileEntityAIBeacon.java:24) ~[TileEntityAIBeacon.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:323) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:132) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:229) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:281) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:875) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:403) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:255) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:531) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]
[13:08:03] [server thread/INFO]: Saving chunks for level 'simple'/Nether
[13:08:03] [server thread/INFO]: Saving chunks for level 'simple'/The End
[13:08:03] [server thread/INFO] [FML]: Unloading dimension 0
[13:08:03] [server thread/INFO] [FML]: Unloading dimension -1
[13:08:03] [server thread/INFO] [FML]: Unloading dimension 1
[13:08:04] [Client thread/FATAL]: Unreported exception thrown!
java.lang.NullPointerException
at com.AutonMatrix.block.AM_BlockBeacon.onBlockActivated(AM_BlockBeacon.java:46) ~[AM_BlockBeacon.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:380) ~[PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1497) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2010) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:995) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:910) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_65]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_65]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
---- Minecraft Crash Report ----
// My bad.

Time: 8/22/14 1:08 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at com.AutonMatrix.block.AM_BlockBeacon.onBlockActivated(AM_BlockBeacon.java:46)
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:380)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1497)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2010)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:995)
at net.minecraft.client.Minecraft.run(Minecraft.java:910)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


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

-- Head --
Stacktrace:
at com.AutonMatrix.block.AM_BlockBeacon.onBlockActivated(AM_BlockBeacon.java:46)
at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:380)
at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1497)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player865'/0, l='MpServer', x=850.32, y=2.62, z=-89.52]]
Chunk stats: MultiplayerChunkCache: 270, 270
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (881,4,-102), Chunk: (at 1,0,10 in 55,-7; contains blocks 880,0,-112 to 895,255,-97), Region: (1,-1; contains chunks 32,-32 to 63,-1, blocks 512,0,-512 to 1023,255,-1)
Level time: 77856 game time, 4337 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 1 total; [EntityClientPlayerMP['Player865'/0, l='MpServer', x=850.32, y=2.62, z=-89.52]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2522)
at net.minecraft.client.Minecraft.run(Minecraft.java:939)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

To be specific it seems to happen only with an empty hand, so how do I fix that, or make it detect if right clicked with an empty hand?

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

You have at least a null pointer exception on right click.

Did you actually check if the player is holding something before you're trying to check that illusive item?

Minecraft doesn't check before it returns a method like a sensibly written program would do,

instead it just throws the nulls everywhere and hopes you catch them.

 

And then you have something about nbt which I do not wish to adress since I simply do not know what that is about?

Nbt not being able to find its mapping, how?

It would be nice if someone else could clarify that or otherwise I would definitely need to see the code about that.

Posted

Well, I have fixed that issue, now I have discovered something with my testing, you see I was making my block print a certain phrase when it's right clicked with a stick, and noticed it printed it two times, how would I resolve this, for future reference?

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

Ok and now I can't seem to understand how to get the texture to change correctly, I seem to be confusing myself :(

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

To see if I can get help... here are the render file and the block file.

 

package com.AutonMatrix.renderer;

import org.lwjgl.opengl.GL11;

import com.AutonMatrix.block.AM_BlockBeacon;
import com.AutonMatrix.lib.Strings;
import com.AutonMatrix.model.Modelaibeacon;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class RenderAIBeacon extends TileEntitySpecialRenderer {

private static final ResourceLocation texture = new ResourceLocation(Strings.MODID + ":" + "textures/model/beaco.png");
private static ResourceLocation texturea = AM_BlockBeacon.texturee;
private Modelaibeacon model;

public RenderAIBeacon(){
	this.model = new Modelaibeacon();
}

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
	GL11.glPushMatrix();
		GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
		GL11.glRotatef(180, 0F, 0F, 1F);

		this.bindTexture(texturea);

		GL11.glPushMatrix();
			this.model.renderModel(0.0625F);
		GL11.glPopMatrix();
	GL11.glPopMatrix();

}

}

package com.AutonMatrix.block;

import com.AutonMatrix.creativeTabs.AM_CreativeTabs;
import com.AutonMatrix.lib.Strings;
import com.AutonMatrix.tileentity.TileEntityAIBeacon;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class AM_BlockBeacon extends BlockContainer {

public static ResourceLocation texturee = new ResourceLocation(Strings.MODID + ":" + "textures/model/beaco.png");

public AM_BlockBeacon(String name) {
	super(Material.circuits);
	this.setBlockName(name);
	this.setCreativeTab(AM_CreativeTabs.tabBlock);
	setBlockBounds(6f/16f, 0.0F, 6f/16f, 10f/16f , 0.875f , 10f/16f);

}

public int getRenderType(){
	return -1;
}

public boolean isOpaqueCube(){
	return false;
}

public boolean renderAsNormalBlock(){
	return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityAIBeacon();
}

@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float hitx, float hity, float hitz, int metadata)
    {
	texturee = new ResourceLocation(Strings.MODID + ":" + "textures/model/beaco.png");
	return metadata;

    }

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_){
	if(entityplayer.getHeldItem() != null ){
		if(entityplayer.getHeldItem().getItem().equals(Items.stick)){
			System.out.println("Item is a stick");
			texturee = new ResourceLocation(Strings.MODID + ":" + "textures/model/beac2.png");
			return true;
		}
		else{
			System.out.println("Item isn't a stick");
			texturee = new ResourceLocation(Strings.MODID + ":" + "textures/model/beac1.png");
			return true;
		}
	}
	else{
		System.out.println("No Item in hand");
		return true;
	}		


}

}

 

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

I don't want to be annoying but try to find something out yourself, I too had to just look at the error logs and look up how things are done in minecraft. E.g. I've only been modding, like what? 2 weeks? Which also applies to java since I come from c++/vb.net and only got into that to mod minecraft.

If you want to get further than this try to be a bit more proactive in finding your problems.

 

Well, I have fixed that issue, now I have discovered something with my testing, you see I was making my block print a certain phrase when it's right clicked with a stick, and noticed it printed it two times, how would I resolve this, for future reference?

 

I have noticed that the right click function, no matter where it is applied to in minecraft, triggers twice. I haven't bothered looking for a solution since if does that it could be an intended feature, and well, it's so easy to fix in the function itself that it really isn't bothersome at all. It might just be however that the basecode doesn't distinguish between a key-down and a key-up so two keysignals are sent.

In any case, don't worry about it.

 

Ok and now I can't seem to understand how to get the texture to change correctly, I seem to be confusing myself

 

You are changing a value in your tileentity class that isn't passed through to your tileentityrender class and secondly, you're trying to load textures in the middle of the runtime of your block, not really ideal if I may say so.

A simple solution: Make a resourcelocation for every texture in your RenderAIBeacon class.

In your Tileentity class(which doesn't seem to be included)create a new byte variable.

If you want to load texture 1, set that var to 1, if you want to load texture 2 set it to 2 etc.

In your render class again, cast your tileentity to your tileentityclass and simple go and get that value with a switch, and if it is 2 bind texture two, if it is 1 bind texture one etc.

Thirdly, the block class is static, e.g. it persists for all blocks that are made of that type, if you would somehow succeed in changing its texture there it would change it for every single other block of that class in your world.

Posted

Hmm, this does make sense.. Kinda ironic, I get high 90's in college level java programming classes, yet minecraft modding makes little sense to me

Member of Aerotech Networks, a Multi-Gaming server.

Also Currently porting the "Rise of the Automatons" minecraft mod

Posted

It triggers once only. Once for client and once for server so it may seem like it triggers twice. When printing debugging lines to console you should always check the side as well (for example if you have World reference, check is World.isRemote returns true or false).

 

To archive desired effect you should decide do you want to use metadata or nbt to store data for texture. If it is just the texture metadata is easiest way to do so. So you store that data in right-click method and in renderer you retrive that data by getting it from block (metadata for example, TileEntity.getWorldObj().getBlockMetadata(.... ) and then check what it is and set correct texture.

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.