Jump to content

Recommended Posts

Posted

Hello,

I checked the BlockWall class and made my own.

How would i check for other walls that have metadata?

For example i have made walls based on the minecraft clayblocks. so 16 colors.

 

I have this now:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {
	Block block = par1.getBlock(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall ){
		return true;
	}
        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

This works exactly how it should, but i wonder how i check for a block with metadata!

I really have no clue how to do that.

I have tried TemBlocks.claywall but that doesn't work

Posted

what do you mean with update? update what?

 

I have also no idea how to use this: IBlockAccess#getBlockMetadata

I know getBlockMetadata, but ....

I'll try some stuff

 

Edit:

I understand you don't want us to present chewed code. I do not ask for that either.

But some vague words do not help me at all, i'm sorry.

I'm 32 years old and i like programming, but i'm not that good skilled.

I came to this forum desperately searching for help for things i really can't figure out!

I know how to look into the minecraft classes and make my own extending them etc etc.

I almost did everything by myself, except by following tutorials

I hope you understand this

 

thank you

Posted

I'm using 1.7.10 because i like to have my own modded Cauldron server.

Just because cauldron support both mods and plugins.

Because there aren't any good enough (my opinion) antigriefing mods for 1.8 and higher, i'm

forced to use GriefPrevention (plugin).

I have already looked into how to mod in 1.8. I have set up a workspace for that.

Now i'm being offtopic, so back to the topic:

 

I know this is a method :getBlockMetadata

I know it returns the meta when called.

I also know how to use it.

It returns an integer and that's my problem. I just don't know how the pieces fit together

 

block==TemBlocks.claywalls

for example an itemstack is much easier then you would do this:

block == new ItemStack(TemBlocks.claywalls,1,0)

But since i can't use itemstacks(ofc not) i can't check specific for that block with metadata 0 (in this example it's 0)

Posted

for example an itemstack is much easier then you would do this:

block == new ItemStack(TemBlocks.claywalls,1,0)

That wouldn't work. For one, I assume 'block' is an instance of Block, which you are trying to test equality against an ItemStack. Totally different things. For another, ItemStack equality does not compare will with the '==' operator - that actually checks identity (Google it).

 

If you want to test equality of a block + metadata, that is exactly what you do:

// let's assume 'World world', 'Block block', int 'x', 'y', and 'z' are given as method parameters
int meta = world.getBlockMetadata(x, y, z);
if (block == TemBlocks.claywalls && meta == 0) {
  // there you go
}

Posted

Well first of all, what i said about that ItemStack stuff was just an example. I know you can't use that in there.

I thought i made that clear. Sorry but my english isn't that good, wich results is bad explanations sometimes.

 

ok so second i tried this already before and it doesn't work:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {
	Block block = par1.getBlock(par2, par3, par4);
	int meta = par1.getBlockMetadata(par2, par3, par4);
	//int meta = par1.getBlockMetadata(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall 
	   ){
		return true;
	}
	if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) ||
		(block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){
			return true;
		}


        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

I haven't provided a World parameter because i'm overriding the method. It doesn't ask me for a world. So i used the first parameter.

For me it seems like it doesn't do anything.

This code was what i came up by myself, but since it didn't worked i came asking help here

Posted

IBlockAccess is roughly equivalent to a World object.

 

Instead of that mess of conditions, you could greatly simplify it:

if (block instanceof BlockWall) {
   return true; // this should cover almost that entire wall of text
}

// this one:
if ((block==TemBlocks.claywalls && meta ==0) || (block==TemBlocks.claywalls && meta ==1) || (block==TemBlocks.claywalls && meta ==2) ||
		(block==TemBlocks.claywalls && meta ==3) || (block==TemBlocks.claywalls && meta ==4) || (block==TemBlocks.claywalls && meta ==5)){
			return true;
		}

// can be changed to:
if (block==TemBlocks.claywalls && meta < 6) {
  return true;
}
// you'll want to check that one before the instanceof BlockWall check, however, or meta will be ignored

