Migrate the Carpet codebase to Mojang Mappings

This commit is contained in:
altrisi committed 2022-01-24 20:33:16 +01:00
1 parent a1a2488bc3
commit 06af9ce8b1
346 files changed
+8353 -8492

No files matched your search

@@ -1,38 +1,37 @@
package carpet.helpers;
import carpet.fakes.ServerPlayerEntityInterface;
import net.minecraft.block.BlockState;
import net.minecraft.command.argument.EntityAnchorArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.entity.passive.HorseBaseEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.MinecartEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.decoration.ItemFrame;
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.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class EntityPlayerActionPack
{
private final ServerPlayerEntity player;
private final ServerPlayer player;
private final Map<ActionType, Action> actions = new TreeMap<>();
@@ -48,7 +47,7 @@ public class EntityPlayerActionPack
private int itemUseCooldown;
public EntityPlayerActionPack(ServerPlayerEntity playerIn)
public EntityPlayerActionPack(ServerPlayer playerIn)
{
player = playerIn;
stopAll();
@@ -84,7 +83,7 @@ public class EntityPlayerActionPack
public EntityPlayerActionPack setSneaking(boolean doSneak)
{
sneaking = doSneak;
player.setSneaking(doSneak);
player.setShiftKeyDown(doSneak);
if (sprinting && sneaking)
setSprinting(false);
return this;
@@ -116,36 +115,36 @@ public class EntityPlayerActionPack
case SOUTH: return look(0, 0);
case EAST: return look(-90, 0);
case WEST: return look(90, 0);
case UP: return look(player.getYaw(), -90);
case DOWN: return look(player.getYaw(), 90);
case UP: return look(player.getYRot(), -90);
case DOWN: return look(player.getYRot(), 90);
}
return this;
}
public EntityPlayerActionPack look(Vec2f rotation)
public EntityPlayerActionPack look(Vec2 rotation)
{
return look(rotation.x, rotation.y);
}
public EntityPlayerActionPack look(float yaw, float pitch)
{
player.setYaw(yaw % 360); //setYaw
player.setPitch(MathHelper.clamp(pitch, -90, 90)); // setPitch
player.setYRot(yaw % 360); //setYaw
player.setXRot(Mth.clamp(pitch, -90, 90)); // setPitch
// maybe player.setPositionAndAngles(player.x, player.y, player.z, yaw, MathHelper.clamp(pitch,-90.0F, 90.0F));
return this;
}
public EntityPlayerActionPack lookAt(Vec3d position)
public EntityPlayerActionPack lookAt(Vec3 position)
{
player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, position);
player.lookAt(EntityAnchorArgument.Anchor.EYES, position);
return this;
}
public EntityPlayerActionPack turn(float yaw, float pitch)
{
return look(player.getYaw() + yaw, player.getPitch() + pitch);
return look(player.getYRot() + yaw, player.getXRot() + pitch);
}
public EntityPlayerActionPack turn(Vec2f rotation)
public EntityPlayerActionPack turn(Vec2 rotation)
{
return turn(rotation.x, rotation.y);
}
@@ -173,12 +172,12 @@ public class EntityPlayerActionPack
List<Entity> entities;
if (onlyRideables)
{
entities = player.world.getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof HorseBaseEntity);
entities = player.level.getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D),
e -> e instanceof Minecart || e instanceof Boat || e instanceof AbstractHorse);
}
else
{
entities = player.world.getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D));
entities = player.level.getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D));
}
if (entities.size()==0)
return this;
@@ -189,7 +188,7 @@ public class EntityPlayerActionPack
{
if (e == player || (currentVehicle == e))
continue;
double dd = player.squaredDistanceTo(e);
double dd = player.distanceToSqr(e);
if (dd<distance)
{
distance = dd;
@@ -197,8 +196,8 @@ public class EntityPlayerActionPack
}
}
if (closest == null) return this;
if (closest instanceof HorseBaseEntity && onlyRideables)
((HorseBaseEntity) closest).interactMob(player, Hand.MAIN_HAND);
if (closest instanceof AbstractHorse && onlyRideables)
((AbstractHorse) closest).mobInteract(player, InteractionHand.MAIN_HAND);
else
player.startRiding(closest,true);
return this;
@@ -238,49 +237,49 @@ public class EntityPlayerActionPack
}
if (forward != 0.0F)
{
player.forwardSpeed = forward*(sneaking?0.3F:1.0F);
player.zza = forward*(sneaking?0.3F:1.0F);
}
if (strafing != 0.0F)
{
player.sidewaysSpeed = strafing*(sneaking?0.3F:1.0F);
player.xxa = strafing*(sneaking?0.3F:1.0F);
}
}
static HitResult getTarget(ServerPlayerEntity player)
static HitResult getTarget(ServerPlayer player)
{
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
return Tracer.rayTrace(player, 1, reach, false);
}
private void dropItemFromSlot(int slot, boolean dropAll)
{
PlayerInventory inv = player.getInventory(); // getInventory;
if (!inv.getStack(slot).isEmpty())
player.dropItem(inv.removeStack(slot,
dropAll ? inv.getStack(slot).getCount() : 1
Inventory inv = player.getInventory(); // getInventory;
if (!inv.getItem(slot).isEmpty())
player.drop(inv.removeItem(slot,
dropAll ? inv.getItem(slot).getCount() : 1
), false, true); // scatter, keep owner
}
public void drop(int selectedSlot, boolean dropAll)
{
PlayerInventory inv = player.getInventory(); // getInventory;
Inventory inv = player.getInventory(); // getInventory;
if (selectedSlot == -2) // all
{
for (int i = inv.size(); i >= 0; i--)
for (int i = inv.getContainerSize(); i >= 0; i--)
dropItemFromSlot(i, dropAll);
}
else // one slot
{
if (selectedSlot == -1)
selectedSlot = inv.selectedSlot;
selectedSlot = inv.selected;
dropItemFromSlot(selectedSlot, dropAll);
}
}
public void setSlot(int slot)
{
player.getInventory().selectedSlot = slot-1;
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
player.getInventory().selected = slot-1;
player.connection.send(new ClientboundSetCarriedItemPacket(slot-1));
}
public enum ActionType
@@ -288,7 +287,7 @@ public class EntityPlayerActionPack
USE(true)
{
@Override
boolean execute(ServerPlayerEntity player, Action action)
boolean execute(ServerPlayer player, Action action)
{
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
if (ap.itemUseCooldown > 0)
@@ -301,23 +300,23 @@ public class EntityPlayerActionPack
return true;
}
HitResult hit = getTarget(player);
for (Hand hand : Hand.values())
for (InteractionHand hand : InteractionHand.values())
{
switch (hit.getType())
{
case BLOCK:
{
player.updateLastActionTime();
ServerWorld world = player.getWorld();
player.resetLastActionTime();
ServerLevel world = player.getLevel();
BlockHitResult blockHit = (BlockHitResult) hit;
BlockPos pos = blockHit.getBlockPos();
Direction side = blockHit.getSide();
if (pos.getY() < player.getWorld().getTopY() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
Direction side = blockHit.getDirection();
if (pos.getY() < player.getLevel().getMaxBuildHeight() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos))
{
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
if (result.isAccepted())
InteractionResult result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
if (result.consumesAction())
{
if (result.shouldSwingHand()) player.swingHand(hand);
if (result.shouldSwing()) player.swing(hand);
ap.itemUseCooldown = 3;
return true;
}
@@ -326,19 +325,19 @@ public class EntityPlayerActionPack
}
case ENTITY:
{
player.updateLastActionTime();
player.resetLastActionTime();
EntityHitResult entityHit = (EntityHitResult) hit;
Entity entity = entityHit.getEntity();
boolean handWasEmpty = player.getStackInHand(hand).isEmpty();
boolean itemFrameEmpty = (entity instanceof ItemFrameEntity) && ((ItemFrameEntity) entity).getHeldItemStack().isEmpty();
Vec3d relativeHitPos = entityHit.getPos().subtract(entity.getX(), entity.getY(), entity.getZ());
if (entity.interactAt(player, relativeHitPos, hand).isAccepted())
boolean handWasEmpty = player.getItemInHand(hand).isEmpty();
boolean itemFrameEmpty = (entity instanceof ItemFrame) && ((ItemFrame) entity).getItem().isEmpty();
Vec3 relativeHitPos = entityHit.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
if (entity.interactAt(player, relativeHitPos, hand).consumesAction())
{
ap.itemUseCooldown = 3;
return true;
}
// fix for SS itemframe always returns CONSUME even if no action is performed
if (player.interact(entity, hand).isAccepted() && !(handWasEmpty && itemFrameEmpty))
if (player.interactOn(entity, hand).consumesAction() && !(handWasEmpty && itemFrameEmpty))
{
ap.itemUseCooldown = 3;
return true;
@@ -346,8 +345,8 @@ public class EntityPlayerActionPack
break;
}
}
ItemStack handItem = player.getStackInHand(hand);
if (player.interactionManager.interactItem(player, player.getWorld(), handItem, hand).isAccepted())
ItemStack handItem = player.getItemInHand(hand);
if (player.gameMode.useItem(player, player.getLevel(), handItem, hand).consumesAction())
{
ap.itemUseCooldown = 3;
return true;
@@ -357,16 +356,16 @@ public class EntityPlayerActionPack
}
@Override
void inactiveTick(ServerPlayerEntity player, Action action)
void inactiveTick(ServerPlayer player, Action action)
{
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
ap.itemUseCooldown = 0;
player.stopUsingItem();
player.releaseUsingItem();
}
},
ATTACK(true) {
@Override
boolean execute(ServerPlayerEntity player, Action action) {
boolean execute(ServerPlayer player, Action action) {
HitResult hit = getTarget(player);
switch (hit.getType()) {
case ENTITY: {
@@ -374,10 +373,10 @@ public class EntityPlayerActionPack
if (!action.isContinuous)
{
player.attack(entityHit.getEntity());
player.swingHand(Hand.MAIN_HAND);
player.swing(InteractionHand.MAIN_HAND);
}
player.resetLastAttackedTicks();
player.updateLastActionTime();
player.resetAttackStrengthTicker();
player.resetLastActionTime();
return true;
}
case BLOCK: {
@@ -389,18 +388,18 @@ public class EntityPlayerActionPack
}
BlockHitResult blockHit = (BlockHitResult) hit;
BlockPos pos = blockHit.getBlockPos();
Direction side = blockHit.getSide();
if (player.isBlockBreakingRestricted(player.world, pos, player.interactionManager.getGameMode())) return false;
if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
Direction side = blockHit.getDirection();
if (player.blockActionRestricted(player.level, pos, player.gameMode.getGameModeForPlayer())) return false;
if (ap.currentBlock != null && player.level.getBlockState(ap.currentBlock).isAir())
{
ap.currentBlock = null;
return false;
}
BlockState state = player.world.getBlockState(pos);
BlockState state = player.level.getBlockState(pos);
boolean blockBroken = false;
if (player.interactionManager.getGameMode().isCreative())
if (player.gameMode.getGameModeForPlayer().isCreative())
{
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY());
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
ap.blockHitDelay = 5;
blockBroken = true;
}
@@ -408,15 +407,15 @@ public class EntityPlayerActionPack
{
if (ap.currentBlock != null)
{
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopY());
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
}
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY());
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
boolean notAir = !state.isAir();
if (notAir && ap.curBlockDamageMP == 0)
{
state.onBlockBreakStart(player.world, pos, player);
state.attack(player.level, pos, player);
}
if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
if (notAir && state.getDestroyProgress(player, player.level, pos) >= 1)
{
ap.currentBlock = null;
//instamine??
@@ -430,19 +429,19 @@ public class EntityPlayerActionPack
}
else
{
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos);
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level, pos);
if (ap.curBlockDamageMP >= 1)
{
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopY());
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
ap.currentBlock = null;
ap.blockHitDelay = 5;
blockBroken = true;
}
player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
player.level.destroyBlockProgress(-1, pos, (int) (ap.curBlockDamageMP * 10));
}
player.updateLastActionTime();
player.swingHand(Hand.MAIN_HAND);
player.resetLastActionTime();
player.swing(InteractionHand.MAIN_HAND);
return blockBroken;
}
}
@@ -450,23 +449,23 @@ public class EntityPlayerActionPack
}
@Override
void inactiveTick(ServerPlayerEntity player, Action action)
void inactiveTick(ServerPlayer player, Action action)
{
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
if (ap.currentBlock == null) return;
player.world.setBlockBreakingInfo(-1, ap.currentBlock, -1);
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopY());
player.level.destroyBlockProgress(-1, ap.currentBlock, -1);
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getLevel().getMaxBuildHeight());
ap.currentBlock = null;
}
},
JUMP(true)
{
@Override
boolean execute(ServerPlayerEntity player, Action action)
boolean execute(ServerPlayer player, Action action)
{
if (action.limit == 1)
{
if (player.isOnGround()) player.jump(); // onGround
if (player.isOnGround()) player.jumpFromGround(); // onGround
}
else
{
@@ -476,7 +475,7 @@ public class EntityPlayerActionPack
}
@Override
void inactiveTick(ServerPlayerEntity player, Action action)
void inactiveTick(ServerPlayer player, Action action)
{
player.setJumping(false);
}
@@ -484,32 +483,32 @@ public class EntityPlayerActionPack
DROP_ITEM(true)
{
@Override
boolean execute(ServerPlayerEntity player, Action action)
boolean execute(ServerPlayer player, Action action)
{
player.updateLastActionTime();
player.dropSelectedItem(false); // dropSelectedItem
player.resetLastActionTime();
player.drop(false); // dropSelectedItem
return false;
}
},
DROP_STACK(true)
{
@Override
boolean execute(ServerPlayerEntity player, Action action)
boolean execute(ServerPlayer player, Action action)
{
player.updateLastActionTime();
player.dropSelectedItem(true); // dropSelectedItem
player.resetLastActionTime();
player.drop(true); // dropSelectedItem
return false;
}
},
SWAP_HANDS(true)
{
@Override
boolean execute(ServerPlayerEntity player, Action action)
boolean execute(ServerPlayer player, Action action)
{
player.updateLastActionTime();
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
player.setStackInHand(Hand.OFF_HAND, player.getStackInHand(Hand.MAIN_HAND));
player.setStackInHand(Hand.MAIN_HAND, itemStack_1);
player.resetLastActionTime();
ItemStack itemStack_1 = player.getItemInHand(InteractionHand.OFF_HAND);
player.setItemInHand(InteractionHand.OFF_HAND, player.getItemInHand(InteractionHand.MAIN_HAND));
player.setItemInHand(InteractionHand.MAIN_HAND, itemStack_1);
return false;
}
};
@@ -521,10 +520,10 @@ public class EntityPlayerActionPack
this.preventSpectator = preventSpectator;
}
void start(ServerPlayerEntity player, Action action) {}
abstract boolean execute(ServerPlayerEntity player, Action action);
void inactiveTick(ServerPlayerEntity player, Action action) {}
void stop(ServerPlayerEntity player, Action action)
void start(ServerPlayer player, Action action) {}
abstract boolean execute(ServerPlayer player, Action action);
void inactiveTick(ServerPlayer player, Action action) {}
void stop(ServerPlayer player, Action action)
{
inactiveTick(player, action);
}