2015-12-06 02:16:52 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockMiner.java") is part of the Actually Additions mod for Minecraft.
|
2015-12-06 02:16:52 +01:00
|
|
|
* 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
|
2015-12-06 02:16:52 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-12-06 02:16:52 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-12-06 02:16:52 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.platform.Window;
|
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
2021-03-01 20:14:50 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
|
2021-08-22 21:09:15 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityVerticalDigger;
|
2015-12-21 22:18:33 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
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;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2021-03-01 20:14:50 +01:00
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2021-03-01 18:11:34 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2015-12-06 02:16:52 +01:00
|
|
|
|
2021-05-05 18:15:25 +02:00
|
|
|
public class BlockVerticalDigger extends DirectionalBlock.Container implements IHudDisplay {
|
2015-12-06 02:16:52 +01:00
|
|
|
|
2021-05-05 18:15:25 +02:00
|
|
|
public BlockVerticalDigger() {
|
2024-03-02 21:23:08 +01:00
|
|
|
super(ActuallyBlocks.defaultPickProps(8F, 30F));
|
2015-12-06 02:16:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
2015-12-06 02:16:52 +01:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2024-03-02 21:23:08 +01:00
|
|
|
public void displayHud(PoseStack matrices, Minecraft minecraft, Player player, ItemStack stack, HitResult rayCast, Window resolution) {
|
|
|
|
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());
|
2021-11-13 18:02:42 +01:00
|
|
|
if (tile instanceof TileEntityVerticalDigger) {
|
|
|
|
TileEntityVerticalDigger miner = (TileEntityVerticalDigger) tile;
|
2021-02-26 22:15:48 +01:00
|
|
|
String info = miner.checkY == 0
|
|
|
|
? "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) + ".";
|
2022-06-05 23:02:36 +02:00
|
|
|
minecraft.font.drawShadow(matrices, info, resolution.getGuiScaledWidth() / 2f + 5, 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) {
|
2021-08-22 17:09:06 +02:00
|
|
|
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;
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-26 22:15:48 +01:00
|
|
|
}
|