Jump to content

Recommended Posts

Posted

Hello Forums,

 

As you already know if you read the title, I'm trying to draw the Player in a Front view onto a GUI.

I don't want/need it to be 3D and therefore dont really want to use the code from the Player Inventory.

 

Can anyone explain to me or post a link to a tutorial how i could do that?

Thanks in advance.

Posted

Draw quads that form the players body (head, legs, arms) and then use the players skin to bind the texture.

First, thank you for that, you at least gave me a starting point to begin with.

But I'm still struggling with this.

 

This Code:

 

public CyberneticsMonitorGui(EntityPlayer player, World world, int x, int y, int z) {
	this.x = x;
	this.y = y;
	this.z = z;
	this.player = player;
	this.world = world;
	this.xSize = 176;
	this.ySize = 192;
}

@Override
public void drawScreen(int mouseX, int mouseY, float renderPartialTicks) {
	this.mc.getTextureManager().bindTexture(image);
	int x = (this.width - xSize) / 2;
	int y = (this.height - ySize) / 2;
	drawTexturedModalRect(x, y, 0, 0, xSize,  ySize);

	drawPlayer(x, y);
}

private void drawPlayer(int x, int y){
	this.mc.getTextureManager().bindTexture(AbstractClientPlayer.locationStevePng);
	int scale = 3;

	//The Coordinates of the panel to draw the player on on the gui
	int panelCornerX = 122;
	int panelCornerY = 11;

	//modify x and y to reduce lenght of drawing call
	x = x + panelCornerX;
	y = y + panelCornerY;

	//Define the sizes and places of the body parts.
	int Uhead = 8;
	int Vhead = 8;
	int Hhead = 8;
	int Whead = 8;
	int Xhead = 4;
	int Yhead = 0;

	int Utorso = 20;
	int Vtorso = 20;
	int Htorso = 12;
	int Wtorso = 4;
	int Xtorso = 4;
	int Ytorso = 8;

	int Uarm = 44;
	int Varm = 20;
	int Harm = 12;
	int Warm = 4;
	int Xarm1 = 0;
	int Yarm1 = 8;
	int Xarm2 = 12;
	int Yarm2 = 8;

	int Uleg = 4;
	int Vleg = 20;
	int Hleg = 12;
	int Wleg = 4;
	int Xleg1 = 4;
	int Yleg1 = 20;
	int Xleg2 = 8;
	int Yleg2 = 20;

	drawPixels(x + Xhead, y + Yhead, Uhead, Vhead, Whead, Hhead, scale);
	drawPixels(x + Xtorso, y + Ytorso, Utorso, Vtorso, Wtorso, Htorso, scale);
	drawPixels(x + Xarm1, y + Yarm1, Uarm, Varm, Warm, Harm, scale);
	drawPixels(x + Xarm2, y + Yarm2, Uarm, Varm, Warm, Harm, scale);
	drawPixels(x + Xleg1, y + Yleg1, Uleg, Vleg, Wleg, Hleg, scale);
	drawPixels(x + Xleg2, y + Yleg2, Uleg, Vleg, Wleg, Hleg, scale);
}

/**
 * Draws the Specified Rectangle on the last binded texture at thrice the size.
 * @param times The factor to scale with
 */
private void drawPixels(int x, int y, int u, int v, int width, int height, int times){
	for(int cu = u; cu < u + width; cu++){
		for(int cv = v; cv < v + height; cv++){
			for(int factor = 0; factor < times; factor++){
				drawTexturedModalRect(x + (cu*3) + factor, y + (cv*3) + factor, cu + u, cv + v, 1, 1);
			}
		}
	}
}

 

Results in:

 

a8a326e3e5.jpg

 

Posted

Hello Forums,

 

As you already know if you read the title, I'm trying to draw the Player in a Front view onto a GUI.

I don't want/need it to be 3D and therefore dont really want to use the code from the Player Inventory.

 

Can anyone explain to me or post a link to a tutorial how i could do that?

Thanks in advance.

 

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

