diff --git a/src/main/java/com/atsuishio/superbwarfare/block/AircraftCatapultBlock.java b/src/main/java/com/atsuishio/superbwarfare/block/AircraftCatapultBlock.java index b9b01f51a..515e64554 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/AircraftCatapultBlock.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/AircraftCatapultBlock.java @@ -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 BlockEntityTicker getTicker(Level pLevel, @NotNull BlockState pState, @NotNull BlockEntityType 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 CODEC = simpleCodec((prop) -> new AircraftCatapultBlock()); - - @Override - protected @NotNull MapCodec 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)); + } + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/AircraftCatapultBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/AircraftCatapultBlockEntity.java deleted file mode 100644 index 5d0bb30c3..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/AircraftCatapultBlockEntity.java +++ /dev/null @@ -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)); - }); - } -} diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java b/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java index 444e154dd..64d4d0841 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModBlockEntities.java @@ -28,7 +28,4 @@ public class ModBlockEntities { public static final DeferredHolder, BlockEntityType> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer", () -> BlockEntityType.Builder.of(VehicleDeployerBlockEntity::new, ModBlocks.VEHICLE_DEPLOYER.get()).build(null)); - - public static final DeferredHolder, BlockEntityType> AIRCRAFT_CATAPULT = REGISTRY.register("aircraft_catapult", - () -> BlockEntityType.Builder.of(AircraftCatapultBlockEntity::new, ModBlocks.AIRCRAFT_CATAPULT.get()).build(null)); }