diff --git a/gradle.properties b/gradle.properties index 0b8ed32..a838496 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.1 -yarn_mappings=1.21.1+build.3 -loader_version=0.16.0 +minecraft_version=1.21.3 +yarn_mappings=1.21.3+build.2 +loader_version=0.16.8 # Mod Properties -mod_version=1.9.6 +mod_version=1.9.7 maven_group=systems.brn archives_base_name=plasticgun # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.102.1+1.21.1 +fabric_version=0.107.0+1.21.3 -polymer_version=0.9.9+1.21 -server_translations_api_version=2.3.1+1.21-pre2 +polymer_version=0.10.1+1.21.3 +server_translations_api_version=2.4.0+1.21.2-rc1 trinkets_version=3.10.0+polymerport.2 diff --git a/src/main/java/systems/brn/plasticgun/PlasticGun.java b/src/main/java/systems/brn/plasticgun/PlasticGun.java index 86407bc..6711a15 100644 --- a/src/main/java/systems/brn/plasticgun/PlasticGun.java +++ b/src/main/java/systems/brn/plasticgun/PlasticGun.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.effect.StatusEffect; @@ -17,8 +18,11 @@ import net.minecraft.item.Item; import net.minecraft.loot.LootTables; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import systems.brn.plasticgun.bullets.BulletEntity; @@ -33,8 +37,6 @@ import systems.brn.plasticgun.lib.CraftingItem; import systems.brn.plasticgun.lib.EventHandler; import systems.brn.plasticgun.lib.ItemGroups; import systems.brn.plasticgun.packets.ModDetect; -import systems.brn.plasticgun.packets.Reload; -import systems.brn.plasticgun.packets.Shoot; import systems.brn.plasticgun.shurikens.ShurikenEntity; import systems.brn.plasticgun.shurikens.ShurikenItem; import systems.brn.plasticgun.testing.DamageTester; @@ -42,6 +44,7 @@ import systems.brn.plasticgun.testing.DamageTester; import java.util.ArrayList; import java.util.Map; +import static net.fabricmc.loader.impl.FabricLoaderImpl.MOD_ID; import static systems.brn.plasticgun.lib.Util.*; public class PlasticGun implements ModInitializer { @@ -68,25 +71,25 @@ public class PlasticGun implements ModInitializer { public static final EntityType BULLET_ENTITY_TYPE = Registry.register( Registries.ENTITY_TYPE, id("bullet"), - EntityType.Builder.create(BulletEntity::new, SpawnGroup.MISC).build() + EntityType.Builder.create(BulletEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("bullet"))) ); public static final EntityType GRENADE_ENTITY_TYPE = Registry.register( Registries.ENTITY_TYPE, id("grenade"), - EntityType.Builder.create(GrenadeEntity::new, SpawnGroup.MISC).build() + EntityType.Builder.create(GrenadeEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("grenade"))) ); public static final EntityType SHURIKEN_ENTITY_TYPE = Registry.register( Registries.ENTITY_TYPE, id("shuriken"), - EntityType.Builder.create(ShurikenEntity::new, SpawnGroup.MISC).build() + EntityType.Builder.create(ShurikenEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("shuriken"))) ); public static final EntityType DAMAGE_TESTER_ENTITY_TYPE = Registry.register( Registries.ENTITY_TYPE, id("damagetester"), - EntityType.Builder.create(DamageTester::new, SpawnGroup.MISC).build() + EntityType.Builder.create(DamageTester::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("damagetester"))) ); public static final Logger logger = LoggerFactory.getLogger(MOD_ID); @@ -339,13 +342,9 @@ public class PlasticGun implements ModInitializer { ItemGroups.register(); PayloadTypeRegistry.playC2S().register(ModDetect.PACKET_ID, ModDetect.PACKET_CODEC); - PayloadTypeRegistry.playC2S().register(Reload.PACKET_ID, Reload.PACKET_CODEC); - PayloadTypeRegistry.playC2S().register(Shoot.PACKET_ID, Shoot.PACKET_CODEC); // Register the global receiver ServerPlayNetworking.registerGlobalReceiver(ModDetect.PACKET_ID, EventHandler::onClientConfirm); - ServerPlayNetworking.registerGlobalReceiver(Reload.PACKET_ID, EventHandler::onClientReload); - ServerPlayNetworking.registerGlobalReceiver(Shoot.PACKET_ID, EventHandler::onClientShoot); PolymerResourcePackUtils.addModAssets(MOD_ID); PolymerResourcePackUtils.markAsRequired(); diff --git a/src/main/java/systems/brn/plasticgun/bullets/BulletEntity.java b/src/main/java/systems/brn/plasticgun/bullets/BulletEntity.java index c34369e..21fbec6 100644 --- a/src/main/java/systems/brn/plasticgun/bullets/BulletEntity.java +++ b/src/main/java/systems/brn/plasticgun/bullets/BulletEntity.java @@ -19,6 +19,7 @@ import net.minecraft.world.World; import systems.brn.plasticgun.grenades.GrenadeExplosionBehavior; import systems.brn.plasticgun.guns.Gun; import systems.brn.plasticgun.lib.WeaponDamageType; +import xyz.nucleoid.packettweaker.PacketContext; import java.lang.reflect.Method; import java.util.List; @@ -87,7 +88,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE } @Override - public EntityType getPolymerEntityType(ServerPlayerEntity player) { + public EntityType getPolymerEntityType(PacketContext packetContext) { return EntityType.ITEM_DISPLAY; } diff --git a/src/main/java/systems/brn/plasticgun/companion/ClientEvents.java b/src/main/java/systems/brn/plasticgun/companion/ClientEvents.java index 170412f..f6ecf73 100644 --- a/src/main/java/systems/brn/plasticgun/companion/ClientEvents.java +++ b/src/main/java/systems/brn/plasticgun/companion/ClientEvents.java @@ -1,6 +1,5 @@ package systems.brn.plasticgun.companion; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -8,30 +7,11 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.render.RenderTickCounter; import net.minecraft.util.math.ColorHelper; import systems.brn.plasticgun.packets.ModDetect; -import systems.brn.plasticgun.packets.Reload; -import systems.brn.plasticgun.packets.Shoot; import java.util.UUID; import static systems.brn.plasticgun.PlasticGun.flashbangEffect; -import static systems.brn.plasticgun.lib.Util.shouldSendClickEvents; - public class ClientEvents { - public static void tick(MinecraftClient minecraftClient) { - if (minecraftClient.options.useKey.isPressed() && minecraftClient.player != null) { - if (shouldSendClickEvents(minecraftClient.player)) { - UUID reloadUUID = UUID.randomUUID(); - ClientPlayNetworking.send(new Reload(reloadUUID)); - } - } - if (minecraftClient.options.attackKey.isPressed() && minecraftClient.player != null) { - if (shouldSendClickEvents(minecraftClient.player)) { - UUID shootUUID = UUID.randomUUID(); - ClientPlayNetworking.send(new Shoot(shootUUID)); - } - } - } - public static void join(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) { UUID joinUUID = UUID.randomUUID(); packetSender.sendPacket(new ModDetect(joinUUID)); @@ -42,7 +22,7 @@ public class ClientEvents { if (MinecraftClient.getInstance().player.hasStatusEffect(flashbangEffect)) { int width = drawContext.getScaledWindowWidth(); int height = drawContext.getScaledWindowHeight(); - drawContext.fill(0, 0, width, height, ColorHelper.Argb.fromFloats(1, 1, 1, 1)); + drawContext.fill(0, 0, width, height, ColorHelper.fromFloats(1, 1, 1, 1)); } } } diff --git a/src/main/java/systems/brn/plasticgun/companion/PlasticGunClient.java b/src/main/java/systems/brn/plasticgun/companion/PlasticGunClient.java index d8230a3..c45601e 100644 --- a/src/main/java/systems/brn/plasticgun/companion/PlasticGunClient.java +++ b/src/main/java/systems/brn/plasticgun/companion/PlasticGunClient.java @@ -8,7 +8,6 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; public class PlasticGunClient implements ClientModInitializer { @Override public void onInitializeClient() { - ClientTickEvents.END_CLIENT_TICK.register(ClientEvents::tick); ClientPlayConnectionEvents.JOIN.register(ClientEvents::join); HudRenderCallback.EVENT.register(ClientEvents::HUDDraw); } diff --git a/src/main/java/systems/brn/plasticgun/effects/FlashbangEffect.java b/src/main/java/systems/brn/plasticgun/effects/FlashbangEffect.java index ccfa3bf..80aede0 100644 --- a/src/main/java/systems/brn/plasticgun/effects/FlashbangEffect.java +++ b/src/main/java/systems/brn/plasticgun/effects/FlashbangEffect.java @@ -6,7 +6,9 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import systems.brn.plasticgun.PlasticGun; +import xyz.nucleoid.packettweaker.PacketContext; import static systems.brn.plasticgun.PlasticGun.flashbangEffect; @@ -26,13 +28,13 @@ public class FlashbangEffect extends StatusEffect implements PolymerStatusEffect // Called when the effect is applied. @Override - public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { - return super.applyUpdateEffect(entity, amplifier); + public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) { + return super.applyUpdateEffect(world, entity, amplifier); } @Override - public StatusEffect getPolymerReplacement(ServerPlayerEntity player){ - if (PlasticGun.clientsWithMod.contains(player)){ + public StatusEffect getPolymerReplacement(PacketContext packetContext){ + if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){ return flashbangEffect.value(); } return StatusEffects.BLINDNESS.value(); diff --git a/src/main/java/systems/brn/plasticgun/effects/StunEffect.java b/src/main/java/systems/brn/plasticgun/effects/StunEffect.java index 0db02be..db245f2 100644 --- a/src/main/java/systems/brn/plasticgun/effects/StunEffect.java +++ b/src/main/java/systems/brn/plasticgun/effects/StunEffect.java @@ -7,7 +7,9 @@ import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import systems.brn.plasticgun.PlasticGun; +import xyz.nucleoid.packettweaker.PacketContext; import static systems.brn.plasticgun.PlasticGun.stunEffect; @@ -34,16 +36,16 @@ public class StunEffect extends StatusEffect implements PolymerStatusEffect { // Called when the effect is applied. @Override - public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) { applied = true; entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, stunDuration, 255, true, false)); entity.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, stunDuration, 255, true, false)); - return super.applyUpdateEffect(entity, amplifier); + return super.applyUpdateEffect(world, entity, amplifier); } @Override - public StatusEffect getPolymerReplacement(ServerPlayerEntity player) { - if (PlasticGun.clientsWithMod.contains(player)){ + public StatusEffect getPolymerReplacement(PacketContext packetContext) { + if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){ return stunEffect.value(); } return null; diff --git a/src/main/java/systems/brn/plasticgun/grenades/FragmentationExplosionBehavior.java b/src/main/java/systems/brn/plasticgun/grenades/FragmentationExplosionBehavior.java index 48b6b45..20487b4 100644 --- a/src/main/java/systems/brn/plasticgun/grenades/FragmentationExplosionBehavior.java +++ b/src/main/java/systems/brn/plasticgun/grenades/FragmentationExplosionBehavior.java @@ -63,8 +63,8 @@ public class FragmentationExplosionBehavior extends ExplosionBehavior { } @Override - public float calculateDamage(Explosion explosion, Entity entity) { - float original = super.calculateDamage(explosion, entity); + public float calculateDamage(Explosion explosion, Entity entity, float amount) { + float original = super.calculateDamage(explosion, entity, amount); if (entity instanceof LivingEntity livingEntity) { original = (float) getFinalDamage(livingEntity, WeaponDamageType.FRAGMENTATION_GRENADE, original); if (original > 0) { diff --git a/src/main/java/systems/brn/plasticgun/grenades/GrenadeExplosionBehavior.java b/src/main/java/systems/brn/plasticgun/grenades/GrenadeExplosionBehavior.java index 3ffa1c0..aef4ad7 100644 --- a/src/main/java/systems/brn/plasticgun/grenades/GrenadeExplosionBehavior.java +++ b/src/main/java/systems/brn/plasticgun/grenades/GrenadeExplosionBehavior.java @@ -13,8 +13,8 @@ public class GrenadeExplosionBehavior extends ExplosionBehavior { @Override - public float calculateDamage(Explosion explosion, Entity entity) { - float original = super.calculateDamage(explosion, entity); + public float calculateDamage(Explosion explosion, Entity entity, float amount) { + float original = super.calculateDamage(explosion, entity, amount); if (entity instanceof LivingEntity livingEntity) { original = (float) getFinalDamage(livingEntity, WeaponDamageType.GRENADE, original); if (original > 0) { diff --git a/src/main/java/systems/brn/plasticgun/guns/Gun.java b/src/main/java/systems/brn/plasticgun/guns/Gun.java index 7c2b21e..b2b4f4a 100644 --- a/src/main/java/systems/brn/plasticgun/guns/Gun.java +++ b/src/main/java/systems/brn/plasticgun/guns/Gun.java @@ -254,7 +254,7 @@ public class Gun extends SimpleItem implements PolymerItem { yaw -= (float) (horizontalRecoilMin + rng.nextFloat() * (horizontalRecoilMax - horizontalRecoilMin)); - entity.teleport(serverWorld, pos.x, pos.y, pos.z, PositionFlag.ROT, yaw, newPitch); + entity.teleport(serverWorld, pos.x, pos.y, pos.z, PositionFlag.ROT, yaw, newPitch, true); double velocityRecoil = rng.nextDouble() * (velocityRecoilMax - velocityRecoilMin); if (velocityRecoil > 0) { entity.setVelocity(currentLook.multiply(velocityRecoil)); diff --git a/src/main/java/systems/brn/plasticgun/lib/EventHandler.java b/src/main/java/systems/brn/plasticgun/lib/EventHandler.java index f0d9ae4..aa5b07e 100644 --- a/src/main/java/systems/brn/plasticgun/lib/EventHandler.java +++ b/src/main/java/systems/brn/plasticgun/lib/EventHandler.java @@ -15,29 +15,25 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import systems.brn.plasticgun.grenades.GrenadeEntity; import systems.brn.plasticgun.grenades.GrenadeItem; import systems.brn.plasticgun.packets.ModDetect; -import systems.brn.plasticgun.packets.Reload; -import systems.brn.plasticgun.packets.Shoot; - import java.util.function.Predicate; import static systems.brn.plasticgun.PlasticGun.*; import static systems.brn.plasticgun.lib.GunComponents.*; public class EventHandler { - public static TypedActionResult onItemUse(PlayerEntity playerEntity, World world, Hand hand) { - ItemStack stack = playerEntity.getStackInHand(hand); + public static ActionResult onItemUse(PlayerEntity playerEntity, World world, Hand hand) { if (playerEntity instanceof ServerPlayerEntity serverPlayerEntity) { if (!world.isClient && !clientsWithMod.contains(serverPlayerEntity)) { rightClickWithItem(serverPlayerEntity, hand); } } - return TypedActionResult.pass(stack); + return ActionResult.PASS; } public static void rightClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) { @@ -161,16 +157,4 @@ public class EventHandler { } } - - public static void onClientReload(Reload reload, ServerPlayNetworking.Context context) { - ServerPlayerEntity player = context.player(); - Hand hand = player.getActiveHand(); - rightClickWithItem(player, hand); - } - - public static void onClientShoot(Shoot shoot, ServerPlayNetworking.Context context) { - ServerPlayerEntity player = context.player(); - Hand hand = player.getActiveHand(); - leftClickWithItem(player, hand); - } } diff --git a/src/main/java/systems/brn/plasticgun/lib/SimpleItem.java b/src/main/java/systems/brn/plasticgun/lib/SimpleItem.java index 8e953fa..62e6db1 100644 --- a/src/main/java/systems/brn/plasticgun/lib/SimpleItem.java +++ b/src/main/java/systems/brn/plasticgun/lib/SimpleItem.java @@ -2,35 +2,32 @@ package systems.brn.plasticgun.lib; import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.item.SimplePolymerItem; -import eu.pb4.polymer.resourcepack.api.PolymerModelData; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.minecraft.item.*; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; import systems.brn.plasticgun.PlasticGun; +import xyz.nucleoid.packettweaker.PacketContext; public abstract class SimpleItem extends SimplePolymerItem implements PolymerItem { - private final PolymerModelData polymerModel; + private final Identifier polymerModel; protected final Identifier identifier; public SimpleItem(Settings settings, Identifier identifier, Item replacement) { super(settings, replacement); this.identifier = identifier; - this.polymerModel = PolymerResourcePackUtils.requestModel(replacement, identifier.withPath("item/" + identifier.getPath())); + this.polymerModel = PolymerResourcePackUtils.getBridgedModelId(identifier.withPath("item/" + identifier.getPath())); } @Override - public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) { -// if(PlasticGun.clientsWithMod.contains(player)){ -// return this; -// } - return this.polymerModel.item(); + public Identifier getPolymerItemModel(ItemStack stack, PacketContext context) { + return this.polymerModel; } @Override - public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) { - return this.polymerModel.value(); + public Item getPolymerItem(ItemStack itemStack, PacketContext player) { + return Items.STICK; } } \ No newline at end of file diff --git a/src/main/java/systems/brn/plasticgun/lib/TrinketPolymerItem.java b/src/main/java/systems/brn/plasticgun/lib/TrinketPolymerItem.java index 41fb75f..b1e09b4 100644 --- a/src/main/java/systems/brn/plasticgun/lib/TrinketPolymerItem.java +++ b/src/main/java/systems/brn/plasticgun/lib/TrinketPolymerItem.java @@ -9,8 +9,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundEvent; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; @@ -27,10 +27,10 @@ public class TrinketPolymerItem extends SimpleItem implements Trinket { } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { ItemStack stack = user.getStackInHand(hand); if (equipItem(user, stack)) { - return TypedActionResult.success(stack, world.isClient()); + return ActionResult.SUCCESS; } return super.use(world, user, hand); } diff --git a/src/main/java/systems/brn/plasticgun/lib/Util.java b/src/main/java/systems/brn/plasticgun/lib/Util.java index 5e68a60..87c07bb 100644 --- a/src/main/java/systems/brn/plasticgun/lib/Util.java +++ b/src/main/java/systems/brn/plasticgun/lib/Util.java @@ -8,7 +8,6 @@ import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData; import net.fabricmc.fabric.api.loot.v3.LootTableEvents; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.data.DataTracker; @@ -18,6 +17,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.ModelTransformationMode; import net.minecraft.loot.LootTable; import net.minecraft.loot.entry.ItemEntry; import net.minecraft.particle.BlockStateParticleEffect; diff --git a/src/main/java/systems/brn/plasticgun/packets/Reload.java b/src/main/java/systems/brn/plasticgun/packets/Reload.java deleted file mode 100644 index 5f1cf19..0000000 --- a/src/main/java/systems/brn/plasticgun/packets/Reload.java +++ /dev/null @@ -1,19 +0,0 @@ -package systems.brn.plasticgun.packets; - - -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Uuids; - -import java.util.UUID; - -public record Reload(UUID slapped) implements CustomPayload { - public static final Id PACKET_ID = new Id<>(CustomPayload.id("reload").id()); - public static final PacketCodec PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Reload::new, Reload::slapped).cast(); - - @Override - public Id getId() { - return PACKET_ID; - } -} diff --git a/src/main/java/systems/brn/plasticgun/packets/Shoot.java b/src/main/java/systems/brn/plasticgun/packets/Shoot.java deleted file mode 100644 index eaef0b3..0000000 --- a/src/main/java/systems/brn/plasticgun/packets/Shoot.java +++ /dev/null @@ -1,19 +0,0 @@ -package systems.brn.plasticgun.packets; - - -import net.minecraft.network.RegistryByteBuf; -import net.minecraft.network.codec.PacketCodec; -import net.minecraft.network.packet.CustomPayload; -import net.minecraft.util.Uuids; - -import java.util.UUID; - -public record Shoot(UUID slapped) implements CustomPayload { - public static final Id PACKET_ID = new Id<>(CustomPayload.id("shoot").id()); - public static final PacketCodec PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Shoot::new, Shoot::slapped).cast(); - - @Override - public Id getId() { - return PACKET_ID; - } -} diff --git a/src/main/java/systems/brn/plasticgun/testing/DamageTester.java b/src/main/java/systems/brn/plasticgun/testing/DamageTester.java index 3552f4e..8b50204 100644 --- a/src/main/java/systems/brn/plasticgun/testing/DamageTester.java +++ b/src/main/java/systems/brn/plasticgun/testing/DamageTester.java @@ -11,10 +11,12 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Arm; import eu.pb4.polymer.core.api.entity.PolymerEntity; import net.minecraft.world.World; +import xyz.nucleoid.packettweaker.PacketContext; import java.util.Collections; @@ -25,10 +27,10 @@ public class DamageTester extends LivingEntity implements PolymerEntity { } @Override - public boolean damage(DamageSource source, float amount) { + public boolean damage(ServerWorld world, DamageSource source, float amount) { Entity attacker = source.getAttacker(); if (attacker instanceof PlayerEntity player) { - player.sendMessage(Text.literal("You damaged by " + amount)); + player.sendMessage(Text.literal("You damaged by " + amount), false); if (player.isSneaking()) { this.remove(RemovalReason.KILLED); } @@ -39,13 +41,8 @@ public class DamageTester extends LivingEntity implements PolymerEntity { public static DefaultAttributeContainer.Builder createDamageTesterAttributes() { return LivingEntity.createLivingAttributes() - .add(EntityAttributes.GENERIC_MAX_HEALTH, 1.0) - .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 0.0); - } - - @Override - public EntityType getPolymerEntityType(ServerPlayerEntity player) { - return EntityType.ZOMBIE; + .add(EntityAttributes.MAX_HEALTH, 1.0) + .add(EntityAttributes.ATTACK_DAMAGE, 0.0); } @Override @@ -67,4 +64,9 @@ public class DamageTester extends LivingEntity implements PolymerEntity { public Arm getMainArm() { return Arm.RIGHT; } + + @Override + public EntityType getPolymerEntityType(PacketContext context) { + return EntityType.ZOMBIE; + } } diff --git a/src/main/java/systems/brn/plasticgun/throwables/ThrowableProjectile.java b/src/main/java/systems/brn/plasticgun/throwables/ThrowableProjectile.java index f7e4914..1e37c2e 100644 --- a/src/main/java/systems/brn/plasticgun/throwables/ThrowableProjectile.java +++ b/src/main/java/systems/brn/plasticgun/throwables/ThrowableProjectile.java @@ -9,6 +9,7 @@ import net.minecraft.item.Items; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import xyz.nucleoid.packettweaker.PacketContext; import java.lang.reflect.Method; import java.util.List; @@ -45,6 +46,11 @@ public class ThrowableProjectile extends PersistentProjectileEntity implements P } + @Override + public EntityType getPolymerEntityType(PacketContext context) { + return EntityType.ITEM_DISPLAY; + } + @Override public void modifyRawTrackedData(List> data, ServerPlayerEntity player, boolean initial) { setProjectileData(data, initial, scale, this.itemStack); @@ -73,10 +79,5 @@ public class ThrowableProjectile extends PersistentProjectileEntity implements P return this.itemStack(); } - @Override - public EntityType getPolymerEntityType(ServerPlayerEntity player) { - return EntityType.ITEM_DISPLAY; - } - }