207 lines
9.3 KiB
Java
207 lines
9.3 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.blocks.gui.PrinterScreen;
|
|
import com.dairymoose.modernlife.core.CustomBlocks;
|
|
import com.dairymoose.modernlife.tileentities.PrinterBlockEntity;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import java.util.stream.Stream;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.nbt.ListTag;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
import net.minecraft.world.Containers;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.MenuProvider;
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
import net.minecraft.world.inventory.ChestMenu;
|
|
import net.minecraft.world.inventory.MenuType;
|
|
import net.minecraft.world.item.ItemStack;
|
|
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.EntityBlock;
|
|
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.phys.BlockHitResult;
|
|
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.fml.DistExecutor;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PrinterBlock.class */
|
|
public class PrinterBlock extends StandardHorizontalBlock implements EntityBlock {
|
|
protected static final VoxelShape SHAPE_SOUTH = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(1.0d, 0.0d, 0.0d, 15.0d, 8.0d, 13.0d), Block.box(5.0d, 0.0d, 13.0d, 11.0d, 1.0d, 16.0d)}).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);
|
|
|
|
public PrinterBlock(Properties p_i48377_1_) {
|
|
super(p_i48377_1_);
|
|
}
|
|
|
|
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())) {
|
|
BlockEntity lvt_6_1_ = p_196243_2_.getBlockEntity(p_196243_3_);
|
|
if (lvt_6_1_ instanceof PrinterBlockEntity) {
|
|
Containers.dropContents(p_196243_2_, p_196243_3_, (PrinterBlockEntity) lvt_6_1_);
|
|
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 BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
PrinterBlockEntity toReturn = (PrinterBlockEntity) PrinterBlockEntity.PRINTER.create(pos, state);
|
|
return toReturn;
|
|
}
|
|
public MenuProvider getMenuProvider(BlockState p_220052_1_, Level p_220052_2_, BlockPos p_220052_3_) {
|
|
return new MenuProvider() { // from class: com.dairymoose.modernlife.blocks.PrinterBlock.1
|
|
public AbstractContainerMenu createMenu(int paramInt, Inventory paramInventory, Player paramPlayer) {
|
|
BlockEntity tileEntity = p_220052_2_.getBlockEntity(p_220052_3_);
|
|
if (tileEntity instanceof PrinterBlockEntity) {
|
|
PrinterBlockEntity printerBlockEntity = (PrinterBlockEntity) tileEntity;
|
|
return new ChestMenu(MenuType.GENERIC_9x3, paramInt, paramInventory, printerBlockEntity, 3);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Component getDisplayName() {
|
|
return new TextComponent("Printer");
|
|
}
|
|
};
|
|
}
|
|
|
|
public InteractionResult use(BlockState blockState, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTrace) {
|
|
MenuProvider lvt_7_1_;
|
|
ItemStack itemStack = player.getMainHandItem();
|
|
if (itemStack.getItem() == CustomBlocks.ITEM_CAMERA.get() || itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get()) {
|
|
if (itemStack.getItem() == CustomBlocks.ITEM_CAMERA.get() && itemStack.getTag() != null && itemStack.getTag().contains("ImageList")) {
|
|
int photoCount = 0;
|
|
ListTag listTag = (ListTag) itemStack.getTag().get("ImageList");
|
|
if (listTag instanceof ListTag) {
|
|
ListTag imageList = listTag;
|
|
photoCount = imageList.size();
|
|
}
|
|
if (photoCount > 0) {
|
|
if (world.isClientSide) {
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> {
|
|
return new Runnable() { // from class: com.dairymoose.modernlife.blocks.PrinterBlock.2
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Minecraft.getInstance().setScreen(new PrinterScreen(pos));
|
|
}
|
|
};
|
|
});
|
|
}
|
|
} else {
|
|
MenuProvider lvt_7_1_2 = getMenuProvider(blockState, world, pos);
|
|
if (lvt_7_1_2 != null) {
|
|
player.openMenu(lvt_7_1_2);
|
|
}
|
|
}
|
|
} else if (itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get() && world.isClientSide) {
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> {
|
|
return new Runnable() { // from class: com.dairymoose.modernlife.blocks.PrinterBlock.3
|
|
final /* synthetic */ BlockPos val$pos;
|
|
|
|
RunnableC00493(BlockPos pos2) {
|
|
pos = pos2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Minecraft.getInstance().setScreen(new PrinterScreen(pos));
|
|
}
|
|
};
|
|
});
|
|
}
|
|
} else if (!world.isClientSide && (lvt_7_1_ = getMenuProvider(blockState, world, pos2)) != null) {
|
|
player.openMenu(lvt_7_1_);
|
|
}
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.dairymoose.modernlife.blocks.PrinterBlock$2 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PrinterBlock$2.class */
|
|
public class RunnableC00482 implements Runnable {
|
|
final /* synthetic */ BlockPos val$pos;
|
|
|
|
RunnableC00482(BlockPos pos2) {
|
|
pos = pos2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Minecraft.getInstance().setScreen(new PrinterScreen(pos));
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.dairymoose.modernlife.blocks.PrinterBlock$3 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PrinterBlock$3.class */
|
|
public class RunnableC00493 implements Runnable {
|
|
final /* synthetic */ BlockPos val$pos;
|
|
|
|
RunnableC00493(BlockPos pos2) {
|
|
pos = pos2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
Minecraft.getInstance().setScreen(new PrinterScreen(pos));
|
|
}
|
|
}
|
|
|
|
/* renamed from: com.dairymoose.modernlife.blocks.PrinterBlock$4 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PrinterBlock$4.class */
|
|
static /* synthetic */ class C00504 {
|
|
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) {
|
|
switch (C00504.$SwitchMap$net$minecraft$core$Direction[bs.getValue(HorizontalDirectionalBlock.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;
|
|
}
|
|
}
|
|
}
|