mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-25 22:44:44 +00:00
124 lines
4.0 KiB
Java
124 lines
4.0 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 @ [Aug 23, 2015, 7:23:26 PM (GMT)]
|
|
*/
|
|
package vazkii.botania.common.block;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.BlockStateContainer;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.IBlockAccess;
|
|
import net.minecraft.world.World;
|
|
import vazkii.botania.api.state.BotaniaStateProps;
|
|
import vazkii.botania.common.block.tile.TileCacophonium;
|
|
import vazkii.botania.common.lib.LibBlockNames;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class BlockCacophonium extends BlockMod {
|
|
|
|
protected BlockCacophonium() {
|
|
super(Material.WOOD, LibBlockNames.CACOPHONIUM);
|
|
setHardness(0.8F);
|
|
setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.POWERED, false));
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public BlockStateContainer createBlockState() {
|
|
return new BlockStateContainer(this, BotaniaStateProps.POWERED);
|
|
}
|
|
|
|
@Override
|
|
public int getMetaFromState(IBlockState state) {
|
|
return state.getValue(BotaniaStateProps.POWERED) ? 8 : 0;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public IBlockState getStateFromMeta(int meta) {
|
|
return getDefaultState().withProperty(BotaniaStateProps.POWERED, meta == 8);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSilkHarvest(World world, BlockPos pos, @Nonnull IBlockState state, EntityPlayer player) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean registerInCreative() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos fromPos) {
|
|
boolean power = world.isBlockIndirectlyGettingPowered(pos) > 0 || world.isBlockIndirectlyGettingPowered(pos.up()) > 0;
|
|
boolean powered = state.getValue(BotaniaStateProps.POWERED);
|
|
|
|
if(power && !powered) {
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
if(tile != null && tile instanceof TileCacophonium)
|
|
((TileCacophonium) tile).annoyDirewolf();
|
|
world.setBlockState(pos, state.withProperty(BotaniaStateProps.POWERED, true), 4);
|
|
} else if(!power && powered)
|
|
world.setBlockState(pos, state.withProperty(BotaniaStateProps.POWERED, false), 4);
|
|
}
|
|
|
|
@Override
|
|
public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest) {
|
|
if (willHarvest) {
|
|
// Copy of super.removedByPlayer but don't set to air yet
|
|
// This is so getDrops below will have a TE to work with
|
|
onBlockHarvested(world, pos, state, player);
|
|
return true;
|
|
} else {
|
|
return super.removedByPlayer(state, world, pos, player, willHarvest);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void harvestBlock(@Nonnull World world, EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, TileEntity te, ItemStack stack) {
|
|
super.harvestBlock(world, player, pos, state, te, stack);
|
|
// Now delete the block and TE
|
|
world.setBlockToAir(pos);
|
|
}
|
|
|
|
@Override
|
|
public void getDrops(NonNullList<ItemStack> stacks, IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune) {
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
if(tile != null && tile instanceof TileCacophonium) {
|
|
stacks.add(new ItemStack(Blocks.NOTEBLOCK));
|
|
ItemStack thingy = ((TileCacophonium) tile).stack;
|
|
if(!thingy.isEmpty())
|
|
stacks.add(thingy.copy());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
|
|
return new TileCacophonium();
|
|
}
|
|
|
|
}
|