129 lines
5.2 KiB
Java
129 lines
5.2 KiB
Java
package org.betterx.betterend.blocks;
|
|
|
|
import org.betterx.bclib.blocks.BaseAttachedBlock;
|
|
import org.betterx.bclib.client.render.BCLRenderLayer;
|
|
import org.betterx.bclib.interfaces.RenderLayerProvider;
|
|
import org.betterx.bclib.items.tool.BaseShearsItem;
|
|
import org.betterx.bclib.util.BlocksHelper;
|
|
import org.betterx.betterend.interfaces.PottablePlant;
|
|
import org.betterx.betterend.registry.EndFeatures;
|
|
import org.betterx.worlds.together.tag.v3.CommonBlockTags;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
|
import net.minecraft.world.item.enchantment.Enchantments;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.BonemealableBlock;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
|
|
|
|
import net.minecraft.world.level.storage.loot.LootParams;
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
|
|
import java.util.EnumMap;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
public class SmallJellyshroomBlock extends BaseAttachedBlock implements RenderLayerProvider, BonemealableBlock, PottablePlant {
|
|
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
|
|
|
|
public SmallJellyshroomBlock() {
|
|
super(FabricBlockSettings.of(Material.PLANT).sound(SoundType.NETHER_WART).noCollission());
|
|
}
|
|
|
|
@Override
|
|
@SuppressWarnings("deprecation")
|
|
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
|
return BOUNDING_SHAPES.get(state.getValue(FACING));
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
|
|
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
|
|
if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
|
|
Enchantments.SILK_TOUCH,
|
|
tool
|
|
) > 0) {
|
|
return Lists.newArrayList(new ItemStack(this));
|
|
} else {
|
|
return Lists.newArrayList();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
|
Direction direction = state.getValue(FACING);
|
|
BlockPos blockPos = pos.relative(direction.getOpposite());
|
|
BlockState support = world.getBlockState(blockPos);
|
|
return canSupportCenter(world, blockPos, direction) && support.canOcclude() && support.getLightEmission() == 0;
|
|
}
|
|
|
|
@Override
|
|
public BCLRenderLayer getRenderLayer() {
|
|
return BCLRenderLayer.CUTOUT;
|
|
}
|
|
|
|
static {
|
|
BOUNDING_SHAPES.put(Direction.UP, Block.box(3, 0, 3, 13, 16, 13));
|
|
BOUNDING_SHAPES.put(Direction.DOWN, Block.box(3, 0, 3, 13, 16, 13));
|
|
BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0));
|
|
BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5));
|
|
BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0));
|
|
BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0));
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(LevelReader world, BlockPos pos, BlockState state, boolean isClient) {
|
|
return state.getValue(FACING) == Direction.UP && world.getBlockState(pos.below())
|
|
.is(CommonBlockTags.END_STONES);
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(Level world, RandomSource random, BlockPos pos, BlockState state) {
|
|
return random.nextInt(16) == 0;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(ServerLevel world, RandomSource random, BlockPos pos, BlockState state) {
|
|
BlocksHelper.setWithUpdate(world, pos, Blocks.AIR);
|
|
EndFeatures.JELLYSHROOM.getFeature()
|
|
.place(new FeaturePlaceContext<net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration>(
|
|
Optional.empty(),
|
|
world,
|
|
null,
|
|
random,
|
|
pos,
|
|
null
|
|
));
|
|
}
|
|
|
|
@Override
|
|
public boolean canPlantOn(Block block) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
@Environment(EnvType.CLIENT)
|
|
public String getPottedState() {
|
|
return "facing=up";
|
|
}
|
|
}
|