Jump to content

Recommended Posts

Posted

Hi,

I have a techne model and rendered it during the RenderPlayerEvent. The model is 100% correct, but the model doesn't stay on the player's back, as it is a backpack model. I want it to be physically attached to the player's back so that wherever the player is moving, looking, etc., the backpack is always in the correct position. Here is my model code and rendering code:

 

Model:

public class ModelPlayerBackpack extends ModelBase
{

protected static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation(Main.MOD_ID + ":" + "textures/player/playerbackpack.png");

protected ModelRenderer baseOne;
protected ModelRenderer baseTwo;
protected ModelRenderer sideOne;
protected ModelRenderer sideTwo;
protected ModelRenderer pouchOne;
protected ModelRenderer pouchTwo;

public ModelPlayerBackpack()
{
	this.textureWidth = 64;
	this.textureHeight = 64;

	this.baseOne = new ModelRenderer(this, 0, 52);
	this.baseOne.addBox(-3.0F, -5.5F, -0.5F, 6, 11, 1);
	this.baseOne.setRotationPoint(0.0F, 6.0F, 2.5F);
	this.baseOne.setTextureSize(64, 64);
	this.baseOne.mirror = true;
	this.setRotation(this.baseOne, 0.0F, 0.0F, 0.0F);

	this.baseTwo = new ModelRenderer(this, 0, 42);
	this.baseTwo.addBox(-2.5F, -4.5F, -0.5F, 5, 9, 1);
	this.baseTwo.setRotationPoint(0.0F, 6.0F, 3.5F);
	this.baseTwo.setTextureSize(64, 64);
	this.baseTwo.mirror = true;
	this.setRotation(this.baseTwo, 0.0F, 0.0F, 0.0F);

	this.sideOne = new ModelRenderer(this, 0, 32);
	this.sideOne.addBox(-1.0F, -4.0F, 0.0F, 2, 8, 2);
	this.sideOne.setRotationPoint(4.0F, 6.0F, 3.0F);
	this.sideOne.setTextureSize(64, 64);
	this.sideOne.mirror = true;
	this.setRotation(this.sideOne, 0.0F, 0.0F, 0.0F);

	this.sideTwo = new ModelRenderer(this, 0, 32);
	this.sideTwo.addBox(-1.0F, -4.0F, 0.0F, 2, 8, 2);
	this.sideTwo.setRotationPoint(-4.0F, 6.0F, 3.0F);
	this.sideTwo.setTextureSize(64, 64);
	this.sideTwo.mirror = true;
	this.setRotation(this.sideTwo, 0.0F, 0.0F, 0.0F);

	this.pouchOne = new ModelRenderer(this, 14, 59);
	this.pouchOne.addBox(-2.0F, -1.5F, 0.0F, 4, 3, 2);
	this.pouchOne.setRotationPoint(0.0F, 4.0F, 4.0F);
	this.pouchOne.setTextureSize(64, 64);
	this.pouchOne.mirror = true;
	this.setRotation(this.pouchOne, 0.0F, 0.0F, 0.0F);

	this.pouchTwo = new ModelRenderer(this, 14, 59);
	this.pouchTwo.addBox(-2.0F, -1.5F, 0.0F, 4, 3, 2);
	this.pouchTwo.setRotationPoint(0.0F, 8.0F, 4.0F);
	this.pouchTwo.setTextureSize(64, 64);
	this.pouchTwo.mirror = true;
	this.setRotation(this.pouchTwo, 0.0F, 0.0F, 0.0F);
}

public void setRotation(ModelRenderer par1ModelRenderer, float par2Float, float par3Float, float par4Float)
{
	par1ModelRenderer.rotateAngleX = par2Float;
	par1ModelRenderer.rotateAngleY = par3Float;
	par1ModelRenderer.rotateAngleZ = par4Float;
}

@Override
public void setRotationAngles(float par1Float, float par2Float, float par3Float, float par4Float, float par5Float, float par6Float, Entity par7Entity)
{
	super.setRotationAngles(par1Float, par2Float, par3Float, par4Float, par5Float, par6Float, par7Entity);
}

@Override
public void render(Entity par1Entity, float par2Float, float par3Float, float par4Float, float par5Float, float par6Float, float par7Float)
{
	super.render(par1Entity, par2Float, par3Float, par4Float, par5Float, par6Float, par7Float);
	this.setRotationAngles(par2Float, par3Float, par4Float, par5Float, par6Float, par7Float, par1Entity);
	this.baseOne.render(par7Float);
	this.baseTwo.render(par7Float);
	this.sideOne.render(par7Float);
	this.sideTwo.render(par7Float);
	this.pouchOne.render(par7Float);
	this.pouchTwo.render(par7Float);
}

}

 

Render:

public class RenderModelPlayerBackpack 
{

private ModelPlayerBackpack modelPlayerBackpack = new ModelPlayerBackpack();

@SubscribeEvent
public void renderPlayerEvent(RenderPlayerEvent.Pre par1RenderPlayerEvent)
{
	Minecraft.getMinecraft().getTextureManager().bindTexture(this.modelPlayerBackpack.RESOURCE_LOCATION);
	this.modelPlayerBackpack.render(Minecraft.getMinecraft().thePlayer, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
}

}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

It looks like the problem is with this line:

this.modelPlayerBackpack.render(Minecraft.getMinecraft().thePlayer, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);

 

You aren't rotating the model at all (the 0's), you need to make one of those (not sure which one, experimenting should do the trick though) the player's Y rotation. I'm going to assume it's the second one though.

