95 lines
3.1 KiB
Java
95 lines
3.1 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.world.entity.vehicle;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
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.EntityType;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
public class Minecart
|
|
extends AbstractMinecart {
|
|
private float rotationOffset;
|
|
private float playerRotationOffset;
|
|
|
|
public Minecart(EntityType<?> type, Level level) {
|
|
super(type, level);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult interact(Player player, InteractionHand hand) {
|
|
if (!player.isSecondaryUseActive() && !this.isVehicle() && (this.level().isClientSide() || player.startRiding(this))) {
|
|
this.playerRotationOffset = this.rotationOffset;
|
|
if (!this.level().isClientSide()) {
|
|
return player.startRiding(this) ? InteractionResult.CONSUME : InteractionResult.PASS;
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return InteractionResult.PASS;
|
|
}
|
|
|
|
@Override
|
|
protected Item getDropItem() {
|
|
return Items.MINECART;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getPickResult() {
|
|
return new ItemStack(Items.MINECART);
|
|
}
|
|
|
|
@Override
|
|
public void activateMinecart(ServerLevel level, int xt, int yt, int zt, boolean state) {
|
|
if (state) {
|
|
if (this.isVehicle()) {
|
|
this.ejectPassengers();
|
|
}
|
|
if (this.getHurtTime() == 0) {
|
|
this.setHurtDir(-this.getHurtDir());
|
|
this.setHurtTime(10);
|
|
this.setDamage(50.0f);
|
|
this.markHurt();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isRideable() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void tick() {
|
|
double lastKnownYRot = this.getYRot();
|
|
Vec3 lastKnownPos = this.position();
|
|
super.tick();
|
|
double tickDiff = ((double)this.getYRot() - lastKnownYRot) % 360.0;
|
|
if (this.level().isClientSide() && lastKnownPos.distanceTo(this.position()) > 0.01) {
|
|
this.rotationOffset += (float)tickDiff;
|
|
this.rotationOffset %= 360.0f;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void positionRider(Entity passenger, Entity.MoveFunction moveFunction) {
|
|
Player player;
|
|
super.positionRider(passenger, moveFunction);
|
|
if (this.level().isClientSide() && passenger instanceof Player && (player = (Player)passenger).shouldRotateWithMinecart() && Minecart.useExperimentalMovement(this.level())) {
|
|
float yRot = (float)Mth.rotLerp(0.5, (double)this.playerRotationOffset, (double)this.rotationOffset);
|
|
player.setYRot(player.getYRot() - (yRot - this.playerRotationOffset));
|
|
this.playerRotationOffset = yRot;
|
|
}
|
|
}
|
|
}
|
|
|