From 22ca18b1d6cd5cb51c4fe5d5914bb2269e10a265 Mon Sep 17 00:00:00 2001 From: silnarm Date: Sat, 14 Oct 2023 13:31:06 +1100 Subject: [PATCH 1/2] player-use-pertick-interpolated * add player position/rotation interpolation to perTick use action --- .../IEntityPlayerActionPackActionTypeUse.java | 26 ++++++++ .../IServerPlayerEntity.java | 29 +++++++++ .../EntityPlayerActionPackActionMixin.java | 19 ++++-- ...EntityPlayerActionPackActionTypeMixin.java | 39 ++++++++++++ ...ityPlayerActionPackActionTypeUseMixin.java | 60 +++++++++++++++++++ .../pertick/ServerPlayerEntityMixin.java | 59 ++++++++++++++++++ .../resources/carpet-tis-addition.mixins.json | 3 + 7 files changed, 231 insertions(+), 4 deletions(-) create mode 100644 src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java create mode 100644 src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java create mode 100644 src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java create mode 100644 src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java create mode 100644 src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java new file mode 100644 index 000000000..7e26df5d4 --- /dev/null +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java @@ -0,0 +1,26 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.helpers.carpet.playerActionEnhanced; + +public interface IEntityPlayerActionPackActionTypeUse +{ + void setTickPart(float f); +} diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java new file mode 100644 index 000000000..dd579460c --- /dev/null +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java @@ -0,0 +1,29 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.helpers.carpet.playerActionEnhanced; + +public interface IServerPlayerEntity +{ + void pushOldPosRot(); + + void swapOldPosRot(boolean lastTickValues); + +} diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java index a5fb245b8..a981ec480 100644 --- a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java @@ -22,6 +22,8 @@ import carpet.helpers.EntityPlayerActionPack; import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackAction; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackActionTypeUse; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IServerPlayerEntity; import carpettisaddition.helpers.carpet.playerActionEnhanced.randomly.gen.RandomGen; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Final; @@ -90,15 +92,24 @@ private void perTickMultiplier(EntityPlayerActionPack actionPack, EntityPlayerAc { if (this.perTick != null) { + ServerPlayerEntity player = ((EntityPlayerActionPackAccessor)actionPack).getPlayer(); + IServerPlayerEntity iplayer = (IServerPlayerEntity)(Object)player; + EntityPlayerActionPackActionTypeAccessor typeAccessor = ((EntityPlayerActionPackActionTypeAccessor)(Object)type); + EntityPlayerActionPack.Action self = (EntityPlayerActionPack.Action)(Object)this; + IEntityPlayerActionPackActionTypeUse actionTypeUSE = (IEntityPlayerActionPackActionTypeUse)(Object)EntityPlayerActionPack.ActionType.USE; + + iplayer.swapOldPosRot(true); + for (int i = 0; i < this.perTick - 1; i++) { - EntityPlayerActionPackActionTypeAccessor typeAccessor = ((EntityPlayerActionPackActionTypeAccessor)(Object)type); - ServerPlayerEntity player = ((EntityPlayerActionPackAccessor)actionPack).getPlayer(); - EntityPlayerActionPack.Action self = (EntityPlayerActionPack.Action)(Object)this; - + actionTypeUSE.setTickPart((i + 1) / (float)perTick); typeAccessor.invokeExecute(player, self); typeAccessor.invokeInactiveTick(player, self); } + + actionTypeUSE.setTickPart(1.0f); + iplayer.swapOldPosRot(false); + iplayer.pushOldPosRot(); } } } diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java new file mode 100644 index 000000000..98a54220e --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java @@ -0,0 +1,39 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; + +import carpet.helpers.EntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityPlayerActionPack.ActionType.class) +public class EntityPlayerActionPackActionTypeMixin +{ + @Inject(method = "start", at = @At("HEAD"), remap = false) + private void onStart(ServerPlayerEntity player, EntityPlayerActionPack.Action action, CallbackInfo info) + { + ((IServerPlayerEntity)(Object)player).pushOldPosRot(); + } +} diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java new file mode 100644 index 000000000..00d408f78 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java @@ -0,0 +1,60 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; + +//#if MC > 11903 +//$$ import carpet.script.utils.Tracer; +//#else +import carpet.helpers.Tracer; +//#endif +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackActionTypeUse; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.hit.HitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(targets = "carpet.helpers.EntityPlayerActionPack$ActionType$1") +public class EntityPlayerActionPackActionTypeUseMixin implements IEntityPlayerActionPackActionTypeUse +{ + private float tickPart = 1.0f; + + @Redirect( + method = "execute", + at = @At( + value = "INVOKE", + target = "Lcarpet/helpers/EntityPlayerActionPack;getTarget(Lnet/minecraft/server/network/ServerPlayerEntity;)Lnet/minecraft/util/hit/HitResult;", + remap = false + ), + remap = false + ) + private HitResult doRayTrace(ServerPlayerEntity player) + { + double reach = player.interactionManager.isCreative() ? 5 : 4.5f; + return Tracer.rayTrace(player, tickPart, reach, false); + } + + @Override + public void setTickPart(float f) + { + tickPart = f; + } +} diff --git a/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java b/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java new file mode 100644 index 000000000..7719318a7 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java @@ -0,0 +1,59 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.mixins.command.player.pertick; + +import carpettisaddition.helpers.carpet.playerActionEnhanced.IServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ServerPlayerEntity.class) +public abstract class ServerPlayerEntityMixin implements IServerPlayerEntity +{ + private Vec3d posLastTick; + private Vec2f rotLastTick; + + public void pushOldPosRot() + { + ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; + posLastTick = self.getPos(); + rotLastTick = self.getRotationClient(); + } + + public void swapOldPosRot(boolean lastTickValues) + { + ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; + if (lastTickValues) { + self.prevX = posLastTick.x; + self.prevY = posLastTick.y; + self.prevZ = posLastTick.z; + self.prevPitch = rotLastTick.x; + self.prevYaw = rotLastTick.y; + } else { + self.prevX = self.getPos().x; + self.prevY = self.getPos().y; + self.prevZ = self.getPos().z; + self.prevPitch = self.getPitch(1.0f); + self.prevYaw = self.getYaw(1.0f); + } + } +} diff --git a/src/main/resources/carpet-tis-addition.mixins.json b/src/main/resources/carpet-tis-addition.mixins.json index 48096b6d5..808e8c043 100644 --- a/src/main/resources/carpet-tis-addition.mixins.json +++ b/src/main/resources/carpet-tis-addition.mixins.json @@ -24,6 +24,8 @@ "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionAccessor", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionMixin", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeAccessor", + "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeMixin", + "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeUseMixin", "carpet.tweaks.command.playerActionEnhanced.PlayerCommandMixin", "carpet.tweaks.command.spawnTrackingRestart.SpawnCommandMixin", "carpet.tweaks.command.tickWarpMaximumDuration.TickCommandMixin", @@ -150,6 +152,7 @@ "command.manipulate.entity.MobEntityAccessor", "command.mobcapsLocal.SpawnCommandAccessor", "command.mobcapsLocal.SpawnCommandMixin", + "command.player.pertick.ServerPlayerEntityMixin", "command.raid.RaidAccessor", "command.raid.RaidManagerAccessor", "command.raid.RaidMixin", From 4f5e7ebe2d71dc3d12d5e2d26862302fb18e9a7e Mon Sep 17 00:00:00 2001 From: silnarm Date: Sat, 14 Oct 2023 20:35:43 +1100 Subject: [PATCH 2/2] player-use-pertick-interpolated * remove static in ActionType.USE, move 'tickPart' to ActionPack. * move last tick pos/rot into Action * dupe USE mixin for ATTACK * change some names --- ...eUse.java => IEntityPlayerActionPack.java} | 5 +- .../IEntityPlayerActionPackAction.java | 3 + .../IServerPlayerEntity.java | 8 ++- .../EntityPlayerActionPackActionMixin.java | 29 ++++++--- ...PlayerActionPackActionTypeAttackMixin.java | 62 +++++++++++++++++++ ...EntityPlayerActionPackActionTypeMixin.java | 3 +- ...ityPlayerActionPackActionTypeUseMixin.java | 26 ++++---- .../EntityPlayerActionPackMixin.java | 41 ++++++++++++ .../pertick/ServerPlayerEntityMixin.java | 32 ++++------ .../resources/carpet-tis-addition.mixins.json | 2 + 10 files changed, 165 insertions(+), 46 deletions(-) rename src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/{IEntityPlayerActionPackActionTypeUse.java => IEntityPlayerActionPack.java} (91%) create mode 100644 src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeAttackMixin.java create mode 100644 src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackMixin.java diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java similarity index 91% rename from src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java rename to src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java index 7e26df5d4..29b458cf4 100644 --- a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackActionTypeUse.java +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java @@ -20,7 +20,8 @@ package carpettisaddition.helpers.carpet.playerActionEnhanced; -public interface IEntityPlayerActionPackActionTypeUse +public interface IEntityPlayerActionPack { - void setTickPart(float f); + void setTickPart(float tp); + float getTickPart(); } diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackAction.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackAction.java index 575e0789f..929f65b9d 100644 --- a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackAction.java +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPackAction.java @@ -21,10 +21,13 @@ package carpettisaddition.helpers.carpet.playerActionEnhanced; import carpettisaddition.helpers.carpet.playerActionEnhanced.randomly.gen.RandomGen; +import net.minecraft.server.network.ServerPlayerEntity; public interface IEntityPlayerActionPackAction { void setIntervalRandomGenerator(RandomGen gen); void setPerTickMultiplier(int perTick); + + void savePosAndRot(ServerPlayerEntity player); } diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java index dd579460c..686ef5f52 100644 --- a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java @@ -20,10 +20,12 @@ package carpettisaddition.helpers.carpet.playerActionEnhanced; +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; + public interface IServerPlayerEntity { - void pushOldPosRot(); - - void swapOldPosRot(boolean lastTickValues); + void pushOldPosRot(Vec3d pos, Vec2f rot); + void popOldPosRot(); } diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java index a981ec480..55984b2ec 100644 --- a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionMixin.java @@ -21,11 +21,13 @@ package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; import carpet.helpers.EntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPack; import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackAction; -import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackActionTypeUse; import carpettisaddition.helpers.carpet.playerActionEnhanced.IServerPlayerEntity; import carpettisaddition.helpers.carpet.playerActionEnhanced.randomly.gen.RandomGen; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -72,6 +74,8 @@ private void changeIntervalRandomly(CallbackInfoReturnable cir) ///////////////////////////////// perTick ///////////////////////////////// private Integer perTick = null; + private Vec3d posLastTick = null; + private Vec2f rotLastTick = null; @Override public void setPerTickMultiplier(int perTick) @@ -79,6 +83,13 @@ public void setPerTickMultiplier(int perTick) this.perTick = perTick; } + @Override + public void savePosAndRot(ServerPlayerEntity player) + { + posLastTick = player.getPos(); + rotLastTick = player.getRotationClient(); + } + @Inject( method = "tick", at = @At( @@ -93,23 +104,23 @@ private void perTickMultiplier(EntityPlayerActionPack actionPack, EntityPlayerAc if (this.perTick != null) { ServerPlayerEntity player = ((EntityPlayerActionPackAccessor)actionPack).getPlayer(); - IServerPlayerEntity iplayer = (IServerPlayerEntity)(Object)player; - EntityPlayerActionPackActionTypeAccessor typeAccessor = ((EntityPlayerActionPackActionTypeAccessor)(Object)type); + EntityPlayerActionPackActionTypeAccessor typeAccessor = (EntityPlayerActionPackActionTypeAccessor)(Object)type; EntityPlayerActionPack.Action self = (EntityPlayerActionPack.Action)(Object)this; - IEntityPlayerActionPackActionTypeUse actionTypeUSE = (IEntityPlayerActionPackActionTypeUse)(Object)EntityPlayerActionPack.ActionType.USE; - iplayer.swapOldPosRot(true); + ((IServerPlayerEntity)(Object)player).pushOldPosRot(posLastTick, rotLastTick); for (int i = 0; i < this.perTick - 1; i++) { - actionTypeUSE.setTickPart((i + 1) / (float)perTick); + ((IEntityPlayerActionPack)(Object)actionPack).setTickPart((i + 1) / (float)perTick); typeAccessor.invokeExecute(player, self); typeAccessor.invokeInactiveTick(player, self); } - actionTypeUSE.setTickPart(1.0f); - iplayer.swapOldPosRot(false); - iplayer.pushOldPosRot(); + ((IEntityPlayerActionPack)(Object)actionPack).setTickPart(1.0f); + ((IServerPlayerEntity)(Object)player).popOldPosRot(); + savePosAndRot(player); + posLastTick = player.getPos(); + rotLastTick = player.getRotationClient(); } } } diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeAttackMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeAttackMixin.java new file mode 100644 index 000000000..68ecd3e16 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeAttackMixin.java @@ -0,0 +1,62 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; + +//#if MC > 11903 +//$$ import carpet.script.utils.Tracer; +//$$ import carpet.fakes.ServerPlayerInterface; +//#else +import carpet.helpers.Tracer; +import carpet.fakes.ServerPlayerEntityInterface; +//#endif +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.hit.HitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(targets = "carpet.helpers.EntityPlayerActionPack$ActionType$2") +public class EntityPlayerActionPackActionTypeAttackMixin +{ + @Redirect( + method = "execute", + at = @At( + value = "INVOKE", + target = "Lcarpet/helpers/EntityPlayerActionPack;getTarget(Lnet/minecraft/server/network/ServerPlayerEntity;)Lnet/minecraft/util/hit/HitResult;", + remap = false + ), + remap = false, + require = 0 + ) + private HitResult doRayTrace(ServerPlayerEntity player) + { + double reach = player.interactionManager.isCreative() ? 5 : 4.5f; + float tickPart = ((IEntityPlayerActionPack)(Object)(( + //#if MC > 11903 + //$$ ServerPlayerInterface + //#else + ServerPlayerEntityInterface + //#endif + )(Object)player).getActionPack()).getTickPart(); + return Tracer.rayTrace(player, tickPart, reach, false); + } +} diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java index 98a54220e..8ab18b78f 100644 --- a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java @@ -21,6 +21,7 @@ package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; import carpet.helpers.EntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackAction; import carpettisaddition.helpers.carpet.playerActionEnhanced.IServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; @@ -34,6 +35,6 @@ public class EntityPlayerActionPackActionTypeMixin @Inject(method = "start", at = @At("HEAD"), remap = false) private void onStart(ServerPlayerEntity player, EntityPlayerActionPack.Action action, CallbackInfo info) { - ((IServerPlayerEntity)(Object)player).pushOldPosRot(); + ((IEntityPlayerActionPackAction)(Object)action).savePosAndRot(player); } } diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java index 00d408f78..23d173e1c 100644 --- a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java @@ -22,10 +22,14 @@ //#if MC > 11903 //$$ import carpet.script.utils.Tracer; +//$$ import carpet.fakes.ServerPlayerInterface; //#else import carpet.helpers.Tracer; +import carpet.fakes.ServerPlayerEntityInterface; //#endif -import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackActionTypeUse; +import carpet.helpers.EntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPackAction; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.hit.HitResult; import org.spongepowered.asm.mixin.Mixin; @@ -33,10 +37,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(targets = "carpet.helpers.EntityPlayerActionPack$ActionType$1") -public class EntityPlayerActionPackActionTypeUseMixin implements IEntityPlayerActionPackActionTypeUse +public class EntityPlayerActionPackActionTypeUseMixin { - private float tickPart = 1.0f; - @Redirect( method = "execute", at = @At( @@ -44,17 +46,19 @@ public class EntityPlayerActionPackActionTypeUseMixin implements IEntityPlayerAc target = "Lcarpet/helpers/EntityPlayerActionPack;getTarget(Lnet/minecraft/server/network/ServerPlayerEntity;)Lnet/minecraft/util/hit/HitResult;", remap = false ), - remap = false + remap = false, + require = 0 ) private HitResult doRayTrace(ServerPlayerEntity player) { double reach = player.interactionManager.isCreative() ? 5 : 4.5f; + float tickPart = ((IEntityPlayerActionPack)(Object)(( + //#if MC > 11903 + //$$ ServerPlayerInterface + //#else + ServerPlayerEntityInterface + //#endif + )(Object)player).getActionPack()).getTickPart(); return Tracer.rayTrace(player, tickPart, reach, false); } - - @Override - public void setTickPart(float f) - { - tickPart = f; - } } diff --git a/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackMixin.java b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackMixin.java new file mode 100644 index 000000000..443cc9264 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackMixin.java @@ -0,0 +1,41 @@ +/* + * This file is part of the Carpet TIS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Fallen_Breath and contributors + * + * Carpet TIS Addition is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Carpet TIS Addition is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Carpet TIS Addition. If not, see . + */ + +package carpettisaddition.mixins.carpet.tweaks.command.playerActionEnhanced; + +import carpet.helpers.EntityPlayerActionPack; +import carpettisaddition.helpers.carpet.playerActionEnhanced.IEntityPlayerActionPack; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(EntityPlayerActionPack.class) +public class EntityPlayerActionPackMixin implements IEntityPlayerActionPack +{ + private float tickPart = 1.0f; + + public void setTickPart(float tp) + { + tickPart = tp; + } + + public float getTickPart() + { + return tickPart; + } +} diff --git a/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java b/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java index 7719318a7..b47df4ae7 100644 --- a/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java +++ b/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java @@ -29,31 +29,23 @@ @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerEntityMixin implements IServerPlayerEntity { - private Vec3d posLastTick; - private Vec2f rotLastTick; - - public void pushOldPosRot() + public void pushOldPosRot(Vec3d pos, Vec2f rot) { ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; - posLastTick = self.getPos(); - rotLastTick = self.getRotationClient(); + self.prevX = pos.x; + self.prevY = pos.y; + self.prevZ = pos.z; + self.prevPitch = rot.x; + self.prevYaw = rot.y; } - public void swapOldPosRot(boolean lastTickValues) + public void popOldPosRot() { ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; - if (lastTickValues) { - self.prevX = posLastTick.x; - self.prevY = posLastTick.y; - self.prevZ = posLastTick.z; - self.prevPitch = rotLastTick.x; - self.prevYaw = rotLastTick.y; - } else { - self.prevX = self.getPos().x; - self.prevY = self.getPos().y; - self.prevZ = self.getPos().z; - self.prevPitch = self.getPitch(1.0f); - self.prevYaw = self.getYaw(1.0f); - } + self.prevX = self.getPos().x; + self.prevY = self.getPos().y; + self.prevZ = self.getPos().z; + self.prevPitch = self.getPitch(1.0f); + self.prevYaw = self.getYaw(1.0f); } } diff --git a/src/main/resources/carpet-tis-addition.mixins.json b/src/main/resources/carpet-tis-addition.mixins.json index 808e8c043..ea1561f85 100644 --- a/src/main/resources/carpet-tis-addition.mixins.json +++ b/src/main/resources/carpet-tis-addition.mixins.json @@ -24,8 +24,10 @@ "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionAccessor", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionMixin", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeAccessor", + "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeAttackMixin", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeMixin", "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackActionTypeUseMixin", + "carpet.tweaks.command.playerActionEnhanced.EntityPlayerActionPackMixin", "carpet.tweaks.command.playerActionEnhanced.PlayerCommandMixin", "carpet.tweaks.command.spawnTrackingRestart.SpawnCommandMixin", "carpet.tweaks.command.tickWarpMaximumDuration.TickCommandMixin",