-
Notifications
You must be signed in to change notification settings - Fork 755
/
OrientableSmelteryBlock.java
62 lines (53 loc) · 2.4 KB
/
OrientableSmelteryBlock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package slimeknights.tconstruct.smeltery.block.component;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType.BlockEntitySupplier;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import slimeknights.tconstruct.smeltery.block.entity.component.SmelteryComponentBlockEntity;
import javax.annotation.Nullable;
/** Shared logic for smeltery blocks with four directions to face */
public class OrientableSmelteryBlock extends SearedBlock implements EntityBlock {
public static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
private final BlockEntitySupplier<? extends SmelteryComponentBlockEntity> blockEntity;
public OrientableSmelteryBlock(Properties properties, boolean requiredBlockEntity, BlockEntitySupplier<? extends SmelteryComponentBlockEntity> blockEntity) {
super(properties, requiredBlockEntity);
this.blockEntity = blockEntity;
}
@Override
@Nullable
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
if (requiredBlockEntity || state.getValue(IN_STRUCTURE)) {
return blockEntity.create(pos, state);
}
return null;
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block,BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}
@Deprecated
@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}
@Deprecated
@Override
public BlockState mirror(BlockState state, Mirror mirror) {
return state.setValue(FACING, mirror.mirror(state.getValue(FACING)));
}
}