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

184 lines
6.3 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.AltarUtil;
import WayofTime.bloodmagic.altar.ComponentType;
import WayofTime.bloodmagic.altar.IAltarManipulator;
import WayofTime.bloodmagic.altar.IBloodAltar;
2018-03-08 03:43:00 +00:00
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.core.data.Binding;
2018-03-08 03:43:00 +00:00
import WayofTime.bloodmagic.core.data.SoulNetwork;
import WayofTime.bloodmagic.iface.IAltarReader;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.iface.IDocumentedBlock;
import WayofTime.bloodmagic.orb.BloodOrb;
import WayofTime.bloodmagic.orb.IBloodOrb;
2017-08-16 04:30:48 +00:00
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.util.Utils;
2018-03-08 03:43:00 +00:00
import WayofTime.bloodmagic.util.helper.NetworkHelper;
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.AxisAlignedBB;
2016-03-18 17:16:38 +00:00
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.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 {
private static final AxisAlignedBB BODY = new AxisAlignedBB(0, 0, 0, 16 / 16F, 12 / 16F, 16 / 16F);
2017-08-16 04:30:48 +00:00
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);
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BODY;
}
@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);
2018-07-22 14:10:00 +00:00
if (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);
Binding binding = ((IBindable) orbStack.getItem()).getBinding(orbStack);
if (orb != null && binding != null) {
SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(binding);
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;
2018-03-10 08:07:19 +00:00
ItemStack playerItem = player.getHeldItem(hand);
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);
2018-03-10 08:07:19 +00:00
if (tile instanceof TileAltar)
((TileAltar) tile).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();
}
// 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<>();
IBloodAltar altar = ((IBloodAltar) world.getTileEntity(pos));
2018-03-10 02:00:04 +00:00
Pair<BlockPos, ComponentType> missingBlock = AltarUtil.getFirstMissingComponent(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);
}
}