public static int rotate = 0;
public static void drawPlayerOnGui(Minecraft mc, int par1, int par2, int par3, float par4, float par5)
{
	rotate ++;
	if(rotate >= 360){
		rotate = 0;
	}
	GL11.glEnable(GL11.GL_COLOR_MATERIAL);
	GL11.glPushMatrix();
	GL11.glTranslatef((float)35, (float)120, 50.0F);
	GL11.glScalef((float)(-30), (float)30, (float)30);
	GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(-((float)Math.atan((double)(par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);

	GL11.glTranslatef(0.0F, mc.thePlayer.yOffset, 0.0F);
	RenderManager.instance.playerViewY = 180.0F;
	GL11.glPushMatrix();
	GL11.glRotatef(180, 0, 0, 1);
	GL11.glRotatef(rotate, 0, 1, 0);

	RenderManager.instance.renderEntityWithPosYaw(mc.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
	GL11.glPopMatrix();
	GL11.glPopMatrix();
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}

Posted

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

//Some Code
}

 

I tried to avoid that because I don't udnerstand what exactly is happening and therefore can only modify it with trial and error.

I'm now using the version of that code used in the inventory until something other comes up, but the arms move and the Item the Player is holding is drawn too.

Any Idea how I can prevent that?

Posted

If you are actually drying the draw the player itself onto the screen then try this. This is some OLD code (1.5.2) so it very well may not work.

//Some Code
}

 

I tried to avoid that because I don't udnerstand what exactly is happening and therefore can only modify it with trial and error.

I'm now using the version of that code used in the inventory until something other comes up, but the arms move and the Item the Player is holding is drawn too.

Any Idea how I can prevent that?

That IS the code that was used in the inventory. And you can't make the arms not move because you are directly calling upon the player's render. In order for that to work the way you want, you would have to create a new model and not bind it to an entity in order for that to work.

Posted

@deadrecon98

You have weird way of helping ppl. Not that I am condemning that you want to help, but if you don't know how to make something, please don't say "you can't" or "you must do it that way". Don't take it as offense please.

 

But now back to thread:

Drawin player is quite simple. As long as you have players skin loaded it's even simplier.

// Only for Client-side!!!
ResourceLocation skin = ((AbstractClientPlayer) player).getLocationSkin();

This will give you read-to-use resource, if reffered player has cached skin on your client.

 

Next you can do whetever the hell you want with it.

this.mc.getTextureManager().bindTexture(skin); //bind texture to renderer
this.drawTexturedModalRect(xPos, yPos, xOffset, yOffset, width, height);

 

Edit: Start with drawTexturedModalRect(0, 0, 0, 0, 256, 256); - it should give the idea of how to move texture around.

 

You can render parts of resource few times to archive full player front-texture.

 

Quite simple.

 

As to code provided by deadrecon98 - this is very outdated code. in 1.7.10 you can find new one for rendering player (probably in GuiInventory, i don't remember) and in 1.8 there is even renderer for EntityLivingBase.

1.7.10 is no longer supported by forge, you are on your own.

Posted

@deadrecon98

You have weird way of helping ppl. Not that I am condemning that you want to help, but if you don't know how to make something, please don't say "you can't" or "you must do it that way". Don't take it as offense please.

 

But now back to thread:

Drawin player is quite simple. As long as you have players skin loaded it's even simplier.

// Only for Client-side!!!
ResourceLocation skin = ((AbstractClientPlayer) player).getLocationSkin();

This will give you read-to-use resource, if reffered player has cached skin on your client.

 

Next you can do whetever the hell you want with it.

this.mc.getTextureManager().bindTexture(skin); //bind texture to renderer
this.drawTexturedModalRect(xPos, yPos, xOffset, yOffset, width, height);

 

Edit: Start with drawTexturedModalRect(0, 0, 0, 0, 256, 256); - it should give the idea of how to move texture around.

 

You can render parts of resource few times to archive full player front-texture.

 

Quite simple.

 

As to code provided by deadrecon98 - this is very outdated code. in 1.7.10 you can find new one for rendering player (probably in GuiInventory, i don't remember) and in 1.8 there is even renderer for EntityLivingBase.

 

It works now, thanks!

 

There was one problem with the texture being cropped, but with a little google-fu I was able to find a solution for that:

GL11.glScaled(scale, scale/2, scale);

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.