2018-12-22 14:57:19 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityEndFlower;
|
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-23 16:05:52 +01:00
|
|
|
import net.minecraft.block.*;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2020-01-29 01:34:58 +01:00
|
|
|
import net.minecraft.client.renderer.RenderType;
|
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;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.fluid.FluidState;
|
2018-12-22 14:57:19 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.loot.LootContext;
|
|
|
|
import net.minecraft.loot.LootParameters;
|
2018-12-22 14:57:19 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2020-01-24 17:05:41 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2018-12-22 14:57:19 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-01-23 16:05:52 +01:00
|
|
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3d;
|
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;
|
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
|
|
|
|
2020-01-29 01:34:58 +01:00
|
|
|
public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
|
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-10-17 21:13:45 +02:00
|
|
|
super(Properties.create(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) {
|
2020-09-22 03:17:02 +02:00
|
|
|
Vector3d vec3d = state.getOffset(worldIn, pos);
|
2020-01-23 16:05:52 +01:00
|
|
|
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;
|
2020-01-30 13:45:19 +01:00
|
|
|
BlockPos pos = new BlockPos(x, dragon.world.getHeight(Heightmap.Type.WORLD_SURFACE, 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
|
2020-09-22 03:17:02 +02:00
|
|
|
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState 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
|
|
|
}
|
2020-01-24 17:05:41 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
|
|
|
TileEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
|
|
|
|
if (tile instanceof TileEntityEndFlower && ((TileEntityEndFlower) tile).isDrainMode)
|
|
|
|
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() {
|
2020-09-22 03:17:02 +02:00
|
|
|
return RenderType::getCutout;
|
2020-01-29 01:34:58 +01:00
|
|
|
}
|
2018-12-22 14:57:19 +01:00
|
|
|
}
|