Jump to content

Recommended Posts

Posted

Hi.

 

I was wondering if it's possible to "hook" Mobs rendering and substitute with my own, or rather adding effects to their rendering for a specific entity in:

 

for (Entity entity : (List<EntityMob>)worldObj.getEntitiesWithinAABB(EntityMob.class, box)) {
}

 

also contrl their sizes  and everything.

 

Thank you in advance.

Not all things in the world are red, there are round objects too!

Posted

OK, so I read a few tutorials and answers to questions, also some source code and came upp with this:

 

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRenderLivingPre(RenderLivingEvent.Pre event) {

	EntityLivingBase e = event.entity;

	if(e.getEntityData().getBoolean("shouldberesized")) {
		glPushMatrix();
		glScalef(2F, 2F, 2F);
	}

}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRenderLivingPost(RenderLivingEvent.Post event) {

	EntityLivingBase e = event.entity;

	if(e.getEntityData().getBoolean("shouldberesized")) {			
		 glPopMatrix();			

	}
}

 

Dont worry about the "e.getEntityData().getBoolean("shouldberesized")" bit because that works.

Also I didn't translate the position.

 

But thats not my problem.

 

The problem is that the entity (in my test cases, a Creeper) dont get doubled in size, it only floats up and then som strange perspective glitches happen.

That entites behind the creeper gets in front as seen here: http://image.baver.se/img/BOR64wp

 

In the picture, the creeper is standing besides the stone block, and the slime is about 10-15 blocks behind the creeper.

 

So 2 problems, the scaling dont work and that the perspective is off. But maybe the perspective is because it isn't translated?

Not all things in the world are red, there are round objects too!

Posted

 

if the reder works the de same in 1.8.9 as 1.8  you must change the size and respect to dis you must change also the translation to fix your render position, in 1.8 i beeen creating zombies whith diferents sizes form 1.5M to 7M and was a pain i could'n get a formula to calculate it dinamically and end fixing every size and translation at hand

 

f6 is the scaling factor for the render and alt is the heigth the entity must be render whith relation to the ground

 

 

            GlStateManager.scale(1.0F * f6, 1.0F * f6, 1.0F * f6);

           

            GlStateManager.translate(0.0F, alt , 0.0F);

Posted

I tried now with the translate.

And the result is that the creeper now is flying :)

 

http://image.baver.se/img/iqfpdKn

 

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRenderLivingPre(RenderLivingEvent.Pre event) {

	EntityLivingBase e = event.entity;

	if(e.getEntityData().getBoolean("isConsumedSacrificeAltar")) {
		glPushMatrix();
		glScalef(2F, 2F, 2F);
		glTranslatef(0, 4F, 0);
	}

}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onRenderLivingPost(RenderLivingEvent.Post event) {

	EntityLivingBase e = event.entity;

	if(e.getEntityData().getBoolean("isConsumedSacrificeAltar")) {			
		 glPopMatrix();			

	}
}

Not all things in the world are red, there are round objects too!

Posted

in teresting 

in mi render model a positive value in GlStateManager.translate(0.0F, alt , 0.0F); causes the entity to go down, the other thing is mi values are not so high

 

for example mi mob of 4M

           

            //4.M

            case 9:{ f6 = 2.00F  ; alt = -0.75F;  };break;

 

 

