Posted November 22, 20204 yr I have entity: class KnifeEntity : ThrowableEntity { var knife = ItemStack(PhoenixItems.ZIRCONIUM_KNIFE.get()) var isReal = false; constructor(type: EntityType<KnifeEntity>, worldIn: World) : super(type, worldIn) constructor(worldIn: World, owner: LivingEntity, isReal: Boolean) : super(PhoenixEntities.KNIFE.get(), owner, worldIn) { this.isReal = isReal; } @OnlyIn(Dist.CLIENT) override fun handleStatusUpdate(id: Byte) { if (id.toInt() == 3) { for (i in 0..7) { //Появляются частицы лавы. В обычном майнкрафте они образуются на потолке, если сверху лава. world.addParticle(ParticleTypes.RAIN, posX, posY, posZ, 0.0, 0.0, 0.0) } } } override fun onImpact(result: RayTraceResult) { if (!world.isRemote) { var dropItem = isReal dropItem = when (result.type) { ENTITY -> dropItem and (knife.item as KnifeItem).onHitEntity(world, owner, this, (result as EntityRayTraceResult).entity, knife) BLOCK -> dropItem and (knife.item as KnifeItem).onHitBlock(world, owner, (result as BlockRayTraceResult).pos, this, knife) MISS -> dropItem } if (dropItem) world.addEntity(ItemEntity(world, posX, posY, posZ, knife)) onKillCommand() } } override fun registerData() { } } And renderer: public class KnifeRenderer<T extends KnifeEntity> extends EntityRenderer<T> { private final ItemRenderer itemRenderer; private final float scale = 1; public KnifeRenderer(EntityRendererManager renderManagerIn) { super(renderManagerIn); itemRenderer = Minecraft.getInstance().getItemRenderer(); } protected int getBlockLight(T entityIn, float partialTicks) { return super.getBlockLight(entityIn, partialTicks); } @Override public void render(T entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) { Phoenix.getLOGGER().error("no..."); matrixStackIn.push(); matrixStackIn.scale(this.scale, this.scale, this.scale); matrixStackIn.rotate(this.renderManager.getCameraOrientation()); matrixStackIn.rotate(Vector3f.YP.rotationDegrees(180.0F)); this.itemRenderer.renderItem(new ItemStack(PhoenixItems.INSTANCE.getZIRCONIUM_KNIFE().get()), ItemCameraTransforms.TransformType.GROUND, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn); matrixStackIn.pop(); super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn); } public ResourceLocation getEntityTexture(T entity) { return AtlasTexture.LOCATION_BLOCKS_TEXTURE; } } Register: public static void onClientSetup(FMLClientSetupEvent event) { ... RenderingRegistry.registerEntityRenderingHandler(PhoenixEntities.getKNIFE().get(), KnifeRenderer::new); ... } Item: class KnifeItem(tier: IItemTier, attackDamageIn: Float, attackSpeedIn: Float, maxUsages: Int) : ToolItem(attackDamageIn, attackSpeedIn, tier, breakableBlocks, Properties().group(Phoenix.PHOENIX).maxDamage(maxUsages)) { val damage: Float = attackDamageIn + tier.attackDamage override fun onItemRightClick(world : World, player : PlayerEntity, hand : Hand): ActionResult<ItemStack> { val itemstack = player.getHeldItem(hand) world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5f, 0.4f / (random.nextFloat() * 0.4f + 0.8f)) var coolDown = 10 val speed = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemstack) coolDown = (coolDown * speed.toDouble() / 3).toInt() player.cooldownTracker.setCooldown(this, coolDown) if (!world.isRemote) { val knife = KnifeEntity(world, player, true) knife.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f) world.addEntity(knife) val count = EnchantmentHelper.getEnchantmentLevel(Enchantments.MULTISHOT, itemstack) + 1 for (i in 0..count - 1) { addTask(5) { val knife2 = KnifeEntity(world, player, false) knife2.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f) world.addEntity(knife2) } } } itemstack.count = 0 return ActionResult(ActionResultType.SUCCESS, itemstack) } fun onHitBlock(world: World, owner: LivingEntity, pos: BlockPos, knife: KnifeEntity, item: ItemStack): Boolean { var shouldBroke = false val block = world.getBlockState(pos).block for (tag in breakableBlocksTypes) if (block.isIn(tag)) { shouldBroke = true break } if (breakableBlocks.contains(world.getBlockState(pos).block) || shouldBroke) { WorldUtils.destroyBlock(world, pos, true, owner, item) } item.damageItem(1, owner, { p: LivingEntity? -> world.playSound(null, owner.position, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5f, 0.4f / (random.nextFloat() * 0.4f + 0.8f)) }) return !(block !== Blocks.SNOW_BLOCK && block !== Blocks.SNOW && block.isIn(Tags.Blocks.SAND)) } fun onHitEntity(world: World?, owner: LivingEntity, knife: KnifeEntity, hitted: Entity, knifeItem: ItemStack): Boolean { val powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, knifeItem) val damage = damage + powerLevel.toDouble() * 0.6 if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, knifeItem) > 0 && hitted.type !== EntityType.SNOW_GOLEM) hitted.setFire(100) hitted.attackEntityFrom(DamageSource.causeThrownDamage(knife, knife.thrower), damage.toFloat()) return hitted.type !== EntityType.SNOW_GOLEM && hitted.type !== EntityType.END_CRYSTAL && hitted.type !== EntityType.PANDA } override fun canApplyAtEnchantingTable(stack: ItemStack, enchantment: Enchantment): Boolean { return enchantment === Enchantments.POWER || enchantment === Enchantments.QUICK_CHARGE || enchantment === Enchantments.MENDING || enchantment === Enchantments.FLAME || enchantment === Enchantments.SILK_TOUCH || enchantment === Enchantments.UNBREAKING } companion object { var breakableBlocks: Set<Block> = ImmutableSet.of(Blocks.SPONGE, Blocks.VINE, Blocks.SEA_PICKLE, Blocks.WET_SPONGE) var breakableBlocksTypes: Set<Tag<Block?>> = ImmutableSet.of(Tags.Blocks.GLASS, Tags.Blocks.STAINED_GLASS_PANES) } } Entity exits(it has damage), but render isn't runned... I can not see it. And If i tap F3 + B there are not any hit boxes of it. It is really strange... I need some help.
November 22, 20204 yr You also need to override createSpawnPacket in your entity class, and use the forge NetworkHooks class to get the correct spawn packet (sending a default vanilla packet won't work), so your entity will be rendered on the client Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
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.