2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.block;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2015-11-02 12:39:44 -08:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2015-11-11 10:45:46 -08:00
|
|
|
import WayofTime.bloodmagic.api.altar.IAltarManipulator;
|
2015-11-03 10:34:11 -05:00
|
|
|
import WayofTime.bloodmagic.api.iface.IAltarReader;
|
|
|
|
import WayofTime.bloodmagic.tile.TileAltar;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
2015-11-03 10:34:11 -05:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-11-03 10:34:11 -05:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class BlockAltar extends BlockContainer {
|
|
|
|
|
|
|
|
public BlockAltar() {
|
|
|
|
super(Material.rock);
|
|
|
|
|
2015-11-02 12:39:44 -08:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".altar");
|
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
|
|
|
|
2015-11-02 15:28:33 -08:00
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFullCube() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRenderType() {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World world, int meta) {
|
2015-11-03 10:34:11 -05:00
|
|
|
return new TileAltar();
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
2015-11-03 10:34:11 -05:00
|
|
|
|
|
|
|
@Override
|
2015-11-11 10:45:46 -08:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, 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;
|
|
|
|
|
|
|
|
ItemStack playerItem = player.getCurrentEquippedItem();
|
|
|
|
|
2015-11-11 10:45:46 -08:00
|
|
|
if (playerItem != null) {
|
|
|
|
if (playerItem.getItem() instanceof IAltarReader || playerItem.getItem() instanceof IAltarManipulator) {
|
2015-11-03 10:34:11 -05:00
|
|
|
playerItem.getItem().onItemRightClick(playerItem, world, player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-11 10:45:46 -08:00
|
|
|
if (altar.getStackInSlot(0) == null && playerItem != null) {
|
2015-11-03 10:34:11 -05:00
|
|
|
ItemStack newItem = playerItem.copy();
|
|
|
|
newItem.stackSize = 1;
|
2015-11-11 10:45:46 -08:00
|
|
|
playerItem.stackSize--;
|
2015-11-03 10:34:11 -05:00
|
|
|
altar.setInventorySlotContents(0, newItem);
|
|
|
|
// altar.startCycle();
|
2015-11-11 10:45:46 -08:00
|
|
|
} else if (altar.getStackInSlot(0) != null && playerItem == null) {
|
2015-11-03 10:34:11 -05:00
|
|
|
player.inventory.addItemStackToInventory(altar.getStackInSlot(0));
|
2015-11-11 10:45:46 -08:00
|
|
|
altar.clear();
|
2015-11-03 10:34:11 -05:00
|
|
|
// altar.setActive();
|
|
|
|
}
|
2015-11-11 10:45:46 -08:00
|
|
|
|
2015-11-03 10:34:11 -05:00
|
|
|
world.markBlockForUpdate(pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-03 09:11:39 -08:00
|
|
|
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState) {
|
|
|
|
TileAltar tileAltar = (TileAltar) world.getTileEntity(blockPos);
|
|
|
|
if (tileAltar != null)
|
|
|
|
tileAltar.dropItems();
|
|
|
|
|
2015-11-03 10:34:11 -05:00
|
|
|
super.breakBlock(world, blockPos, blockState);
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|