private void findBestEquipment() { int bestScore = -1; ItemStack bestWeapon = null; int bestLocation = 0; ItemStack currentCheck; int currentScore; for (int i = 0; i < this.inventory.mainInventory.length; i++) { currentCheck = this.inventory.mainInventory[i]; if (currentCheck == null) continue; Multimap map = currentCheck.getAttributeModifiers(); Collection Attributes = (Collection) map.get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); if (Attributes.size() == 0) currentScore = 0; else currentScore = (int) ((AttributeModifier) Attributes.toArray()[0]).getAmount(); NBTTagList enchList = currentCheck.getEnchantmentTagList(); if (enchList == null) currentScore += 0; else { for (int j = 0; j < enchList.tagCount(); j++) { NBTTagCompound comp = (NBTTagCompound) enchList.getCompoundTagAt(j); int enchId = comp.getShort("id"); int enchLvl = comp.getShort("lvl"); switch (enchId) { case 16: currentScore += (1 * enchLvl); break; case 19: currentScore += (1 * enchLvl); break; case 20: currentScore += (2 * enchLvl); break; default: currentScore += 1; } } } UnDeath.logging.info( String.format("Item %s got score %d", currentCheck.toString(), currentScore)); if (currentScore > bestScore) { bestWeapon = currentCheck; bestLocation = i; bestScore = currentScore; } } if (bestScore == -1) { UnDeath.logging.info("No weapons found"); this.inventory.currentItem = -1; return; } UnDeath.logging.info( String.format("Best Weapon is %s with score %d", bestWeapon.toString(), bestScore)); this.inventory.currentItem = bestLocation; }
private static void doPlayer(EntityPlayerMP player, VoteEvent vote) { if (!ConfigServerVote.msgAll.equals("")) { player.playerNetServerHandler.sendPacket( new S02PacketChat( new ChatComponentText( ChatOutputHandler.formatColors( ConfigServerVote.msgAll .replaceAll("%service", vote.serviceName) .replaceAll("%player", vote.player))))); } if (!ConfigServerVote.msgVoter.equals("")) { ChatOutputHandler.sendMessage( player, ChatOutputHandler.formatColors( ConfigServerVote.msgAll .replaceAll("%service", vote.serviceName) .replaceAll("%player", vote.player))); } if (!ConfigServerVote.freeStuff.isEmpty()) { for (ItemStack stack : ConfigServerVote.freeStuff) { LoggingHandler.felog.debug(stack.toString()); player.inventory.addItemStackToInventory(stack.copy()); } } }
private void ExtractItem() { TileEntity tile = LazUtils.XYZCoords.FromTile(this).Next(currentfacing).ToTile(); if (tile instanceof IInventory) { if (LazUtils.InventoryCore.ExtractOneFromInventory((IInventory) tile, false) != null) { ItemStack stack = LazUtils.InventoryCore.ExtractOneFromInventory((IInventory) tile, true); if (YATS.IS_DEBUG) LazUtils.logNormal( "Heartbreak! Extracting item at " + xCoord + "," + yCoord + "," + zCoord + ": (" + stack.toString() + ")"); TileEntity tile2 = LazUtils.XYZCoords.FromTile(this).Next(currentfacing.getOpposite()).ToTile(); if (tile2 instanceof ITubeConnectible && ((ITubeConnectible) tile2).IsConnectedOnSide(currentfacing)) ((ITubeConnectible) tile2) .AcceptCapsule(new ItemCapsule(stack, Colours.NONE, currentfacing.getOpposite())); else if (tile2 instanceof IInventory && LazUtils.InventoryCore.CanAddToInventory((IInventory) tile2, stack)) LazUtils.InventoryCore.AddToInventory((IInventory) tile2, stack); else { LazUtils.XYZCoords coords = LazUtils.XYZCoords.FromTile(this).Next(currentfacing.getOpposite()); EntityItem item = new EntityItem(worldObj, coords.x, coords.y, coords.z, stack); worldObj.spawnEntityInWorld(item); } } } }
/** Called upon block activation (right click on the block.) */ @Override public boolean onBlockActivated( World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { if (player.isSneaking()) { player.openGui(FullPower.instance, GuiHandler.GuiIDs.CAMO_MINE.ordinal(), world, x, y, z); } TileEntityCamoMine te = (TileEntityCamoMine) world.getTileEntity(x, y, z); if (te.getCamouflage(side) != null) { ItemStack camoStack = te.getCamouflage(side); te.setCamouflage(null, side); EntityItem itemEntity = new EntityItem(world, x, y, z, camoStack); LogHelper.info("StackSize=" + camoStack.stackSize); // Tell world this item needs to be spawned world.spawnEntityInWorld(itemEntity); } else { ItemStack playerItem = player.getCurrentEquippedItem(); if (playerItem != null) { ItemStack camoStack = playerItem.splitStack(1); // Remove 1 from stack ChatHelper.send(camoStack.toString()); te.setCamouflage(camoStack, side); } } } return true; }
public void setRepresentativeItem(ItemStack representativeItem) { if (representativeItem == null) { this.representativeItem = null; } else if (matches(representativeItem) != null) { this.representativeItem = representativeItem; } else { TinkerRegistry.log.warn( "Itemstack {} cannot represent material {} since it is not associated with the material!", representativeItem.toString(), identifier); } }
public void setShard(ItemStack stack) { if (stack == null) { this.shardItem = null; } else { RecipeMatch.Match match = matches(stack); if (match != null) { if (match.amount == VALUE_Shard) { this.shardItem = stack; } else { TinkerRegistry.log.warn( "Itemstack {} cannot be shard of material {} since it does not have the correct value! (is {}, has to be {})", representativeItem.toString(), identifier, match.amount, VALUE_Shard); } } else { TinkerRegistry.log.warn( "Itemstack {} cannot be shard of material {} since it is not associated with the material!", stack.toString(), identifier); } } }
private static void loadTransformer() { for (TransformData data : ConfigRegistry.transformData) { ItemStack output = RecipeTransformer.dataToItemStack(data.output, true).get(0); Object input = RecipeTransformer.dataToObject(data.input); System.out.println("---------------- INPUT -----------------"); System.out.println("INPUT: " + data.input); System.out.println("---------------- OUTPUT -----------------"); System.out.println( "OUTPUT: " + data.output + " -> " + (output == null ? "NULL" : output.toString())); System.out.println("CODE: " + data.code); transformationContainer.add(new TransformerContainer(input, output, data.code)); } for (TransformerContainer con : transformationContainer) { CristalRegistry.register(new WeakCristalTransformation(con)); } }
@Override public void writeToWorld(IBuilderContext context) { if (mode == Mode.ClearIfInvalid) { if (!getSchematic().isAlreadyBuilt(context, x, y, z)) { if (BuildCraftBuilders.dropBrokenBlocks) { BlockUtils.breakBlock((WorldServer) context.world(), x, y, z); } else { context.world().setBlockToAir(x, y, z); } } } else { try { getSchematic().placeInWorld(context, x, y, z, stackConsumed); // This is slightly hackish, but it's a very important way to verify // the stored requirements. if (!context.world().isAirBlock(x, y, z) && getSchematic().getBuildingPermission() == BuildingPermission.ALL && getSchematic() instanceof SchematicBlock) { SchematicBlock sb = (SchematicBlock) getSchematic(); // Copy the old array of stored requirements. ItemStack[] oldRequirementsArray = sb.storedRequirements; List<ItemStack> oldRequirements = Arrays.asList(oldRequirementsArray); sb.storedRequirements = new ItemStack[0]; sb.storeRequirements(context, x, y, z); for (ItemStack s : sb.storedRequirements) { boolean contains = false; for (ItemStack ss : oldRequirements) { if (StackHelper.isMatchingItem(s, ss)) { contains = true; break; } } if (!contains) { BCLog.logger.warn( "Blueprint has MISMATCHING REQUIREMENTS! Potential corrupted/hacked blueprint! Removed mismatched block."); BCLog.logger.warn( "Location: " + x + ", " + y + ", " + z + " - ItemStack: " + s.toString()); context.world().removeTileEntity(x, y, z); context.world().setBlockToAir(x, y, z); return; } } // Restore the stored requirements. sb.storedRequirements = oldRequirementsArray; } // Once the schematic has been written, we're going to issue // calls // to various functions, in particular updating the tile entity. // If these calls issue problems, in order to avoid corrupting // the world, we're logging the problem and setting the block to // air. TileEntity e = context.world().getTileEntity(x, y, z); if (e != null) { e.updateEntity(); } } catch (Throwable t) { t.printStackTrace(); context.world().setBlockToAir(x, y, z); } } }