Jump to content

[Solved]TileEntitySpecialRenderer not rendering based on adjacent blocks[1.6]


Recommended Posts

Posted

Hello,

 

I made a cable-like block with a custom model etc. and the middle part renders always as i want to, but it doesn't render other parts based on the cables next to it.

 

[spoiler=TileEntitySpecialRenderer]

package larsg310.mod.techcraft.renderer.tileentity;

import larsg310.mod.techcraft.lib.ConnectingIds;
import larsg310.mod.techcraft.lib.Reference;
import larsg310.mod.techcraft.model.ModelRedstonePowerCable;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

public class TileEntityRedstonePowerCableRenderer extends TileEntitySpecialRenderer
{
private ModelRedstonePowerCable model;
public ResourceLocation REDSTONE_POWER_CABLE_TEXTURE = new ResourceLocation(Reference.MOD_ID, "textures/model/ModelRedstonePowerCable.png");

public TileEntityRedstonePowerCableRenderer()
{
	this.model = new ModelRedstonePowerCable();
}
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)
{
	World world = tileentity.worldObj;

	GL11.glPushMatrix();
	GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
	GL11.glRotatef(180, 0, 0, 1);
	this.bindTexture(REDSTONE_POWER_CABLE_TEXTURE);
	GL11.glPushMatrix();
	model.renderAll(world, (int)x, (int)y, (int)z);
	GL11.glPopMatrix();
	GL11.glPopMatrix();
}
}

 

 

[spoiler=Model Class]

package larsg310.mod.techcraft.model;

import larsg310.mod.techcraft.lib.ConnectingIds;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;

public class ModelRedstonePowerCable extends ModelBase
{
ModelRenderer Middle;
    ModelRenderer ExtensionNorth;
    ModelRenderer ExtensionEast;
    ModelRenderer ExtensionSouth;
    ModelRenderer ExtensionWest;
    ModelRenderer ExtensionDown;
    ModelRenderer ExtensionUp;
  
  public ModelRedstonePowerCable()
  {
      textureWidth = 64;
      textureHeight = 64;
    
      Middle = new ModelRenderer(this, 0, 0);
      Middle.addBox(0F, 0F, 0F, 4, 4, 4);
      Middle.setRotationPoint(-2F, 14F, -2F);
      Middle.setTextureSize(64, 64);
      Middle.mirror = true;
      setRotation(Middle, 0F, 0F, 0F);
      ExtensionNorth = new ModelRenderer(this, 0, 9);
      ExtensionNorth.addBox(0F, 0F, 0F, 4, 4, 6);
      ExtensionNorth.setRotationPoint(-2F, 14F, 2F);
      ExtensionNorth.setTextureSize(64, 64);
      ExtensionNorth.mirror = true;
      setRotation(ExtensionNorth, 0F, 0F, 0F);
      ExtensionEast = new ModelRenderer(this, 0, 20);
      ExtensionEast.addBox(0F, 0F, 0F, 6, 4, 4);
      ExtensionEast.setRotationPoint(2F, 14F, -2F);
      ExtensionEast.setTextureSize(64, 64);
      ExtensionEast.mirror = true;
      setRotation(ExtensionEast, 0F, 0F, 0F);
      ExtensionSouth = new ModelRenderer(this, 0, 9);
      ExtensionSouth.addBox(0F, 0F, 0F, 4, 4, 6);
      ExtensionSouth.setRotationPoint(-2F, 14F, -8F);
      ExtensionSouth.setTextureSize(64, 64);
      ExtensionSouth.mirror = true;
      setRotation(ExtensionSouth, 0F, 0F, 0F);
      ExtensionWest = new ModelRenderer(this, 0, 20);
      ExtensionWest.addBox(0F, 0F, 0F, 6, 4, 4);
      ExtensionWest.setRotationPoint(-8F, 14F, -2F);
      ExtensionWest.setTextureSize(64, 64);
      ExtensionWest.mirror = true;
      setRotation(ExtensionWest, 0F, 0F, 0F);
      ExtensionDown = new ModelRenderer(this, 0, 29);
      ExtensionDown.addBox(0F, 0F, 0F, 4, 6, 4);
      ExtensionDown.setRotationPoint(-2F, 18F, -2F);
      ExtensionDown.setTextureSize(64, 64);
      ExtensionDown.mirror = true;
      setRotation(ExtensionDown, 0F, 0F, 0F);
      ExtensionUp = new ModelRenderer(this, 0, 29);
      ExtensionUp.addBox(0F, 0F, 0F, 4, 6, 4);
      ExtensionUp.setRotationPoint(-2F, 8F, -2F);
      ExtensionUp.setTextureSize(64, 64);
      ExtensionUp.mirror = true;
      setRotation(ExtensionUp, 0F, 0F, 0F);
  }
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Middle.render(f5);
    ExtensionNorth.render(f5);
    ExtensionEast.render(f5);
    ExtensionSouth.render(f5);
    ExtensionWest.render(f5);
    ExtensionDown.render(f5);
    ExtensionUp.render(f5);
  }
  public void renderAll(World world, int x, int y, int z)
  {
    Middle.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "north")) ExtensionNorth.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "east")) ExtensionEast.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "south")) ExtensionSouth.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "west")) ExtensionWest.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "up")) ExtensionDown.render(0.0625F);
    if(ConnectingIds.getCableConnectings(world, x, y, z, "down")) ExtensionUp.render(0.0625F);
  }
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
  {
    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
  }
}

 

 