Posted

I tried all the values individually in that line by plugging in Minecraft.getMinecraft().thePlayer.rotationYaw. None of those seemed to do anything.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Ah, this could be the problem:

 

This is the code from the armor stand.

public void setRotationAngles(float p_78087_1_, float p_78087_2_, float p_78087_3_, float p_78087_4_, float p_78087_5_, float p_78087_6_, Entity p_78087_7_)
    {
        if (p_78087_7_ instanceof EntityArmorStand)
        {
            EntityArmorStand entityarmorstand = (EntityArmorStand)p_78087_7_;
            this.bipedHead.rotateAngleX = 0.017453292F * entityarmorstand.getHeadRotation().getX();
            this.bipedHead.rotateAngleY = 0.017453292F * entityarmorstand.getHeadRotation().getY();
            this.bipedHead.rotateAngleZ = 0.017453292F * entityarmorstand.getHeadRotation().getZ();
            this.bipedHead.setRotationPoint(0.0F, 1.0F, 0.0F);
            this.bipedBody.rotateAngleX = 0.017453292F * entityarmorstand.getBodyRotation().getX();
            this.bipedBody.rotateAngleY = 0.017453292F * entityarmorstand.getBodyRotation().getY();
            this.bipedBody.rotateAngleZ = 0.017453292F * entityarmorstand.getBodyRotation().getZ();
            this.bipedLeftArm.rotateAngleX = 0.017453292F * entityarmorstand.getLeftArmRotation().getX();
            this.bipedLeftArm.rotateAngleY = 0.017453292F * entityarmorstand.getLeftArmRotation().getY();
            this.bipedLeftArm.rotateAngleZ = 0.017453292F * entityarmorstand.getLeftArmRotation().getZ();
            this.bipedRightArm.rotateAngleX = 0.017453292F * entityarmorstand.getRightArmRotation().getX();
            this.bipedRightArm.rotateAngleY = 0.017453292F * entityarmorstand.getRightArmRotation().getY();
            this.bipedRightArm.rotateAngleZ = 0.017453292F * entityarmorstand.getRightArmRotation().getZ();
            this.bipedLeftLeg.rotateAngleX = 0.017453292F * entityarmorstand.getLeftLegRotation().getX();
            this.bipedLeftLeg.rotateAngleY = 0.017453292F * entityarmorstand.getLeftLegRotation().getY();
            this.bipedLeftLeg.rotateAngleZ = 0.017453292F * entityarmorstand.getLeftLegRotation().getZ();
            this.bipedLeftLeg.setRotationPoint(1.9F, 11.0F, 0.0F);
            this.bipedRightLeg.rotateAngleX = 0.017453292F * entityarmorstand.getRightLegRotation().getX();
            this.bipedRightLeg.rotateAngleY = 0.017453292F * entityarmorstand.getRightLegRotation().getY();
            this.bipedRightLeg.rotateAngleZ = 0.017453292F * entityarmorstand.getRightLegRotation().getZ();
            this.bipedRightLeg.setRotationPoint(-1.9F, 11.0F, 0.0F);
            copyModelAngles(this.bipedHead, this.bipedHeadwear);
        }
    }

 

You'll notice it doesn't call super.setRotationAngles (like you did), the reason for that is because super.setRotationAngles does nothing, it's an empty method. So in your implementation of it, you need to do what the armor stand did, rotation the model parts of your model according to the entity that wears it.

Posted

Not working. This just makes the individual model parts spin on its axis / rotation points. I need something that will turn the whole model based on player rotation yaw.

@Override
public void setRotationAngles(float par1Float, float par2Float, float par3Float, float par4Float, float par5Float, float par6Float, Entity par7Entity)
{
if (par7Entity instanceof EntityPlayer)
        {
            EntityPlayer entityplayer = (EntityPlayer) par7Entity;
            this.baseOne.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
            this.baseTwo.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
            this.sideOne.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
            this.sideTwo.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
            this.pouchOne.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
            this.pouchTwo.rotateAngleY = 0.017453292F * entityplayer.rotationYaw;
        }
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

If I set all the rotation offset points to the same area, my model renders oddly. Besides, if I did that I would just be able to call GL.glRotated to rotate the whole model and would achieve the same thing. The armor stand needs to rotate its specific parts and I need to rotate the thing as a whole with the player.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Sorry, the images aren't doing what I want them to do. Basically the model pieces are bunching up together into 1 piece. The armor stand's rotation points aren't the same either.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Posted

Why dont you use the mainpart.addChild() method? That whay all parts will stay at their places when you rotate the mainPart. That way you only have to worry about one rotation.

 

Also keep in mind that the rotation point of the player is the exact centre of the player model, while your model is separated a fair bit from that point!

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

I'll give you a way to do this easier.

 

Build your model in Techne where the backpack is on the players back in the right spot.  Heck use the model biped as a start.

 

Change your model to extend modelbiped.  Reset all the base models parts (such as leg, body, ect) to size zero.

 

When the player is rendered, send a call to render your backpack when applicable. 

 

If you use the renderlivingentity event, be sure to put a marker on your render version or you will get an infinite loops.

 

This oversimplifies it, such as leaving our your render class, ect. 

 

 

The reason to do this is there is no need to do anything with calculating positions, rotations, sneak, riding, ect.  The base code takes care of it for you.  Easy as can be.

Long time Bukkit & Forge Programmer

Happy to try and help

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

    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
  • Topics

×
×
  • Create New...

Important Information

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