2016-02-25 13:54:18 +00:00
|
|
|
package WayofTime.bloodmagic.block;
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2018-04-07 20:05:32 +00:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
|
|
|
import WayofTime.bloodmagic.item.block.ItemBlockDemonCrystal;
|
2018-02-16 02:49:01 +00:00
|
|
|
import WayofTime.bloodmagic.soul.EnumDemonWillType;
|
|
|
|
import WayofTime.bloodmagic.soul.PlayerDemonWillHandler;
|
2017-08-16 04:30:48 +00:00
|
|
|
import WayofTime.bloodmagic.tile.TileDemonCrystal;
|
2018-04-07 20:05:32 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
2016-02-26 03:00:02 +00:00
|
|
|
import net.minecraft.block.Block;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.block.material.Material;
|
2016-02-25 21:19:57 +00:00
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-02-25 21:19:57 +00:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-04-07 20:05:32 +00:00
|
|
|
import net.minecraft.item.ItemBlock;
|
2016-02-25 21:19:57 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.util.EnumBlockRenderType;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.util.EnumHand;
|
2017-01-02 05:43:34 +00:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-02-25 15:45:00 +00:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2016-02-25 13:54:18 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2018-04-07 20:05:32 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-01-02 05:43:34 +00:00
|
|
|
import javax.annotation.Nullable;
|
2017-08-16 04:30:48 +00:00
|
|
|
import java.util.Random;
|
2017-01-02 05:43:34 +00:00
|
|
|
|
2018-04-07 20:05:32 +00:00
|
|
|
public class BlockDemonCrystal extends Block implements IBMBlock, IVariantProvider {
|
2016-02-25 13:54:18 +00:00
|
|
|
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 6);
|
2018-03-02 03:27:38 +00:00
|
|
|
public static final PropertyEnum<EnumDemonWillType> TYPE = PropertyEnum.create("type", EnumDemonWillType.class);
|
|
|
|
public static final PropertyEnum<EnumFacing> ATTACHED = PropertyEnum.create("attached", EnumFacing.class);
|
2016-02-25 13:54:18 +00:00
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public BlockDemonCrystal() {
|
2016-04-24 17:06:28 +00:00
|
|
|
super(Material.ROCK);
|
2016-02-26 03:00:02 +00:00
|
|
|
this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumDemonWillType.DEFAULT).withProperty(ATTACHED, EnumFacing.UP));
|
2016-02-25 13:54:18 +00:00
|
|
|
|
2017-08-15 03:53:42 +00:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".demonCrystal.");
|
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2016-02-25 13:54:18 +00:00
|
|
|
setHardness(2.0F);
|
|
|
|
setResistance(5.0F);
|
|
|
|
setHarvestLevel("pickaxe", 2);
|
|
|
|
}
|
|
|
|
|
2016-02-26 03:00:02 +00:00
|
|
|
@Override
|
2018-04-07 20:05:32 +00:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
|
|
|
if (world.isRemote)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileDemonCrystal) {
|
|
|
|
TileDemonCrystal crystal = (TileDemonCrystal) tile;
|
|
|
|
|
|
|
|
if (PlayerDemonWillHandler.getTotalDemonWill(EnumDemonWillType.DEFAULT, player) > 1024)
|
|
|
|
crystal.dropSingleCrystal();
|
|
|
|
}
|
2016-02-26 03:00:02 +00:00
|
|
|
|
2018-04-07 20:05:32 +00:00
|
|
|
return true;
|
2016-02-26 03:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-07 20:05:32 +00:00
|
|
|
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileDemonCrystal) {
|
|
|
|
EnumDemonWillType type = state.getValue(TYPE);
|
|
|
|
int number = ((TileDemonCrystal) tile).getCrystalCount();
|
2016-02-26 03:00:02 +00:00
|
|
|
|
2018-04-07 20:05:32 +00:00
|
|
|
drops.add(getItemStackDropped(type, number));
|
2016-02-26 03:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 21:19:57 +00:00
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
2018-04-07 20:05:32 +00:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileDemonCrystal) {
|
|
|
|
TileDemonCrystal crystal = (TileDemonCrystal) tile;
|
|
|
|
state = state.withProperty(AGE, crystal.getCrystalCountForRender());
|
|
|
|
state = state.withProperty(ATTACHED, crystal.getPlacement());
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileDemonCrystal) {
|
|
|
|
TileDemonCrystal crystal = (TileDemonCrystal) tile;
|
|
|
|
EnumFacing placement = crystal.getPlacement();
|
|
|
|
BlockPos offsetPos = pos.offset(placement.getOpposite());
|
|
|
|
IBlockState offsetState = world.getBlockState(offsetPos);
|
|
|
|
|
|
|
|
if (!offsetState.isSideSolid(world, offsetPos, placement))
|
|
|
|
world.destroyBlock(pos, true);
|
2016-07-26 23:05:48 +00:00
|
|
|
}
|
2018-04-07 20:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side) {
|
|
|
|
BlockPos offsetPos = pos.offset(side.getOpposite());
|
|
|
|
IBlockState offsetState = world.getBlockState(offsetPos);
|
|
|
|
|
|
|
|
return offsetState.isSideSolid(world, offsetPos, side) && this.canPlaceBlockAt(world, pos);
|
2016-02-25 21:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
|
2018-04-07 20:05:32 +00:00
|
|
|
for (EnumDemonWillType willType : EnumDemonWillType.values())
|
|
|
|
list.add(new ItemStack(this, 1, willType.ordinal()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
|
|
|
|
super.harvestBlock(world, player, pos, state, tile, stack);
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
|
|
|
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
|
2016-02-25 21:19:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 13:54:18 +00:00
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
|
2016-02-25 13:54:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean isOpaqueCube(IBlockState state) {
|
2016-03-22 13:31:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean isFullCube(IBlockState state) {
|
2016-02-25 13:54:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public boolean causesSuffocation(IBlockState state) {
|
2016-02-25 13:54:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public EnumBlockRenderType getRenderType(IBlockState state) {
|
2016-03-18 17:16:38 +00:00
|
|
|
return EnumBlockRenderType.MODEL;
|
2016-02-25 13:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public IBlockState getStateFromMeta(int meta) {
|
2016-02-25 21:19:57 +00:00
|
|
|
return this.getDefaultState().withProperty(TYPE, EnumDemonWillType.values()[meta]);
|
2016-02-25 13:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
public int getMetaFromState(IBlockState state) {
|
2017-01-02 05:43:34 +00:00
|
|
|
return state.getValue(TYPE).ordinal();
|
2016-02-25 13:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-16 04:30:48 +00:00
|
|
|
protected BlockStateContainer createBlockState() {
|
2017-01-02 05:43:34 +00:00
|
|
|
return new BlockStateContainer(this, TYPE, AGE, ATTACHED);
|
2016-02-25 13:54:18 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 05:43:34 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public TileEntity createTileEntity(World world, IBlockState state) {
|
|
|
|
return new TileDemonCrystal();
|
|
|
|
}
|
|
|
|
|
2017-08-16 04:30:48 +00:00
|
|
|
public static ItemStack getItemStackDropped(EnumDemonWillType type, int crystalNumber) {
|
2018-04-07 20:05:32 +00:00
|
|
|
ItemStack stack = ItemStack.EMPTY;
|
2017-08-16 04:30:48 +00:00
|
|
|
switch (type) {
|
|
|
|
case CORROSIVE:
|
2018-02-07 02:59:47 +00:00
|
|
|
stack = EnumDemonWillType.CORROSIVE.getStack();
|
2017-08-16 04:30:48 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT:
|
2018-02-07 02:59:47 +00:00
|
|
|
stack = EnumDemonWillType.DEFAULT.getStack();
|
2017-08-16 04:30:48 +00:00
|
|
|
break;
|
|
|
|
case DESTRUCTIVE:
|
2018-02-07 02:59:47 +00:00
|
|
|
stack = EnumDemonWillType.DESTRUCTIVE.getStack();
|
2017-08-16 04:30:48 +00:00
|
|
|
break;
|
|
|
|
case STEADFAST:
|
2018-02-07 02:59:47 +00:00
|
|
|
stack = EnumDemonWillType.STEADFAST.getStack();
|
2017-08-16 04:30:48 +00:00
|
|
|
break;
|
|
|
|
case VENGEFUL:
|
2018-02-07 02:59:47 +00:00
|
|
|
stack = EnumDemonWillType.VENGEFUL.getStack();
|
2017-08-16 04:30:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.setCount(crystalNumber);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2018-04-07 20:05:32 +00:00
|
|
|
@Override
|
|
|
|
public ItemBlock getItem() {
|
|
|
|
return new ItemBlockDemonCrystal(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void gatherVariants(@Nonnull Int2ObjectMap<String> variants) {
|
|
|
|
for (EnumDemonWillType willType : EnumDemonWillType.values())
|
|
|
|
variants.put(willType.ordinal(), "age=3,attached=up,type=" + willType.getName());
|
|
|
|
}
|
2016-02-25 13:54:18 +00:00
|
|
|
}
|