85 lines
3.8 KiB
Java
85 lines
3.8 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
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.FaceAttachedHorizontalDirectionalBlock;
|
|
import net.minecraft.world.level.block.Mirror;
|
|
import net.minecraft.world.level.block.Rotation;
|
|
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.AttachFace;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/CeilingFanBlock.class */
|
|
public class CeilingFanBlock extends FaceAttachedHorizontalDirectionalBlock {
|
|
protected static final VoxelShape SHAPE_NORTH = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(7.25d, 14.0d, 7.25d, 8.75d, 16.0d, 8.75d), Block.box(0.0d, 13.95d, 0.15d, 16.0d, 14.95d, 16.15d)}).reduce((v1, v2) -> {
|
|
return Shapes.join((VoxelShape) v1, (VoxelShape) v2, BooleanOp.OR);
|
|
}).get();
|
|
public static final IntegerProperty SPEED = IntegerProperty.create("speed", 0, 1);
|
|
|
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
|
return state;
|
|
}
|
|
|
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
|
return state;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
|
|
list.add(new TextComponent("Requires redstone power to operate"));
|
|
}
|
|
|
|
public CeilingFanBlock(Properties props) {
|
|
super(props);
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(SPEED, 0)).setValue(FaceAttachedHorizontalDirectionalBlock.FACE, AttachFace.CEILING));
|
|
}
|
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
int speedValue = 0;
|
|
BlockPos pos = context.getClickedPos();
|
|
boolean signal = context.getLevel().hasNeighborSignal(pos);
|
|
if (signal) {
|
|
speedValue = 1;
|
|
}
|
|
return (BlockState) defaultBlockState().setValue(SPEED, Integer.valueOf(speedValue));
|
|
}
|
|
|
|
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos neighborPos, boolean p_220069_6_) {
|
|
int speedValue = 0;
|
|
boolean signal = world.hasNeighborSignal(pos);
|
|
if (signal) {
|
|
speedValue = 1;
|
|
}
|
|
if (block != this && speedValue != ((Integer) state.getValue(SPEED)).intValue()) {
|
|
world.setBlock(pos, (BlockState) state.setValue(SPEED, Integer.valueOf(speedValue)), 2);
|
|
}
|
|
}
|
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(new Property[]{FaceAttachedHorizontalDirectionalBlock.FACE, SPEED});
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState bs, BlockGetter reader, BlockPos pos, CollisionContext sel) {
|
|
return SHAPE_NORTH;
|
|
}
|
|
}
|