private static void parseModItems() { HashMap<String, ItemStackSet> modSubsets = new HashMap<String, ItemStackSet>(); for (Item item : (Iterable<Item>) Item.itemRegistry) { UniqueIdentifier ident = GameRegistry.findUniqueIdentifierFor(item); if(ident == null) { NEIClientConfig.logger.error("Failed to find identifier for: "+item); continue; } String modId = GameRegistry.findUniqueIdentifierFor(item).modId; itemOwners.put(item, modId); ItemStackSet itemset = modSubsets.get(modId); if(itemset == null) modSubsets.put(modId, itemset = new ItemStackSet()); itemset.with(item); } API.addSubset("Mod.Minecraft", modSubsets.remove("minecraft")); for(Entry<String, ItemStackSet> entry : modSubsets.entrySet()) { ModContainer mc = FMLCommonHandler.instance().findContainerFor(entry.getKey()); if(mc == null) NEIClientConfig.logger.error("Missing container for "+entry.getKey()); else API.addSubset("Mod."+mc.getName(), entry.getValue()); } }
@SubscribeEvent public void onBlockPlaced(BlockEvent.PlaceEvent event) { if (event.player.capabilities.isCreativeMode) return; int playerDimension = event.player.dimension; if (dimensionWhitelist.keySet().contains(playerDimension)) { Set<UniqueIdentifier> uniqueIdentifierWhitelist = dimensionWhitelist.get(playerDimension); UniqueIdentifier placedBlockUniqueIdentifier = GameRegistry.findUniqueIdentifierFor(event.placedBlock); if (!uniqueIdentifierWhitelist.contains(placedBlockUniqueIdentifier)) { event.setCanceled(true); } } }
private Map<Integer, Set<UniqueIdentifier>> parseBlockWhitelist(String[] rawBlockWhitelist) { HashMap<Integer, Set<UniqueIdentifier>> map = new HashMap<Integer, Set<UniqueIdentifier>>(); for (String s : rawBlockWhitelist) { int i = s.indexOf(':'); int dim = Integer.parseInt(s.substring(0, i)); Set<UniqueIdentifier> whitelist; if (!map.containsKey(dim)) { whitelist = new HashSet<UniqueIdentifier>(); map.put(dim, whitelist); } else { whitelist = map.get(dim); } String blockID = s.substring(i + 1); whitelist.add(new UniqueIdentifier(blockID)); } return map; }
public StructureBlock(Block b, int meta, TileEntity te) { if(b == null) { Log.warn("StructureBlock.StructureBlock: Null block"); b = Blocks.air; } UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(b); if(uid == null) { modId = "minecraft"; blockName = "air"; Log.warn("StructureBlock.StructureBlock: Null UID for " + b); } else { modId = uid.modId; blockName = uid.name; } blockMeta = (short) meta; if(te != null) { tileEntity = new NBTTagCompound(); te.writeToNBT(tileEntity); } else { tileEntity = null; } }
public static ItemStack getItemStack(JsonObject json, String element) { JsonObject obj = getObjectField(json, element); if(obj == null) { return null; } String uid = getStringField(obj, "uid", null); if(uid == null) { return null; } UniqueIdentifier u = new UniqueIdentifier(uid); ItemStack res = GameRegistry.findItemStack(u.modId, u.name, 1); if(res == null) { return res; } res.setItemDamage(getIntField(obj, "meta", res.getItemDamage())); String nbtStr = getStringField(obj, "nbt", null); if(nbtStr != null) { NBTTagCompound nbt = parseNBT(nbtStr); if(nbt != null) { res.setTagCompound(nbt); } } return res; }
@Override public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) { if(src == null) { return JsonNull.INSTANCE; } JsonObject res = new JsonObject(); UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(src.getItem()); res.addProperty("item", id.modId + ":" + id.name); res.addProperty("number", src.stackSize); res.addProperty("meta", src.getItemDamage()); String nbt = serializeNBT(src.stackTagCompound); if(nbt != null && nbt.trim().length() > 0) { res.addProperty("nbt", nbt); } return res; }
public static void replaceRecipeResults() { // replace smelting results OresPlus.log.info("Replacing smelting results"); Collection smeltingResultsList = FurnaceRecipes.smelting().getSmeltingList().values(); for (Object result : smeltingResultsList.toArray()) { if (result instanceof ItemStack) { Item item = ((ItemStack)result).getItem(); UniqueIdentifier itemUid = GameRegistry.findUniqueIdentifierFor(item); if (itemUid.modId != "minecraft" && itemUid.modId != References.MOD_ID) { OresPlus.log.info("Recipe Result " + itemUid.modId + ":" + itemUid.name); ItemStack newItem = new ItemStack(Ores.manager.getOreItem(itemUid.name), ((ItemStack)result).stackSize); if (newItem != null) { ((ItemStack)result).func_150996_a(newItem.getItem()); net.minecraft.init.Items.apple.setDamage(newItem, net.minecraft.init.Items.apple.getDamage(((ItemStack)result))); } } } } }
public static Attribute loadAttributeFromNBT(NBTTagCompound nbt) { ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbt); if (itemStack == null) { String uuid = nbt.getString(TAG_UNIQUE_ID); if (uuid.contains(":")) { UniqueIdentifier uniqueId = new UniqueIdentifier(uuid); itemStack = GameRegistry.findItemStack(uniqueId.modId, uniqueId.name, 1); if (itemStack != null) { int dmg = nbt.getShort("Damage"); itemStack.setItemDamage(dmg); ModLogger.log(Level.WARN, "Invalid Id for attribute '" + uniqueId.toString() + "' corrected."); } else { ModLogger.log(Level.WARN, "Block attribute '" + uniqueId.toString() + "' was unable to be recovered. Was a mod removed?"); } } else { ModLogger.log(Level.WARN, "Unable to resolve attribute '" + uuid + "'"); } } return new Attribute(itemStack); }
public EnderID(ItemStack stack) throws BlockConversionException { if(!(stack instanceof ItemStack)) throw new BlockConversionException("", "unknown", "Custom item stacks unsupported!"); UniqueIdentifier itemID = GameRegistry.findUniqueIdentifierFor(stack.getItem()); if(itemID == null) { this.modId = "Minecraft"; this.name = stack.getItem().getUnlocalizedName(); } else { this.modId = itemID.modId; this.name = itemID.name; } this.metadata = stack.getItemDamage(); this.stackSize = stack.stackSize; if(blacklistedItems.contains(getItemIdentifier())) throw new BlockConversionException(modId, name, "Blacklisted!"); if(stack.hasTagCompound()) { NBTTagCompound compound = stack.getTagCompound(); try { this.compound = CompressedStreamTools.compress(compound); } catch(Exception e) { e.printStackTrace(); throw new BlockConversionException(modId, name, "Could not compress NBT tag compound!"); } if(!isAllowedTagCompound(compound)) throw new BlockConversionException(modId, name, "NBT tag compound cannot be sent!"); } }
public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2, boolean checkMeta, boolean checkNBT, boolean checkOreDict, boolean checkModSimilarity){ if(stack1 == null && stack2 == null) return true; if(stack1 == null && stack2 != null || stack1 != null && stack2 == null) return false; if(checkModSimilarity) { UniqueIdentifier id1 = GameRegistry.findUniqueIdentifierFor(stack1.getItem()); if(id1 == null || id1.modId == null) return false; String modId1 = id1.modId; UniqueIdentifier id2 = GameRegistry.findUniqueIdentifierFor(stack2.getItem()); if(id2 == null || id2.modId == null) return false; String modId2 = id2.modId; return modId1.equals(modId2); } if(checkOreDict) { return isSameOreDictStack(stack1, stack2); } if(stack1.getItem() != stack2.getItem()) return false; boolean metaSame = stack1.getItemDamage() == stack2.getItemDamage(); boolean nbtSame = stack1.hasTagCompound() ? stack1.getTagCompound().equals(stack2.getTagCompound()) : !stack2.hasTagCompound(); return (!checkMeta || metaSame) && (!checkNBT || nbtSame); }
private static Map<String, Object> createBasicProperties(Item item, ItemStack itemstack) { Map<String, Object> map = Maps.newHashMap(); UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(item); map.put("id", id != null? id.toString() : "?"); map.put("name", id != null? id.name : "?"); map.put("mod_id", id != null? id.modId : "?"); map.put("display_name", getNameForItemStack(itemstack)); map.put("raw_name", getRawNameForStack(itemstack)); map.put("qty", itemstack.stackSize); map.put("dmg", itemstack.getItemDamage()); if (item.showDurabilityBar(itemstack)) map.put("health_bar", item.getDurabilityForDisplay(itemstack)); map.put("max_dmg", itemstack.getMaxDamage()); map.put("max_size", itemstack.getMaxStackSize()); return map; }
/** * @deprecated no replacement planned */ @Deprecated public static ModContainer findModOwner(String string) { UniqueIdentifier ui = new UniqueIdentifier(string); if (customOwners.containsKey(ui)) { return customOwners.get(ui); } return Loader.instance().getIndexedModList().get(ui.modId); }
static UniqueIdentifier getUniqueName(Block block) { if (block == null) return null; String name = getMain().iBlockRegistry.func_148750_c(block); UniqueIdentifier ui = new UniqueIdentifier(name); if (customItemStacks.contains(ui.modId, ui.name)) { return null; } return ui; }
static UniqueIdentifier getUniqueName(Item item) { if (item == null) return null; String name = getMain().iItemRegistry.func_148750_c(item); UniqueIdentifier ui = new UniqueIdentifier(name); if (customItemStacks.contains(ui.modId, ui.name)) { return null; } return ui; }
/** * Raw constructor designed for serialization usages. */ public BlockSnapshot(int dimension, int x, int y, int z, String modid, String blockName, int meta, int flag, NBTTagCompound nbt) { this.dimId = dimension; this.x = x; this.y = y; this.z = z; this.meta = meta; this.flag = flag; this.blockIdentifier = new UniqueIdentifier(modid + ":" + blockName); this.nbt = nbt; }
/** * Check if player actually swims in a fluid * * @param pPlayer */ private void CheckPlayerTouchesBlock( EntityPlayer pPlayer ) { if( _mRnd.nextInt( _mExecuteChance ) != 0 ) { return; } try { int blockX = MathHelper.floor_double( pPlayer.posX ); int blockY = MathHelper.floor_double( pPlayer.boundingBox.minY ); int blockZ = MathHelper.floor_double( pPlayer.posZ ); Block pBlockContact = pPlayer.worldObj.getBlock( blockX, blockY, blockZ ); Block pBlockUnderFeet = pPlayer.worldObj.getBlock( blockX, blockY - 1, blockZ ); UniqueIdentifier tUidContact = GameRegistry.findUniqueIdentifierFor( pBlockContact ); UniqueIdentifier tUidFeet = GameRegistry.findUniqueIdentifierFor( pBlockUnderFeet ); // Skip air block and null results if( tUidContact != null && tUidContact.toString() != "minecraft:air" ) { HazardousItems.HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluidExact( tUidContact.toString() ); if( hf != null && hf.getCheckContact() ) { DoHIEffects(hf, pPlayer); } } if( tUidFeet != null && tUidFeet.toString() != "minecraft:air" ) { HazardousItems.HazardousItem hi = _mHazardItemsCollection.FindHazardousItemExact( tUidFeet.toString() ); if( hi != null && hi.getCheckContact() ) { DoHIEffects(hi, pPlayer); } } } catch( Exception e ) { _mLogger.error( "HazardousItemsHandler.CheckPlayerTouchesBlock.error", "Something bad happend while processing the onPlayerTick event" ); e.printStackTrace(); } }
static UniqueIdentifier getUniqueName(Block block) { if (block == null) return null; String name = getMain().iBlockRegistry.getNameForObject(block); UniqueIdentifier ui = new UniqueIdentifier(name); if (customItemStacks.contains(ui.modId, ui.name)) { return null; } return ui; }
static UniqueIdentifier getUniqueName(Item item) { if (item == null) return null; String name = getMain().iItemRegistry.getNameForObject(item); UniqueIdentifier ui = new UniqueIdentifier(name); if (customItemStacks.contains(ui.modId, ui.name)) { return null; } return ui; }
public StructureBlock(NBTTagCompound tag) { UniqueIdentifier uid = new UniqueIdentifier(tag.getString("uid")); modId = uid.modId; blockName = uid.name; blockMeta = tag.getShort("meta"); if(tag.hasKey("te")) { tileEntity = tag.getCompoundTag("te"); } else { tileEntity = null; } }
@Override public Block deserialize(JsonElement je, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if(!je.isJsonPrimitive() || !je.getAsJsonPrimitive().isString()) { return null; } UniqueIdentifier blkId = new UniqueIdentifier(je.getAsString()); Block blk = GameRegistry.findBlock(blkId.modId, blkId.name); return blk; }
@Override public JsonElement serialize(Block src, Type typeOfSrc, JsonSerializationContext context) { UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(src); if(id == null) { return null; } return new JsonPrimitive(id.toString()); }
@Override public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if(!json.isJsonObject()) { return null; } JsonObject obj = json.getAsJsonObject(); String itemStr = JsonUtil.getStringField(obj, "item", null); UniqueIdentifier itemId = new UniqueIdentifier(itemStr); Item item = GameRegistry.findItem(itemId.modId, itemId.name); if(item == null) { throw new JsonParseException("No item found for " + itemStr); } ItemStack res = new ItemStack(item, JsonUtil.getIntField(obj, "number", 1), JsonUtil.getIntField(obj, "meta", 0)); String nbt64 = JsonUtil.getStringField(obj, "nbt", null); if(nbt64 != null) { res.stackTagCompound = deserializeNBT(nbt64); } else { try { String nbtString = JsonUtil.getStringField(obj, "nbtString", null); if(nbtString != null) { NBTTagCompound nbt = JsonUtil.parseNBT(nbtString); if(nbt != null) { res.stackTagCompound = nbt; } } } catch (Exception e) { Log.warn("GsonIO.ItemStackIO.deserialize: Could not deserialize nbt string. " + e); } } return res; }
/** * Get an ItemDescriptor from an Item * * @param pItem * @return */ public static ItemDescriptor fromItem( Item pItem ) { ItemDescriptor tRet = null; if( pItem != null ) { UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor( pItem ); tRet = ( UID != null ) ? new ItemDescriptor( UID.modId, UID.name ) : null; } return tRet; }
/** * Get an ItemDescriptor from an ItemStack * * @param pItemStack * @return */ public static ItemDescriptor fromStack( ItemStack pItemStack ) { ItemDescriptor tRet = null; if( pItemStack != null ) { UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor( pItemStack.getItem() ); tRet = ( UID != null ) ? new ItemDescriptor( UID.modId, UID.name, pItemStack.getItemDamage() ) : null; } return tRet; }
public ItemFingerprint(ItemStack stack) { String itemId = GameData.getItemRegistry().getNameForObject(stack.getItem()); this.id = new UniqueIdentifier(itemId); this.damage = stack.getItemDamage(); NBTTagCompound tag = stack.getTagCompound(); this.nbtHash = tag != null? ItemUtils.getNBTHash(tag) : null; }
/** * Forces the specified stack to have a facade if possible. * * @param block * @param meta */ private void forceEnabled( final Block block, final int meta ) { // Sanity check if( block == null ) { return; } // Get the uid for the block UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor( block ); if( uid == null ) { return; } // Get the mod and block names String modName = this.sanitizer.matcher( uid.modId ).replaceAll( "" ); String blockName = this.sanitizer.matcher( uid.name ).replaceAll( "" ); // Get the property Property prop = FacadeConfig.instance.get( modName, blockName + ( meta == 0 ? "" : "." + meta ), true ); // Set it to true prop.set( true ); }
@Override public void processCommand(ICommandSender sender, String[] args) { if (sender instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)sender; ItemStack stack = player.inventory.getCurrentItem(); if (args.length > 0) { stack = new ItemStack(Item.getItemById(Integer.parseInt(args[0]))); } if (stack == null) { sender.addChatMessage(new ChatComponentText("No such item.")); } else { List<String> oreDictNames = new ArrayList<String>(); for (int id : OreDictionary.getOreIDs(stack)) { oreDictNames.add(OreDictionary.getOreName(id)); } String textOreDictNames = ""; for (String oreDictName : oreDictNames) { textOreDictNames += oreDictName + ". "; } if (StringUtils.isNullOrEmpty(textOreDictNames)) { textOreDictNames = "<empty>"; } UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(stack.getItem()); String textUid = uid.modId + ":" + uid.name; sender.addChatMessage(new ChatComponentText("> OreDict Names: " + textOreDictNames)); sender.addChatMessage(new ChatComponentText("> Unique Name: " + textUid)); } } }
static UniqueIdentifier getUniqueName(Block block) { if (block == null) return null; ItemData itemData = idMap.get(block.field_71990_ca); if (itemData == null || !itemData.isOveridden() || customItemStacks.contains(itemData.getModId(), itemData.getItemType())) { return null; } return new UniqueIdentifier(itemData.getModId(), itemData.getItemType()); }
static UniqueIdentifier getUniqueName(Item item) { if (item == null) return null; ItemData itemData = idMap.get(item.field_77779_bT); if (itemData == null || !itemData.isOveridden() || customItemStacks.contains(itemData.getModId(), itemData.getItemType())) { return null; } return new UniqueIdentifier(itemData.getModId(), itemData.getItemType()); }
static UniqueIdentifier getUniqueName(Block block) { if (block == null) return null; ItemData itemData = idMap.get(block.blockID); if (itemData == null || !itemData.isOveridden() || customItemStacks.contains(itemData.getModId(), itemData.getItemType())) { return null; } return new UniqueIdentifier(itemData.getModId(), itemData.getItemType()); }