User Tools

Site Tools


tutorial:projectiles

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:projectiles [2020/11/16 22:17] – tutorial-download spxctreofficialtutorial:projectiles [2021/09/20 06:27] – Entity#remove() -> kill() and small java 16 changes upcraftlp
Line 108: Line 108:
  entity.damage(DamageSource.thrownProjectile(this, this.getOwner()), (float)i); // deals damage  entity.damage(DamageSource.thrownProjectile(this, this.getOwner()), (float)i); // deals damage
  
- if (entity instanceof LivingEntity) { // checks if entity is an instance of LivingEntity (meaning it is not a boat or minecart) + if (entity instanceof LivingEntity livingEntity) { // checks if entity is an instance of LivingEntity (meaning it is not a boat or minecart) 
- ((LivingEntity) entity).addStatusEffect((new StatusEffectInstance(StatusEffects.BLINDNESS, 20 * 3, 0))); // applies a status effect + livingEntity.addStatusEffect((new StatusEffectInstance(StatusEffects.BLINDNESS, 20 * 3, 0))); // applies a status effect 
- ((LivingEntity) entity).addStatusEffect((new StatusEffectInstance(StatusEffects.SLOWNESS, 20 * 3, 2))); // applies a status effect + livingEntity.addStatusEffect((new StatusEffectInstance(StatusEffects.SLOWNESS, 20 * 3, 2))); // applies a status effect 
- ((LivingEntity) entity).addStatusEffect((new StatusEffectInstance(StatusEffects.POISON, 20 * 3, 1))); // applies a status effect + livingEntity.addStatusEffect((new StatusEffectInstance(StatusEffects.POISON, 20 * 3, 1))); // applies a status effect 
- entity.playSound(SoundEvents.AMBIENT_CAVE, 2F, 1F); // plays a sound for the entity hit only+ livingEntity.playSound(SoundEvents.AMBIENT_CAVE, 2F, 1F); // plays a sound for the entity hit only
  }  }
  }  }
Line 120: Line 120:
  if (!this.world.isClient) { // checks if the world is client  if (!this.world.isClient) { // checks if the world is client
  this.world.sendEntityStatus(this, (byte)3); // particle?  this.world.sendEntityStatus(this, (byte)3); // particle?
- this.remove(); // kills the projectile+ this.kill(); // kills the projectile
  }  }
  
Line 256: Line 256:
  @Override  @Override
  public void onInitializeClient() {  public void onInitializeClient() {
- EntityRendererRegistry.INSTANCE.register(ProjectileTutorialMod.PackedSnowballEntityType, (dispatcher, context) -> + EntityRendererRegistry.INSTANCE.register(ProjectileTutorialMod.PackedSnowballEntityType, (context) -> 
- new FlyingItemEntityRenderer(dispatcher, context.getItemRenderer()));+  new FlyingItemEntityRenderer(context));
  [. . .]  [. . .]
  }  }
Line 276: Line 276:
  PacketBufUtil.writeAngle(byteBuf, e.pitch);  PacketBufUtil.writeAngle(byteBuf, e.pitch);
  PacketBufUtil.writeAngle(byteBuf, e.yaw);  PacketBufUtil.writeAngle(byteBuf, e.yaw);
- return ServerSidePacketRegistry.INSTANCE.toPacket(packetID, byteBuf);+ return ServerPlayNetworking.createS2CPacket(packetID, byteBuf);
  }  }
  public static final class PacketBufUtil {  public static final class PacketBufUtil {
Line 400: Line 400:
 @Override @Override
  public void onInitializeClient() {  public void onInitializeClient() {
- EntityRendererRegistry.INSTANCE.register(ProjectileTutorialMod.PackedSnowballEntityType, (dispatcher, context) -> + EntityRendererRegistry.INSTANCE.register(ProjectileTutorialMod.PackedSnowballEntityType, (context) -> 
- new FlyingItemEntityRenderer(dispatcher, context.getItemRenderer()));+ new FlyingItemEntityRenderer(context));
  receiveEntityPacket();  receiveEntityPacket();
  }  }
tutorial/projectiles.txt · Last modified: 2024/03/08 01:56 by netuserget