// and this part:
block != this
// do you not want your wall blocks to be able to connect to themselves? Seems weird, but okay

If it's not working as you expect, try something simpler at first: always return true. Does your block connect to everything? Good, at least you know that part is working, and now you can start introducing some logic into it one piece at a time.

 

If it didn't work, then you can rule out your #canConnectWallTo implementation as the problem and begin looking elsewhere for issues.

Posted

Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours.

 

Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Using "instanceof" means that your walls will connect to any other mod's walls that extend BlockWall. That would mean that yours would connect to mine (see Uncle Jeff's Anystone Walls at CurseForge), and mine would connect to yours.

 

Also: Don't forget gates (using the same "instanceof" so you connect to my iron gate etc).

'instanceof BlockWall' means that yes, but not 'instanceof' - he can use 'instanceof CustomBlockWall' or whatever his Block class is and restrict the connections to his custom wall blocks instead of allowing all, if that's what he wants, but I assumed he would want them to connect to other walls as well (the logical thing to allow in most cases).

Posted

Ok i found the problem....

For some reason i made my metawalls having each a different id, so i remade my CustomWallsColored.class so it has metadata. Really i facepalmed when i figured that out lol.

 

So now it works perfectly and it looks like this:

@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {

	Block block = par1.getBlock(par2, par3, par4);
	int meta = par1.getBlockMetadata(par2, par3, par4);
	//int meta = par1.getBlockMetadata(par2, par3, par4);
	if(block==TemBlocks.andesitewall || block==TemBlocks.smoothandesitewall || block==TemBlocks.andesitebrickwall ||
	   block==TemBlocks.dioritewall || block==TemBlocks.smoothdioritewall || block==TemBlocks.dioritebrickwall || 
	   block==TemBlocks.granitewall || block==TemBlocks.smoothgranitewall || block==TemBlocks.granitebrickwall ||
	   block==TemBlocks.prismarinewall || block==TemBlocks.smoothprismarinewall || block==TemBlocks.darkprismarinewall ||
	   block==TemBlocks.chalkstonewall || block==TemBlocks.smoothchalkstonewall || block==TemBlocks.chalkstonebrickwall ||
	   block==TemBlocks.marblestonewall || block==TemBlocks.smoothmarblestonewall || block==TemBlocks.marblestonebrickwall){
		return true;
	}
	for(int i=0; i<16; i++){
		if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){
				return true;
			}
		}
        return block != this && block != Blocks.fence_gate ? (block.getMaterial().isOpaque() && block.renderAsNormalBlock() ? block.getMaterial() != Material.gourd : false) : true;
    }

I also made a for loop to shorten the code.

 

I will take a look at that "instanceof", it would be much better if it can connect to any wall of any mod.

Posted

Your for loop is kinda... pointless.

for(int i=0; i<16; i++){
if ((block==TemBlocks.claywalls && meta ==i) || (block==TemBlocks.claybrickwalls && meta ==i) || (block==TemBlocks.brickswalls && meta ==i) ){
	return true;
}
}

If you think about what that is doing, i starts at 0 and goes all the way to 15, so every value less than 16, which is every possible metadata value for a Block... why even check?

 

And if you DO want to check meta for some reason, why do it in a for loop when you can just check it like this:

if (meta < 16 && (block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls)) {
   // the block is one of the ones you want and the meta is from 0 to 15...
   // same exact logic as your for loop, but far more efficient and succinct
}

Posted

I don't think my for loop is pointless, because it cycles trough all the metadata.

That's the point of it. If i don't make that check the walls do not connect to eachother. I tried that before!

Ofc your stuff works also.

Mine code checks every metadata and your checks is it's smaller than 16.

I agree to the "same exact logic" but not the far more efficient. Perhaps yours is a bit more efficient.

I learned to use for loops in c++ because they are very powerfull and fast. So why would that be different in java?

Besides that i like to use for loops and my code works.

Even more important is knowing what the code does and so i do!

 

Anyway i thank you for posting your variant

Posted

I don't think my for loop is pointless, because it cycles trough all the metadata.

 