a 4 as you have in the code must set the entity very deep down in the ground  so your render model must be diferent from the mine

 

  //#################################################################################################################
    /**
     * Sets the models various rotation angles then renders the model.
     */
    @Override
    public void render(Entity merEntity, float p_78088_2_, float p_78088_3_, float p_78088_4_, float p_78088_5_, float p_78088_6_, float p_78088_7_)
    {
    	
    	//System.out.println("render()");
        this.setRotationAngles(p_78088_2_, p_78088_3_, p_78088_4_, p_78088_5_, p_78088_6_, p_78088_7_, merEntity);
        GlStateManager.pushMatrix();

        if (this.isChild)

        {
            float f6 = 2.0F;
            GlStateManager.scale(1.5F / f6, 1.5F / f6, 1.5F / f6);
                        
            GlStateManager.translate(0.0F, 16.0F * p_78088_7_, 0.0F);
            this.bipedHead.render(p_78088_7_);
            GlStateManager.popMatrix();
            GlStateManager.pushMatrix();
            GlStateManager.scale(1.0F / f6, 1.0F / f6, 1.0F / f6);
            GlStateManager.translate(0.0F, 24.0F * p_78088_7_, 0.0F);
            
            this.exclamacionIcon.render(p_78088_7_);
            this.bipedBody.render(p_78088_7_);
            this.bipedRightArm.render(p_78088_7_);
            this.bipedLeftArm.render(p_78088_7_);
            this.bipedRightLeg.render(p_78088_7_);
            this.bipedLeftLeg.render(p_78088_7_);
            this.bipedHeadwear.render(p_78088_7_);
            
            this.biPhalous_A00.render(p_78088_7_);
            this.biPhalous_B00.render(p_78088_7_);
            this.biPhalous_C00.render(p_78088_7_);
            this.biPhalous_D00.render(p_78088_7_);
        }
        
        else
        {        
        	
        	
        	
        	
        if (merEntity instanceof aldeanoMercenario ){
        aldeanoMercenario merc = (aldeanoMercenario) merEntity;

        //lrsb = merc.getDataWatcher().getWatchableObjectInt(23);
        lrsb = merc.getLrsb();
        }

        if (merEntity instanceof zombieMercenario ){
        zombieMercenario merc = (zombieMercenario) merEntity;

        //lrsb = merc.getDataWatcher().getWatchableObjectInt(23);
        lrsb = merc.getLrsb();
        }

        if (merEntity instanceof zombieMercenarioE ){
        zombieMercenarioE merc = (zombieMercenarioE) merEntity;

        //lrsb = merc.getDataWatcher().getWatchableObjectInt(23);
        lrsb = merc.getLrsb();
        }
        
        
        tamaño			= (byte) ((lrsb % 10000000 	) / 1000000		);
        
            float f6 = 0.0F ;
            float alt = 0.0F;
                 
            
            switch(tamaño)
            {
                       
            //1.5M
            case 1:{ f6 = 0.75F  ; alt = 0.5F  ;  };break; 
            
            //1.624M
            case 2:{ f6 = 0.812F ; alt = 0.4F  ;  };break; 

            //1.75M
            case 3:{ f6 = 0.875F ; alt = 0.2F  ;  };break; 
            
            //1.87M
            case 4:{ f6 = 0.9375F; alt = 0.05F ;  };break; 

            //2.00M
            default:{ f6 = 1.0F  ; alt = 0.00F ;  };break; 
            
            //2.25M
            case 6:{ f6 = 1.125F ; alt = -0.15F;  };break; 

            //2.5M
            case 7:{ f6 = 1.25F  ; alt = -0.3F ;  };break; 
            
            //3.0M
            case 8:{ f6 = 1.5F  ; alt = -0.5F  ;  };break; 
            
            //4.M
            case 9:{ f6 = 2.00F  ; alt = -0.75F;  };break; 
   
            //7M
            case 10:{ f6 = 3.5F   ; alt = -1.00F;  };break; 
            }
            
            GlStateManager.scale(1.0F * f6, 1.0F * f6, 1.0F * f6);
            
            GlStateManager.translate(0.0F, alt , 0.0F); 
             
        	if (merEntity.isSneaking())
            {
                GlStateManager.translate(0.0F, alt + 0.2F, 0.0F);
            }

        	this.exclamacionIcon.render(p_78088_7_);
            this.bipedHead.render(p_78088_7_);
            this.bipedBody.render(p_78088_7_);
            this.bipedRightArm.render(p_78088_7_);
            this.bipedLeftArm.render(p_78088_7_);
            
            this.villagerArms.render(p_78088_7_);
            this.bipedRightLeg.render(p_78088_7_);
            this.bipedLeftLeg.render(p_78088_7_);
            this.bipedHeadwear.render(p_78088_7_);
            
            this.biPhalous_A00.render(p_78088_7_);
            this.biPhalous_B00.render(p_78088_7_);
            this.biPhalous_C00.render(p_78088_7_);
            this.biPhalous_D00.render(p_78088_7_);
        }
       
        GlStateManager.popMatrix();
        

Posted

Ok, made some progress..

 

If I only scale Y to 2F

then the creeper gets taller, but now seems stretched because i only scaled Y.

GL11.glScalef(1F, 2F, 1F);

 

http://image.baver.se/img/nxeP8Po

 

But then if I scale all (X Y Z) the Y scaling disappear.

GL11.glScalef(2F, 2F, 2F);

 

http://image.baver.se/img/NDm60iN

 

Am I thinking wrong?

Not all things in the world are red, there are round objects too!

Posted

I think your pushing and popping of the matrix is probably screwing up. You have them both happen conditionally, but what if one of the conditions isn't true? You might do extra pops or pushes. Furthermore, I'm not certain what happens if you push in the Pre event and pop in the Post event because these events are called for ALL the entities. So what will happen is that it will push, push, push, and then pop, pop, pop.

 

I think you shouldn't need a matrix at all because I believe the render event should already have a matrix that is focused on the entity of interest. So I'd try just scaling directly.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

The condition is the same for both the push and pop, so if the condition is true for the push it is also true for the pop.

 

But you were right about the pushing and popping, commented those lines and tried again.

 

Now the creeper scales in all directions perfectly (Only my translation that is screwed now, but I will fix it)

 

BUT.. Theres always a but :P

 

Now my tileentity also goes flying in the air.

 

So the ariginal problem is solved, thanks.

 

Now I will troubleshoot why my tilentity fly in the air. But thats probably because my translation is f* up ;)

 

[EDIT]

It seems like if i dont push and pop signs and other mobs get screwed up.

[EDIT2]

It only happens if I look at the creeper though.

 

Not all things in the world are red, there are round objects too!

Posted

Only my translation that is screwed now, but I will fix it

 

if you scale you always need to also translate because otherwise the entity will scale into the ground. So you have to translate by the eye level then translate back by new scaled eye level.

 

I figured out the formula for that: GL11.glTranslatef(0F, 1.5F-1.5F*scaleFactor, 0F);

 

Maybe that is the issue you've been facing -- the model origin is offset from the entity origin by the eye level?

 

Not sure about your entity flying away problem though...

 

Instead of events, if this is for your own custom entities only, you can @Override  the preRenderCallback() method in the custom Renderer class for your entity. I usually do my entity scaling there. Or you could also do it within your Model class.

 

If you want to do the scaling for all entities then yes you need to get the events working for you.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.