use of lumien.randomthings.tileentity.TileEntityRuneBase in project Random-Things by lumien231.
the class ItemRunePattern method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = worldIn.getBlockState(pos);
if (worldIn.isAirBlock(pos.up()) && state.isSideSolid(worldIn, pos, EnumFacing.UP)) {
ItemStack me = player.getHeldItem(hand);
if (me.getTagCompound() != null) {
int[] runeData = me.getTagCompound().getIntArray("runeData");
int[][] actualRuneData = new int[4][4];
boolean anyThing = player.capabilities.isCreativeMode;
for (int i = 0; i < runeData.length; i++) {
int x = i % 4;
int y = i / 4;
int runeType = runeData[i];
if (runeType != -1 && !player.capabilities.isCreativeMode) {
boolean available = false;
for (int s = 0; s < player.inventory.getSizeInventory(); s++) {
ItemStack stack = player.inventory.getStackInSlot(s);
if (!stack.isEmpty() && stack.getItem() == ModItems.runeDust && stack.getItemDamage() == runeType) {
if (!worldIn.isRemote) {
stack.shrink(1);
}
available = true;
}
}
if (!available) {
runeType = -1;
} else {
anyThing = true;
}
}
actualRuneData[x][y] = runeType;
}
if (anyThing) {
if (!worldIn.isRemote) {
worldIn.setBlockState(pos.up(), ModBlocks.runeBase.getDefaultState());
TileEntityRuneBase te = (TileEntityRuneBase) worldIn.getTileEntity(pos.up());
te.setRuneData(actualRuneData);
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.FAIL;
}
Aggregations