Try some stuff

This commit is contained in:
Bruno Rybársky 2024-11-01 23:35:39 +01:00
parent 2395fa83ff
commit 78633a1338
No known key found for this signature in database
GPG Key ID: 6C9206A821C70598
18 changed files with 67 additions and 138 deletions

@ -2,17 +2,17 @@
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.1 minecraft_version=1.21.3
yarn_mappings=1.21.1+build.3 yarn_mappings=1.21.3+build.2
loader_version=0.16.0 loader_version=0.16.8
# Mod Properties # Mod Properties
mod_version=1.9.6 mod_version=1.9.7
maven_group=systems.brn maven_group=systems.brn
archives_base_name=plasticgun archives_base_name=plasticgun
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # 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 polymer_version=0.10.1+1.21.3
server_translations_api_version=2.3.1+1.21-pre2 server_translations_api_version=2.4.0+1.21.2-rc1
trinkets_version=3.10.0+polymerport.2 trinkets_version=3.10.0+polymerport.2

@ -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.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffect;
@ -17,8 +18,11 @@ import net.minecraft.item.Item;
import net.minecraft.loot.LootTables; import net.minecraft.loot.LootTables;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import systems.brn.plasticgun.bullets.BulletEntity; 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.EventHandler;
import systems.brn.plasticgun.lib.ItemGroups; import systems.brn.plasticgun.lib.ItemGroups;
import systems.brn.plasticgun.packets.ModDetect; 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.ShurikenEntity;
import systems.brn.plasticgun.shurikens.ShurikenItem; import systems.brn.plasticgun.shurikens.ShurikenItem;
import systems.brn.plasticgun.testing.DamageTester; import systems.brn.plasticgun.testing.DamageTester;
@ -42,6 +44,7 @@ import systems.brn.plasticgun.testing.DamageTester;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import static net.fabricmc.loader.impl.FabricLoaderImpl.MOD_ID;
import static systems.brn.plasticgun.lib.Util.*; import static systems.brn.plasticgun.lib.Util.*;
public class PlasticGun implements ModInitializer { public class PlasticGun implements ModInitializer {
@ -68,25 +71,25 @@ public class PlasticGun implements ModInitializer {
public static final EntityType<BulletEntity> BULLET_ENTITY_TYPE = Registry.register( public static final EntityType<BulletEntity> BULLET_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE, Registries.ENTITY_TYPE,
id("bullet"), id("bullet"),
EntityType.Builder.<BulletEntity>create(BulletEntity::new, SpawnGroup.MISC).build() EntityType.Builder.<BulletEntity>create(BulletEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("bullet")))
); );
public static final EntityType<GrenadeEntity> GRENADE_ENTITY_TYPE = Registry.register( public static final EntityType<GrenadeEntity> GRENADE_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE, Registries.ENTITY_TYPE,
id("grenade"), id("grenade"),
EntityType.Builder.<GrenadeEntity>create(GrenadeEntity::new, SpawnGroup.MISC).build() EntityType.Builder.<GrenadeEntity>create(GrenadeEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("grenade")))
); );
public static final EntityType<ShurikenEntity> SHURIKEN_ENTITY_TYPE = Registry.register( public static final EntityType<ShurikenEntity> SHURIKEN_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE, Registries.ENTITY_TYPE,
id("shuriken"), id("shuriken"),
EntityType.Builder.<ShurikenEntity>create(ShurikenEntity::new, SpawnGroup.MISC).build() EntityType.Builder.<ShurikenEntity>create(ShurikenEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("shuriken")))
); );
public static final EntityType<DamageTester> DAMAGE_TESTER_ENTITY_TYPE = Registry.register( public static final EntityType<DamageTester> DAMAGE_TESTER_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE, Registries.ENTITY_TYPE,
id("damagetester"), 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); public static final Logger logger = LoggerFactory.getLogger(MOD_ID);
@ -339,13 +342,9 @@ public class PlasticGun implements ModInitializer {
ItemGroups.register(); ItemGroups.register();
PayloadTypeRegistry.playC2S().register(ModDetect.PACKET_ID, ModDetect.PACKET_CODEC); 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 // Register the global receiver
ServerPlayNetworking.registerGlobalReceiver(ModDetect.PACKET_ID, EventHandler::onClientConfirm); 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.addModAssets(MOD_ID);
PolymerResourcePackUtils.markAsRequired(); PolymerResourcePackUtils.markAsRequired();

@ -19,6 +19,7 @@ import net.minecraft.world.World;
import systems.brn.plasticgun.grenades.GrenadeExplosionBehavior; import systems.brn.plasticgun.grenades.GrenadeExplosionBehavior;
import systems.brn.plasticgun.guns.Gun; import systems.brn.plasticgun.guns.Gun;
import systems.brn.plasticgun.lib.WeaponDamageType; import systems.brn.plasticgun.lib.WeaponDamageType;
import xyz.nucleoid.packettweaker.PacketContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
@ -87,7 +88,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
} }
@Override @Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) { public EntityType<?> getPolymerEntityType(PacketContext packetContext) {
return EntityType.ITEM_DISPLAY; return EntityType.ITEM_DISPLAY;
} }

