Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fake players using wrong reach values #1883

Open
wants to merge 2 commits into
base: 1.20.2
Choose a base branch
from
Open
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
26 changes: 20 additions & 6 deletions src/main/java/carpet/helpers/EntityPlayerActionPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;

import carpet.logging.Logger;
import carpet.patches.EntityPlayerMPFake;
import carpet.script.utils.Tracer;
import net.minecraft.commands.arguments.EntityAnchorArgument;
Expand All @@ -24,7 +25,9 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.entity.vehicle.Minecart;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
Expand Down Expand Up @@ -110,6 +113,7 @@ public EntityPlayerActionPack setStrafing(float value)
strafing = value;
return this;
}

public EntityPlayerActionPack look(Direction direction)
{
return switch (direction)
Expand Down Expand Up @@ -238,7 +242,12 @@ public void onUpdate()
}
}
}
float vel = sneaking?0.3F:1.0F;

boolean slowedByItem = player.isUsingItem();

float vel = sneaking?0.30F:1.0F;
vel *= slowedByItem?0.20F:1.0F;

// The != 0.0F checks are needed given else real players can't control minecarts, however it works with fakes and else they don't stop immediately
if (forward != 0.0F || player instanceof EntityPlayerMPFake) {
player.zza = forward * vel;
Expand All @@ -250,8 +259,13 @@ public void onUpdate()

static HitResult getTarget(ServerPlayer player)
{
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
return Tracer.rayTrace(player, 1, reach, false);
double blockReach = player.gameMode.isCreative() ? 5 : 4.5f;
double entityReach = player.gameMode.isCreative() ? 5 : 3f;

HitResult hit = Tracer.rayTrace(player, 1, blockReach, false);

if (hit.getType() == HitResult.Type.BLOCK) return hit;
return Tracer.rayTrace(player, 1, entityReach, false);
}

private void dropItemFromSlot(int slot, boolean dropAll)
Expand Down Expand Up @@ -378,8 +392,6 @@ boolean execute(ServerPlayer player, Action action) {
player.attack(entityHit.getEntity());
player.swing(InteractionHand.MAIN_HAND);
}
player.resetAttackStrengthTicker();
player.resetLastActionTime();
return true;
}
case BLOCK: {
Expand Down Expand Up @@ -443,11 +455,13 @@ else if (ap.currentBlock == null || !ap.currentBlock.equals(pos))
player.level().destroyBlockProgress(-1, pos, (int) (ap.curBlockDamageMP * 10));

}
player.resetLastActionTime();
player.swing(InteractionHand.MAIN_HAND);
return blockBroken;
}
}
if (!action.isContinuous) player.swing(InteractionHand.MAIN_HAND);
player.resetAttackStrengthTicker();
player.resetLastActionTime();
return false;
}

Expand Down