mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 03:39:17 +00:00
136 lines
4.8 KiB
Java
136 lines
4.8 KiB
Java
/**
|
|
* This class was created by <Vazkii>. It's distributed as
|
|
* part of the Botania Mod. Get the Source Code in github:
|
|
* https://github.com/Vazkii/Botania
|
|
*
|
|
* Botania is Open Source and distributed under the
|
|
* Botania License: http://botaniamod.net/license.php
|
|
*
|
|
* File Created @ [Nov 17, 2014, 5:31:53 PM (GMT)]
|
|
*/
|
|
package vazkii.botania.common.block;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.DyeColor;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.Hand;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
|
import net.minecraft.world.IBlockReader;
|
|
import net.minecraft.world.ILightReader;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.storage.loot.LootContext;
|
|
import net.minecraft.world.storage.loot.LootParameters;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
import vazkii.botania.api.subtile.TileEntitySpecialFlower;
|
|
import vazkii.botania.api.wand.IWandHUD;
|
|
import vazkii.botania.api.wand.IWandable;
|
|
import vazkii.botania.common.block.decor.BlockFloatingFlower;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import java.util.function.Supplier;
|
|
|
|
public class BlockFloatingSpecialFlower extends BlockFloatingFlower implements IWandable, IWandHUD {
|
|
private final Supplier<? extends TileEntitySpecialFlower> teProvider;
|
|
|
|
public BlockFloatingSpecialFlower(Properties props, Supplier<? extends TileEntitySpecialFlower> teProvider) {
|
|
super(DyeColor.WHITE, props);
|
|
this.teProvider = teProvider;
|
|
}
|
|
|
|
@Override
|
|
public int getLightValue(@Nonnull BlockState state, ILightReader world, @Nonnull BlockPos pos) {
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
return tile instanceof TileEntitySpecialFlower ? ((TileEntitySpecialFlower) tile).getLightValue() : lightValue;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasComparatorInputOverride(BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) {
|
|
return ((TileEntitySpecialFlower) world.getTileEntity(pos)).getComparatorInputOverride();
|
|
}
|
|
|
|
@Override
|
|
public int getWeakPower(BlockState state, IBlockReader world, BlockPos pos, Direction side) {
|
|
return ((TileEntitySpecialFlower) world.getTileEntity(pos)).getPowerLevel(side);
|
|
}
|
|
|
|
@Override
|
|
public int getStrongPower(BlockState state, IBlockReader world, BlockPos pos, Direction side) {
|
|
return getWeakPower(state, world, pos, side);
|
|
}
|
|
|
|
@Override
|
|
public boolean canProvidePower(BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
@Override
|
|
public void animateTick(BlockState state, World world, BlockPos pos, Random rand) {}
|
|
|
|
@Override
|
|
public void onBlockHarvested(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
|
super.onBlockHarvested(world, pos, state, player);
|
|
((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockHarvested(world, pos, state, player);
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public List<ItemStack> getDrops(@Nonnull BlockState state, @Nonnull LootContext.Builder builder) {
|
|
List<ItemStack> drops = super.getDrops(state, builder);
|
|
TileEntity te = builder.get(LootParameters.BLOCK_ENTITY);
|
|
|
|
if(te instanceof TileEntitySpecialFlower) {
|
|
return ((TileEntitySpecialFlower) te).getDrops(drops, builder);
|
|
} else {
|
|
return drops;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean onUsedByWand(PlayerEntity player, ItemStack stack, World world, BlockPos pos, Direction side) {
|
|
return ((TileEntitySpecialFlower) world.getTileEntity(pos)).onWanded(player, stack);
|
|
}
|
|
|
|
@Override
|
|
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
|
|
((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockPlacedBy(world, pos, state, entity, stack);
|
|
}
|
|
|
|
@Override
|
|
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
|
|
return super.onBlockActivated(state, world, pos, player, hand, hit)
|
|
|| ((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockActivated(world, pos, state, player, hand, hit) || super.onBlockActivated(state, world, pos, player, hand, hit);
|
|
}
|
|
|
|
@Override
|
|
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) {
|
|
((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockAdded(world, pos, state);
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
@Override
|
|
public void renderHUD(Minecraft mc, World world, BlockPos pos) {
|
|
((TileEntitySpecialFlower) world.getTileEntity(pos)).renderHUD(mc);
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public TileEntity createTileEntity(@Nonnull BlockState state, @Nonnull IBlockReader world) {
|
|
return teProvider.get();
|
|
}
|
|
}
|