260 lines
12 KiB
Java
260 lines
12 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.core.CustomBlocks;
|
|
import com.dairymoose.modernlife.core.ModernLifeClient;
|
|
import com.dairymoose.modernlife.tileentities.CanvasBlockEntity;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import java.text.DecimalFormat;
|
|
import java.util.List;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
import net.minecraft.world.Container;
|
|
import net.minecraft.world.Containers;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
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.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
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.SoundType;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
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.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.material.Material;
|
|
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/CanvasBlock.class */
|
|
public class CanvasBlock extends Block implements EntityBlock {
|
|
protected static final VoxelShape SHAPE_SOUTH = (VoxelShape) Stream.of(Block.box(0.0d, 0.0d, 0.0d, 16.0d, 16.0d, 1.5d)).reduce((v1, v2) -> {
|
|
return Shapes.join(v1, v2, BooleanOp.OR);
|
|
}).get();
|
|
protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);
|
|
protected static final VoxelShape SHAPE_NORTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST);
|
|
protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH);
|
|
protected static final VoxelShape SHAPE_SOUTH_SIZE_0 = (VoxelShape) Stream.of(Block.box(0.0d, 0.0d, 0.0d, 15.99d, 15.99d, 1.5d)).reduce((v1, v2) -> {
|
|
return Shapes.join(v1, v2, BooleanOp.OR);
|
|
}).get();
|
|
protected static final VoxelShape SHAPE_WEST_SIZE_0 = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH_SIZE_0);
|
|
protected static final VoxelShape SHAPE_NORTH_SIZE_0 = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST_SIZE_0);
|
|
protected static final VoxelShape SHAPE_EAST_SIZE_0 = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH_SIZE_0);
|
|
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
|
public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7);
|
|
public static final int MAX_SIZE = ((Integer) SIZE.getPossibleValues().stream().max((i, i2) -> {
|
|
return i.intValue() - i2.intValue();
|
|
}).get()).intValue();
|
|
|
|
public CanvasBlock() {
|
|
super(Properties.of(Material.CLOTH_DECORATION).sound(SoundType.BAMBOO).strength(1.0f, 10.0f));
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.SOUTH)).setValue(SIZE, 1));
|
|
}
|
|
|
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
|
return (BlockState) state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
|
}
|
|
|
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
|
return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
|
}
|
|
|
|
public void onRemove(BlockState p_196243_1_, Level p_196243_2_, BlockPos p_196243_3_, BlockState p_196243_4_, boolean p_196243_5_) {
|
|
if (!p_196243_1_.is(p_196243_4_.getBlock())) {
|
|
Container blockEntity = (Container) p_196243_2_.getBlockEntity(p_196243_3_);
|
|
if (blockEntity != null) {
|
|
Containers.dropContents(p_196243_2_, p_196243_3_, blockEntity);
|
|
p_196243_2_.updateNeighbourForOutputSignal(p_196243_3_, this);
|
|
}
|
|
super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_, p_196243_4_, p_196243_5_);
|
|
}
|
|
}
|
|
|
|
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
|
|
if (!worldIn.isClientSide) {
|
|
BlockEntity e = worldIn.getBlockEntity(pos);
|
|
if (e instanceof CanvasBlockEntity) {
|
|
CanvasBlockEntity tile = (CanvasBlockEntity) e;
|
|
tile.setItem(0, itemStack.copy());
|
|
}
|
|
}
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
|
|
Long canvasUniqueId = null;
|
|
if (itemStack.getTag() != null && itemStack.getTag().contains("UniqueId")) {
|
|
list.add(new TextComponent("A work of art"));
|
|
long uniqueId = itemStack.getTag().getLong("UniqueId");
|
|
list.add(new TextComponent("ID = " + uniqueId));
|
|
canvasUniqueId = Long.valueOf(uniqueId);
|
|
} else {
|
|
list.add(new TextComponent("For use with an easel"));
|
|
}
|
|
if (canvasUniqueId != null) {
|
|
int width = ModernLifeClient.getCanvasWidth(canvasUniqueId.longValue());
|
|
int height = ModernLifeClient.getCanvasHeight(canvasUniqueId.longValue());
|
|
list.add(new TextComponent(width + "x" + height + " pixels"));
|
|
}
|
|
if (itemStack.getTag() != null && itemStack.getTag().contains("Size")) {
|
|
int size = itemStack.getTag().getInt("Size");
|
|
list.add(new TextComponent(""));
|
|
if (size == 1) {
|
|
list.add(new TextComponent("Normal print"));
|
|
return;
|
|
}
|
|
if (size == 2) {
|
|
list.add(new TextComponent("Large print"));
|
|
return;
|
|
}
|
|
if (size == 3) {
|
|
list.add(new TextComponent("Extra Large print"));
|
|
return;
|
|
}
|
|
if (size == 4) {
|
|
list.add(new TextComponent("Massive print"));
|
|
return;
|
|
}
|
|
if (size == 5) {
|
|
list.add(new TextComponent("Large square print"));
|
|
return;
|
|
}
|
|
if (size == 6) {
|
|
list.add(new TextComponent("Extra Large square print"));
|
|
return;
|
|
}
|
|
if (size == 7) {
|
|
list.add(new TextComponent("Massive square print"));
|
|
return;
|
|
}
|
|
if (size == 0) {
|
|
list.add(new TextComponent("Custom print"));
|
|
CompoundTag nbt = itemStack.getTag();
|
|
DecimalFormat df = new DecimalFormat("#.##");
|
|
if (nbt.contains("BlockWidth") && nbt.contains("BlockHeight")) {
|
|
float blockWidth = nbt.getFloat("BlockWidth");
|
|
float blockHeight = nbt.getFloat("BlockHeight");
|
|
list.add(new TextComponent(df.format(blockWidth) + "x" + df.format(blockHeight)));
|
|
}
|
|
if (nbt.contains("xOffset") && nbt.contains("yOffset")) {
|
|
float xOffset = nbt.getFloat("xOffset");
|
|
float yOffset = nbt.getFloat("yOffset");
|
|
if (xOffset != 0.0f || yOffset != 0.0f) {
|
|
list.add(new TextComponent("(" + df.format(xOffset) + ", " + df.format(yOffset) + ")"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, LevelAccessor p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
|
|
if (p_196271_1_.getValue(FACING).getOpposite() == p_196271_2_ && !p_196271_1_.canSurvive(p_196271_4_, p_196271_5_)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
|
|
}
|
|
|
|
/* renamed from: com.dairymoose.modernlife.blocks.CanvasBlock$1 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/CanvasBlock$1.class */
|
|
static /* synthetic */ class C00111 {
|
|
static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];
|
|
|
|
static {
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 1;
|
|
} catch (NoSuchFieldError e) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 2;
|
|
} catch (NoSuchFieldError e2) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 3;
|
|
} catch (NoSuchFieldError e3) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 4;
|
|
} catch (NoSuchFieldError e4) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState bs, BlockGetter reader, BlockPos pos, CollisionContext sel) {
|
|
if (((Integer) bs.getValue(SIZE)).intValue() == 0) {
|
|
switch (C00111.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
|
|
case 1:
|
|
return SHAPE_NORTH_SIZE_0;
|
|
case 2:
|
|
return SHAPE_SOUTH_SIZE_0;
|
|
case 3:
|
|
return SHAPE_EAST_SIZE_0;
|
|
case 4:
|
|
return SHAPE_WEST_SIZE_0;
|
|
}
|
|
}
|
|
switch (C00111.$SwitchMap$net$minecraft$core$Direction[bs.getValue(FACING).ordinal()]) {
|
|
case 1:
|
|
return SHAPE_NORTH;
|
|
case 2:
|
|
return SHAPE_SOUTH;
|
|
case 3:
|
|
return SHAPE_EAST;
|
|
case 4:
|
|
return SHAPE_WEST;
|
|
default:
|
|
return SHAPE_NORTH;
|
|
}
|
|
}
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
CanvasBlockEntity toReturn = (CanvasBlockEntity) CanvasBlockEntity.CANVAS.create(pos, state);
|
|
return toReturn;
|
|
}
|
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(new Property[]{FACING, SIZE});
|
|
}
|
|
|
|
public boolean canSurvive(BlockState p_196260_1_, LevelReader p_196260_2_, BlockPos p_196260_3_) {
|
|
return FaceAttachedHorizontalDirectionalBlock.canAttach(p_196260_2_, p_196260_3_, p_196260_1_.getValue(FACING).getOpposite());
|
|
}
|
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
int size;
|
|
Direction[] var2 = context.getNearestLookingDirections();
|
|
for (Direction lvt_5_1_ : var2) {
|
|
if (lvt_5_1_.getAxis() != Direction.Axis.Y) {
|
|
BlockState lvt_6_2_ = (BlockState) defaultBlockState().setValue(FACING, lvt_5_1_.getOpposite());
|
|
if (lvt_6_2_.canSurvive(context.getLevel(), context.getClickedPos())) {
|
|
ItemStack itemStack = context.getItemInHand();
|
|
if (itemStack != null && itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get() && itemStack.getTag() != null && itemStack.getTag().contains("Size") && (size = itemStack.getTag().getInt("Size")) >= 0 && size <= MAX_SIZE) {
|
|
lvt_6_2_ = (BlockState) lvt_6_2_.setValue(SIZE, Integer.valueOf(size));
|
|
}
|
|
return lvt_6_2_;
|
|
}
|
|
}
|
|
}
|
|
return defaultBlockState();
|
|
}
|
|
}
|