User Tools

Site Tools


tutorial:projectiles

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:projectiles [2020/11/16 19:47] – created spxctreofficialtutorial:projectiles [2020/11/16 22:05] – fixing my idiotic mistakes spxctreofficial
Line 202: Line 202:
  */  */
  if (!world.isClient) {  if (!world.isClient) {
- SnowballEntity snowballEntity = new SnowballEntity(world, user);+ PackedSnowballEntity snowballEntity = new PackedSnowballEntity(world, user);
  snowballEntity.setItem(itemStack);  snowballEntity.setItem(itemStack);
  snowballEntity.setProperties(user, user.pitch, user.yaw, 0.0F, 1.5F, 0F);  snowballEntity.setProperties(user, user.pitch, user.yaw, 0.0F, 1.5F, 0F);
Line 217: Line 217:
 } }
 </code> </code>
 +Make sure that the projectile that you are launching with this item is indeed your custom ''ProjectileEntity''. Verify this by checking ''PackedSnowballEntity snowballEntity = new PackedSnowballEntity(world, user);''
 +\\
 Now, we are finished with creating an item for the ''ProjectileEntity''. Keep in mind that if you do not understand how to create an item, refer to the [[https://fabricmc.net/wiki/tutorial:items|"Item" tutorial]]. Now, we are finished with creating an item for the ''ProjectileEntity''. Keep in mind that if you do not understand how to create an item, refer to the [[https://fabricmc.net/wiki/tutorial:items|"Item" tutorial]].
 \\ \\
Line 244: Line 245:
 ===== Rendering your Projectile Entity ===== ===== Rendering your Projectile Entity =====
  
-Your projectile entity is now defined and registered, but we are not done. Without a renderer, the ''ProjectileEntity'' will crash Minecraft. To fix this, we will define and register the ''EntityRenderer'' for our ''ProjectileEntity''. To do this, we will need a ''EntityRenderer'' in the **ClientModInitializer** and a spawn packet to make sure the texture is rendered correctly+Your projectile entity is now defined and registered, but we are not done. Without a renderer, the ''ProjectileEntity'' will crash Minecraft. To fix this, we will define and register the ''EntityRenderer'' for our ''ProjectileEntity''. To do this, we will need a ''EntityRenderer'' in the **ClientModInitializer** and a spawn packet to make sure the texture is rendered correctly
 +\\ 
 +Before we start, we will quickly define an Identifier that we will be using a lot: our PacketID. 
 +<code java> 
 +public static final Identifier PacketID = new Identifier(ProjectileTutorialMod.ModID, "spawn_packet"); 
 +</code>
 \\ \\
 First on the list, we should get the ''EntityRenderer'' out of the way. Go into your **ClientModInitializer** and write the following: First on the list, we should get the ''EntityRenderer'' out of the way. Go into your **ClientModInitializer** and write the following:
Line 356: Line 362:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
  public void receiveEntityPacket() {  public void receiveEntityPacket() {
- ClientSidePacketRegistry.INSTANCE.register(new Identifier(ProjectileTutorialMod.ModID, "entity_packet"), (ctx, byteBuf) -> {+ ClientSidePacketRegistry.INSTANCE.register(PacketID, (ctx, byteBuf) -> {
  EntityType<?> et = Registry.ENTITY_TYPE.get(byteBuf.readVarInt());  EntityType<?> et = Registry.ENTITY_TYPE.get(byteBuf.readVarInt());
  UUID uuid = byteBuf.readUuid();  UUID uuid = byteBuf.readUuid();
Line 378: Line 384:
  });  });
  });  });
 + }
 +</code>
 +
 +Back in our ''ProjectileEntity'' class, we must add a method to make sure everything works correctly.
 +<code java [enable_line_numbers="true"]>
 +        @Override
 + public Packet createSpawnPacket() {
 + return EntitySpawnPacket.create(this, ProjectileTutorialClient.PacketID);
  }  }
 </code> </code>
Line 395: Line 409:
  
 Now, your projectile should be working in-game! Just make sure your textures are in the right place, and your item and projectile should be working. Now, your projectile should be working in-game! Just make sure your textures are in the right place, and your item and projectile should be working.
 +
 +[INSERT USABLE PICTURE HERE]
tutorial/projectiles.txt · Last modified: 2024/03/08 01:56 by netuserget