ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java

87 lines
3.6 KiB
Java
Raw Normal View History

2016-06-05 04:05:37 +02:00
/*
* This file ("BlockPlayerInterface.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-06-05 04:05:37 +02:00
*/
package de.ellpeck.actuallyadditions.mod.blocks;
2021-02-27 21:24:26 +01:00
import com.mojang.blaze3d.matrix.MatrixStack;
2016-06-05 04:05:37 +02:00
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2021-03-01 20:14:50 +01:00
import net.minecraft.block.BlockState;
2021-02-27 17:22:03 +01:00
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
2021-03-01 20:14:50 +01:00
import net.minecraft.entity.LivingEntity;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
2016-06-05 04:05:37 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.TextFormatting;
2021-03-01 20:14:50 +01:00
import net.minecraft.world.IBlockReader;
2016-06-05 04:05:37 +02:00
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
2021-03-01 20:14:50 +01:00
import net.minecraftforge.api.distmarker.OnlyIn;
2016-06-05 04:05:37 +02:00
2019-05-02 09:10:29 +02:00
public class BlockPlayerInterface extends BlockContainerBase implements IHudDisplay {
public BlockPlayerInterface() {
2021-03-01 20:14:50 +01:00
super(ActuallyBlocks.defaultPickProps(0, 4.5F, 10.0F));
2016-06-05 04:05:37 +02:00
}
//@Override
public TileEntity newBlockEntity(IBlockReader worldIn) {
2016-06-05 04:05:37 +02:00
return new TileEntityPlayerInterface();
}
@Override
public void setPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity player, ItemStack stack) {
TileEntity tile = world.getBlockEntity(pos);
2019-05-02 09:10:29 +02:00
if (tile instanceof TileEntityPlayerInterface) {
TileEntityPlayerInterface face = (TileEntityPlayerInterface) tile;
if (face.connectedPlayer == null) {
face.connectedPlayer = player.getUUID();
2021-03-01 20:14:50 +01:00
face.playerName = player.getName().getString();
face.setChanged();
face.sendUpdate();
2016-06-05 04:05:37 +02:00
}
}
super.setPlacedBy(world, pos, state, player, stack);
2016-06-05 04:05:37 +02:00
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2021-02-27 21:24:26 +01:00
public void displayHud(MatrixStack matrices, Minecraft minecraft, PlayerEntity player, ItemStack stack, RayTraceResult rayCast, MainWindow resolution) {
2021-03-01 20:14:50 +01:00
if (!(rayCast instanceof BlockRayTraceResult)) {
return;
}
TileEntity tile = minecraft.level.getBlockEntity(((BlockRayTraceResult) rayCast).getBlockPos());
2019-05-02 09:10:29 +02:00
if (tile != null) {
if (tile instanceof TileEntityPlayerInterface) {
TileEntityPlayerInterface face = (TileEntityPlayerInterface) tile;
String name = face.playerName == null
? "Unknown"
: face.playerName;
minecraft.font.drawShadow(matrices, "Bound to: " + TextFormatting.RED + name, resolution.getGuiScaledWidth() / 2f + 5, resolution.getGuiScaledHeight() / 2f + 5, StringUtil.DECIMAL_COLOR_WHITE);
minecraft.font.drawShadow(matrices, "UUID: " + TextFormatting.DARK_GREEN + face.connectedPlayer, resolution.getGuiScaledWidth() / 2f + 5, resolution.getGuiScaledHeight() / 2f + 15, StringUtil.DECIMAL_COLOR_WHITE);
}
}
}
2021-03-01 20:14:50 +01:00
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return Shapes.PLAYER_INTERFACE_SHAPE;
}
2016-06-05 04:05:37 +02:00
}