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

95 lines
3.8 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;
2024-03-02 21:23:08 +01:00
import com.mojang.blaze3d.platform.Window;
2021-03-01 20:14:50 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityVerticalDigger;
import net.minecraft.client.Minecraft;
2024-03-03 01:20:53 +01:00
import net.minecraft.client.gui.GuiGraphics;
2024-03-02 21:23:08 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
2024-03-04 20:21:48 +01:00
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
2024-03-02 21:23:08 +01:00
import javax.annotation.Nullable;
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() {
2024-03-02 21:23:08 +01:00
super(ActuallyBlocks.defaultPickProps(8F, 30F));
}
@Override
2024-03-02 21:23:08 +01:00
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
2021-11-13 18:02:42 +01:00
return this.openGui(worldIn, player, pos, TileEntityVerticalDigger.class);
2015-12-19 10:30:39 +01:00
}
2024-03-02 21:23:08 +01:00
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileEntityVerticalDigger(pos, state);
}
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
return level.isClientSide? TileEntityVerticalDigger::clientTick : TileEntityVerticalDigger::serverTick;
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2024-03-03 01:20:53 +01:00
public void displayHud(GuiGraphics guiGraphics, Minecraft minecraft, Player player, ItemStack stack, HitResult rayCast, Window resolution) {
2024-03-02 21:23:08 +01:00
if (!(rayCast instanceof BlockHitResult)) {
2021-03-01 20:14:50 +01:00
return;
}
2024-03-02 21:23:08 +01:00
BlockEntity tile = minecraft.level.getBlockEntity(((BlockHitResult) rayCast).getBlockPos());
2024-03-03 01:20:53 +01:00
if (tile instanceof TileEntityVerticalDigger miner) {
String info = miner.checkY == 0
2021-02-26 22:15:48 +01:00
? "Done Mining!"
: miner.checkY == -1
2021-11-13 18:02:42 +01:00
? "Calculating positions..."
: "Mining at " + (miner.getBlockPos().getX() + miner.checkX) + ", " + miner.checkY + ", " + (miner.getBlockPos().getZ() + miner.checkZ) + ".";
2024-03-03 01:20:53 +01:00
guiGraphics.drawString(minecraft.font, info, (int) (resolution.getGuiScaledWidth() / 2f + 5), (int) (resolution.getGuiScaledHeight() / 2f - 20), 0xFFFFFF);
2021-03-01 20:14:50 +01:00
}
}
@Override
2024-03-02 21:23:08 +01:00
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
switch (state.getValue(FACING)) {
2021-03-01 20:14:50 +01:00
case NORTH:
2024-03-02 21:23:08 +01:00
return VoxelShapes.MinerShapes.SHAPE_N;
2021-03-01 20:14:50 +01:00
case EAST:
2024-03-02 21:23:08 +01:00
return VoxelShapes.MinerShapes.SHAPE_E;
2021-03-01 20:14:50 +01:00
case SOUTH:
2024-03-02 21:23:08 +01:00
return VoxelShapes.MinerShapes.SHAPE_S;
2021-03-01 20:14:50 +01:00
case WEST:
2024-03-02 21:23:08 +01:00
return VoxelShapes.MinerShapes.SHAPE_W;
2021-03-01 20:14:50 +01:00
default:
2024-03-02 21:23:08 +01:00
return VoxelShapes.MinerShapes.SHAPE_N;
}
}
2021-02-26 22:15:48 +01:00
}