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);
}
}
Aggregations