DimDima09 Posted June 9, 2022 Posted June 9, 2022 Hello everyone. I have a problem: after moving to 1.19 from 1.18.2 my projectile starts disappearing after throwing it, but it still impacts with ground, how can i fix it? Quote
DimDima09 Posted June 9, 2022 Author Posted June 9, 2022 1 minute ago, diesieben07 said: Show your code. Main class: private void setup(final FMLCommonSetupEvent event) { //EntityRenderers.register(Entities.TRAVERTINE_PROJECTILE.get(), ThrownItemRenderer::new); EntityRenderers.register(Entities.TRAVERTINE_PIECE_PROJECTILE.get(), ThrownItemRenderer::new); } Item class: package com.dimucathedev.shaftcraft.Items; import com.dimucathedev.shaftcraft.Entities.TravertinePieceEntity; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import java.util.List; public class TravertinePieceProjectile extends Item { public TravertinePieceProjectile(Properties p_41383_) { super(p_41383_); } @Override public void appendHoverText(ItemStack p_41421_, @Nullable Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) { p_41423_.add(Component.translatable("tooltip.travertine_throwable2")); p_41423_.add(Component.translatable("tooltip.travertine_throwable1")); } @Override public InteractionResultHolder<ItemStack> use(Level p_43142_, Player p_43143_, InteractionHand p_43144_) { ItemStack stack = p_43143_.getItemInHand(p_43144_); if (!p_43142_.isClientSide()) { TravertinePieceEntity e = new TravertinePieceEntity(p_43142_,p_43143_); e.setItem(stack); e.shootFromRotation(p_43143_, p_43143_.getXRot(), p_43143_.getYRot(),1.0F, 1.5F, 1.0F); p_43142_.addFreshEntity(e); } if (!p_43143_.getAbilities().instabuild) { stack.shrink(1); } return InteractionResultHolder.sidedSuccess(stack, p_43142_.isClientSide()); } } Entity class: package com.dimucathedev.shaftcraft.Entities; import com.dimucathedev.shaftcraft.Registry.DieMessages; import com.dimucathedev.shaftcraft.Registry.Entities; import com.dimucathedev.shaftcraft.Registry.Items.Items; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ItemParticleOption; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.network.protocol.Packet; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; import net.minecraftforge.network.NetworkHooks; import java.util.Random; public class TravertinePieceEntity extends ThrowableItemProjectile { public TravertinePieceEntity(EntityType<? extends TravertinePieceEntity> p_37391_, Level p_37392_) { super(p_37391_, p_37392_); } public TravertinePieceEntity(Level p_37399_, LivingEntity p_37400_) { super(Entities.TRAVERTINE_PIECE_PROJECTILE.get(), p_37400_, p_37399_); } public TravertinePieceEntity(Level p_37394_, double p_37395_, double p_37396_, double p_37397_) { super(Entities.TRAVERTINE_PIECE_PROJECTILE.get(), p_37395_, p_37396_, p_37397_, p_37394_); } @Override protected Item getDefaultItem() { return Items.TRAVERTINE_PIECE.get(); } private ParticleOptions getParticle() { ItemStack itemstack = this.getItemRaw(); return itemstack.isEmpty() ? new ItemParticleOption(ParticleTypes.ITEM, new ItemStack(Items.TRAVERTINE_BLOCK_ITEM.get())) : new ItemParticleOption(ParticleTypes.ITEM, itemstack); } @Override public void handleEntityEvent(byte p_37402_) { if (p_37402_ == 3) { ParticleOptions particleoptions = this.getParticle(); for(int i = 0; i < 8; ++i) { this.level.addParticle(particleoptions, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D); } } } public static int count(String str, String target) { return (str.length() - str.replace(target, "").length()) / target.length(); } @Override protected void onHit(HitResult p_37260_) { handleEntityEvent((byte)3); Random r = new Random(); if (p_37260_.getType() == HitResult.Type.ENTITY){ Entity e = ((EntityHitResult)p_37260_).getEntity(); e.hurt(DieMessages.wasKilledByStone(((EntityHitResult)p_37260_).getEntity(), getOwner()), r.nextInt(5)); kill(); return; } var pos = new BlockPos(p_37260_.getLocation().x, p_37260_.getLocation().y, p_37260_.getLocation().z); int a = count(level.getBlockState(pos).getBlock().getName().toString(), "glass"); if (a > 0) { level.destroyBlock(pos, false); } else { if(r.nextDouble(10) > 6) //if(!((Player)getOwner()).getAbilities().instabuild) spawnSelf(p_37260_); else kill(); } } public void spawnSelf(HitResult p_37260_){ ItemEntity entity = new ItemEntity(level, p_37260_.getLocation().x,p_37260_.getLocation().y,p_37260_.getLocation().z,new ItemStack(Items.TRAVERTINE_PIECE.get())); level.addFreshEntity(entity); kill(); } @Override public Packet<?> getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } } Note: projectile is visible for a secong, but then it becomes invisible Quote
DimDima09 Posted June 9, 2022 Author Posted June 9, 2022 57 minutes ago, diesieben07 said: Entity renderer registration must be done in EntityRenderersEvent.RegisterRenderers. Make sure you are using the latest Forge version, there was a problem with the spawning packet that was added. Updating forge resolved this problem, thank you very much! Quote
Recommended Posts
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.