136 lines
7.2 KiB
Java
136 lines
7.2 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.tileentities.ExtractorBlockEntity;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import java.util.List;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.Containers;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.TooltipFlag;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
import net.minecraft.world.level.block.HopperBlock;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
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.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.material.Material;
|
|
import net.minecraft.world.level.material.MaterialColor;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ExtractorBlock.class */
|
|
public class ExtractorBlock extends HopperBlock implements EntityBlock {
|
|
protected static final VoxelShape SHAPE_NORTH = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(1.0d, 0.0d, -1.0d, 15.0d, 14.0d, 3.0d), Block.box(3.0d, 2.0d, 8.0d, 13.0d, 12.0d, 9.0d), Block.box(7.0d, 13.975d, -4.0d, 9.0d, 14.975d, 1.0d), Block.box(7.0d, -0.975d, -4.0d, 9.0d, 0.025d, 1.0d), Block.box(0.025d, 6.0d, -4.0d, 1.025d, 8.0d, 1.0d), Block.box(14.975d, 6.0d, -4.0d, 15.975d, 8.0d, 1.0d), Block.box(4.0d, 3.0d, 9.0d, 12.0d, 11.0d, 16.0d), Block.box(2.0d, 2.0d, -0.95d, 3.0d, 13.0d, 9.0d), Block.box(13.0d, 2.0d, -0.95d, 14.0d, 13.0d, 9.0d), Block.box(3.0d, 12.0d, -0.95d, 13.0d, 13.0d, 9.0d), Block.box(2.0d, 1.0d, -0.95d, 14.0d, 2.0d, 9.0d)}).reduce((v1, v2) -> {
|
|
return Shapes.join((VoxelShape) v1, (VoxelShape) v2, BooleanOp.OR);
|
|
}).get();
|
|
protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH);
|
|
protected static final VoxelShape SHAPE_SOUTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_EAST);
|
|
protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);
|
|
|
|
public ExtractorBlock() {
|
|
super(Properties.of(Material.METAL, MaterialColor.STONE).requiresCorrectToolForDrops().strength(3.0f, 4.8f).sound(SoundType.METAL).noOcclusion());
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(HopperBlock.FACING, Direction.NORTH)).setValue(HopperBlock.ENABLED, true));
|
|
}
|
|
|
|
public ExtractorBlock(Properties props) {
|
|
super(props);
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(HopperBlock.FACING, Direction.NORTH)).setValue(HopperBlock.ENABLED, true));
|
|
}
|
|
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
|
return ModernLifeUtil.createTickerHelper(type, ExtractorBlockEntity.EXTRACTOR, ExtractorBlockEntity::tick);
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
|
|
list.add(new TextComponent("Extracts items from attached chests or from the space in front of it"));
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState p_220053_1_, BlockGetter p_220053_2_, BlockPos p_220053_3_, CollisionContext p_220053_4_) {
|
|
switch (p_220053_1_.getValue(HopperBlock.FACING).ordinal()) {
|
|
case 1:
|
|
return SHAPE_NORTH;
|
|
case 2:
|
|
return SHAPE_NORTH;
|
|
case 3:
|
|
return SHAPE_SOUTH;
|
|
case 4:
|
|
return SHAPE_WEST;
|
|
case 5:
|
|
return SHAPE_EAST;
|
|
default:
|
|
return SHAPE_NORTH;
|
|
}
|
|
}
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
return ExtractorBlockEntity.EXTRACTOR.create(pos, state);
|
|
}
|
|
|
|
public void setPlacedBy(Level p_180633_1_, BlockPos p_180633_2_, BlockState p_180633_3_, LivingEntity p_180633_4_, ItemStack p_180633_5_) {
|
|
if (p_180633_5_.hasCustomHoverName()) {
|
|
ExtractorBlockEntity blockEntity = (ExtractorBlockEntity) p_180633_1_.getBlockEntity(p_180633_2_);
|
|
if (blockEntity instanceof ExtractorBlockEntity) {
|
|
blockEntity.setCustomName(p_180633_5_.getHoverName());
|
|
}
|
|
}
|
|
}
|
|
|
|
public void onRemove(BlockState p_196243_1_, Level p_196243_2_, BlockPos p_196243_3_, BlockState p_196243_4_, boolean p_196243_5_) {
|
|
if (!p_196243_1_.is(p_196243_4_.getBlock())) {
|
|
ExtractorBlockEntity blockEntity = (ExtractorBlockEntity) p_196243_2_.getBlockEntity(p_196243_3_);
|
|
if (blockEntity instanceof ExtractorBlockEntity) {
|
|
Containers.dropContents(p_196243_2_, p_196243_3_, blockEntity);
|
|
p_196243_2_.updateNeighbourForOutputSignal(p_196243_3_, this);
|
|
}
|
|
super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_, p_196243_4_, p_196243_5_);
|
|
}
|
|
}
|
|
|
|
public void entityInside(BlockState p_196262_1_, Level p_196262_2_, BlockPos p_196262_3_, Entity p_196262_4_) {
|
|
ExtractorBlockEntity blockEntity = (ExtractorBlockEntity) p_196262_2_.getBlockEntity(p_196262_3_);
|
|
if (blockEntity instanceof ExtractorBlockEntity) {
|
|
blockEntity.entityInside(p_196262_4_);
|
|
}
|
|
}
|
|
|
|
public InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos p_225533_3_, Player p_225533_4_, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
|
|
if (p_225533_2_.isClientSide) {
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
ExtractorBlockEntity blockEntity = (ExtractorBlockEntity) p_225533_2_.getBlockEntity(p_225533_3_);
|
|
if (blockEntity instanceof ExtractorBlockEntity) {
|
|
p_225533_4_.openMenu(blockEntity);
|
|
p_225533_4_.awardStat(Stats.INSPECT_HOPPER);
|
|
}
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext p_196258_1_) {
|
|
Direction direction = p_196258_1_.getHorizontalDirection();
|
|
return (BlockState) ((BlockState) defaultBlockState().setValue(HopperBlock.FACING, direction)).setValue(HopperBlock.ENABLED, true);
|
|
}
|
|
}
|