添加轮椅创人

This commit is contained in:
Atsuihsio 2024-12-27 01:03:49 +08:00
parent 7febbbc028
commit bc1982581f
7 changed files with 87 additions and 68 deletions

View file

@ -1,10 +1,16 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.Vec3;
import org.joml.Math;
@ -32,6 +38,16 @@ public class MobileVehicleEntity extends Entity {
super(pEntityType, pLevel);
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean isPushable() {
return false;
}
@Override
public boolean isPickable() {
return !this.isRemoved();
@ -53,6 +69,8 @@ public class MobileVehicleEntity extends Entity {
handleClientSync();
crushEntities(this.getDeltaMovement());
this.refreshDimensions();
}
@ -76,6 +94,34 @@ public class MobileVehicleEntity extends Entity {
--interpolationSteps;
}
/**
* 撞击实体并造成伤害
* @param velocity 动量
*/
public void crushEntities(Vec3 velocity) {
var frontBox = getBoundingBox().move(velocity.scale(0.5));
var velAdd = velocity.add(0, 0, 0).scale(1.5);
for (var entity : level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)) {
double entitySize = entity.getBbWidth() * entity.getBbHeight();
double thisSize = this.getBbWidth() * this.getBbHeight();
double f = Math.min(entitySize / thisSize, 2);
double f1 = Math.min(thisSize / entitySize, 4);
if (!(entity instanceof TargetEntity)) {
this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z);
}
if (velocity.length() > 0.25 && entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) {
if (!this.level().isClientSide) {
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
}
entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z);
entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (20 * velocity.length()));
}
}
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int interpolationSteps, boolean interpolate) {
this.x = x;

View file

@ -19,6 +19,7 @@ import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
@ -44,7 +45,6 @@ import net.minecraft.world.entity.*;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.entity.vehicle.ContainerEntity;
import net.minecraft.world.inventory.AbstractContainerMenu;
@ -55,7 +55,6 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@ -83,6 +82,8 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
@ -154,29 +155,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
ContainerHelper.loadAllItems(compound, this.getItemStacks());
}
@Override
public boolean canCollideWith(Entity pEntity) {
if (this.getDeltaMovement().length() > 0.2) {
return false;
} else {
return canVehicleCollide(this, pEntity);
}
}
public static boolean canVehicleCollide(Entity pVehicle, Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !pVehicle.isPassengerOfSameVehicle(pEntity);
}
@Override
public boolean canBeCollidedWith() {
return super.canBeCollidedWith();
}
@Override
public boolean isPushable() {
return true;
}
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
@ -198,7 +176,7 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
@Override
public boolean hurt(DamageSource source, float amount) {
if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
}
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
@ -335,8 +313,11 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
destroy();
}
if (this.isVehicle() && this.getDeltaMovement().length() > 0.05) {
crushEntities(this.getDeltaMovement());
if (this.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 2 * getLookAngle().x, this.getY() + getSubmergedHeight(this), this.getZ() + 2 * getLookAngle().z, 4, 0.5, 0, 0.5, 0.1, true);
// sendParticle(serverLevel, ParticleTypes.CLOUD, x, y + 3, z, 30, 2, 1, 2, 0.01, true);
// sendParticle(serverLevel, ParticleTypes.FALLING_WATER, x, y + 3, z, 50, 1.5, 4, 1.5, 1, true);
// sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, x, y, z, 60, 3, 0.5, 3, 0.1, true);
}
controlBoat();
@ -437,33 +418,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
}
/**
* 撞击实体并造成伤害
* @param velocity 动量
*/
public void crushEntities(Vec3 velocity) {
var frontBox = getBoundingBox().move(velocity.scale(0.5));
var velAdd = velocity.add(0, 0, 0).scale(1.5);
for (var entity : level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)) {
double entitySize = entity.getBbWidth() * entity.getBbHeight();
double thisSize = this.getBbWidth() * this.getBbHeight();
double f = Math.min(entitySize / thisSize, 2);
double f1 = Math.min(thisSize / entitySize, 4);
if (!(entity instanceof TargetEntity)) {
this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z);
}
if (velocity.length() > 0.2 && entity.isAlive() && !(entity instanceof ItemEntity || entity instanceof Projectile || entity instanceof ProjectileEntity)) {
if (!this.level().isClientSide) {
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
}
entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z);
entity.hurt(ModDamageTypes.causeVehicleStrikeDamage(this.level().registryAccess(), this, this.getFirstPassenger() == null ? this : this.getFirstPassenger()), (float) (25 * velocity.length()));
}
}
}
/**
* 撞掉莲叶和冰块

View file

@ -1,7 +1,9 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
@ -20,6 +22,8 @@ import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
@ -75,16 +79,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
this.entityData.set(ENERGY, compound.getFloat("Energy"));
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean canCollideWith(Entity pEntity) {
return (pEntity.canBeCollidedWith() || pEntity.isPushable()) && !this.isPassengerOfSameVehicle(pEntity);
}
@Override
protected float getEyeHeight(Pose pPose, EntityDimensions pSize) {
return 0.75F;
@ -128,11 +122,30 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity,
@Override
public InteractionResult interact(Player player, InteractionHand hand) {
if (this.getFirstPassenger() == null) {
if (player.getVehicle() == this) return InteractionResult.PASS;
if (player.isShiftKeyDown() && player.getMainHandItem().is(ModItems.CROWBAR.get())) {
ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)) {
player.drop(stack, false);
}
this.remove(RemovalReason.DISCARDED);
this.discard();
} else {
if (player.getMainHandItem().is(Items.IRON_INGOT)) {
if (this.entityData.get(HEALTH) < MAX_HEALTH) {
this.entityData.set(HEALTH, Math.min(this.entityData.get(HEALTH) + 0.5f * MAX_HEALTH, MAX_HEALTH));
player.getMainHandItem().shrink(1);
if (!this.level().isClientSide) {
this.level().playSound(null, this, SoundEvents.IRON_GOLEM_REPAIR, this.getSoundSource(), 1, 1);
}
} else {
player.startRiding(this);
}
return InteractionResult.sidedSuccess(this.level().isClientSide());
}
player.startRiding(this);
return InteractionResult.sidedSuccess(this.level().isClientSide());
}
return InteractionResult.PASS;
return InteractionResult.sidedSuccess(this.level().isClientSide());
}
@Override

View file

@ -107,6 +107,7 @@ public class ModTabs {
output.accept(ContainerBlockItem.createMle1934Instance());
output.accept(ContainerBlockItem.createAnnihilatorInstance());
output.accept(ContainerBlockItem.createSpeedboatInstance());
output.accept(ContainerBlockItem.createWheelChairInstance());
} else {
output.accept(registryObject.get());
if (registryObject.get() == ModItems.ARMOR_PLATE.get()) {

View file

@ -104,4 +104,7 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
public static ItemStack createSpeedboatInstance() {
return createInstance(ModEntities.SPEEDBOAT.get());
}
public static ItemStack createWheelChairInstance() {
return createInstance(ModEntities.WHEEL_CHAIR.get());
}
}

View file

@ -362,6 +362,7 @@
"entity.superbwarfare.drone": "Drone",
"entity.superbwarfare.annihilator": "Annihilator Energy Gun",
"entity.superbwarfare.speedboat": "Speedboat",
"entity.superbwarfare.wheel_chair": "WheelChair",
"key.categories.superbwarfare": "Superb Warfare",
"key.superbwarfare.hold_zoom": "Zoom(Hold)",

View file

@ -362,6 +362,7 @@
"entity.superbwarfare.drone": "无人机",
"entity.superbwarfare.annihilator": "歼灭者能量炮",
"entity.superbwarfare.speedboat": "快艇",
"entity.superbwarfare.wheel_chair": "轮椅",
"key.categories.superbwarfare": "卓越前线",
"key.superbwarfare.hold_zoom": "瞄准(按住)",