|
| 1 | +package com.bymarcin.mmrcreate.block; |
| 2 | + |
| 3 | +import com.bymarcin.mmrcreate.blockentity.KineticOutputHatchEntity; |
| 4 | +import com.simibubi.create.content.kinetics.base.DirectionalKineticBlock; |
| 5 | +import com.simibubi.create.foundation.block.IBE; |
| 6 | +import com.tterrag.registrate.util.entry.BlockEntityEntry; |
| 7 | +import es.degrassi.mmreborn.common.block.BlockDynamicColor; |
| 8 | +import net.minecraft.core.BlockPos; |
| 9 | +import net.minecraft.core.Direction; |
| 10 | +import net.minecraft.server.level.ServerLevel; |
| 11 | +import net.minecraft.util.RandomSource; |
| 12 | +import net.minecraft.world.level.Level; |
| 13 | +import net.minecraft.world.level.LevelReader; |
| 14 | +import net.minecraft.world.level.block.entity.BlockEntityType; |
| 15 | +import net.minecraft.world.level.block.state.BlockState; |
| 16 | + |
| 17 | +public class BlockKineticOutputHatch<T extends KineticOutputHatchEntity> extends DirectionalKineticBlock implements IBE<T>, BlockDynamicColor { |
| 18 | + private final Class<T> tClass; |
| 19 | + private final BlockEntityEntry<? extends T> blockEntityType; |
| 20 | + |
| 21 | + public BlockKineticOutputHatch(Properties properties, Class<T> tClass, BlockEntityEntry<? extends T> entityType) { |
| 22 | + super(properties); |
| 23 | + this.tClass = tClass; |
| 24 | + this.blockEntityType = entityType; |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void onPlace(BlockState state, Level worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { |
| 29 | + super.onPlace(state, worldIn, pos, oldState, isMoving); |
| 30 | + if (worldIn.isClientSide()) |
| 31 | + return; |
| 32 | + if (!worldIn.getBlockTicks() |
| 33 | + .hasScheduledTick(pos, this)) |
| 34 | + worldIn.scheduleTick(pos, this, 1); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { |
| 39 | + withBlockEntityDo(level, pos, (e)->{ |
| 40 | + e.updateGeneratedRotation(); |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public Class<T> getBlockEntityClass() { |
| 46 | + return tClass; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public BlockEntityType<? extends T> getBlockEntityType() { |
| 51 | + return blockEntityType.get(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public Direction.Axis getRotationAxis(BlockState state) { |
| 56 | + return state.getValue(FACING).getAxis(); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) { |
| 61 | + return face == state.getValue(FACING).getOpposite(); |
| 62 | + } |
| 63 | +} |
0 commit comments