BloodMagic/src/main/java/WayofTime/bloodmagic/block/BlockAltar.java

190 lines
6.7 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.block;
2017-08-16 04:30:48 +00:00
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.altar.BloodAltar;
import WayofTime.bloodmagic.apibutnotreally.altar.EnumAltarComponent;
import WayofTime.bloodmagic.apibutnotreally.altar.IAltarManipulator;
import WayofTime.bloodmagic.apibutnotreally.altar.IBloodAltar;
import WayofTime.bloodmagic.apibutnotreally.iface.IAltarReader;
import WayofTime.bloodmagic.apibutnotreally.iface.IBindable;
import WayofTime.bloodmagic.apibutnotreally.iface.IDocumentedBlock;
import WayofTime.bloodmagic.apibutnotreally.orb.BloodOrb;
import WayofTime.bloodmagic.apibutnotreally.orb.IBloodOrb;
import WayofTime.bloodmagic.apibutnotreally.saving.SoulNetwork;
import WayofTime.bloodmagic.apibutnotreally.util.helper.NetworkHelper;
2017-08-16 04:30:48 +00:00
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.util.Utils;
import com.google.common.base.Strings;
2017-01-02 05:43:34 +00:00
import net.minecraft.block.Block;
2016-03-18 17:16:38 +00:00
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
2017-08-16 04:24:59 +00:00
import net.minecraft.item.ItemBlock;
2016-03-18 17:16:38 +00:00
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;
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;
2017-01-02 05:43:34 +00:00
import javax.annotation.Nullable;
2017-08-16 04:30:48 +00:00
import java.util.ArrayList;
import java.util.List;
2017-01-02 05:43:34 +00:00
2017-08-16 04:30:48 +00:00
public class BlockAltar extends Block implements IVariantProvider, IDocumentedBlock, IBMBlock {
public BlockAltar() {
2016-04-24 17:06:28 +00:00
super(Material.ROCK);
setUnlocalizedName(BloodMagic.MODID + ".altar");
setCreativeTab(BloodMagic.TAB_BM);
2016-01-03 08:00:09 +00:00
setHardness(2.0F);
setResistance(5.0F);
setHarvestLevel("pickaxe", 1);
}
@Override
2017-08-16 04:30:48 +00:00
public boolean hasComparatorInputOverride(IBlockState state) {
return true;
}
@Override
2017-08-16 04:30:48 +00:00
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
if (world.isRemote)
return 0;
TileEntity tile = world.getTileEntity(pos);
2017-08-16 04:30:48 +00:00
if (tile != null && tile instanceof TileAltar) {
TileAltar altar = (TileAltar) tile;
ItemStack orbStack = altar.getStackInSlot(0);
2017-08-16 04:30:48 +00:00
if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) {
if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) {
2017-08-16 03:21:54 +00:00
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
IBindable bindable = (IBindable) orbStack.getItem();
2017-08-16 04:30:48 +00:00
if (orb != null && !Strings.isNullOrEmpty(bindable.getOwnerUUID(orbStack))) {
SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(bindable.getOwnerUUID(orbStack));
2017-08-16 03:21:54 +00:00
int maxEssence = orb.getCapacity();
int currentEssence = soulNetwork.getCurrentEssence();
int level = currentEssence * 15 / maxEssence;
return Math.min(15, level) % 16;
}
}
2017-08-16 04:30:48 +00:00
} else {
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
2017-08-16 04:30:48 +00:00
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
2015-11-02 23:28:33 +00:00
return false;
}
@Override
2017-08-16 04:30:48 +00:00
public boolean isOpaqueCube(IBlockState state) {
return false;
}
2015-11-02 23:28:33 +00:00
@Override
2017-08-16 04:30:48 +00:00
public boolean isFullCube(IBlockState state) {
2015-11-02 23:28:33 +00:00
return false;
}
@Override
2017-08-16 04:30:48 +00:00
public boolean causesSuffocation(IBlockState state) {
2017-01-02 05:43:34 +00:00
return true;
2015-11-02 23:28:33 +00:00
}
@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;
2015-11-02 23:28:33 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
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
2017-08-16 04:30:48 +00:00
if (playerItem.getItem() instanceof IAltarReader || playerItem.getItem() instanceof IAltarManipulator) {
2017-01-02 05:43:34 +00:00
playerItem.getItem().onItemRightClick(world, player, hand);
return true;
2015-11-03 15:34:11 +00:00
}
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
2017-08-16 04:30:48 +00:00
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
TileEntity tile = world.getTileEntity(blockPos);
2017-08-16 04:30:48 +00:00
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);
}
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 TileAltar();
}
// IVariantProvider
2016-03-16 22:37:55 +00:00
@Override
2017-08-16 04:30:48 +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;
}
// IDocumentedBlock
@Override
2017-08-16 04:30:48 +00:00
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)
2017-01-02 09:18:29 +00:00
docs.add(new TextComponentTranslation("chat.bloodmagic.altar.nextTier", new TextComponentTranslation(missingBlock.getRight().getKey()), Utils.prettifyBlockPosString(missingBlock.getLeft())));
return docs;
}
2017-08-16 04:24:59 +00:00
@Override
public ItemBlock getItem() {
return new ItemBlock(this);
}
}