mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-06-26 14:41:42 +02:00
82 lines
3.2 KiB
Java
82 lines
3.2 KiB
Java
/*
|
|
* This file ("BlockCoalGenerator.java") is part of the Actually Additions mod for Minecraft.
|
|
* It is created and owned by Ellpeck and distributed
|
|
* under the Actually Additions License to be found at
|
|
* http://ellpeck.de/actaddlicense
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
*
|
|
* © 2015-2017 Ellpeck
|
|
*/
|
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoalGenerator;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
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.BlockState;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
public class BlockCoalGenerator extends DirectionalBlock.Container {
|
|
public BlockCoalGenerator() {
|
|
super(ActuallyBlocks.defaultPickProps().randomTicks());
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
return new TileEntityCoalGenerator(pos, state);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
|
|
return level.isClientSide? TileEntityCoalGenerator::clientTick : TileEntityCoalGenerator::serverTick;
|
|
}
|
|
|
|
@Override
|
|
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
|
|
BlockEntity tile = world.getBlockEntity(pos);
|
|
if (tile instanceof TileEntityCoalGenerator) {
|
|
if (((TileEntityCoalGenerator) tile).currentBurnTime > 0) {
|
|
for (int i = 0; i < 5; i++) {
|
|
world.addParticle(ParticleTypes.SMOKE, (double) pos.getX() + 0.5F, (double) pos.getY() + 1.0F, (double) pos.getZ() + 0.5F, 0.0D, 0.0D, 0.0D);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
|
return this.openGui(world, player, pos, TileEntityCoalGenerator.class);
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
|
switch (state.getValue(FACING)) {
|
|
case EAST:
|
|
return VoxelShapes.CoalGeneratorShapes.EAST;
|
|
case SOUTH:
|
|
return VoxelShapes.CoalGeneratorShapes.SOUTH;
|
|
case WEST:
|
|
return VoxelShapes.CoalGeneratorShapes.WEST;
|
|
default:
|
|
return VoxelShapes.CoalGeneratorShapes.NORTH;
|
|
}
|
|
}
|
|
}
|