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

89 lines
3.9 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockLavaFactoryController.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02: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-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2015-06-06 01:25:53 +02:00
2024-03-02 21:23:08 +01:00
import com.mojang.blaze3d.platform.Window;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
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.TileEntityLavaFactoryController;
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.network.chat.Component;
2024-03-02 21:23:08 +01:00
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;
2015-06-06 01:25:53 +02:00
2021-03-01 20:14:50 +01:00
public class BlockLavaFactoryController extends DirectionalBlock.Container implements IHudDisplay {
2015-06-06 01:25:53 +02:00
public BlockLavaFactoryController() {
2024-03-02 21:23:08 +01:00
super(ActuallyBlocks.defaultPickProps(4.5F, 20.0F));
2015-06-06 01:25:53 +02:00
}
2024-03-02 21:23:08 +01:00
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileEntityLavaFactoryController(pos, state);
}
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> entityType) {
return level.isClientSide? TileEntityLavaFactoryController::clientTick : TileEntityLavaFactoryController::serverTick;
2015-06-06 01:25:53 +02:00
}
@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
TileEntityLavaFactoryController factory = (TileEntityLavaFactoryController) minecraft.level.getBlockEntity(((BlockHitResult) rayCast).getBlockPos());
2019-05-02 09:10:29 +02:00
if (factory != null) {
int state = factory.isMultiblock();
2019-05-02 09:10:29 +02:00
if (state == TileEntityLavaFactoryController.NOT_MULTI) {
guiGraphics.drawWordWrap(minecraft.font, Component.translatable("tooltip." + ActuallyAdditions.MODID + ".factory.notPart.desc"), resolution.getGuiScaledWidth() / 2 + 5, resolution.getGuiScaledHeight() / 2 + 5, 200, 0xFFFFFF);
2019-05-02 09:10:29 +02:00
} else if (state == TileEntityLavaFactoryController.HAS_AIR || state == TileEntityLavaFactoryController.HAS_LAVA) {
guiGraphics.drawWordWrap(minecraft.font, Component.translatable("tooltip." + ActuallyAdditions.MODID + ".factory.working.desc"), resolution.getGuiScaledWidth() / 2 + 5, resolution.getGuiScaledHeight() / 2 + 5, 200, 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 EAST:
2024-03-02 21:23:08 +01:00
return VoxelShapes.LavaFactoryShapes.SHAPE_E;
2021-03-01 20:14:50 +01:00
case SOUTH:
2024-03-02 21:23:08 +01:00
return VoxelShapes.LavaFactoryShapes.SHAPE_S;
2021-03-01 20:14:50 +01:00
case WEST:
2024-03-02 21:23:08 +01:00
return VoxelShapes.LavaFactoryShapes.SHAPE_W;
2021-03-01 20:14:50 +01:00
default:
2024-03-02 21:23:08 +01:00
return VoxelShapes.LavaFactoryShapes.SHAPE_N;
2021-03-01 20:14:50 +01:00
}
}
2015-06-06 01:25:53 +02:00
}