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

190 lines
6.6 KiB
Java
Raw Normal View History

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