2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.block;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2016-03-18 17:16:38 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-06-03 00:03:21 +00:00
|
|
|
import WayofTime.bloodmagic.altar.BloodAltar;
|
|
|
|
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
|
|
|
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
|
|
|
import WayofTime.bloodmagic.api.iface.IDocumentedBlock;
|
2016-06-22 01:20:49 +00:00
|
|
|
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumBlockRenderType;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-06-03 00:03:21 +00:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2016-03-18 17:16:38 +00:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2015-11-29 02:25:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2015-11-11 18:45:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
2015-11-03 15:34:11 +00:00
|
|
|
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
2016-02-08 21:49:40 +00:00
|
|
|
import WayofTime.bloodmagic.api.iface.IBindable;
|
2016-06-12 20:41:02 +00:00
|
|
|
import WayofTime.bloodmagic.api.saving.SoulNetwork;
|
2016-02-08 21:49:40 +00:00
|
|
|
import WayofTime.bloodmagic.api.orb.IBloodOrb;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
2015-11-03 15:34:11 +00:00
|
|
|
import WayofTime.bloodmagic.tile.TileAltar;
|
2015-11-12 21:05:23 +00:00
|
|
|
import WayofTime.bloodmagic.util.Utils;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2016-03-18 17:16:38 +00:00
|
|
|
import com.google.common.base.Strings;
|
2016-03-16 22:37:55 +00:00
|
|
|
|
2016-06-03 00:03:21 +00:00
|
|
|
public class BlockAltar extends BlockContainer implements IVariantProvider, IDocumentedBlock
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
|
|
|
public BlockAltar()
|
|
|
|
{
|
2016-04-24 17:06:28 +00:00
|
|
|
super(Material.ROCK);
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-29 02:25:46 +00:00
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".altar");
|
2015-11-02 20:39:44 +00:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
2016-01-03 08:00:09 +00:00
|
|
|
setHardness(2.0F);
|
|
|
|
setResistance(5.0F);
|
2016-05-03 11:29:35 +00:00
|
|
|
setHarvestLevel("pickaxe", 1);
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 21:49:40 +00:00
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public boolean hasComparatorInputOverride(IBlockState state)
|
2016-02-08 21:49:40 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos)
|
2016-02-08 21:49:40 +00:00
|
|
|
{
|
|
|
|
if (world.isRemote)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
|
|
|
if (tile != null && tile instanceof TileAltar)
|
|
|
|
{
|
|
|
|
TileAltar altar = (TileAltar) tile;
|
|
|
|
ItemStack orbStack = altar.getStackInSlot(0);
|
|
|
|
|
|
|
|
if (world.getBlockState(pos.down()).getBlock() instanceof BlockBloodStoneBrick)
|
|
|
|
{
|
|
|
|
if (orbStack != null && orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable)
|
|
|
|
{
|
|
|
|
IBloodOrb bloodOrb = (IBloodOrb) orbStack.getItem();
|
|
|
|
IBindable bindable = (IBindable) orbStack.getItem();
|
|
|
|
if (!Strings.isNullOrEmpty(bindable.getOwnerUUID(orbStack)))
|
|
|
|
{
|
|
|
|
SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(bindable.getOwnerUUID(orbStack));
|
|
|
|
|
|
|
|
int maxEssence = bloodOrb.getMaxEssence(orbStack.getItemDamage());
|
|
|
|
int currentEssence = soulNetwork.getCurrentEssence();
|
|
|
|
int level = currentEssence * 15 / maxEssence;
|
|
|
|
return Math.min(15, level) % 16;
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 22:41:06 +00:00
|
|
|
} else
|
|
|
|
{
|
2016-02-08 21:49:40 +00:00
|
|
|
int maxEssence = altar.getCapacity();
|
|
|
|
int currentEssence = altar.getCurrentBlood();
|
|
|
|
int level = currentEssence * 15 / maxEssence;
|
|
|
|
return Math.min(15, level) % 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:28:33 +00:00
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-02 23:28:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-22 13:31:47 +00:00
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:28:33 +00:00
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public boolean isFullCube(IBlockState state)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-02 23:28:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-05 06:43:18 +00:00
|
|
|
public boolean causesSuffocation()
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-02 23:28:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public EnumBlockRenderType getRenderType(IBlockState state)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2016-03-18 17:16:38 +00:00
|
|
|
return EnumBlockRenderType.MODEL;
|
2015-11-02 23:28:33 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 03:22:14 +00:00
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public TileEntity createNewTileEntity(World world, int meta)
|
|
|
|
{
|
2015-11-03 15:34:11 +00:00
|
|
|
return new TileAltar();
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
2015-11-03 15:34:11 +00:00
|
|
|
|
|
|
|
@Override
|
2016-03-18 17:16:38 +00:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-11-03 15:34:11 +00:00
|
|
|
TileAltar altar = (TileAltar) world.getTileEntity(pos);
|
|
|
|
|
|
|
|
if (altar == null || player.isSneaking())
|
|
|
|
return false;
|
|
|
|
|
2016-03-18 17:16:38 +00:00
|
|
|
ItemStack playerItem = player.inventory.getCurrentItem();
|
2015-11-03 15:34:11 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (playerItem != null)
|
|
|
|
{
|
|
|
|
if (playerItem.getItem() instanceof IAltarReader || playerItem.getItem() instanceof IAltarManipulator)
|
|
|
|
{
|
2016-03-18 17:16:38 +00:00
|
|
|
playerItem.getItem().onItemRightClick(playerItem, world, player, hand);
|
2015-11-03 15:34:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:15:19 +00:00
|
|
|
if (Utils.insertItemToTile(altar, player))
|
|
|
|
altar.startCycle();
|
|
|
|
else
|
|
|
|
altar.setActive();
|
2015-11-11 18:45:46 +00:00
|
|
|
|
2016-03-18 17:16:38 +00:00
|
|
|
world.notifyBlockUpdate(pos, state, state, 3);
|
2015-11-03 15:34:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState)
|
|
|
|
{
|
2016-06-28 11:20:28 +00:00
|
|
|
TileEntity tile = world.getTileEntity(blockPos);
|
|
|
|
if (tile instanceof TileAltar)
|
|
|
|
{
|
|
|
|
TileAltar tileAltar = (TileAltar) world.getTileEntity(blockPos);
|
|
|
|
if (tileAltar != null)
|
|
|
|
tileAltar.dropItems();
|
|
|
|
}
|
2015-11-03 17:11:39 +00:00
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
super.breakBlock(world, blockPos, blockState);
|
|
|
|
}
|
|
|
|
|
2016-06-03 00:03:21 +00:00
|
|
|
// IVariantProvider
|
|
|
|
|
2016-03-16 22:37:55 +00:00
|
|
|
@Override
|
2016-03-16 22:41:06 +00:00
|
|
|
public List<Pair<Integer, String>> getVariants()
|
|
|
|
{
|
2016-03-16 22:37:55 +00:00
|
|
|
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(0, "normal"));
|
|
|
|
return ret;
|
|
|
|
}
|
2016-06-03 00:03:21 +00:00
|
|
|
|
|
|
|
// IDocumentedBlock
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<ITextComponent> getDocumentation(EntityPlayer player, World world, BlockPos pos, IBlockState state)
|
|
|
|
{
|
|
|
|
List<ITextComponent> docs = new ArrayList<ITextComponent>();
|
|
|
|
IBloodAltar altar = ((IBloodAltar) world.getTileEntity(pos));
|
|
|
|
Pair<BlockPos, EnumAltarComponent> missingBlock = BloodAltar.getAltarMissingBlock(world, pos, altar.getTier().toInt());
|
|
|
|
if (missingBlock != null)
|
|
|
|
docs.add(new TextComponentTranslation("chat.BloodMagic.altar.nextTier", new TextComponentTranslation(missingBlock.getRight().getKey()), Utils.prettifyBlockPosString(missingBlock.getLeft())));
|
|
|
|
|
|
|
|
return docs;
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|