移除弹射器的方块实体

This commit is contained in:
Atsuishio 2025-05-15 00:46:37 +08:00 committed by Light_Quanta
parent e4b0228d45
commit 87ca42f096
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 26 additions and 84 deletions

View file

@ -1,18 +1,17 @@
package com.atsuishio.superbwarfare.block;
import com.atsuishio.superbwarfare.block.entity.AircraftCatapultBlockEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
@ -20,12 +19,12 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
public class AircraftCatapultBlock extends BaseEntityBlock {
public class AircraftCatapultBlock extends Block {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final IntegerProperty POWER = BlockStateProperties.POWER;
@ -36,21 +35,6 @@ public class AircraftCatapultBlock extends BaseEntityBlock {
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(POWER, 0).setValue(UPDATING, false));
}
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) {
return new AircraftCatapultBlockEntity(pPos, pState);
}
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, @NotNull BlockState pState, @NotNull BlockEntityType<T> pBlockEntityType) {
if (!pLevel.isClientSide) {
return createTickerHelper(pBlockEntityType, ModBlockEntities.AIRCRAFT_CATAPULT.get(), AircraftCatapultBlockEntity::serverTick);
} else {
return createTickerHelper(pBlockEntityType, ModBlockEntities.AIRCRAFT_CATAPULT.get(), AircraftCatapultBlockEntity::clientTick);
}
}
@Override
@ParametersAreNonnullByDefault
@ -68,13 +52,6 @@ public class AircraftCatapultBlock extends BaseEntityBlock {
builder.add(FACING).add(POWER).add(UPDATING);
}
public static final MapCodec<AircraftCatapultBlock> CODEC = simpleCodec((prop) -> new AircraftCatapultBlock());
@Override
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
return CODEC;
}
@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) {
return RenderShape.MODEL;
@ -82,7 +59,7 @@ public class AircraftCatapultBlock extends BaseEntityBlock {
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection());
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}
@Override
@ -130,4 +107,21 @@ public class AircraftCatapultBlock extends BaseEntityBlock {
}
return max;
}
@Override
@ParametersAreNonnullByDefault
public void stepOn(Level pLevel, BlockPos pPos, BlockState pState, Entity pEntity) {
super.stepOn(pLevel, pPos, pState, pEntity);
var direction = pState.getValue(AircraftCatapultBlock.FACING);
int power = pState.getValue(AircraftCatapultBlock.POWER);
if (power == 0) return;
float rate = power / 400f;
if (pEntity instanceof LivingEntity) {
rate = power / 50f;
}
if (pEntity.getDeltaMovement().dot(new Vec3(direction.getStepX(), 0, direction.getStepZ())) < 0.2 * power) {
pEntity.addDeltaMovement(new Vec3(direction.getStepX() * rate, 0, direction.getStepZ() * rate));
}
}
}

View file

@ -1,49 +0,0 @@
package com.atsuishio.superbwarfare.block.entity;
import com.atsuishio.superbwarfare.block.AircraftCatapultBlock;
import com.atsuishio.superbwarfare.init.ModBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
public class AircraftCatapultBlockEntity extends BlockEntity {
public AircraftCatapultBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(ModBlockEntities.AIRCRAFT_CATAPULT.get(), pPos, pBlockState);
}
public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, AircraftCatapultBlockEntity blockEntity) {
var direction = pState.getValue(AircraftCatapultBlock.FACING);
int power = pState.getValue(AircraftCatapultBlock.POWER);
if (power == 0) return;
var list = pLevel.getEntitiesOfClass(Entity.class, new AABB(pPos.above()));
list.forEach(entity -> {
float rate = power / 1200f;
if (entity instanceof LivingEntity) {
rate = power / 100f;
}
if (entity.getDeltaMovement().dot(new Vec3(direction.getStepX(), 0, direction.getStepZ())) < 0.2 * power) {
entity.addDeltaMovement(new Vec3(direction.getStepX() * rate, 0, direction.getStepZ() * rate));
}
});
}
public static void clientTick(Level pLevel, BlockPos pPos, BlockState pState, AircraftCatapultBlockEntity blockEntity) {
var direction = pState.getValue(AircraftCatapultBlock.FACING);
int power = pState.getValue(AircraftCatapultBlock.POWER);
if (power == 0) return;
var list = pLevel.getEntitiesOfClass(Player.class, new AABB(pPos.above()));
list.forEach(entity -> {
if (entity.getAbilities().flying) return;
entity.addDeltaMovement(new Vec3(direction.getStepX() * power / 100f, 0, direction.getStepZ() * power / 100f));
});
}
}

View file

@ -28,7 +28,4 @@ public class ModBlockEntities {
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<VehicleDeployerBlockEntity>> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer",
() -> BlockEntityType.Builder.of(VehicleDeployerBlockEntity::new, ModBlocks.VEHICLE_DEPLOYER.get()).build(null));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<AircraftCatapultBlockEntity>> AIRCRAFT_CATAPULT = REGISTRY.register("aircraft_catapult",
() -> BlockEntityType.Builder.of(AircraftCatapultBlockEntity::new, ModBlocks.AIRCRAFT_CATAPULT.get()).build(null));
}