@ -1,6 +1,5 @@
package systems.brn.plasticgun.companion; package systems.brn.plasticgun.companion;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; 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.client.render.RenderTickCounter;
import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.ColorHelper;
import systems.brn.plasticgun.packets.ModDetect; import systems.brn.plasticgun.packets.ModDetect;
import systems.brn.plasticgun.packets.Reload;
import systems.brn.plasticgun.packets.Shoot;
import java.util.UUID; import java.util.UUID;
import static systems.brn.plasticgun.PlasticGun.flashbangEffect; import static systems.brn.plasticgun.PlasticGun.flashbangEffect;
import static systems.brn.plasticgun.lib.Util.shouldSendClickEvents;
public class ClientEvents { 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) { public static void join(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) {
UUID joinUUID = UUID.randomUUID(); UUID joinUUID = UUID.randomUUID();
packetSender.sendPacket(new ModDetect(joinUUID)); packetSender.sendPacket(new ModDetect(joinUUID));
@ -42,7 +22,7 @@ public class ClientEvents {
if (MinecraftClient.getInstance().player.hasStatusEffect(flashbangEffect)) { if (MinecraftClient.getInstance().player.hasStatusEffect(flashbangEffect)) {
int width = drawContext.getScaledWindowWidth(); int width = drawContext.getScaledWindowWidth();
int height = drawContext.getScaledWindowHeight(); 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));
} }
} }
} }

@ -8,7 +8,6 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
public class PlasticGunClient implements ClientModInitializer { public class PlasticGunClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(ClientEvents::tick);
ClientPlayConnectionEvents.JOIN.register(ClientEvents::join); ClientPlayConnectionEvents.JOIN.register(ClientEvents::join);
HudRenderCallback.EVENT.register(ClientEvents::HUDDraw); HudRenderCallback.EVENT.register(ClientEvents::HUDDraw);
} }

