2020-02-25 15:14:56 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
|
2020-02-25 15:14:56 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.*;
|
|
|
|
import net.minecraft.client.renderer.RenderType;
|
2021-12-05 23:32:31 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
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.BushBlock;
|
|
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
|
|
import net.minecraft.world.level.block.SoundType;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2020-02-25 15:14:56 +01:00
|
|
|
|
2020-10-19 03:05:13 +02:00
|
|
|
import java.util.Arrays;
|
2020-02-25 15:14:56 +01:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2021-12-05 23:32:31 +01:00
|
|
|
public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType, EntityBlock {
|
2020-02-25 15:14:56 +01:00
|
|
|
|
2021-12-05 23:32:31 +01:00
|
|
|
protected static final VoxelShape SHAPE = Block.box(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
|
2020-02-25 15:56:46 +01:00
|
|
|
private final String baseName;
|
2020-10-19 03:05:13 +02:00
|
|
|
private final Block[] allowedGround;
|
2020-02-25 15:14:56 +01:00
|
|
|
|
2020-10-19 03:05:13 +02:00
|
|
|
public BlockAuraBloom(String baseName, Block... allowedGround) {
|
2021-12-05 23:32:31 +01:00
|
|
|
super(Properties.of(Material.PLANT).noCollission().strength(0).sound(SoundType.GRASS));
|
2020-02-25 15:56:46 +01:00
|
|
|
this.baseName = baseName;
|
2020-10-19 03:05:13 +02:00
|
|
|
this.allowedGround = allowedGround;
|
2020-02-25 15:14:56 +01:00
|
|
|
ModRegistry.add(this);
|
2020-02-25 15:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
|
|
|
|
BlockPos down = pos.below();
|
|
|
|
return this.mayPlaceOn(levelIn.getBlockState(down), levelIn, down);
|
2020-10-19 03:05:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
protected boolean mayPlaceOn(BlockState state, BlockGetter levelIn, BlockPos pos) {
|
|
|
|
return Arrays.stream(this.allowedGround).anyMatch(state::is);
|
2020-02-25 15:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
public void entityInside(BlockState state, Level levelIn, BlockPos pos, Entity entityIn) {
|
2020-02-25 15:56:46 +01:00
|
|
|
if (this == ModBlocks.AURA_CACTUS)
|
2021-12-05 23:32:31 +01:00
|
|
|
entityIn.hurt(DamageSource.CACTUS, 1);
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
|
|
|
Vec3 vec3d = state.getOffset(levelIn, pos);
|
|
|
|
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
generator.simpleBlock(this, generator.models().cross(this.getBaseName(), generator.modLoc("block/" + this.getBaseName())));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomItemModel(ItemModelGenerator generator) {
|
|
|
|
generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Supplier<RenderType> getRenderType() {
|
2021-12-05 23:32:31 +01:00
|
|
|
return RenderType::cutout;
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
2020-02-25 15:56:46 +01:00
|
|
|
return this.baseName;
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:32:31 +01:00
|
|
|
@org.jetbrains.annotations.Nullable
|
2020-02-25 15:14:56 +01:00
|
|
|
@Override
|
2021-12-05 23:32:31 +01:00
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
2021-12-04 15:40:09 +01:00
|
|
|
return new BlockEntityAuraBloom();
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
}
|