BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockSpellTable.java

70 lines
2.1 KiB
Java
Raw Normal View History

package WayofTime.alchemicalWizardry.common.block;
2014-10-13 20:33:20 +00:00
import WayofTime.alchemicalWizardry.common.items.BlankSpell;
2015-07-30 14:21:53 +00:00
import WayofTime.alchemicalWizardry.common.tileEntity.TESpellTable;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
2015-07-29 18:35:00 +00:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2015-07-29 18:35:00 +00:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
2015-07-29 15:30:24 +00:00
public class BlockSpellTable extends BlockContainer
{
2015-07-29 15:30:24 +00:00
public BlockSpellTable()
{
super(Material.rock);
setHardness(2.0F);
setResistance(5.0F);
}
2015-08-24 21:27:49 +00:00
@Override
public int getRenderType()
{
return 3;
}
@Override
2015-07-29 18:35:00 +00:00
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
{
2015-07-30 14:21:53 +00:00
TESpellTable tileEntity = (TESpellTable) world.getTileEntity(blockPos);
if (tileEntity == null || player.isSneaking())
{
return false;
}
ItemStack playerItem = player.getCurrentEquippedItem();
if (playerItem != null)
{
if (playerItem.getItem() instanceof BlankSpell)
{
2015-01-16 15:00:50 +00:00
if (playerItem.getTagCompound() == null)
{
playerItem.setTagCompound(new NBTTagCompound());
}
2015-01-16 15:00:50 +00:00
NBTTagCompound itemTag = playerItem.getTagCompound();
2015-07-29 18:35:00 +00:00
itemTag.setInteger("xCoord", blockPos.getX());
itemTag.setInteger("yCoord", blockPos.getY());
itemTag.setInteger("zCoord", blockPos.getZ());
2015-07-29 12:23:01 +00:00
itemTag.setInteger("dimensionId", world.provider.getDimensionId());
return true;
}
}
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int metaMaybe)
{
2015-07-30 14:21:53 +00:00
return new TESpellTable();
}
}