Search in sources :

Example 6 with TileEntityRuneBase

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) TileEntityRuneBase(lumien.randomthings.tileentity.TileEntityRuneBase)

Aggregations

TileEntityRuneBase (lumien.randomthings.tileentity.TileEntityRuneBase)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)4 IBlockState (net.minecraft.block.state.IBlockState)3 EntityItem (net.minecraft.entity.item.EntityItem)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockContactButton (lumien.randomthings.block.BlockContactButton)1 ItemSpade (net.minecraft.item.ItemSpade)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 RightClickBlock (net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1