Started by
Elastico345
on
Topic category: Help with Minecraft modding (Java Edition)
Because If I ride to it, I'm floating above it which looks weird. So I would like to know whats the code to change the Y position of the player when they're riding to it.
heres the image of it.
Didn't i reply to this topic? for some reason im seeing that my replies get removed on multiple posts...
yea i just realized that yesterday as well
Mind saying that code again? I'm gonna copy and paste that again on my notepad
my apologies for the late reply here is the code again *NOTE paste this code after the part that makes the mob rideable:
public void updatePassenger(Entity passenger) {
if (this.isPassenger(passenger)) {
float f = MathHelper.cos(this.renderYawOffset * 0.017453292F);
float f1 = MathHelper.sin(this.renderYawOffset * 0.017453292F);
float f2 = 0.3F;
passenger.setPosition(this.posX + (double) (0.3F * f1), this.posY + this.getMountedYOffset() + 2.2D + passenger.getYOffset(),
this.posZ - (double) (0.3F * f));
}
}
change the 2.2D to your likings.
Is this also possible with x,y,z?
you have to edit the model to do x z position
Where do you put it into the
package net.mcreator.car_mod;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumHand;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelBase;
import java.util.Iterator;
import java.util.ArrayList;
@Elementscar_mod.ModElement.Tag
public class MCreatorHotrod extends Elementscar_mod.ModElement {
public static final int ENTITYID = 35;
public static final int ENTITYID_RANGED = 36;
public MCreatorHotrod(Elementscar_mod instance) {
super(instance, 64);
}
@Override
public void initElements() {
elements.entities.add(() -> EntityEntryBuilder.create().entity(EntityCustom.class).id(new ResourceLocation("car_mod", "hotrod"), ENTITYID)
.name("hotrod").tracker(64, 1, true).build());
}
private Biome[] allbiomes(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
Iterator<Biome> itr = in.iterator();
ArrayList<Biome> ls = new ArrayList<Biome>();
while (itr.hasNext())
ls.add(itr.next());
return ls.toArray(new Biome[ls.size()]);
}
@SideOnly(Side.CLIENT)
@Override
public void preInit(FMLPreInitializationEvent event) {
RenderingRegistry.registerEntityRenderingHandler(EntityCustom.class, renderManager -> {
return new RenderLiving(renderManager, new ModelFordmodela(), 0f) {
protected ResourceLocation getEntityTexture(Entity entity) {
return new ResourceLocation("car_mod:textures/hotrod.png");
}
};
});
}
public static class EntityCustom extends EntityCreature {
public EntityCustom(World world) {
super(world);
setSize(0.6f, 1.8f);
experienceValue = 0;
this.isImmuneToFire = false;
setNoAI(!true);
enablePersistence();
}
@Override
public EnumCreatureAttribute getCreatureAttribute() {
return EnumCreatureAttribute.UNDEFINED;
}
@Override
protected boolean canDespawn() {
return false;
}
@Override
protected Item getDropItem() {
return new ItemStack(MCreatorSpawnHotrod.block, (int) (1)).getItem();
}
@Override
public net.minecraft.util.SoundEvent getAmbientSound() {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(""));
}
@Override
public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("block.anvil.fall"));
}
@Override
public net.minecraft.util.SoundEvent getDeathSound() {
return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.generic.explode"));
}
@Override
protected float getSoundVolume() {
return 1.0F;
}
@Override
public boolean attackEntityFrom(DamageSource source, float amount) {
if (source.getImmediateSource() instanceof EntityArrow)
return false;
if (source.getImmediateSource() instanceof EntityPotion)
return false;
if (source == DamageSource.FALL)
return false;
if (source == DamageSource.CACTUS)
return false;
if (source == DamageSource.DROWN)
return false;
if (source == DamageSource.LIGHTNING_BOLT)
return false;
return super.attackEntityFrom(source, amount);
}
@Override
public boolean processInteract(EntityPlayer entity, EnumHand hand) {
super.processInteract(entity, hand);
entity.startRiding(this);
int x = (int) this.posX;
int y = (int) this.posY;
int z = (int) this.posZ;
ItemStack itemstack = entity.getHeldItem(hand);
return true;
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
if (this.getEntityAttribute(SharedMonsterAttributes.ARMOR) != null)
this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0D);
if (this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED) != null)
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D);
if (this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH) != null)
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1D);
if (this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE) != null)
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0D);
}
@Override
public void travel(float ti, float tj, float tk) {
Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
if (this.isBeingRidden()) {
this.rotationYaw = entity.rotationYaw;
this.prevRotationYaw = this.rotationYaw;
this.rotationPitch = entity.rotationPitch * 0.5F;
this.setRotation(this.rotationYaw, this.rotationPitch);
this.jumpMovementFactor = this.getAIMoveSpeed() * 0.15F;
this.renderYawOffset = entity.rotationYaw;
this.rotationYawHead = entity.rotationYaw;
this.stepHeight = 1.0F;
if (entity instanceof EntityLivingBase) {
this.setAIMoveSpeed((float) this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue());
float forward = ((EntityLivingBase) entity).moveForward;
float strafe = 0;
super.travel(strafe, 0, forward);
}
this.prevLimbSwingAmount = this.limbSwingAmount;
double d1 = this.posX - this.prevPosX;
double d0 = this.posZ - this.prevPosZ;
float f1 = MathHelper.sqrt(d1 * d1 + d0 * d0) * 4.0F;
if (f1 > 1.0F)
f1 = 1.0F;
this.limbSwingAmount += (f1 - this.limbSwingAmount) * 0.4F;
this.limbSwing += this.limbSwingAmount;
return;
}
this.stepHeight = 0.5F;
this.jumpMovementFactor = 0.02F;
super.travel(ti, tj, tk);
}
}
// Made with Blockbench
// Paste this code into your mod.
public static class ModelFordmodela extends ModelBase {
private final ModelRenderer engine;
private final ModelRenderer body;
private final ModelRenderer backwheels;
private final ModelRenderer frontwheels;
public ModelFordmodela() {
textureWidth = 256;
textureHeight = 256;
engine = new ModelRenderer(this);
engine.setRotationPoint(0.0F, 14.0F, 0.0F);
setRotationAngle(engine, 0.0F, 0.0F, 0.7854F);
engine.cubeList.add(new ModelBox(engine, 0, 0, -11.6569F, 3.3284F, -32.0F, 4, 3, 12, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 32, 0, -5.1569F, -3.1716F, -32.0F, 3, 4, 12, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 0, -9.6569F, 6.0284F, -31.5F, 2, 3, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 0, -9.6569F, 6.0284F, -28.5F, 2, 3, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 0, -9.6569F, 6.0284F, -25.5F, 2, 3, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 0, -9.6569F, 6.0284F, -22.5F, 2, 3, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 5, -2.4569F, -1.1716F, -31.5F, 3, 2, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 5, -2.4569F, -1.1716F, -28.5F, 3, 2, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 5, -2.4569F, -1.1716F, -25.5F, 3, 2, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 0, 5, -2.4569F, -1.1716F, -22.5F, 3, 2, 2, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 0, -13.6569F, 8.3284F, -31.5F, 6, 2, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 0, -13.6569F, 8.3284F, -28.5F, 6, 2, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 0, -13.6569F, 8.3284F, -25.5F, 6, 2, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 0, -13.6569F, 8.3284F, -22.5F, 6, 2, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 4, -0.4569F, -5.1716F, -31.5F, 2, 6, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 4, -0.4569F, -5.1716F, -28.5F, 2, 6, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 4, -0.4569F, -5.1716F, -25.5F, 2, 6, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 20, 4, -0.4569F, -5.1716F, -22.5F, 2, 6, 2, 0.05F, false));
engine.cubeList.add(new ModelBox(engine, 28, 4, -10.1569F, 12.3284F, -33.5F, 5, 1, 1, -0.05F, false));
engine.cubeList.add(new ModelBox(engine, 28, 6, 3.8431F, -1.6716F, -33.5F, 1, 5, 1, -0.05F, false));
body = new ModelRenderer(this);
body.setRotationPoint(0.0F, 6.0F, 0.0F);
body.cubeList.add(new ModelBox(body, 0, 15, -10.0F, 4.0F, -32.0F, 8, 8, 12, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 15, -8.5F, 5.5F, -33.0F, 5, 5, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 21, -5.5F, 1.5F, -33.0F, 2, 2, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 40, 16, -9.0F, 1.0F, -31.0F, 6, 3, 10, 0.0F, false));
body.cubeList.add(new ModelBox(body, 28, 16, -8.0F, -1.0F, -29.0F, 4, 2, 6, 0.0F, false));
body.cubeList.add(new ModelBox(body, 40, 29, -9.0F, -3.0F, -30.5F, 6, 2, 8, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 35, -9.0F, 5.0F, -20.0F, 6, 6, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 16, 35, -8.5F, 5.5F, -18.0F, 5, 5, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 72, 0, -8.0F, 7.0F, -12.0F, 4, 6, 22, 0.0F, false));
body.cubeList.add(new ModelBox(body, 30, 39, -12.0F, 12.0F, -31.0F, 12, 1, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 30, 39, -12.0F, 12.0F, -23.0F, 12, 1, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 124, 0, -13.0F, 11.5F, -39.0F, 1, 2, 23, 0.0F, false));
body.cubeList.add(new ModelBox(body, 124, 0, 0.0F, 11.5F, -39.0F, 1, 2, 23, 0.0F, false));
body.cubeList.add(new ModelBox(body, 50, 0, -13.0F, 8.5F, -37.0F, 1, 3, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 50, 0, 0.0F, 8.5F, -37.0F, 1, 3, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 50, 4, -14.5F, 5.5F, -38.0F, 3, 3, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 50, 4, -0.5F, 5.5F, -38.0F, 3, 3, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 42, -20.0F, 12.5F, -16.0F, 28, 1, 44, 0.0F, false));
body.cubeList.add(new ModelBox(body, 72, 28, -18.0F, 3.0F, -12.0F, 24, 3, 4, 0.0F, false));
body.cubeList.add(new ModelBox(body, 60, 0, -1.3F, 4.5F, -12.0F, 2, 2, 6, 0.0F, false));
body.cubeList.add(new ModelBox(body, 60, 0, -2.3F, 5.0F, -7.0F, 1, 1, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 60, 0, 0.7F, 5.0F, -7.0F, 1, 1, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 70, 0, -3.3F, 3.0F, -7.0F, 1, 5, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 70, 0, 1.7F, 3.0F, -7.0F, 1, 5, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 60, 8, -2.8F, 7.5F, -7.0F, 5, 1, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 60, 8, -2.8F, 2.5F, -7.0F, 5, 1, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 43, -15.5F, 10.5F, -4.0F, 7, 2, 10, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 43, -3.5F, 10.5F, -4.0F, 7, 2, 10, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 55, -15.5F, 0.5F, 4.0F, 7, 10, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 55, -3.5F, 0.5F, 4.0F, 7, 10, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 172, 0, -18.0F, 3.5F, 10.0F, 24, 9, 16, 0.0F, false));
body.cubeList.add(new ModelBox(body, 128, 25, -18.0F, 2.5F, -16.0F, 24, 10, 4, 0.0F, false));
body.cubeList.add(new ModelBox(body, 128, 39, -20.0F, 2.5F, 26.0F, 28, 10, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 87, -20.0F, 2.5F, -16.0F, 2, 10, 42, 0.0F, false));
body.cubeList.add(new ModelBox(body, 88, 87, 6.0F, 2.5F, -16.0F, 2, 10, 42, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 87, -20.0F, -3.5F, -13.0F, 1, 6, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 4, 87, 7.0F, -3.5F, -13.0F, 1, 6, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 139, -20.0F, -3.5F, 7.0F, 1, 6, 20, 0.0F, false));
body.cubeList.add(new ModelBox(body, 42, 139, 7.0F, -3.5F, 7.0F, 1, 6, 20, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 165, -20.0F, -5.5F, -13.0F, 28, 2, 40, 0.0F, false));
body.cubeList.add(new ModelBox(body, 46, 87, -19.5F, -4.5F, -16.0F, 27, 1, 3, 0.0F, false));
body.cubeList.add(new ModelBox(body, 0, 139, -10.5F, 2.0F, -38.0F, 9, 11, 1, 0.0F, false));
body.cubeList.add(new ModelBox(body, 22, 139, -10.0F, 13.0F, -39.0F, 8, 1, 5, 0.0F, false));
body.cubeList.add(new ModelBox(body, 22, 145, -10.0F, 1.0F, -39.0F, 8, 1, 3, 0.0F, false));
body.cubeList.add(new ModelBox(body, 48, 139, -11.0F, 1.5F, -39.0F, 1, 12, 3, 0.0F, false));
body.cubeList.add(new ModelBox(body, 48, 139, -2.0F, 1.5F, -39.0F, 1, 12, 3, 0.0F, false));
body.cubeList.add(new ModelBox(body, 46, 91, -17.0F, 13.0F, -34.0F, 22, 1, 2, 0.05F, false));
body.cubeList.add(new ModelBox(body, 46, 94, -17.0F, 9.0F, -34.0F, 1, 4, 2, 0.0F, false));
body.cubeList.add(new ModelBox(body, 46, 94, 4.0F, 9.0F, -34.0F, 1, 4, 2, 0.0F, false));
backwheels = new ModelRenderer(this);
backwheels.setRotationPoint(-6.0F, 17.5F, 18.5F);
backwheels.cubeList.add(new ModelBox(backwheels, 0, 94, -15.0F, -2.5F, -1.5F, 1, 3, 3, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 94, 14.0F, -3.5F, -0.5F, 1, 3, 3, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 207, -20.0F, -7.5F, -6.5F, 5, 13, 13, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 207, 15.0F, -7.5F, -6.5F, 5, 13, 13, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 233, -20.0F, 5.5F, -4.5F, 5, 1, 9, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 233, 15.0F, 5.5F, -4.5F, 5, 1, 9, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 233, -20.0F, -8.5F, -4.5F, 5, 1, 9, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 233, 15.0F, -8.5F, -4.5F, 5, 1, 9, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 243, -20.0F, -5.5F, -7.5F, 5, 9, 1, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 243, 15.0F, -5.5F, -7.5F, 5, 9, 1, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 243, -20.0F, -5.5F, 6.5F, 5, 9, 1, 0.0F, false));
backwheels.cubeList.add(new ModelBox(backwheels, 0, 243, 15.0F, -5.5F, 6.5F, 5, 9, 1, 0.0F, false));
frontwheels = new ModelRenderer(this);
frontwheels.setRotationPoint(-6.0F, 19.0F, -33.0F);
frontwheels.cubeList.add(new ModelBox(frontwheels, 0, 94, -12.0F, -2.5F, -1.5F, 1, 3, 3, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 0, 94, 11.0F, -2.5F, -1.5F, 1, 3, 3, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 207, -16.0F, -6.0F, -5.0F, 4, 10, 10, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 207, 12.0F, -6.0F, -5.0F, 4, 10, 10, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 227, -16.0F, -4.0F, -6.0F, 4, 6, 1, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 227, 12.0F, -4.0F, -6.0F, 4, 6, 1, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 227, -16.0F, -4.0F, 5.0F, 4, 6, 1, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 227, 12.0F, -4.0F, 5.0F, 4, 6, 1, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 234, -16.0F, 4.0F, -3.0F, 4, 1, 6, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 234, 12.0F, 4.0F, -3.0F, 4, 1, 6, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 234, -16.0F, -7.0F, -3.0F, 4, 1, 6, 0.0F, false));
frontwheels.cubeList.add(new ModelBox(frontwheels, 36, 234, 12.0F, -7.0F, -3.0F, 4, 1, 6, 0.0F, false));
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
engine.render(f5);
body.render(f5);
backwheels.render(f5);
frontwheels.render(f5);
}
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) {
super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
this.backwheels.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
this.frontwheels.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
}
}
}
I dont know where to put that bit of code
bro, for some reason, the ur code doesn't work for me
can someone help me, i dont know where to put it, it doesn't work for me, i'm using 1.16.2 minecraft by the way