@ -6,7 +6,9 @@ import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import systems.brn.plasticgun.PlasticGun; import systems.brn.plasticgun.PlasticGun;
import xyz.nucleoid.packettweaker.PacketContext;
import static systems.brn.plasticgun.PlasticGun.flashbangEffect; import static systems.brn.plasticgun.PlasticGun.flashbangEffect;
@ -26,13 +28,13 @@ public class FlashbangEffect extends StatusEffect implements PolymerStatusEffect
// Called when the effect is applied. // Called when the effect is applied.
@Override @Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
return super.applyUpdateEffect(entity, amplifier); return super.applyUpdateEffect(world, entity, amplifier);
} }
@Override @Override
public StatusEffect getPolymerReplacement(ServerPlayerEntity player){ public StatusEffect getPolymerReplacement(PacketContext packetContext){
if (PlasticGun.clientsWithMod.contains(player)){ if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){
return flashbangEffect.value(); return flashbangEffect.value();
} }
return StatusEffects.BLINDNESS.value(); return StatusEffects.BLINDNESS.value();

@ -7,7 +7,9 @@ import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import systems.brn.plasticgun.PlasticGun; import systems.brn.plasticgun.PlasticGun;
import xyz.nucleoid.packettweaker.PacketContext;
import static systems.brn.plasticgun.PlasticGun.stunEffect; import static systems.brn.plasticgun.PlasticGun.stunEffect;
@ -34,16 +36,16 @@ public class StunEffect extends StatusEffect implements PolymerStatusEffect {
// Called when the effect is applied. // Called when the effect is applied.
@Override @Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
applied = true; applied = true;
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, stunDuration, 255, true, false)); entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, stunDuration, 255, true, false));
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, 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 @Override
public StatusEffect getPolymerReplacement(ServerPlayerEntity player) { public StatusEffect getPolymerReplacement(PacketContext packetContext) {
if (PlasticGun.clientsWithMod.contains(player)){ if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){
return stunEffect.value(); return stunEffect.value();
} }
return null; return null;

@ -63,8 +63,8 @@ public class FragmentationExplosionBehavior extends ExplosionBehavior {
} }
@Override @Override
public float calculateDamage(Explosion explosion, Entity entity) { public float calculateDamage(Explosion explosion, Entity entity, float amount) {
float original = super.calculateDamage(explosion, entity); float original = super.calculateDamage(explosion, entity, amount);
if (entity instanceof LivingEntity livingEntity) { if (entity instanceof LivingEntity livingEntity) {
original = (float) getFinalDamage(livingEntity, WeaponDamageType.FRAGMENTATION_GRENADE, original); original = (float) getFinalDamage(livingEntity, WeaponDamageType.FRAGMENTATION_GRENADE, original);
if (original > 0) { if (original > 0) {

@ -13,8 +13,8 @@ public class GrenadeExplosionBehavior extends ExplosionBehavior {
@Override @Override
public float calculateDamage(Explosion explosion, Entity entity) { public float calculateDamage(Explosion explosion, Entity entity, float amount) {
float original = super.calculateDamage(explosion, entity); float original = super.calculateDamage(explosion, entity, amount);
if (entity instanceof LivingEntity livingEntity) { if (entity instanceof LivingEntity livingEntity) {
original = (float) getFinalDamage(livingEntity, WeaponDamageType.GRENADE, original); original = (float) getFinalDamage(livingEntity, WeaponDamageType.GRENADE, original);
if (original > 0) { if (original > 0) {

@ -254,7 +254,7 @@ public class Gun extends SimpleItem implements PolymerItem {
yaw -= (float) (horizontalRecoilMin + rng.nextFloat() * (horizontalRecoilMax - horizontalRecoilMin)); 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); double velocityRecoil = rng.nextDouble() * (velocityRecoilMax - velocityRecoilMin);
if (velocityRecoil > 0) { if (velocityRecoil > 0) {
entity.setVelocity(currentLook.multiply(velocityRecoil)); entity.setVelocity(currentLook.multiply(velocityRecoil));

@ -15,29 +15,25 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import systems.brn.plasticgun.grenades.GrenadeEntity; import systems.brn.plasticgun.grenades.GrenadeEntity;
import systems.brn.plasticgun.grenades.GrenadeItem; import systems.brn.plasticgun.grenades.GrenadeItem;
import systems.brn.plasticgun.packets.ModDetect; import systems.brn.plasticgun.packets.ModDetect;
import systems.brn.plasticgun.packets.Reload;
import systems.brn.plasticgun.packets.Shoot;
import java.util.function.Predicate; import java.util.function.Predicate;
import static systems.brn.plasticgun.PlasticGun.*; import static systems.brn.plasticgun.PlasticGun.*;
import static systems.brn.plasticgun.lib.GunComponents.*; import static systems.brn.plasticgun.lib.GunComponents.*;
public class EventHandler { public class EventHandler {
public static TypedActionResult<ItemStack> onItemUse(PlayerEntity playerEntity, World world, Hand hand) { public static ActionResult onItemUse(PlayerEntity playerEntity, World world, Hand hand) {
ItemStack stack = playerEntity.getStackInHand(hand);
if (playerEntity instanceof ServerPlayerEntity serverPlayerEntity) { if (playerEntity instanceof ServerPlayerEntity serverPlayerEntity) {
if (!world.isClient && !clientsWithMod.contains(serverPlayerEntity)) { if (!world.isClient && !clientsWithMod.contains(serverPlayerEntity)) {
rightClickWithItem(serverPlayerEntity, hand); rightClickWithItem(serverPlayerEntity, hand);
} }
} }
return TypedActionResult.pass(stack); return ActionResult.PASS;
} }
public static void rightClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) { 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);
}
} }

@ -2,35 +2,32 @@ package systems.brn.plasticgun.lib;
import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.core.api.item.SimplePolymerItem; import eu.pb4.polymer.core.api.item.SimplePolymerItem;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import systems.brn.plasticgun.PlasticGun; import systems.brn.plasticgun.PlasticGun;
import xyz.nucleoid.packettweaker.PacketContext;
public abstract class SimpleItem extends SimplePolymerItem implements PolymerItem { public abstract class SimpleItem extends SimplePolymerItem implements PolymerItem {
private final PolymerModelData polymerModel; private final Identifier polymerModel;
protected final Identifier identifier; protected final Identifier identifier;
public SimpleItem(Settings settings, Identifier identifier, Item replacement) { public SimpleItem(Settings settings, Identifier identifier, Item replacement) {
super(settings, replacement); super(settings, replacement);
this.identifier = identifier; this.identifier = identifier;
this.polymerModel = PolymerResourcePackUtils.requestModel(replacement, identifier.withPath("item/" + identifier.getPath())); this.polymerModel = PolymerResourcePackUtils.getBridgedModelId(identifier.withPath("item/" + identifier.getPath()));
} }
@Override @Override
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) { public Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
// if(PlasticGun.clientsWithMod.contains(player)){ return this.polymerModel;
// return this;
// }
return this.polymerModel.item();
} }
@Override @Override
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) { public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
return this.polymerModel.value(); return Items.STICK;
} }
} }

@ -9,8 +9,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent; import net.minecraft.world.event.GameEvent;
@ -27,10 +27,10 @@ public class TrinketPolymerItem extends SimpleItem implements Trinket {
} }
@Override @Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { public ActionResult use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand); ItemStack stack = user.getStackInHand(hand);
if (equipItem(user, stack)) { if (equipItem(user, stack)) {
return TypedActionResult.success(stack, world.isClient()); return ActionResult.SUCCESS;
} }
return super.use(world, user, hand); return super.use(world, user, hand);
} }

@ -8,7 +8,6 @@ import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData;
import net.fabricmc.fabric.api.loot.v3.LootTableEvents; import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
@ -18,6 +17,7 @@ import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ModelTransformationMode;
import net.minecraft.loot.LootTable; import net.minecraft.loot.LootTable;
import net.minecraft.loot.entry.ItemEntry; import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;

@ -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<Reload> PACKET_ID = new Id<>(CustomPayload.id("reload").id());
public static final PacketCodec<RegistryByteBuf, Reload> PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Reload::new, Reload::slapped).cast();
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

@ -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<Shoot> PACKET_ID = new Id<>(CustomPayload.id("shoot").id());
public static final PacketCodec<RegistryByteBuf, Shoot> PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Shoot::new, Shoot::slapped).cast();
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

@ -11,10 +11,12 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.entity.PolymerEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;
import java.util.Collections; import java.util.Collections;
@ -25,10 +27,10 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
} }
@Override @Override
public boolean damage(DamageSource source, float amount) { public boolean damage(ServerWorld world, DamageSource source, float amount) {
Entity attacker = source.getAttacker(); Entity attacker = source.getAttacker();
if (attacker instanceof PlayerEntity player) { 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()) { if (player.isSneaking()) {
this.remove(RemovalReason.KILLED); this.remove(RemovalReason.KILLED);
} }
@ -39,13 +41,8 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
public static DefaultAttributeContainer.Builder createDamageTesterAttributes() { public static DefaultAttributeContainer.Builder createDamageTesterAttributes() {
return LivingEntity.createLivingAttributes() return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 1.0) .add(EntityAttributes.MAX_HEALTH, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 0.0); .add(EntityAttributes.ATTACK_DAMAGE, 0.0);
}
@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
return EntityType.ZOMBIE;
} }
@Override @Override
@ -67,4 +64,9 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
public Arm getMainArm() { public Arm getMainArm() {
return Arm.RIGHT; return Arm.RIGHT;
} }
@Override
public EntityType<?> getPolymerEntityType(PacketContext context) {
return EntityType.ZOMBIE;
}
} }

@ -9,6 +9,7 @@ import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; 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 @Override
public void modifyRawTrackedData(List<DataTracker.SerializedEntry<?>> data, ServerPlayerEntity player, boolean initial) { public void modifyRawTrackedData(List<DataTracker.SerializedEntry<?>> data, ServerPlayerEntity player, boolean initial) {
setProjectileData(data, initial, scale, this.itemStack); setProjectileData(data, initial, scale, this.itemStack);
@ -73,10 +79,5 @@ public class ThrowableProjectile extends PersistentProjectileEntity implements P
return this.itemStack(); return this.itemStack();
} }
@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
return EntityType.ITEM_DISPLAY;
}
} }