I'm not putting in the ConnectingIds class, because i know it works because i'm using it to make the block bounds in the block class. If you need mor classes i'll put them here.

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't be the cause of the code you've put here if you say the middle part renders. The cables will render if you remove the check if they are connected or not right? Then it should be the cause of the check. I would suggest placing a breakpoint just before a check and tracing down why it returns false.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}
public static boolean getCableConnectings(World world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction);
}
public static int getNorthBlock()
{
	return world.getBlockId(x-1, y, z);
}
public static int getSouthBlock()
{
	return world.getBlockId(x+1, y, z);
}
public static int getEastBlock()
{
	return world.getBlockId(x, y, z-1);
}
public static int getWestBlock()
{
	return world.getBlockId(x, y, z+1);
}
public static int getUpBlock()
{
	return world.getBlockId(x, y-1, z);
}
public static int getDownBlock()
{
	return world.getBlockId(x, y+1, z);
}
public static boolean isConnecting(String direction)
{
	boolean north = false;
	boolean east = false;
	boolean south = false;
	boolean west = false;
	boolean up = false;
	boolean down = false;

	if(direction == "north")
	{
		if(getNorthBlock() == TCBlocks.redstonePowerCable.blockID) north = true;
		else if(getNorthBlock() == TCBlocks.redstonePowerGenerator.blockID) north = true;
		return north;
	}
	if(direction == "south")
	{
		if(getSouthBlock() == TCBlocks.redstonePowerCable.blockID) south = true;
		else if(getSouthBlock() == TCBlocks.redstonePowerGenerator.blockID) south = true;
		return south;
	}
	if(direction == "east")
	{
		if(getEastBlock() == TCBlocks.redstonePowerCable.blockID) east = true;
		else if(getEastBlock() == TCBlocks.redstonePowerGenerator.blockID) east = true;
		return east;
	}
	if(direction == "west")
	{
		if(getWestBlock() == TCBlocks.redstonePowerCable.blockID) west = true;
		else if(getWestBlock() == TCBlocks.redstonePowerGenerator.blockID) west = true;
		return west;
	}
	if(direction == "up")
	{
		if(getUpBlock() == TCBlocks.redstonePowerCable.blockID) up = true;
		else if(getUpBlock() == TCBlocks.redstonePowerGenerator.blockID) up = true;
		return up;
	}
	if(direction == "down")
	{
		if(getDownBlock() == TCBlocks.redstonePowerCable.blockID) down = true;
		else if(getDownBlock() == TCBlocks.redstonePowerGenerator.blockID) down = true;
		return down;
	}
	return false;
}
}

 

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

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}

 

 

Gah! x..X

Don't use static variables like that.  While it's not messing up when executed, its generally not good practice.  Those are prime examples of values that should be passed to the various functions that use them.

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

Serieusly, i can't find it. Here's some more code:

[spoiler=ConnectingIds]

package larsg310.mod.techcraft.lib;

import larsg310.mod.techcraft.block.TCBlocks;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ConnectingIds
{
private static IBlockAccess world;
private static int x;
private static int y;
private static int z;

public static boolean getCableConnectings(IBlockAccess world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;

	return isConnecting(direction); 
}

 

 

Gah! x..X

Don't use static variables like that.  While it's not messing up when executed, its generally not good practice.  Those are prime examples of values that should be passed to the various functions that use them.

Ok, I'll change that after it renders. I have a picture of the bounding boxes that work, and use the same class. Maybe it has something to with that the boundingbox method passes the IBlockAccess variable to the ConnectingIds class, but the TileEntitySpecialRenderer class a worldObj.

[spoiler=Image]3DzAYT2.png

 

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

I've been trying to figure it out for about 3 days, but i can't find the problem. I really need the help!

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

Hi

 

I've spent a few minutes looking at your posts and code and to be honest I really don't understand what it is supposed to do, or how it is supposed to work.

 

Could you describe to us in some more detail what you're trying to do?  What are "cables", "middle parts", and "extensions"?  Perhaps you could mock up a screenshot of what the possible arrangements should be, using (say) stone for middle parts and something else for cables (redstone? wood?)

 

-TGG

 

Posted

Ok, i'm gonna do my best to explain it.

 

First of all the middle part is what is supposed to render all the time, even if there are no other cables next to it. The extensions are the part that need to render based on adjacent cables, like if there are 2 cables next to each other and they are connecting. In my bounding box picture you can see what i mean with "connecting" [spoiler=Bounding Boxes]3DzAYT2.png

As you can see,the bounding boxes are extending out to the cable block next to it, and the same for the other directions. In this picture:

 

pX0pgwZ.png

you can see that if there are 2 cables (stone) next to each other the extensions (repeaters) are facing to the cable next to it. And if there are no other cables next to it, it doesn't render any extensions at all.

yT7oBgg.png

I hope that i explained it well enough to understand, and if you need more explanation, just aks  ;)

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

