From 2ce633d9e3065d6730aeeaaceaa21853761684a1 Mon Sep 17 00:00:00 2001 From: samolego <34912839+samolego@users.noreply.github.com> Date: Sun, 8 Oct 2023 11:27:38 +0200 Subject: [PATCH] Some updates for 1.20.2 --- .../AClientboundAddPlayerPacket.java | 43 ----- ...acketListenerImplMixin_BungeeListener.java | 17 +- ...mePacketListenerImplMixin_PacketFaker.java | 34 ++-- .../samo_lego/taterzens/npc/TaterzenNPC.java | 168 ++++++++++++------ .../taterzens/npc/commands/BungeeCommand.java | 50 +++--- .../resources/taterzens.common.mixins.json | 1 - fabric/gradle.properties | 8 +- .../forge/platform/ForgePlatform.java | 1 + gradle.properties | 8 +- 9 files changed, 184 insertions(+), 146 deletions(-) delete mode 100644 common/src/main/java/org/samo_lego/taterzens/mixin/accessors/AClientboundAddPlayerPacket.java diff --git a/common/src/main/java/org/samo_lego/taterzens/mixin/accessors/AClientboundAddPlayerPacket.java b/common/src/main/java/org/samo_lego/taterzens/mixin/accessors/AClientboundAddPlayerPacket.java deleted file mode 100644 index c908f2702..000000000 --- a/common/src/main/java/org/samo_lego/taterzens/mixin/accessors/AClientboundAddPlayerPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.samo_lego.taterzens.mixin.accessors; - -import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.UUID; - -@Mixin(ClientboundAddPlayerPacket.class) -public interface AClientboundAddPlayerPacket { - @Mutable - @Accessor("entityId") - void setId(int id); - - @Mutable - @Accessor("entityId") - int getId(); - - @Mutable - @Accessor("playerId") - void setUuid(UUID uuid); - - @Mutable - @Accessor("x") - void setX(double x); - - @Mutable - @Accessor("y") - void setY(double y); - - @Mutable - @Accessor("z") - void setZ(double z); - - @Mutable - @Accessor("yRot") - void setYRot(byte yRot); - - @Mutable - @Accessor("xRot") - void setXRot(byte xRot); -} diff --git a/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_BungeeListener.java b/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_BungeeListener.java index 56dec09b3..e168d0c89 100644 --- a/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_BungeeListener.java +++ b/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_BungeeListener.java @@ -4,9 +4,13 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.network.ServerCommonPacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.samo_lego.taterzens.Taterzens; import org.samo_lego.taterzens.npc.commands.BungeeCommand; @@ -19,7 +23,6 @@ import java.util.Collections; -import static net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket.BRAND; import static org.samo_lego.taterzens.Taterzens.config; import static org.samo_lego.taterzens.npc.commands.BungeeCommand.AVAILABLE_SERVERS; import static org.samo_lego.taterzens.npc.commands.BungeeCommand.BUNGEE_CHANNEL; @@ -28,7 +31,7 @@ * Handles bungee packets. */ @Mixin(value = ServerGamePacketListenerImpl.class) -public class ServerGamePacketListenerImplMixin_BungeeListener { +public abstract class ServerGamePacketListenerImplMixin_BungeeListener extends ServerCommonPacketListenerImpl { @Unique private static final String GET_SERVERS = "GetServers"; @Shadow @@ -37,9 +40,13 @@ public class ServerGamePacketListenerImplMixin_BungeeListener { @Unique private static final String taterzens$permission = "taterzens.npc.edit.commands.addBungee"; + public ServerGamePacketListenerImplMixin_BungeeListener(MinecraftServer minecraftServer, Connection connection, CommonListenerCookie commonListenerCookie) { + super(minecraftServer, connection, commonListenerCookie); + } + @Inject(method = "handleCustomPayload", at = @At("TAIL")) - private void onCustomPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci) { - ResourceLocation packetId = packet.getIdentifier(); + private void taterzens_onCustomPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci) { + ResourceLocation packetId = packet.payload().id(); CommandSourceStack commandSourceStack = player.createCommandSourceStack(); boolean hasPermission = Taterzens.getInstance().getPlatform().checkPermission(commandSourceStack, taterzens$permission, config.perms.npcCommandPermissionLevel); diff --git a/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_PacketFaker.java b/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_PacketFaker.java index 1da209d5f..0c0f170b9 100644 --- a/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_PacketFaker.java +++ b/common/src/main/java/org/samo_lego/taterzens/mixin/network/ServerGamePacketListenerImplMixin_PacketFaker.java @@ -1,20 +1,22 @@ package org.samo_lego.taterzens.mixin.network; import com.mojang.authlib.GameProfile; +import net.minecraft.network.Connection; import net.minecraft.network.PacketSendListener; import net.minecraft.network.protocol.BundlePacket; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.CommonListenerCookie; +import net.minecraft.server.network.ServerCommonPacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.Nullable; import org.samo_lego.taterzens.interfaces.ITaterzenEditor; -import org.samo_lego.taterzens.mixin.accessors.AClientboundAddPlayerPacket; import org.samo_lego.taterzens.mixin.accessors.AClientboundPlayerInfoUpdatePacket; import org.samo_lego.taterzens.mixin.accessors.AClientboundSetEntityDataPacket; import org.samo_lego.taterzens.npc.TaterzenNPC; @@ -34,7 +36,7 @@ * Used to "fake" the TaterzenNPC entity type. */ @Mixin(value = ServerGamePacketListenerImpl.class, priority = 900) -public abstract class ServerGamePacketListenerImplMixin_PacketFaker { +public abstract class ServerGamePacketListenerImplMixin_PacketFaker extends ServerCommonPacketListenerImpl { @Unique private final Map tablistQueue = new LinkedHashMap<>(); @@ -45,24 +47,26 @@ public abstract class ServerGamePacketListenerImplMixin_PacketFaker { @Unique private int queueTick; - @Shadow - public abstract void send(Packet packet, @Nullable PacketSendListener packetSendListener); + @Unique + private final ServerGamePacketListenerImpl self = (ServerGamePacketListenerImpl) (Object) this; + + public ServerGamePacketListenerImplMixin_PacketFaker(MinecraftServer minecraftServer, Connection connection, CommonListenerCookie commonListenerCookie) { + super(minecraftServer, connection, commonListenerCookie); + } - @Shadow - public abstract void send(Packet packet); /** * Changes entity type if entity is an instance of {@link TaterzenNPC}. */ - @Inject(method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V", + @Inject(method = "send", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V"), cancellable = true) - private void changeEntityType(Packet packet, PacketSendListener listener, CallbackInfo ci) { + private void taterzen_changeEntityType(Packet packet, PacketSendListener listener, CallbackInfo ci) { Level world = player.level(); if (packet instanceof BundlePacket bPacket && !this.skipCheck) { for (Packet subPacket : bPacket.subPackets()) { - if (subPacket instanceof ClientboundAddPlayerPacket) { - Entity entity = world.getEntity(((AClientboundAddPlayerPacket) subPacket).getId()); + if (subPacket instanceof ClientboundAddEntityPacket) { + Entity entity = world.getEntity(((ClientboundAddEntityPacket) subPacket).getId()); if (!(entity instanceof TaterzenNPC npc)) return; @@ -72,13 +76,13 @@ private void changeEntityType(Packet packet, PacketSendListener listener, Cal //noinspection ConstantConditions var entry = new ClientboundPlayerInfoUpdatePacket.Entry(profile.getId(), profile, false, 0, GameType.SURVIVAL, npc.getDisplayName(), null); ((AClientboundPlayerInfoUpdatePacket) playerAddPacket).setEntries(Collections.singletonList(entry)); - this.send(playerAddPacket, listener); + self.send(playerAddPacket, listener); // Before we send this packet, we have // added player to tablist, otherwise client doesn't // show it ... :mojank: this.skipCheck = true; - this.send(packet, listener); + self.send(packet, listener); this.skipCheck = false; // And now we can remove it from tablist @@ -92,7 +96,7 @@ private void changeEntityType(Packet packet, PacketSendListener listener, Cal tablistQueue.put(uuid, new NpcPlayerUpdate(npc.getGameProfile(), npc.getTabListName(), queueTick + config.taterzenTablistTimeout)); } - this.send(new ClientboundRotateHeadPacket(entity, (byte) ((int) (entity.getYHeadRot() * 256.0F / 360.0F))), listener); + self.send(new ClientboundRotateHeadPacket(entity, (byte) ((int) (entity.getYHeadRot() * 256.0F / 360.0F))), listener); ci.cancel(); } else if (subPacket instanceof ClientboundSetEntityDataPacket) { @@ -137,7 +141,7 @@ private void removeTaterzenFromTablist(CallbackInfo ci) { ClientboundPlayerInfoRemovePacket taterzensRemovePacket = new ClientboundPlayerInfoRemovePacket(toRemove); this.skipCheck = true; - this.send(taterzensRemovePacket); + self.send(taterzensRemovePacket); this.skipCheck = false; } } diff --git a/common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java b/common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java index bf1c40749..07e1bbb81 100644 --- a/common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java +++ b/common/src/main/java/org/samo_lego/taterzens/npc/TaterzenNPC.java @@ -14,13 +14,10 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket; +import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ChunkMap; -import net.minecraft.server.level.ServerChunkCache; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.*; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.util.Mth; @@ -42,6 +39,7 @@ import net.minecraft.world.entity.monster.CrossbowAttackMob; import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.monster.RangedAttackMob; +import net.minecraft.world.entity.player.ChatVisiblity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Projectile; @@ -64,7 +62,6 @@ import org.samo_lego.taterzens.interfaces.ITaterzenEditor; import org.samo_lego.taterzens.interfaces.ITaterzenPlayer; import org.samo_lego.taterzens.mixin.accessors.AChunkMap; -import org.samo_lego.taterzens.mixin.accessors.AClientboundAddPlayerPacket; import org.samo_lego.taterzens.mixin.accessors.AEntityTrackerEntry; import org.samo_lego.taterzens.npc.ai.goal.*; import org.samo_lego.taterzens.npc.commands.AbstractTaterzenCommand; @@ -154,7 +151,7 @@ public TaterzenNPC(Level world) { * instead, as this one doesn't set the position and custom name. * * @param entityType Taterzen entity type - * @param world Taterzen's world + * @param world Taterzen's world */ public TaterzenNPC(EntityType entityType, Level world) { super(entityType, world); @@ -191,6 +188,7 @@ public TaterzenNPC(EntityType entityType, Level world) /** * Creates default taterzen attributes. + * * @return attribute supplier builder. */ public static AttributeSupplier.Builder createTaterzenAttributes() { @@ -208,7 +206,16 @@ public static AttributeSupplier.Builder createTaterzenAttributes() { * player synched data. */ public void constructFakePlayer() { - this.fakePlayer = new ServerPlayer(this.getServer(), (ServerLevel) this.level(), this.gameProfile); + this.fakePlayer = new ServerPlayer(this.getServer(), (ServerLevel) this.level(), this.gameProfile, new ClientInformation( + "en_US", + 0, + ChatVisiblity.FULL, + true, + 0x7f, + HumanoidArm.RIGHT, + false, + false + )); this.fakePlayer.getEntityData().set(getPLAYER_MODE_CUSTOMISATION(), (byte) 0x7f); this.fakePlayer.setPos(this.getX(), this.getY(), this.getZ()); this.fakePlayer.setXRot(this.getXRot()); @@ -219,6 +226,7 @@ public void constructFakePlayer() { /** * Adds sounds to the list of ambient sounds of a Taterzen. + * * @param ambientSound The ambient sound resource location to add. */ public void addAmbientSound(String ambientSound) { @@ -227,6 +235,7 @@ public void addAmbientSound(String ambientSound) { /** * Adds sounds to the list of hurt sounds of a Taterzen. + * * @param hurtSound The hurt sound resource location to add. */ public void addHurtSound(String hurtSound) { @@ -235,6 +244,7 @@ public void addHurtSound(String hurtSound) { /** * Adds sounds to the list of death sounds of a Taterzen. + * * @param deathSound The death sound resource location to add. */ public void addDeathSound(String deathSound) { @@ -243,6 +253,7 @@ public void addDeathSound(String deathSound) { /** * Removes sounds from the list of ambient sounds of a Taterzen. + * * @param index The index of the ambient sound resource location within the NPCData structure. */ public void removeAmbientSound(int index) { @@ -251,6 +262,7 @@ public void removeAmbientSound(int index) { /** * Removes sounds from the list of hurt sounds of a Taterzen. + * * @param index The index of the hurt sound resource location within the NPCData structure. */ public void removeHurtSound(int index) { @@ -259,6 +271,7 @@ public void removeHurtSound(int index) { /** * Removes sounds from the list of death sounds of a Taterzen. + * * @param index The index of the death sound resource location within the NPCData structure. */ public void removeDeathSound(int index) { @@ -396,6 +409,7 @@ public void setMovement(NPCData.Movement movement) { /** * Gets current movement of taterzen. + * * @return current movement */ public NPCData.Movement getMovement() { @@ -404,6 +418,7 @@ public NPCData.Movement getMovement() { /** * Adds block position as a node in path of Taterzen. + * * @param blockPos position to add. */ public void addPathTarget(BlockPos blockPos) { @@ -422,6 +437,7 @@ public SynchedEntityData getEntityData() { /** * Handles name visibility on sneaking + * * @param sneaking whether npc's name should look like on sneaking. */ @Override @@ -432,6 +448,7 @@ public void setShiftKeyDown(boolean sneaking) { /** * Sets the npc pose. + * * @param pose entity pose. */ @Override @@ -442,6 +459,7 @@ public void setPose(Pose pose) { /** * Removes node from path targets. + * * @param blockPos position from path to remove */ public void removePathTarget(BlockPos blockPos) { @@ -450,6 +468,7 @@ public void removePathTarget(BlockPos blockPos) { /** * Gets the path nodes / targets. + * * @return array list of block positions. */ public ArrayList getPathTargets() { @@ -476,7 +495,7 @@ public void aiStep() { professionLoop: for (TaterzenProfession profession : this.professions.values()) { InteractionResult result = profession.tickMovement(); - switch(result) { + switch (result) { case CONSUME: // Stop processing others, but continue with base Taterzen movement tick break professionLoop; case FAIL: // Stop whole movement tick @@ -495,7 +514,7 @@ public void aiStep() { LivingEntity target = this.getTarget(); if ((this.npcData.movement == NPCData.Movement.FORCED_PATH || - this.npcData.movement == NPCData.Movement.PATH ) && + this.npcData.movement == NPCData.Movement.PATH) && !this.npcData.pathTargets.isEmpty() && !this.isPathFinding()) { // Checking here as well (if path targets size was changed during the previous tick) @@ -582,18 +601,19 @@ public void tick() { @Override public Packet getAddEntityPacket() { - ClientboundAddPlayerPacket addPlayerPacket = new ClientboundAddPlayerPacket(this.fakePlayer); - //noinspection ConstantConditions - AClientboundAddPlayerPacket addPlayerPacketAccessor = (AClientboundAddPlayerPacket) addPlayerPacket; - addPlayerPacketAccessor.setId(this.getId()); - addPlayerPacketAccessor.setUuid(this.getUUID()); - addPlayerPacketAccessor.setX(this.getX()); - addPlayerPacketAccessor.setY(this.getY()); - addPlayerPacketAccessor.setZ(this.getZ()); - addPlayerPacketAccessor.setYRot((byte) ((int) (this.getYHeadRot() * 256.0F / 360.0F))); - addPlayerPacketAccessor.setXRot((byte) ((int) (this.getXRot() * 256.0F / 360.0F))); - - return addPlayerPacket; + return new ClientboundAddEntityPacket( + this.getId(), + this.getUUID(), + this.getX(), + this.getY(), + this.getZ(), + this.getXRot(), + this.getYRot(), + EntityType.PLAYER, + 0, + this.getDeltaMovement(), + this.getYHeadRot() + ); } @@ -612,6 +632,7 @@ public Component getTabListName() { /** * Sets the custom name + * * @param name new name to be set. */ @Override @@ -668,6 +689,7 @@ public void applySkin(GameProfile texturesProfile) { /** * Sets the Taterzen skin from tag + * * @param tag compound tag containing the skin */ public void setSkinFromTag(CompoundTag tag) { @@ -676,7 +698,8 @@ public void setSkinFromTag(CompoundTag tag) { PropertyMap map = this.gameProfile.getProperties(); Property skin = map.get("textures").iterator().next(); map.remove("textures", skin); - } catch (NoSuchElementException ignored) { } + } catch (NoSuchElementException ignored) { + } // Setting the skin try { String value = tag.getString("value"); @@ -687,13 +710,14 @@ public void setSkinFromTag(CompoundTag tag) { propertyMap.put("textures", new Property("textures", value, signature)); } - } catch (Error ignored) { } + } catch (Error ignored) { + } } /** * Writes skin to tag - * @param profile game profile containing skin * + * @param profile game profile containing skin * @return compound tag with skin values */ public CompoundTag writeSkinToTag(GameProfile profile) { @@ -702,14 +726,17 @@ public CompoundTag writeSkinToTag(GameProfile profile) { PropertyMap propertyMap = profile.getProperties(); Property skin = propertyMap.get("textures").iterator().next(); - skinTag.putString("value", skin.getValue()); - skinTag.putString("signature", skin.getSignature()); - } catch (NoSuchElementException ignored) { } + skinTag.putString("value", skin.value()); + skinTag.putString("signature", skin.signature()); + } catch (NoSuchElementException ignored) { + } return skinTag; } + /** * Loads Taterzen from {@link CompoundTag}. + * * @param tag tag to load Taterzen from. */ @Override @@ -978,6 +1005,7 @@ public void addAdditionalSaveData(CompoundTag tag) { /** * Loads Taterzen data from preset file. + * * @param tag tag containing preset name. */ private void loadPresetTag(CompoundTag tag) { @@ -991,6 +1019,7 @@ private void loadPresetTag(CompoundTag tag) { /** * Loads Taterzen data from preset file. Loads team data as well. + * * @param presetFile file containing a taterzen preset. * @param presetName name of the preset. */ @@ -1021,6 +1050,7 @@ public void loadFromPresetFile(File presetFile, String presetName) { /** * Sets player as equipment editor. + * * @param player player that will be marked as equipment editor. */ public void setEquipmentEditor(@Nullable Player player) { @@ -1029,6 +1059,7 @@ public void setEquipmentEditor(@Nullable Player player) { /** * Sets player as equipment editor. + * * @param player player to check. * @return true if player is equipment editor of the NPC, otherwise false. */ @@ -1038,8 +1069,9 @@ public boolean isEquipmentEditor(@NotNull Player player) { /** * Handles interaction (right clicking on the NPC). + * * @param player player interacting with NPC - * @param hand player's interacting hand + * @param hand player's interacting hand * @return {@link InteractionResult#PASS} if NPC has a right click action, otherwise {@link InteractionResult#FAIL} */ @Override @@ -1120,6 +1152,7 @@ public InteractionResult mobInteract(Player player, InteractionHand hand) { /** * Sets the cooldown message. + * * @param message new cooldown message. */ public void setCooldownMessage(String message) { @@ -1128,6 +1161,7 @@ public void setCooldownMessage(String message) { /** * Sets the minimum time between command usage. + * * @param time new minimum time. */ public void setMinCommandInteractionTime(long time) { @@ -1159,6 +1193,7 @@ public boolean shouldDropExperience() { /** * Adds the message to taterzen's message list. + * * @param text message to add */ public void addMessage(Component text) { @@ -1167,7 +1202,8 @@ public void addMessage(Component text) { /** * Adds the message to taterzen's message list. - * @param text message to add + * + * @param text message to add * @param delay message delay, in ticks */ public void addMessage(Component text, int delay) { @@ -1176,8 +1212,9 @@ public void addMessage(Component text, int delay) { /** * Edits the message from taterzen's message list at index. + * * @param index index of the message to edit - * @param text new text message + * @param text new text message */ public void editMessage(int index, Component text) { if (index >= 0 && index < this.npcData.messages.size()) @@ -1186,6 +1223,7 @@ public void editMessage(int index, Component text) { /** * Removes message at index. + * * @param index index of message to be removed. * @return removed message */ @@ -1217,6 +1255,7 @@ public void clearMessages() { /** * Gets {@link ArrayList} of {@link Pair}s of messages and their delays. + * * @return arraylist of pairs with texts and delays. */ public ArrayList> getMessages() { @@ -1225,6 +1264,7 @@ public ArrayList> getMessages() { /** * Used for disabling pushing + * * @param entity colliding entity */ @Override @@ -1236,6 +1276,7 @@ public void push(Entity entity) { /** * Used for disabling pushing + * * @param entity colliding entity */ @Override @@ -1247,6 +1288,7 @@ protected void doPush(Entity entity) { /** * Sets the pushable flag + * * @param pushable whether Taterzen can be pushed */ public void setPushable(boolean pushable) { @@ -1320,6 +1362,7 @@ protected void registerGoals() { /** * Handles death of NPC. + * * @param source damage source responsible for death. */ @Override @@ -1355,6 +1398,7 @@ public void remove(Entity.RemovalReason reason) { /** * Sets Taterzen's {@link NPCData.Behaviour}. + * * @param level behaviour level */ public void setBehaviour(NPCData.Behaviour level) { @@ -1409,6 +1453,7 @@ private void setAttackGoal() { /** * Gets the Taterzen's target selector. + * * @return target selector of Taterzen. */ public GoalSelector getTargetSelector() { @@ -1417,6 +1462,7 @@ public GoalSelector getTargetSelector() { /** * Gets the Taterzen's goal selector. + * * @return goal selector of Taterzen. */ public GoalSelector getGoalSelector() { @@ -1594,8 +1640,9 @@ public void addProfession(ResourceLocation professionId) { /** * Adds {@link TaterzenProfession} to Taterzen. + * * @param professionId ResourceLocation of the profession - * @param profession profession object (implementing {@link TaterzenProfession}) + * @param profession profession object (implementing {@link TaterzenProfession}) */ public void addProfession(ResourceLocation professionId, TaterzenProfession profession) { this.professions.put(professionId, profession); @@ -1612,6 +1659,7 @@ public Collection getProfessionIds() { /** * Removes Taterzen's profession and triggers the corresponding {@link TaterzenProfession#onRemove()} event. + * * @param professionId id of the profession that is in Taterzen's profession map. */ public void removeProfession(ResourceLocation professionId) { @@ -1625,6 +1673,7 @@ public void removeProfession(ResourceLocation professionId) { /** * Gets Taterzen's profession. + * * @param professionId id of the profession that is in Taterzen's profession map. */ @Nullable @@ -1639,6 +1688,7 @@ public boolean canPickUpLoot() { /** * Manages item pickup. + * * @param item item to pick up. */ @Override @@ -1659,6 +1709,7 @@ protected void pickUpItem(ItemEntity item) { /** * Makes Taterzen interact with block at given position. * It doesn't work if given position is too far away (>4 blocks) + * * @param pos position of block to interact with. * @return true if interaction was successfull, otherwise false. */ @@ -1675,6 +1726,7 @@ public boolean interact(BlockPos pos) { /** * Makes Taterzen look at given block position. + * * @param target target block to look at. */ public void lookAt(BlockPos target) { @@ -1683,23 +1735,34 @@ public void lookAt(BlockPos target) { double e = target.getY() - vec3d.y; double f = target.getZ() - vec3d.z; double g = Math.sqrt(d * d + f * f); - this.setXRot(Mth.wrapDegrees((float)(-(Mth.atan2(e, g) * 57.2957763671875D)))); - this.setYBodyRot(Mth.wrapDegrees((float)(Mth.atan2(f, d) * 57.2957763671875D) - 90.0F)); + this.setXRot(Mth.wrapDegrees((float) (-(Mth.atan2(e, g) * 57.2957763671875D)))); + this.setYBodyRot(Mth.wrapDegrees((float) (Mth.atan2(f, d) * 57.2957763671875D) - 90.0F)); this.setYHeadRot(this.getYHeadRot()); } /** * Sets whether Taterzen can perform jumps when in * proximity of target that it is attacking. + * * @param jumpWhileAttacking whether to jump during attacks. */ public void setPerformAttackJumps(boolean jumpWhileAttacking) { this.setTag("JumpAttack", jumpWhileAttacking); } + /** + * Gets follow type for taterzen. + * + * @return follow type + */ + public NPCData.FollowTypes getFollowType() { + return this.npcData.follow.type; + } + /** * Sets the target type to follow. * Changes movement to {@link NPCData.Movement#PATH} as well. + * * @param followType type of target to follow */ public void setFollowType(NPCData.FollowTypes followType) { @@ -1718,32 +1781,27 @@ public void setFollowType(NPCData.FollowTypes followType) { } /** - * Gets follow type for taterzen. - * @return follow type + * Gets the UUID of the entity that taterzen is following. + * + * @return entity UUID if following, otherwise null. */ - public NPCData.FollowTypes getFollowType() { - return this.npcData.follow.type; + @Nullable + public UUID getFollowUuid() { + return this.npcData.follow.targetUuid; } /** * Sets the target uuid to follow. + * * @param followUuid uuid of target to follow */ public void setFollowUuid(@Nullable UUID followUuid) { this.npcData.follow.targetUuid = followUuid; } - /** - * Gets the UUID of the entity that taterzen is following. - * @return entity UUID if following, otherwise null. - */ - @Nullable - public UUID getFollowUuid() { - return this.npcData.follow.targetUuid; - } - /** * Whether this Taterzen should make sound. + * * @param allowSounds whether to allow sounds or not. */ public void setAllowSounds(boolean allowSounds) { @@ -1752,6 +1810,7 @@ public void setAllowSounds(boolean allowSounds) { /** * Sets which skin layers should be shown to clients + * * @param skinLayers byte of skin layers, see wiki.wg for more info. */ public void setSkinLayers(Byte skinLayers) { @@ -1759,9 +1818,9 @@ public void setSkinLayers(Byte skinLayers) { } - /** * Sets the respawn position for taterzen. Can be null to disable respawning. + * * @param respawnPos new respawn position. */ public void setRespawnPos(@Nullable Vec3 respawnPos) { @@ -1770,6 +1829,7 @@ public void setRespawnPos(@Nullable Vec3 respawnPos) { /** * Sets whether taterzen should be able to fly. + * * @param allowFlight whether to allow taterzen to fly or not. */ public void setAllowFlight(boolean allowFlight) { @@ -1788,9 +1848,10 @@ public void setAllowFlight(boolean allowFlight) { /** * Whether taterzen can take fall damage. + * * @param fallDistance fall distance. - * @param multiplier damage multiplier. - * @param source source of damage. + * @param multiplier damage multiplier. + * @param source source of damage. * @return true if damage should be taken, otherwise false. */ @Override @@ -1800,6 +1861,7 @@ public boolean causeFallDamage(float fallDistance, float multiplier, DamageSourc /** * Whether taterzen should be allowed to be edited by entity. + * * @param entity entity to check. * @return true if taterzen can be edited by entity, otherwise false. */ @@ -1809,6 +1871,7 @@ public boolean allowEditBy(Entity entity) { /** * Whether taterzen should be allowed to be edited by provided uuid. + * * @param uuid uuid to check. * @return true if taterzen can be edited by provided uuid, otherwise false. */ @@ -1818,6 +1881,7 @@ public boolean allowEditBy(UUID uuid) { /** * Tries to make taterzen to ride provided entity. + * * @param entity entity to ride. * @return true if taterzen was able to ride provided entity, otherwise false. */ @@ -1830,6 +1894,7 @@ public boolean startRiding(Entity entity) { /** * Whether taterzen is locked. + * * @return true if taterzen is locked, otherwise false. */ public boolean isLocked() { @@ -1838,6 +1903,7 @@ public boolean isLocked() { /** * Sets taterzen to be locked by provided owner's uuid. + * * @param owner entity to lock taterzen to. */ public void setLocked(Entity owner) { @@ -1846,6 +1912,7 @@ public void setLocked(Entity owner) { /** * Sets taterzen to be locked by provided uuid. + * * @param uuid uuid to lock taterzen to. */ public void setLocked(UUID uuid) { @@ -1855,6 +1922,7 @@ public void setLocked(UUID uuid) { /** * Sets whether taterzen should be allowed to be ride entities. * (Mainly used for preventing them being picked up by boats / minecarts.) + * * @param allow whether to allow riding or not. */ public void setAllowRiding(boolean allow) { diff --git a/common/src/main/java/org/samo_lego/taterzens/npc/commands/BungeeCommand.java b/common/src/main/java/org/samo_lego/taterzens/npc/commands/BungeeCommand.java index 626b8b669..d0e0fd201 100644 --- a/common/src/main/java/org/samo_lego/taterzens/npc/commands/BungeeCommand.java +++ b/common/src/main/java/org/samo_lego/taterzens/npc/commands/BungeeCommand.java @@ -5,7 +5,7 @@ import io.netty.buffer.Unpooled; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -34,7 +34,7 @@ public class BungeeCommand extends AbstractTaterzenCommand { /** * "Bungee" command. It's not a standard command, executed by the server, - * but sent as {@link net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket} to player and caught by proxy. + * but sent as {@link ClientboundCustomPayloadPacket} to player and caught by proxy. * * @param proxyMessage proxy command to add, see {@link BungeeMessage} for supported commands. * @param playername player to use when executing the command. @@ -56,20 +56,19 @@ public BungeeCommand() { this.argument = ""; } - @Override - public void execute(TaterzenNPC npc, Player player) { - if (!config.bungee.enableCommands) return; - // Sending command as CustomPayloadS2CPacket - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF(this.proxyMessage.getSubchannel()); - out.writeUTF(this.playername.replace(CLICKER_PLACEHOLDER, player.getGameProfile().getName())); - out.writeUTF(this.argument.replaceAll(CLICKER_PLACEHOLDER, player.getGameProfile().getName())); - + /** + * Sends a packet to proxy. + * + * @param connection connection to use for sending packet. + * @param data data to sent in the packet. + */ + public static void sendProxyPacket(ServerGamePacketListenerImpl connection, byte[] data) { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeBytes(out.toByteArray()); + buf.writeResourceLocation(BUNGEE_CHANNEL); + buf.writeBytes(data); - ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(BUNGEE_CHANNEL, buf); - ((ServerPlayer) player).connection.send(packet); + ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(buf); + connection.send(packet); } @Override @@ -93,18 +92,21 @@ public void fromTag(CompoundTag cmdTag) { this.argument = cmdTag.getString("Argument"); } - /** - * Sends a packet to proxy. - * - * @param connection connection to use for sending packet. - * @param data data to sent in the packet. - */ - public static void sendProxyPacket(ServerGamePacketListenerImpl connection, byte[] data) { + @Override + public void execute(TaterzenNPC npc, Player player) { + if (!config.bungee.enableCommands) return; + // Sending command as CustomPayloadS2CPacket + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(this.proxyMessage.getSubchannel()); + out.writeUTF(this.playername.replace(CLICKER_PLACEHOLDER, player.getGameProfile().getName())); + out.writeUTF(this.argument.replaceAll(CLICKER_PLACEHOLDER, player.getGameProfile().getName())); + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeBytes(data); + buf.writeResourceLocation(BUNGEE_CHANNEL); + buf.writeBytes(out.toByteArray()); - ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(BUNGEE_CHANNEL, buf); - connection.send(packet); + ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(buf); + ((ServerPlayer) player).connection.send(packet); } diff --git a/common/src/main/resources/taterzens.common.mixins.json b/common/src/main/resources/taterzens.common.mixins.json index fe81c461f..a2d76cc4e 100644 --- a/common/src/main/resources/taterzens.common.mixins.json +++ b/common/src/main/resources/taterzens.common.mixins.json @@ -8,7 +8,6 @@ "CommandSourceStackMixin_HideTaterzenExecutor", "ServerPlayInteractionManagerMixin", "accessors.AChunkMap", - "accessors.AClientboundAddPlayerPacket", "accessors.AClientboundPlayerInfoPacket", "accessors.AClientboundPlayerInfoUpdatePacket", "accessors.AClientboundSetEntityDataPacket", diff --git a/fabric/gradle.properties b/fabric/gradle.properties index 267d4942b..3cf077b32 100644 --- a/fabric/gradle.properties +++ b/fabric/gradle.properties @@ -1,5 +1,5 @@ # Dependecies -polymer_registry_sync_version=0.5.0-rc.2+1.20-rc1 -sgui_version=1.2.2+1.20 -carpet_core_version=1.4.111 -translations_api=2.0.0-beta.2+1.19.4-pre2 +polymer_registry_sync_version=0.6.0+1.20.2 +sgui_version=1.3.0+1.20.2 +carpet_core_version=1.4.119 +translations_api=2.1.0+1.20.2-rc2 diff --git a/forge/src/main/java/org/samo_lego/taterzens/forge/platform/ForgePlatform.java b/forge/src/main/java/org/samo_lego/taterzens/forge/platform/ForgePlatform.java index d391b80be..acb85e27c 100644 --- a/forge/src/main/java/org/samo_lego/taterzens/forge/platform/ForgePlatform.java +++ b/forge/src/main/java/org/samo_lego/taterzens/forge/platform/ForgePlatform.java @@ -4,6 +4,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.MobCategory; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.loading.FMLPaths; diff --git a/gradle.properties b/gradle.properties index a30b8756d..919720856 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,16 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G # Fabric Properties -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.4 loader_version=0.14.22 #Fabric api -fabric_version=0.86.1+1.20.1 +fabric_version=0.89.3+1.20.2 #Forge forge_version=47.1.43 -enable_forge=true +enable_forge=false # Mod Properties mod_version=1.11.7 maven_group=org.samo_lego