And then doesn't give a shit what the actual value of the metadata was, because it performed the same check on all of them:

meta == i

It doesn't matter what value

meta

was from the world (because it can only be 0 to 15), at some point during that loop that check will be true.

 

Following that, because you are doing

return true

in the block-check, as soon as it determines that yes, one of these blocks is what we're looking for it never even fucking checks your loop.

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

To be fair, the blocks in the for loop are not included in the preceding if statement, but that does not mean the for loop has a point.

 

Just think about it step by step:

for loop breaks down to this, basically:
if (block correct and 0 == meta) return true;
if (block correct and 1 == meta) return true;
if (block correct and 2 == meta) return true;
// and on up to 15

So, if at any point the metadata value is the same as i, you return true. The metadata value can only be a value from 0 to 15, and you check ALL of those values, so by very nature of the code, at some point i has to equal the metadata value, making the metadata value and thus your for loop completely unnecessary.

 

It literally does nothing different than simply checking if (block == clayWall) for those 3 blocks.

Posted

Just use the elegant block instanceof BlockWall expression already so you won't need this discussion of loops and meta values. And don't forget what I said about gates. For that matter, you might want to think about fences too.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I removed the for loop and changed it to this:

block==TemBlocks.claywalls || block==TemBlocks.claybrickwalls || block==TemBlocks.brickswalls

 

So apparently i do not need to check metadata.

I tried this before and it didn't worked, but that's because i created the walls wrong (they had no metadata at all, and now they do)

 

Thanks for those who helped me out, i really appreciate it.

 

@Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that.

I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this.

If you wanne help me out like an adult or (if you aren't an adult) like a child with good manners, i will be very happy to hear from you.

thank you for understanding.

Posted

@Draco18s : I think you "shit" and "fucks" to much. You can talk to me like a normal person. I would appreciate that.

I'm just a normal guy 32 years old who likes to learn something new. If you want to talk to me like a 12 year old wannebecoolboy, srry i don't have time for this.

 

And we don't have time to have you ignore what we tell you three times. :)

 

You know, like this bit:

 

So apparently i do not need to check metadata.

 

That was pointed out to you at least twice, this is not a surprise revelation.

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

Your expression does not address gates. Shouldn't your walls connect to gates?

 

And what about other mods? Don't you want to connect to other extensions of BlockWall?

 

And what about torches? Can you put a torch on top of your wall?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

  • 3 weeks later...
Posted

Your expression does not address gates. Shouldn't your walls connect to gates?

 

And what about other mods? Don't you want to connect to other extensions of BlockWall?

 

And what about torches? Can you put a torch on top of your wall?

Srry, i didn't saw your post untill now.

Even when it's fixed now, i can still post what i have.

You'll never know if someone could find his answers here.

So here it is:

 

package winnetrie.tem.block;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.BlockWall;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class CustomWalls extends BlockWall {

private Block icon;
private int metaType;
public CustomWalls(Block block, int meta) {
	super(block);
	this.useNeighborBrightness=true;
	this.setCreativeTab(TemBlocks.extrawalls);
	this.icon=block;
	this.metaType=meta;
}
@Override
@SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return  icon.getIcon(side, metaType);
    }
@Override
@SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemstack, CreativeTabs tabs, List list)
    {
	list.add(new ItemStack(itemstack, 1, 0));
    }
@Override
@SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_) {}

public int getRenderType()
    {
        return 32;
    }
public boolean renderAsNormalBlock()
    {
        return false;
    }
@Override
public boolean canPlaceTorchOnTop(World world, int x, int y, int z){
	return true;
}
@Override
public boolean canConnectWallTo(IBlockAccess par1, int par2, int par3, int par4)
    {
	Block block = par1.getBlock(par2, par3, par4);
	int meta = par1.getBlockMetadata(par2, par3, par4);
	return block== this || block instanceof BlockWall || block.isOpaqueCube() || block instanceof BlockFenceGate || block instanceof BlockFence ;
    }
}

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

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

×
×
  • Create New...

Important Information

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