Search in sources :

Example 6 with PacketPlaySound

use of me.desht.pneumaticcraft.common.network.PacketPlaySound in project pnc-repressurized by TeamPneumatic.

the class TileEntityProgrammer method tryProgramDrone.

private void tryProgramDrone(EntityPlayer player) {
    if (!inventory.getStackInSlot(PROGRAM_SLOT).isEmpty()) {
        if (player == null || !player.capabilities.isCreativeMode) {
            List<ItemStack> requiredStacks = getRequiredPuzzleStacks();
            for (ItemStack stack : requiredStacks) {
                if (!hasEnoughPuzzleStacks(player, stack))
                    return;
            }
            for (ItemStack stack : requiredStacks) {
                int left = stack.getCount();
                if (player != null) {
                    for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
                        if (PneumaticCraftUtils.areStacksEqual(stack, player.inventory.getStackInSlot(i), true, true, false, false)) {
                            left -= player.inventory.decrStackSize(i, left).getCount();
                            if (left <= 0)
                                break;
                        }
                    }
                }
                if (left > 0) {
                    for (EnumFacing d : EnumFacing.VALUES) {
                        IItemHandler neighbor = IOHelper.getInventoryForTE(getWorld().getTileEntity(getPos().offset(d)), d.getOpposite());
                        if (neighbor != null) {
                            for (int slot = 0; slot < neighbor.getSlots(); slot++) {
                                ItemStack neighborStack = neighbor.extractItem(slot, left, true);
                                if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
                                    neighborStack = neighbor.extractItem(slot, left, false);
                                    left -= neighborStack.getCount();
                                    if (left <= 0)
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            List<ItemStack> returnedStacks = getReturnedPuzzleStacks();
            for (ItemStack stack : returnedStacks) {
                for (EnumFacing d : EnumFacing.VALUES) {
                    TileEntity te = getWorld().getTileEntity(getPos().offset(d));
                    if (te != null) {
                        stack = IOHelper.insert(te, stack, d.getOpposite(), false);
                        if (stack.isEmpty())
                            break;
                    }
                }
                if (player != null && !stack.isEmpty()) {
                    if (!player.inventory.addItemStackToInventory(stack)) {
                        player.dropItem(stack.copy(), false);
                        stack = ItemStack.EMPTY;
                    }
                }
                if (!stack.isEmpty()) {
                    getWorld().spawnEntity(new EntityItem(getWorld(), getPos().getX() + 0.5, getPos().getY() + 1.5, getPos().getZ() + 0.5, stack));
                }
            }
        }
        ItemStack stack = inventory.getStackInSlot(PROGRAM_SLOT);
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            inventory.setStackInSlot(PROGRAM_SLOT, stack);
        }
        writeProgWidgetsToNBT(stack.getTagCompound());
        NetworkHandler.sendTo(new PacketPlaySound(Sounds.HUD_INIT_COMPLETE, SoundCategory.NEUTRAL, getPos(), 1.0f, 1.0f, false), (EntityPlayerMP) player);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) PacketPlaySound(me.desht.pneumaticcraft.common.network.PacketPlaySound) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

PacketPlaySound (me.desht.pneumaticcraft.common.network.PacketPlaySound)6 PacketSpawnParticle (me.desht.pneumaticcraft.common.network.PacketSpawnParticle)3 TileEntity (net.minecraft.tileentity.TileEntity)3 EntityItem (net.minecraft.entity.item.EntityItem)2 ItemStack (net.minecraft.item.ItemStack)2 Random (java.util.Random)1 BlockPneumaticCraftCamo (me.desht.pneumaticcraft.common.block.BlockPneumaticCraftCamo)1 TubeModule (me.desht.pneumaticcraft.common.block.tubes.TubeModule)1 ItemTubeModule (me.desht.pneumaticcraft.common.item.ItemTubeModule)1 ICamouflageableTE (me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)1 TileEntityPressureTube (me.desht.pneumaticcraft.common.tileentity.TileEntityPressureTube)1 IBlockState (net.minecraft.block.state.IBlockState)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 Vec3d (net.minecraft.util.math.Vec3d)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IItemHandler (net.minecraftforge.items.IItemHandler)1