2018-12-22 14:57:19 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.*;
|
2020-01-29 01:34:58 +01:00
|
|
|
import net.minecraft.client.renderer.RenderType;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.NonNullList;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
|
|
|
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.LevelReader;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
|
|
|
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.levelgen.Heightmap;
|
|
|
|
import net.minecraft.world.level.material.FluidState;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.level.storage.loot.LootContext;
|
|
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2018-12-22 14:57:19 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-12-22 14:57:19 +01:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
2020-01-24 17:05:41 +01:00
|
|
|
import java.util.List;
|
2020-01-29 01:34:58 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-12-22 14:57:19 +01:00
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType, EntityBlock {
|
2018-12-22 14:57:19 +01:00
|
|
|
|
2021-12-15 14:26:42 +01:00
|
|
|
protected static final VoxelShape SHAPE = box(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
|
2020-01-23 16:05:52 +01:00
|
|
|
|
2018-12-22 14:57:19 +01:00
|
|
|
public BlockEndFlower() {
|
2021-12-15 14:26:42 +01:00
|
|
|
super(Properties.of(Material.GRASS).noCollission().strength(0.5F).sound(SoundType.GRASS));
|
2018-12-22 14:57:19 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
ModRegistry.add(this);
|
2021-12-04 15:40:09 +01:00
|
|
|
ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this));
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 16:05:52 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +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-01-23 16:05:52 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 14:57:19 +01:00
|
|
|
@SubscribeEvent
|
2019-11-04 19:08:49 +01:00
|
|
|
public void onDragonTick(LivingUpdateEvent event) {
|
2019-10-20 22:30:49 +02:00
|
|
|
LivingEntity living = event.getEntityLiving();
|
2021-12-15 14:26:42 +01:00
|
|
|
if (living.level.isClientSide || !(living instanceof EnderDragon dragon))
|
2018-12-22 14:57:19 +01:00
|
|
|
return;
|
2021-12-15 14:26:42 +01:00
|
|
|
if (dragon.deathTime < 150 || dragon.deathTime % 10 != 0)
|
2018-12-22 14:57:19 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
2021-12-15 14:26:42 +01:00
|
|
|
int x = dragon.level.random.nextInt(256) - 128;
|
|
|
|
int z = dragon.level.random.nextInt(256) - 128;
|
|
|
|
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
|
|
|
|
if (!dragon.level.isLoaded(pos))
|
2018-12-22 14:57:19 +01:00
|
|
|
continue;
|
2021-12-15 14:26:42 +01:00
|
|
|
if (dragon.level.getBlockState(pos.below()).getBlock() != Blocks.END_STONE)
|
2018-12-22 14:57:19 +01:00
|
|
|
continue;
|
2021-12-15 14:26:42 +01:00
|
|
|
dragon.level.setBlockAndUpdate(pos, this.defaultBlockState());
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
|
|
|
|
return levelIn.getBlockState(pos.below()).getBlock() == Blocks.END_STONE;
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-23 16:05:52 +01:00
|
|
|
public String getBaseName() {
|
|
|
|
return "end_flower";
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
|
|
return new BlockEntityEndFlower(pos, state);
|
2020-01-23 16:05:52 +01:00
|
|
|
}
|
|
|
|
|
2018-12-22 14:57:19 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
|
|
|
|
return willHarvest || super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public void playerDestroy(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
|
|
|
|
super.playerDestroy(levelIn, player, pos, state, te, stack);
|
|
|
|
levelIn.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|
2020-01-24 17:05:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
2021-12-15 14:26:42 +01:00
|
|
|
BlockEntity tile = builder.getParameter(LootContextParams.BLOCK_ENTITY);
|
2021-12-04 15:40:09 +01:00
|
|
|
if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) tile).isDrainMode)
|
2020-01-24 17:05:41 +01:00
|
|
|
return NonNullList.create();
|
|
|
|
return super.getDrops(state, builder);
|
|
|
|
}
|
2020-01-29 00:40:28 +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());
|
|
|
|
}
|
2020-01-29 01:34:58 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Supplier<RenderType> getRenderType() {
|
2021-12-15 14:26:42 +01:00
|
|
|
return RenderType::cutout;
|
2020-01-29 01:34:58 +01:00
|
|
|
}
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|