mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-06-10 01:00:25 +02:00
113 lines
4.6 KiB
Java
113 lines
4.6 KiB
Java
/*
|
|
* This file ("BlockFurnaceDouble.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.TileEntityPoweredFurnace;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.network.chat.Component;
|
|
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.item.ItemStack;
|
|
import net.minecraft.world.item.TooltipFlag;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.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.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.List;
|
|
|
|
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING;
|
|
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.LIT;
|
|
|
|
public class BlockPoweredFurnace extends DirectionalBlock.Container {
|
|
public BlockPoweredFurnace() {
|
|
super(ActuallyBlocks.defaultPickProps().randomTicks().lightLevel(state -> state.getValue(LIT)
|
|
? 12
|
|
: 0));
|
|
|
|
registerDefaultState(getStateDefinition().any().setValue(HORIZONTAL_FACING, Direction.NORTH).setValue(LIT, false));
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
return new TileEntityPoweredFurnace(pos, state);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
|
|
return level.isClientSide? TileEntityPoweredFurnace::clientTick : TileEntityPoweredFurnace::serverTick;
|
|
}
|
|
|
|
@Override
|
|
public void randomTick(BlockState state, ServerLevel worldIn, BlockPos pos, RandomSource random) {
|
|
if (state.getValue(LIT)) {
|
|
for (int i = 0; i < 5; i++) {
|
|
worldIn.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 worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
|
|
return this.openGui(worldIn, player, pos, TileEntityPoweredFurnace.class);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
return defaultBlockState().setValue(HORIZONTAL_FACING, context.getHorizontalDirection().getOpposite()).setValue(LIT, false);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(LIT).add(HORIZONTAL_FACING);
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List<Component> tooltip, TooltipFlag advanced) {
|
|
super.appendHoverText(stack, level, tooltip, advanced);
|
|
tooltip.add(Component.translatable("tooltip.actuallyadditions.previouslyDoubleFurnace").withStyle(ChatFormatting.ITALIC));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
|
switch (state.getValue(HORIZONTAL_FACING)) {
|
|
case EAST:
|
|
return VoxelShapes.FurnaceDoubleShapes.SHAPE_E;
|
|
case SOUTH:
|
|
return VoxelShapes.FurnaceDoubleShapes.SHAPE_S;
|
|
case WEST:
|
|
return VoxelShapes.FurnaceDoubleShapes.SHAPE_W;
|
|
default:
|
|
return VoxelShapes.FurnaceDoubleShapes.SHAPE_N;
|
|
}
|
|
}
|
|
}
|