190 lines
8.2 KiB
Java
190 lines
8.2 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.blocks.gui.chess.CheckState;
|
|
import com.dairymoose.modernlife.blocks.gui.chess.ChessScreen;
|
|
import com.dairymoose.modernlife.renderer.tileentity.ChessBoardBlockEntityRenderer;
|
|
import com.dairymoose.modernlife.tileentities.ChessBoardBlockEntity;
|
|
import java.util.List;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.client.Minecraft;
|
|
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.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.TooltipFlag;
|
|
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.BlockState;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
import net.minecraftforge.fml.DistExecutor;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ChessBoardBlock.class */
|
|
public class ChessBoardBlock extends Block implements EntityBlock {
|
|
protected static final VoxelShape SHAPE = Block.box(2.0d, 0.0d, 2.0d, 14.0d, 1.0d, 14.0d);
|
|
|
|
public ChessBoardBlock(Properties p_i48377_1_) {
|
|
super(p_i48377_1_);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.dairymoose.modernlife.blocks.ChessBoardBlock$1 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ChessBoardBlock$1.class */
|
|
public class RunnableC00141 implements Runnable {
|
|
final /* synthetic */ BlockPos val$pos;
|
|
|
|
RunnableC00141(BlockPos blockPos, BlockPos val$pos) {
|
|
this.val$pos = val$pos;
|
|
BlockPos pos = blockPos;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ChessScreen screen = new ChessScreen(val$pos);
|
|
Minecraft.getInstance().setScreen(screen);
|
|
}
|
|
}
|
|
|
|
public InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos pos, Player p_225533_4_, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
|
|
if (p_225533_2_.isClientSide) {
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> {
|
|
return new Runnable() { // from class: com.dairymoose.modernlife.blocks.ChessBoardBlock.1
|
|
final /* synthetic */ BlockPos val$pos = null;
|
|
|
|
void RunnableC00141(BlockPos pos2) {
|
|
pos = pos2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ChessScreen screen = new ChessScreen(pos);
|
|
Minecraft.getInstance().setScreen(screen);
|
|
}
|
|
};
|
|
});
|
|
}
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
|
|
return 20;
|
|
}
|
|
|
|
public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
|
|
return 5;
|
|
}
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
ChessBoardBlockEntity toReturn = (ChessBoardBlockEntity) ChessBoardBlockEntity.CHESS_BOARD.create(pos, state);
|
|
return toReturn;
|
|
}
|
|
|
|
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 ChessBoardBlockEntity) {
|
|
ChessBoardBlockEntity tile = (ChessBoardBlockEntity) e;
|
|
tile.setItem(0, itemStack.copy());
|
|
}
|
|
}
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
|
|
if (itemStack.getTag() != null && itemStack.getTag().contains("BoardState")) {
|
|
CompoundTag boardState = itemStack.getTag().getCompound("BoardState");
|
|
int currentTurn = boardState.getInt("CurrentTurn");
|
|
String whitePlayer = boardState.getString("WhitePlayer");
|
|
String blackPlayer = boardState.getString("BlackPlayer");
|
|
int newCheckState = boardState.getInt("NewCheckState");
|
|
boolean gameOver = false;
|
|
if (newCheckState == CheckState.BLACK_CHECKMATE.ordinal()) {
|
|
gameOver = true;
|
|
list.add(new TextComponent("White won the game!"));
|
|
} else if (newCheckState == CheckState.WHITE_CHECKMATE.ordinal()) {
|
|
gameOver = true;
|
|
list.add(new TextComponent("Black won the game!"));
|
|
} else {
|
|
list.add(new TextComponent("Game in progress..."));
|
|
}
|
|
list.add(new TextComponent(""));
|
|
list.add(new TextComponent("Turn counter: " + currentTurn));
|
|
list.add(new TextComponent("White player: " + whitePlayer));
|
|
list.add(new TextComponent("Black player: " + blackPlayer));
|
|
if (!gameOver) {
|
|
boolean isWhiteTurn = boardState.getBoolean("IsWhiteTurn");
|
|
if (isWhiteTurn) {
|
|
list.add(new TextComponent("White's turn"));
|
|
return;
|
|
} else {
|
|
list.add(new TextComponent("Black's turn"));
|
|
return;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
list.add(new TextComponent("Place it down and begin a new game!"));
|
|
}
|
|
|
|
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 = p_196243_2_.getBlockEntity(p_196243_3_);
|
|
if (blockEntity instanceof Container) {
|
|
if (p_196243_2_.isClientSide) {
|
|
DistExecutor.runWhenOn(Dist.CLIENT, () -> {
|
|
return new Runnable() { // from class: com.dairymoose.modernlife.blocks.ChessBoardBlock.2
|
|
final /* synthetic */ BlockPos val$p_196243_3_;
|
|
|
|
RunnableC00152(BlockPos p_196243_3_2) {
|
|
p_196243_3_ = p_196243_3_2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ChessBoardBlockEntityRenderer.stateMap.remove(p_196243_3_);
|
|
}
|
|
};
|
|
});
|
|
}
|
|
Containers.dropContents(p_196243_2_, p_196243_3_2, blockEntity);
|
|
p_196243_2_.updateNeighbourForOutputSignal(p_196243_3_2, this);
|
|
}
|
|
super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_2, p_196243_4_, p_196243_5_);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: com.dairymoose.modernlife.blocks.ChessBoardBlock$2 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ChessBoardBlock$2.class */
|
|
public class RunnableC00152 implements Runnable {
|
|
final /* synthetic */ BlockPos val$p_196243_3_;
|
|
|
|
RunnableC00152(BlockPos p_196243_3_2) {
|
|
p_196243_3_ = p_196243_3_2;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ChessBoardBlockEntityRenderer.stateMap.remove(p_196243_3_);
|
|
}
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState p_220053_1_, BlockGetter p_220053_2_, BlockPos p_220053_3_, CollisionContext p_220053_4_) {
|
|
return SHAPE;
|
|
}
|
|
}
|