移植C4 entity

This commit is contained in:
17146 2025-04-02 20:42:37 +08:00
parent 327ac99017
commit 2808eaeeeb
2 changed files with 26 additions and 28 deletions

View file

@ -1,11 +1,14 @@
package com.atsuishio.superbwarfare.entity.projectile; package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -26,10 +29,13 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.*; import net.minecraft.world.phys.*;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -43,7 +49,7 @@ import java.util.UUID;
import static com.atsuishio.superbwarfare.item.C4Bomb.TAG_CONTROL; import static com.atsuishio.superbwarfare.item.C4Bomb.TAG_CONTROL;
public class C4Entity extends Entity implements GeoEntity { public class C4Entity extends Entity implements GeoEntity, OwnableEntity {
protected static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID); protected static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.OPTIONAL_UUID);
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING); protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.STRING);
@ -51,7 +57,6 @@ public class C4Entity extends Entity implements GeoEntity {
public static final EntityDataAccessor<Boolean> IS_CONTROLLABLE = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> IS_CONTROLLABLE = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Integer> BOMB_TICK = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> BOMB_TICK = SynchedEntityData.defineId(C4Entity.class, EntityDataSerializers.INT);
public static final int DEFAULT_DEFUSE_PROGRESS = 100; public static final int DEFAULT_DEFUSE_PROGRESS = 100;
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -152,17 +157,16 @@ public class C4Entity extends Entity implements GeoEntity {
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public @NotNull InteractionResult interact(Player player, InteractionHand hand) { public @NotNull InteractionResult interact(Player player, InteractionHand hand) {
// TODO this.getOwner() if (this.getOwner() == player && player.isShiftKeyDown()) {
// if (this.getOwner() == player && player.isShiftKeyDown()) { if (!this.level().isClientSide()) {
// if (!this.level().isClientSide()) { this.discard();
// this.discard(); }
// }
// if (!player.getAbilities().instabuild) {
// if (!player.getAbilities().instabuild) { ItemHandlerHelper.giveItemToPlayer(player, this.getItemStack());
// ItemHandlerHelper.giveItemToPlayer(player, this.getItemStack()); }
// } return InteractionResult.sidedSuccess(this.level().isClientSide());
// return InteractionResult.sidedSuccess(this.level().isClientSide()); }
// }
return InteractionResult.PASS; return InteractionResult.PASS;
} }
@ -349,9 +353,7 @@ public class C4Entity extends Entity implements GeoEntity {
if (!pTarget.canBeHitByProjectile()) { if (!pTarget.canBeHitByProjectile()) {
return false; return false;
} else { } else {
// TODO this.getOwner() Entity entity = this.getOwner();
// Entity entity = this.getOwner();
Entity entity = null;
return entity == null || !entity.isPassengerOfSameVehicle(pTarget); return entity == null || !entity.isPassengerOfSameVehicle(pTarget);
} }
} }
@ -409,14 +411,13 @@ public class C4Entity extends Entity implements GeoEntity {
} }
} }
// TODO this.getOwner() explosion CustomExplosion explosion = new CustomExplosion(level(), this,
// CustomExplosion explosion = new CustomExplosion(level(), this, ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
// ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(), pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
// pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode();
// explosion.explode(); EventHooks.onExplosionStart(level(), explosion);
// EventHooks.onExplosionStart(level(), explosion); ParticleTool.spawnHugeExplosionParticles(level(), position());
// ParticleTool.spawnHugeExplosionParticles(level(), position()); explosion.finalizeExplosion(false);
// explosion.finalizeExplosion(false);
this.discard(); this.discard();
} }

View file

@ -26,10 +26,7 @@ public class Detonator extends Item {
public static List<Entity> getC4(Player player, Level level) { public static List<Entity> getC4(Player player, Level level) {
return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false) return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false)
.filter(e -> e instanceof C4Entity c4 .filter(e -> e instanceof C4Entity c4 && c4.getOwner() == player)
// TODO c4.getOwner()
// && c4.getOwner() == player
)
.toList(); .toList();
} }