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;
|
2021-12-19 15:32:45 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity;
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
|
2020-02-25 15:14:56 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
2023-02-15 23:52:52 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModItem;
|
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2021-12-05 23:32:31 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
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;
|
2021-12-19 15:32:45 +01:00
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
2021-12-05 23:32:31 +01:00
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2021-12-19 15:32:45 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
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
|
|
|
|
2022-08-01 16:14:37 +02:00
|
|
|
public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, 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) {
|
2023-07-08 12:32:27 +02:00
|
|
|
super(Properties.of().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;
|
2022-06-27 15:24:04 +02:00
|
|
|
ModRegistry.ALL_ITEMS.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) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var down = pos.below();
|
2021-12-05 23:32:31 +01:00
|
|
|
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
|
2023-02-15 23:45:50 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
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)
|
2023-07-08 12:32:27 +02:00
|
|
|
entityIn.hurt(entityIn.damageSources().cactus(), 1);
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-15 23:45:50 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2021-12-05 23:32:31 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var vec3d = state.getOffset(levelIn, pos);
|
2022-06-27 15:24:04 +02:00
|
|
|
return BlockAuraBloom.SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
2022-08-01 16:14:37 +02:00
|
|
|
generator.simpleBlock(this, generator.models().cross(this.getBaseName(), generator.modLoc("block/" + this.getBaseName())).renderType("cutout"));
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomItemModel(ItemModelGenerator generator) {
|
|
|
|
generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-15 16:24:53 +01:00
|
|
|
return new BlockEntityAuraBloom(pos, state);
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|
2021-12-19 15:32:45 +01:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
|
|
|
return ITickableBlockEntity.createTickerHelper(type, ModBlockEntities.AURA_BLOOM);
|
|
|
|
}
|
2020-02-25 15:14:56 +01:00
|
|
|
}
|