mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 03:15:07 +00:00
254 lines
8.5 KiB
Java
254 lines
8.5 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 @ [Jan 26, 2014, 12:22:58 AM (GMT)]
|
|
*/
|
|
package vazkii.botania.common.block.mana;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import net.minecraft.block.SoundType;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.gui.ScaledResolution;
|
|
import net.minecraft.client.renderer.block.statemap.StateMap;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.inventory.IInventory;
|
|
import net.minecraft.item.EnumDyeColor;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.EnumBlockRenderType;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.ChunkCache;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.chunk.Chunk;
|
|
import net.minecraftforge.client.model.ModelLoader;
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
import vazkii.botania.api.BotaniaAPI;
|
|
import vazkii.botania.api.internal.VanillaPacketDispatcher;
|
|
import vazkii.botania.api.lexicon.ILexiconable;
|
|
import vazkii.botania.api.lexicon.LexiconEntry;
|
|
import vazkii.botania.api.state.BotaniaStateProps;
|
|
import vazkii.botania.api.state.enums.PoolVariant;
|
|
import vazkii.botania.api.wand.IWandHUD;
|
|
import vazkii.botania.api.wand.IWandable;
|
|
import vazkii.botania.client.core.handler.ModelHandler;
|
|
import vazkii.botania.common.block.BlockMod;
|
|
import vazkii.botania.common.block.tile.mana.TilePool;
|
|
import vazkii.botania.common.item.block.ItemBlockPool;
|
|
import vazkii.botania.common.lexicon.LexiconData;
|
|
import vazkii.botania.common.lib.LibBlockNames;
|
|
|
|
public class BlockPool extends BlockMod implements IWandHUD, IWandable, ILexiconable {
|
|
|
|
private static final AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 0.5, 1);
|
|
|
|
private boolean lastFragile = false;
|
|
|
|
public BlockPool() {
|
|
super(Material.ROCK, LibBlockNames.POOL);
|
|
setHardness(2.0F);
|
|
setResistance(10.0F);
|
|
setSoundType(SoundType.STONE);
|
|
BotaniaAPI.blacklistBlockFromMagnet(this, Short.MAX_VALUE);
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public BlockStateContainer createBlockState() {
|
|
return new BlockStateContainer(this, BotaniaStateProps.POOL_VARIANT, BotaniaStateProps.COLOR);
|
|
}
|
|
|
|
@Override
|
|
protected IBlockState pickDefaultState() {
|
|
return blockState.getBaseState()
|
|
.withProperty(BotaniaStateProps.POOL_VARIANT, PoolVariant.DEFAULT)
|
|
.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE);
|
|
}
|
|
|
|
@Override
|
|
public int getMetaFromState(IBlockState state) {
|
|
return state.getValue(BotaniaStateProps.POOL_VARIANT).ordinal();
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
if (meta > PoolVariant.values().length) {
|
|
meta = 0;
|
|
}
|
|
return getDefaultState().withProperty(BotaniaStateProps.POOL_VARIANT, PoolVariant.values()[meta]);
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
TileEntity te = world instanceof ChunkCache ? ((ChunkCache)world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
|
|
if (te instanceof TilePool) {
|
|
return state.withProperty(BotaniaStateProps.COLOR, ((TilePool) te).color);
|
|
} else {
|
|
return state.withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE);
|
|
}
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
|
|
return AABB;
|
|
}
|
|
|
|
@Override
|
|
public void registerItemForm() {
|
|
GameRegistry.register(new ItemBlockPool(this), getRegistryName());
|
|
}
|
|
|
|
@Override
|
|
public int damageDropped(IBlockState state) {
|
|
return state.getBlock().getMetaFromState(state);
|
|
}
|
|
|
|
@Override
|
|
public void breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
|
|
TilePool pool = (TilePool) world.getTileEntity(pos);
|
|
lastFragile = pool.fragile;
|
|
super.breakBlock(world, pos, state);
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune) {
|
|
ArrayList<ItemStack> drops = new ArrayList<>();
|
|
|
|
if(!lastFragile)
|
|
drops.add(new ItemStack(this, 1, state.getBlock().getMetaFromState(state)));
|
|
|
|
return drops;
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public void getSubBlocks(CreativeTabs par2, NonNullList<ItemStack> par3) {
|
|
par3.add(new ItemStack(this, 1, 0));
|
|
par3.add(new ItemStack(this, 1, 2));
|
|
par3.add(new ItemStack(this, 1, 3));
|
|
par3.add(new ItemStack(this, 1, 1));
|
|
}
|
|
|
|
@Override
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
|
return new TilePool();
|
|
}
|
|
|
|
@Override
|
|
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity par5Entity) {
|
|
if(par5Entity instanceof EntityItem) {
|
|
TilePool tile = (TilePool) world.getTileEntity(pos);
|
|
if(tile.collideEntityItem((EntityItem) par5Entity))
|
|
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
|
}
|
|
}
|
|
|
|
private static final AxisAlignedBB BOTTOM_AABB = new AxisAlignedBB(0, 0, 0, 1, 1/16.0, 1);
|
|
private static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0, 0, 15/16.0, 1, 0.5, 1);
|
|
private static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0, 0, 0, 1, 0.5, 1/16.0);
|
|
private static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0, 0, 0, 1/16.0, 0.5, 1);
|
|
private static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(15/16.0, 0, 0, 1, 0.5, 1);
|
|
|
|
|
|
@Override
|
|
public void addCollisionBoxToList(IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB entityBox, @Nonnull List<AxisAlignedBB> boxes, Entity entity, boolean isActualState) {
|
|
addCollisionBoxToList(pos, entityBox, boxes, BOTTOM_AABB);
|
|
addCollisionBoxToList(pos, entityBox, boxes, NORTH_AABB);
|
|
addCollisionBoxToList(pos, entityBox, boxes, SOUTH_AABB);
|
|
addCollisionBoxToList(pos, entityBox, boxes, WEST_AABB);
|
|
addCollisionBoxToList(pos, entityBox, boxes, EAST_AABB);
|
|
}
|
|
|
|
@Override
|
|
public boolean isSideSolid(IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side) {
|
|
return side == EnumFacing.DOWN;
|
|
}
|
|
|
|
@Override
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isFullCube(IBlockState state) {
|
|
return false;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public EnumBlockRenderType getRenderType(IBlockState state) {
|
|
if (state.getValue(BotaniaStateProps.POOL_VARIANT) == PoolVariant.FABULOUS)
|
|
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
|
|
else return EnumBlockRenderType.MODEL;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasComparatorInputOverride(IBlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
|
|
TilePool pool = (TilePool) world.getTileEntity(pos);
|
|
int val = (int) ((double) pool.getCurrentMana() / (double) pool.manaCap * 15.0);
|
|
if(pool.getCurrentMana() > 0)
|
|
val = Math.max(val, 1);
|
|
|
|
return val;
|
|
}
|
|
|
|
@Override
|
|
public void renderHUD(Minecraft mc, ScaledResolution res, World world, BlockPos pos) {
|
|
((TilePool) world.getTileEntity(pos)).renderHUD(mc, res);
|
|
}
|
|
|
|
@Override
|
|
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
|
|
((TilePool) world.getTileEntity(pos)).onWanded(player, stack);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public LexiconEntry getEntry(World world, BlockPos pos, EntityPlayer player, ItemStack lexicon) {
|
|
return world.getBlockState(pos).getValue(BotaniaStateProps.POOL_VARIANT) == PoolVariant.FABULOUS ? LexiconData.rainbowRod : LexiconData.pool;
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
@Override
|
|
public void registerModels() {
|
|
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(BotaniaStateProps.COLOR).build());
|
|
ModelHandler.registerBlockToState(this, PoolVariant.values().length);
|
|
}
|
|
}
|