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

86 lines
3.4 KiB
Java
Raw Normal View History

/*
2016-05-16 22:52:27 +02:00
* This file ("BlockMiner.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
2016-05-16 22:52:27 +02:00
* 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-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2021-02-27 21:24:26 +01:00
import com.mojang.blaze3d.matrix.MatrixStack;
2021-03-01 20:14:50 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityMiner;
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-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.ActionResultType;
2021-02-26 22:15:48 +01:00
import net.minecraft.util.Hand;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
2021-03-01 20:14:50 +01:00
import net.minecraft.util.math.BlockRayTraceResult;
2016-03-18 23:47:22 +01:00
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.world.IBlockReader;
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;
2021-05-05 18:15:25 +02:00
public class BlockVerticalDigger extends DirectionalBlock.Container implements IHudDisplay {
2021-05-05 18:15:25 +02:00
public BlockVerticalDigger() {
2021-03-01 20:14:50 +01:00
super(ActuallyBlocks.defaultPickProps(0, 8F, 30F));
}
@Override
public ActionResultType use(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
2021-03-01 20:14:50 +01:00
return this.openGui(worldIn, player, pos, TileEntityMiner.class);
2015-12-19 10:30:39 +01:00
}
@Override
public TileEntity newBlockEntity(IBlockReader world) {
return new TileEntityMiner();
}
@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 instanceof TileEntityMiner) {
TileEntityMiner miner = (TileEntityMiner) tile;
2021-02-26 22:15:48 +01:00
String info = miner.checkY == 0
? "Done Mining!"
: miner.checkY == -1
? "Calculating positions..."
: "Mining at " + (miner.getBlockPos().getX() + miner.checkX) + ", " + miner.checkY + ", " + (miner.getBlockPos().getZ() + miner.checkZ) + ".";
minecraft.font.drawShadow(matrices, info, resolution.getGuiScaledWidth() / 2f + 5, resolution.getGuiScaledHeight() / 2f - 20, StringUtil.DECIMAL_COLOR_WHITE);
2021-03-01 20:14:50 +01:00
}
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch (state.getValue(FACING)) {
2021-03-01 20:14:50 +01:00
case NORTH:
return Shapes.MinerShapes.SHAPE_N;
case EAST:
return Shapes.MinerShapes.SHAPE_E;
case SOUTH:
return Shapes.MinerShapes.SHAPE_S;
case WEST:
return Shapes.MinerShapes.SHAPE_W;
default:
return Shapes.MinerShapes.SHAPE_N;
}
}
2021-02-26 22:15:48 +01:00
}