Started by
Luckydel
on
Topic category: Help with Minecraft modding (Java Edition)
If I set projectile power greater than 4:
https://www.youtube.com/watch?v=lNKYIpI4XPA&feature=emb_title
Model projectile entity:
public class ModelBulletEntity_Model<T extends Entity> extends EntityModel<T> { public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(MainMod.MODID, "bulletentity_model"), "main"); public ModelPart bb_main; public ModelBulletEntity_Model(ModelPart root) { this.bb_main = root.getChild("bb_main"); } public static LayerDefinition createBodyLayer() { MeshDefinition meshdefinition = new MeshDefinition(); PartDefinition partdefinition = meshdefinition.getRoot(); PartDefinition bb_main = partdefinition.addOrReplaceChild("bb_main", CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0F, 0.0F)); return LayerDefinition.create(meshdefinition, 16, 16); } @Override public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { bb_main.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); } public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { } }
Renger projectile entity:
public class GunRenderer extends EntityRenderer<GunEntity> { private static final ResourceLocation texture = new ResourceLocation("main:textures/entities/bulletentity.png"); private final ModelBulletEntity_Model model; public GunRenderer(EntityRendererProvider.Context context) { super(context); model = new ModelBulletEntity_Model(context.bakeLayer(ModelBulletEntity_Model.LAYER_LOCATION)); } @Override public void render(GunEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) { VertexConsumer vb = bufferIn.getBuffer(RenderType.entityCutout(this.getTextureLocation(entityIn))); poseStack.pushPose(); poseStack.mulPose(Vector3f.YP.rotationDegrees(Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()) - 90)); poseStack.mulPose(Vector3f.ZP.rotationDegrees(90 + Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot()))); model.renderToBuffer(poseStack, vb, packedLightIn, OverlayTexture.NO_OVERLAY, 1, 1, 1, 0.0625f); poseStack.popPose(); super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn); } @Override public ResourceLocation getTextureLocation(GunEntity entity) { return texture; } }
Entity:
@OnlyIn(value = Dist.CLIENT, _interface = ItemSupplier.class) public class GunEntity extends AbstractArrow implements ItemSupplier { public GunEntity(PlayMessages.SpawnEntity packet, Level world) { super(MainModEntities.GUN.get(), world); } public GunEntity(EntityType<? extends GunEntity> type, Level world) { super(type, world); } public GunEntity(EntityType<? extends GunEntity> type, double x, double y, double z, Level world) { super(type, x, y, z, world); } public GunEntity(EntityType<? extends GunEntity> type, LivingEntity entity, Level world) { super(type, entity, world); } @Override public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @Override @OnlyIn(Dist.CLIENT) public ItemStack getItem() { return ItemStack.EMPTY; } @Override protected ItemStack getPickupItem() { return ItemStack.EMPTY; } @Override protected void doPostHurtEffects(LivingEntity entity) { super.doPostHurtEffects(entity); entity.setArrowCount(entity.getArrowCount() - 1); } @Override public void tick() { super.tick(); if (this.inGround) this.discard(); } public static GunEntity shoot(Level world, LivingEntity entity, Random random, float power, double damage, int knockback) { GunEntity entityarrow = new GunEntity(MainModEntities.GUN.get(), entity, world); entityarrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0); entityarrow.setSilent(true); entityarrow.setCritArrow(false); entityarrow.setBaseDamage(damage); entityarrow.setKnockback(knockback); world.addFreshEntity(entityarrow); world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (random.nextFloat() * 0.5f + 1) + (power / 2)); return entityarrow; } public static GunEntity shoot(LivingEntity entity, LivingEntity target) { GunEntity entityarrow = new GunEntity(MainModEntities.GUN.get(), entity, entity.level); double dx = target.getX() - entity.getX(); double dy = target.getY() + target.getEyeHeight() - 1.1; double dz = target.getZ() - entity.getZ(); entityarrow.shoot(dx, dy - entityarrow.getY() + Math.hypot(dx, dz) * 0.2F, dz, 8.1f * 2, 12.0F); entityarrow.setSilent(true); entityarrow.setBaseDamage(5); entityarrow.setKnockback(5); entityarrow.setCritArrow(false); entity.level.addFreshEntity(entityarrow); entity.level.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (new Random().nextFloat() * 0.5f + 1)); return entityarrow; } }
if nothing can be done about it, perhaps there is a way to slow down the fall of the projectile? He falls too fast with little power