diff --git a/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java new file mode 100644 index 000000000..29b458cf4 --- /dev/null +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IEntityPlayerActionPack.java @@ -0,0 +1,27 @@ +/* + * 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 IEntityPlayerActionPack +{ + 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 new file mode 100644 index 000000000..686ef5f52 --- /dev/null +++ b/src/main/java/carpettisaddition/helpers/carpet/playerActionEnhanced/IServerPlayerEntity.java @@ -0,0 +1,31 @@ +/* + * 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; + +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; + +public interface IServerPlayerEntity +{ + 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 a5fb245b8..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,9 +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.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; @@ -70,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) @@ -77,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( @@ -90,15 +103,24 @@ private void perTickMultiplier(EntityPlayerActionPack actionPack, EntityPlayerAc { if (this.perTick != null) { + ServerPlayerEntity player = ((EntityPlayerActionPackAccessor)actionPack).getPlayer(); + EntityPlayerActionPackActionTypeAccessor typeAccessor = (EntityPlayerActionPackActionTypeAccessor)(Object)type; + EntityPlayerActionPack.Action self = (EntityPlayerActionPack.Action)(Object)this; + + ((IServerPlayerEntity)(Object)player).pushOldPosRot(posLastTick, rotLastTick); + 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; - + ((IEntityPlayerActionPack)(Object)actionPack).setTickPart((i + 1) / (float)perTick); typeAccessor.invokeExecute(player, self); typeAccessor.invokeInactiveTick(player, self); } + + ((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 new file mode 100644 index 000000000..8ab18b78f --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeMixin.java @@ -0,0 +1,40 @@ +/* + * 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.IEntityPlayerActionPackAction; +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) + { + ((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 new file mode 100644 index 000000000..23d173e1c --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/carpet/tweaks/command/playerActionEnhanced/EntityPlayerActionPackActionTypeUseMixin.java @@ -0,0 +1,64 @@ +/* + * 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 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; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(targets = "carpet.helpers.EntityPlayerActionPack$ActionType$1") +public class EntityPlayerActionPackActionTypeUseMixin +{ + @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/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 new file mode 100644 index 000000000..b47df4ae7 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/command/player/pertick/ServerPlayerEntityMixin.java @@ -0,0 +1,51 @@ +/* + * 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 +{ + public void pushOldPosRot(Vec3d pos, Vec2f rot) + { + ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; + self.prevX = pos.x; + self.prevY = pos.y; + self.prevZ = pos.z; + self.prevPitch = rot.x; + self.prevYaw = rot.y; + } + + public void popOldPosRot() + { + ServerPlayerEntity self = (ServerPlayerEntity)(Object)this; + 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..ea1561f85 100644 --- a/src/main/resources/carpet-tis-addition.mixins.json +++ b/src/main/resources/carpet-tis-addition.mixins.json @@ -24,6 +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", @@ -150,6 +154,7 @@ "command.manipulate.entity.MobEntityAccessor", "command.mobcapsLocal.SpawnCommandAccessor", "command.mobcapsLocal.SpawnCommandMixin", + "command.player.pertick.ServerPlayerEntityMixin", "command.raid.RaidAccessor", "command.raid.RaidManagerAccessor", "command.raid.RaidMixin",