NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockEndFlower.java

105 lines
4 KiB
Java
Raw Normal View History

2018-12-22 14:57:19 +01:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityEndFlower;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
2020-01-22 01:32:26 +01:00
import de.ellpeck.naturesaura.reg.ModTileType;
2020-01-23 16:05:52 +01:00
import net.minecraft.block.*;
2019-11-04 19:08:49 +01:00
import net.minecraft.block.material.Material;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.player.PlayerEntity;
2019-11-04 19:08:49 +01:00
import net.minecraft.fluid.IFluidState;
2018-12-22 14:57:19 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
2020-01-23 16:05:52 +01:00
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
2019-11-04 19:08:49 +01:00
import net.minecraft.world.IBlockReader;
2020-01-23 16:05:52 +01:00
import net.minecraft.world.IWorldReader;
2018-12-22 14:57:19 +01:00
import net.minecraft.world.World;
2019-11-04 19:08:49 +01:00
import net.minecraft.world.gen.Heightmap;
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;
2019-11-04 19:08:49 +01:00
public class BlockEndFlower extends BushBlock implements IModItem, IModelProvider {
2018-12-22 14:57:19 +01:00
2020-01-23 16:05:52 +01:00
protected static final VoxelShape SHAPE = Block.makeCuboidShape(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
2018-12-22 14:57:19 +01:00
public BlockEndFlower() {
2020-01-23 16:05:52 +01:00
super(ModBlocks.prop(Material.PLANTS).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(SoundType.PLANT));
2018-12-22 14:57:19 +01:00
MinecraftForge.EVENT_BUS.register(this);
ModRegistry.add(this);
2020-01-22 01:32:26 +01:00
ModRegistry.add(new ModTileType<>(TileEntityEndFlower::new, this));
2018-12-22 14:57:19 +01:00
}
2020-01-23 16:05:52 +01:00
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
Vec3d vec3d = state.getOffset(worldIn, pos);
return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z);
}
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();
if (living.world.isRemote || !(living instanceof EnderDragonEntity))
2018-12-22 14:57:19 +01:00
return;
2019-10-20 22:30:49 +02:00
EnderDragonEntity dragon = (EnderDragonEntity) living;
2018-12-22 14:57:19 +01:00
if (dragon.deathTicks < 150 || dragon.deathTicks % 10 != 0)
return;
for (int i = 0; i < 6; i++) {
int x = dragon.world.rand.nextInt(256) - 128;
int z = dragon.world.rand.nextInt(256) - 128;
2019-11-04 19:08:49 +01:00
BlockPos pos = new BlockPos(x, dragon.world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, x, z), z);
2018-12-22 14:57:19 +01:00
if (!dragon.world.isBlockLoaded(pos))
continue;
if (dragon.world.getBlockState(pos.down()).getBlock() != Blocks.END_STONE)
continue;
dragon.world.setBlockState(pos, this.getDefaultState());
}
}
@Override
2020-01-23 16:05:52 +01:00
protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
2018-12-22 14:57:19 +01:00
return state.getBlock() == Blocks.END_STONE;
}
@Override
2020-01-23 16:05:52 +01:00
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
return worldIn.getBlockState(pos.down()).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
2019-11-04 19:08:49 +01:00
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
2020-01-22 01:32:26 +01:00
return new TileEntityEndFlower();
2018-12-22 14:57:19 +01:00
}
2020-01-23 16:05:52 +01:00
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
2018-12-22 14:57:19 +01:00
@Override
2019-11-04 19:08:49 +01:00
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid) {
2020-01-23 16:05:52 +01:00
return willHarvest || super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
2018-12-22 14:57:19 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
2018-12-22 14:57:19 +01:00
super.harvestBlock(worldIn, player, pos, state, te, stack);
2019-11-04 19:08:49 +01:00
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
2018-12-22 14:57:19 +01:00
}
}