89 lines
3.5 KiB
Java
89 lines
3.5 KiB
Java
package com.atsuishio.superbwarfare.block;
|
|
|
|
import com.atsuishio.superbwarfare.block.entity.CreativeChargingStationBlockEntity;
|
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
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.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import javax.annotation.ParametersAreNonnullByDefault;
|
|
|
|
public class CreativeChargingStationBlock extends BaseEntityBlock {
|
|
|
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
|
|
|
public CreativeChargingStationBlock() {
|
|
this(Properties.of().sound(SoundType.METAL).strength(3.0f).requiresCorrectToolForDrops());
|
|
}
|
|
|
|
public CreativeChargingStationBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
|
}
|
|
|
|
private static final MapCodec<CreativeChargingStationBlock> CODEC = BlockBehaviour.simpleCodec(CreativeChargingStationBlock::new);
|
|
|
|
@Override
|
|
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
@Override
|
|
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) {
|
|
return RenderShape.MODEL;
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
@ParametersAreNonnullByDefault
|
|
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
|
return new CreativeChargingStationBlockEntity(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.CREATIVE_CHARGING_STATION.get(),
|
|
(pLevel1, pPos, pState1, blockEntity) -> CreativeChargingStationBlockEntity.serverTick(blockEntity)
|
|
);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void onRemove(BlockState pState, @NotNull Level pLevel, @NotNull BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
|
|
if (!pState.is(pNewState.getBlock())) {
|
|
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
|
if (blockentity instanceof CreativeChargingStationBlockEntity) {
|
|
pLevel.updateNeighbourForOutputSignal(pPos, this);
|
|
}
|
|
}
|
|
|
|
super.onRemove(pState, pLevel, pPos, pNewState, pMovedByPiston);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
|
pBuilder.add(FACING);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
|
return this.defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite());
|
|
}
|
|
}
|