Hi

 

OK I think I understand better.

 

A couple of further questions..

 

if you modify your  code to this, what do you see?  Are the Extensions rendering in all six directions properly?  Or just the middle?

public void renderAll(World world, int x, int y, int z)
  {
    Middle.render(0.0625F);
    ExtensionNorth.render(0.0625F);
    ExtensionEast.render(0.0625F);
    ExtensionSouth.render(0.0625F);
    ExtensionWest.render(0.0625F);
    ExtensionDown.render(0.0625F);
    ExtensionUp.render(0.0625F);
  }

 

-TGG

 

Posted

Yeah, they do render if i put that instead, so it must be with the if checks, but i dont see why, it's working for my bounding boxes.

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

Hi

 

Do you know how to use breakpoints?  If so I suggest you add a breakpoint in your renderAll, then trace into your getCableConnectings to see why it's not working.

 

Otherwise, you could add logging code to your methods to see what's happening.

 

	public static boolean getCableConnectings(World world1, int x1, int y1, int z1, String direction)
{
	world = world1;
	x = x1;
	y = y1;
	z = z1;
	System.out.println("getCableConnectings (" + x1 + "," + y1 + "," + z1 + "):" + direction);
	return isConnecting(direction);
}
public static int getNorthBlock()
{
	System.out.println("getNorthBlock (" + (x-1) + "," + y + "," + z +"):" +world.getBlockId(x-1, y, z));
	return world.getBlockId(x-1, y, z);
}
public static int getSouthBlock()
{
	System.out.println("getSouthBlock (" + (x+1) + "," + y + "," + z +"):" +world.getBlockId(x+1, y, z));
            return world.getBlockId(x+1, y, z);
}

{etc}

 

It looks to me like your blockIDs probably aren't right for some reason.

 

-TGG

 

Posted

If i place it on the coordinates (114, 64, 436) it gives me this log:

 

2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (-1, -2, 0
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436
2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436

It seems like it can't always find the right coordinates, but it mostly will, but even then, it's not rendering

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

Hi

 

That's odd

 

I don't understand why this code

		System.out.println("getNorthBlock (" + (x-1) + "," + y + "," + z +"):" +world.getBlockId(x-1, y, z));

give this output

2013-11-03 10:07:11 [iNFO] [sTDOUT] getNorthBlock (113, 64, 436

and why

System.out.println("getCableConnectings (" + x1 + "," + y1 + "," + z1 + "):" + direction);

isn't printing anything.

 

North of (114, 64, 436) is (114, 64, 435) not (113, 64, 436)

 

The point of the logging was to see what the blockID is.  But to be honest I think it would be time well-spent to tear up your ConnectingId class and rewrite it without the static variables.  It might help make the cause of the bug clearer.

 

-TGG

Posted

After a bit of testing, it seems like to me, that the TileEntityRedstonePowerCable#renderTileEntityAt is passing the players position OR the coordinates (0,0,0), cause in the IItemRenderer class (which i will be implementing once this is working) is passing the coordinates (0,0,0)

TileEntityRenderer.instance.renderTileEntityAt(new TileEntityRedstonePowerCable(), 0D, 0D, 0D, 0F);

but i don't know howto put the right coordinates there...

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

Ah now that you say that I think I know what you're problem is! You're using the coordinates given in the TESR method, but these are not world coordinates, these are relative render coordinates and only tell you how much you need to translate the render matrix!

 

TileEntityRenderer, line 157

this.renderTileEntityAt(par1TileEntity, (double)par1TileEntity.xCoord - staticPlayerX, (double)par1TileEntity.yCoord - staticPlayerY, (double)par1TileEntity.zCoord - staticPlayerZ, par2);

 

So the solution is to use tileEntity.xCoord to get all the world coordinates.

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

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.