Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.helpers.carpet.playerActionEnhanced;

public interface IEntityPlayerActionPack
{
void setTickPart(float tp);
float getTickPart();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,13 +74,22 @@ private void changeIntervalRandomly(CallbackInfoReturnable<Boolean> cir)
///////////////////////////////// perTick /////////////////////////////////

private Integer perTick = null;
private Vec3d posLastTick = null;
private Vec2f rotLastTick = null;

@Override
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(
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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;
}
}
Loading