Java Code Examples for cpw.mods.fml.common.registry.GameRegistry#findUniqueIdentifierFor()
The following examples show how to use
cpw.mods.fml.common.registry.GameRegistry#findUniqueIdentifierFor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OreDictHandler.java From bartworks with MIT License | 6 votes |
public static void adaptCacheForWorld(){ Set<String> used = new HashSet<>(OreDictHandler.cache.keySet()); OreDictHandler.cache.clear(); OreDictHandler.cacheNonBW.clear(); for (String s : used) { if (!OreDictionary.getOres(s).isEmpty()) { ItemStack tmpstack = OreDictionary.getOres(s).get(0).copy(); Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(tmpstack.getItem()), (short) tmpstack.getItemDamage()); OreDictHandler.cache.put(s, p); for (ItemStack tmp : OreDictionary.getOres(s)) { Pair<Integer, Short> p2 = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem()); if (UI == null) UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem())); if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")) { OreDictHandler.cacheNonBW.add(p2); } } } } }
Example 2
Source File: PneumaticCraftUtils.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
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); }
Example 3
Source File: ItemStackMetadataBuilder.java From OpenPeripheral with MIT License | 6 votes |
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; }
Example 4
Source File: CustomToolTips.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 5 votes |
public ItemToolTip FindItemToolTip( ItemStack pItem ) { try { Init(); if( pItem == null ) { return null; } //String tUnlocName = pItem.getUnlocalizedName(); GameRegistry.UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor( pItem.getItem() ); String tCompareName = UID.toString(); if( pItem.getItemDamage() > 0 ) { tCompareName = String.format("%s:%d", tCompareName, pItem.getItemDamage()); } for( ItemToolTip itt : mToolTips ) { //if (itt.getUnlocalizedName().equalsIgnoreCase(tUnlocName)) return itt; if( itt.mUnlocalizedName.equalsIgnoreCase( tCompareName ) ) { return itt; } } return null; } catch( Exception e ) { return null; } }
Example 5
Source File: HazardousItemsHandler.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 5 votes |
/** * 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(); } }
Example 6
Source File: CustomFuels.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 5 votes |
public FuelItem FindFuelValue(ItemStack pItem) { try { Init(); if (pItem == null) { return null; } GameRegistry.UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor(pItem.getItem()); String tCompareName = UID.toString(); if (pItem.getItemDamage() > 0) { tCompareName = String.format("%s:%d", tCompareName, pItem.getItemDamage()); } for (FuelItem ifi : mFuelItems) { if (ifi.mItemName.equalsIgnoreCase(tCompareName)) { return ifi; } } return null; } catch (Exception e) { return null; } }
Example 7
Source File: ItemInHandInfoCommand.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 5 votes |
@Override public void processCommand(ICommandSender pCmdSender, String[] pArgs) { try { if (!InGame(pCmdSender)) { PlayerChatHelper.SendPlain(pCmdSender, "You have to execute this command ingame"); return; } EntityPlayer tEp = (EntityPlayer) pCmdSender; ItemStack inHand = null; if (tEp != null) { inHand = tEp.getCurrentEquippedItem(); if (inHand == null) { PlayerChatHelper.SendPlain(pCmdSender, "Pickup an item first"); return; } } GameRegistry.UniqueIdentifier UID = GameRegistry.findUniqueIdentifierFor(inHand.getItem()); PlayerChatHelper.SendPlain(pCmdSender, "== Item info"); PlayerChatHelper.SendPlain(pCmdSender, String.format("Unloc.Name: [%s]", inHand.getUnlocalizedName())); PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemName: [%s]", UID.toString())); PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemMeta: [%s]", inHand.getItemDamage())); PlayerChatHelper.SendPlain(pCmdSender, String.format("FluidContainer: [%s]", getFluidContainerContents(inHand))); PlayerChatHelper.SendPlain(pCmdSender, String.format("ClassName: [%s]", inHand.getItem().getClass().toString())); PlayerChatHelper.SendPlain(pCmdSender, String.format("ItemNBT: [%s]", inHand.stackTagCompound)); } catch (Exception e) { e.printStackTrace(); PlayerChatHelper.SendError(pCmdSender, "Unknown error occoured"); } }
Example 8
Source File: BiomesOPlenty.java From GardenCollection with MIT License | 5 votes |
@Override public int getPlantHeight (Block block, int meta) { GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(block); if (uid.name.equals("foliage")) { if (meta == 3) return 2; } return 1; }
Example 9
Source File: BiomesOPlenty.java From GardenCollection with MIT License | 5 votes |
@Override public int getPlantSectionMeta (Block block, int meta, int section) { GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(block); if (uid.name.equals("foliage")) { if (meta == 3) return (section == 1) ? 3 : 6; } return meta; }
Example 10
Source File: RadioHatchCompat.java From bartworks with MIT License | 4 votes |
public static void run() { DebugLog.log("Starting Generation of missing GT++ rods/longrods"); try { Class rodclass = Class.forName("gtPlusPlus.core.item.base.rods.BaseItemRod"); Class longrodclass = Class.forName("gtPlusPlus.core.item.base.rods.BaseItemRodLong"); Constructor<? extends Item> c1 = rodclass.getConstructor(RadioHatchCompat.materialClass); Constructor<? extends Item> c2 = longrodclass.getConstructor(RadioHatchCompat.materialClass); Field cOwners = GameData.class.getDeclaredField("customOwners"); cOwners.setAccessible(true); Field map = RegistryNamespaced.class.getDeclaredField("field_148758_b"); map.setAccessible(true); Map<Item,String> UniqueIdentifierMap = (Map<Item, String>) map.get(GameData.getItemRegistry()); Map<GameRegistry.UniqueIdentifier, ModContainer> ownerItems = (Map<GameRegistry.UniqueIdentifier, ModContainer>) cOwners.get(null); ModContainer gtpp = null; ModContainer bartworks = null; for (ModContainer container : Loader.instance().getModList()){ if (gtpp != null && bartworks != null) break; else if (container.getModId().equalsIgnoreCase(BartWorksCrossmod.MOD_ID)) bartworks=container; else if (container.getModId().equalsIgnoreCase("miscutils")) gtpp=container; } for (Object mats : (Set) RadioHatchCompat.materialClass.getField("mMaterialMap").get(null)) { if (RadioHatchCompat.isRadioactive.getBoolean(mats)) { if (OreDictionary.getOres("stick" + RadioHatchCompat.unlocalizedName.get(mats)).isEmpty()) { Item it = c1.newInstance(mats); UniqueIdentifierMap.replace(it,"miscutils:"+it.getUnlocalizedName()); GameRegistry.UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(it); ownerItems.replace(ui,bartworks,gtpp); String tanslate = it.getUnlocalizedName()+".name="+RadioHatchCompat.localizedName.get(mats)+" Rod"; RadioHatchCompat.TranslateSet.add(tanslate); DebugLog.log(tanslate); DebugLog.log("Generate: " + RadioHatchCompat.rod + RadioHatchCompat.unlocalizedName.get(mats)); } if (OreDictionary.getOres("stickLong" + RadioHatchCompat.unlocalizedName.get(mats)).isEmpty()) { Item it2 = c2.newInstance(mats); UniqueIdentifierMap.replace(it2,"miscutils:"+it2.getUnlocalizedName()); GameRegistry.UniqueIdentifier ui2 = GameRegistry.findUniqueIdentifierFor(it2); ownerItems.replace(ui2,bartworks,gtpp); DebugLog.log("Generate: " + RadioHatchCompat.longRod + RadioHatchCompat.unlocalizedName.get(mats)); } } } } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { e.printStackTrace(); } }
Example 11
Source File: TooltipEventHandler.java From bartworks with MIT License | 4 votes |
@SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.HIGHEST) public void getTooltip(ItemTooltipEvent event) { if (event == null || event.itemStack == null || event.itemStack.getItem() == null) return; if (TooltipCache.getTooltip(event.itemStack).isEmpty()) { ItemStack tmp = event.itemStack.copy(); Pair<Integer,Short> abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); List<String> tooAdd = new ArrayList<>(); if (OreDictHandler.getNonBWCache().contains(abstractedStack)) { for (Pair<Integer,Short> pair : OreDictHandler.getNonBWCache()) { if (pair.equals(abstractedStack)) { GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem()); if (UI == null) UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem())); if (UI != null) { for (ModContainer modContainer : Loader.instance().getModList()) { if (UI.modId.equals(MainMod.MOD_ID) || UI.modId.equals(BartWorksCrossmod.MOD_ID) || UI.modId.equals("BWCore")) break; if (UI.modId.equals(modContainer.getModId())) { tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and " + ChatColorHelper.RED + modContainer.getName()); } } } else tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and another Mod, that doesn't use the ModContainer propperly!"); } } } Block BLOCK = Block.getBlockFromItem(event.itemStack.getItem()); if (BLOCK != null && BLOCK != Blocks.air) { if (BLOCK instanceof BW_Blocks) { TooltipCache.put(event.itemStack, tooAdd); return; } BioVatLogicAdder.BlockMetaPair PAIR = new BioVatLogicAdder.BlockMetaPair(BLOCK, (byte) event.itemStack.getItemDamage()); HashMap<BioVatLogicAdder.BlockMetaPair, Byte> GLASSMAP = BioVatLogicAdder.BioVatGlass.getGlassMap(); if (GLASSMAP.containsKey(PAIR)) { int tier = GLASSMAP.get(PAIR); tooAdd.add( StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(tier) + GT_Values.VN[tier] + ChatColorHelper.RESET); } else if (BLOCK.getMaterial().equals(Material.glass)) { tooAdd.add(StatCollector.translateToLocal("tooltip.glas.0.name") + " " + BW_ColorUtil.getColorForTier(3) + GT_Values.VN[3] + ChatColorHelper.RESET); } } TooltipCache.put(event.itemStack, tooAdd); event.toolTip.addAll(tooAdd); } else { event.toolTip.addAll(TooltipCache.getTooltip(event.itemStack)); } }
Example 12
Source File: StaticRecipeChangeLoaders.java From bartworks with MIT License | 4 votes |
@SuppressWarnings("ALL") private static void runMoltenUnificationEnfocement(Werkstoff werkstoff) { if (werkstoff.getGenerationFeatures().enforceUnification && werkstoff.hasItemType(WerkstoffLoader.cellMolten)) { try { FluidContainerRegistry.FluidContainerData data = new FluidContainerRegistry.FluidContainerData(new FluidStack(Objects.requireNonNull(molten.get(werkstoff)), 144), werkstoff.get(WerkstoffLoader.cellMolten), Materials.Empty.getCells(1)); Field f = GT_Utility.class.getDeclaredField("sFilledContainerToData"); f.setAccessible(true); Map<GT_ItemStack, FluidContainerRegistry.FluidContainerData> sFilledContainerToData = (Map<GT_ItemStack, FluidContainerRegistry.FluidContainerData>) f.get(null); HashSet torem = new HashSet<>(); ItemStack toReplace = null; for (Map.Entry<GT_ItemStack, FluidContainerRegistry.FluidContainerData> entry : sFilledContainerToData.entrySet()) { final String MODID = GameRegistry.findUniqueIdentifierFor(data.filledContainer.getItem()).modId; if (MODID.equals(MainMod.MOD_ID) || MODID.equals(BartWorksCrossmod.MOD_ID)) continue; if (entry.getValue().fluid.equals(data.fluid) && !entry.getValue().filledContainer.equals(data.filledContainer)) { toReplace = entry.getValue().filledContainer; torem.add(entry); } } sFilledContainerToData.entrySet().removeAll(torem); torem.clear(); if (toReplace != null) { for (GT_Recipe.GT_Recipe_Map map : GT_Recipe.GT_Recipe_Map.sMappings) { torem.clear(); for (GT_Recipe recipe : map.mRecipeList) { for (int i = 0; i < recipe.mInputs.length; i++) { if (GT_Utility.areStacksEqual(recipe.mInputs[i], toReplace)) { torem.add(recipe); // recipe.mInputs[i] = data.filledContainer; } } for (int i = 0; i < recipe.mOutputs.length; i++) { if (GT_Utility.areStacksEqual(recipe.mOutputs[i], toReplace)) { torem.add(recipe); // recipe.mOutputs[i] = data.filledContainer; if (map == GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes && GT_Utility.areStacksEqual(recipe.mOutputs[i], data.filledContainer) && !recipe.mFluidInputs[0].equals(data.fluid)) { torem.add(recipe); // recipe.mOutputs[i] = data.filledContainer; } } } if (recipe.mSpecialItems instanceof ItemStack) { if (GT_Utility.areStacksEqual((ItemStack) recipe.mSpecialItems, toReplace)) { torem.add(recipe); // recipe.mSpecialItems = data.filledContainer; } } } map.mRecipeList.removeAll(torem); } } GT_Utility.addFluidContainerData(data); } catch (NoSuchFieldException | IllegalAccessException | ClassCastException e) { e.printStackTrace(); } } }
Example 13
Source File: TileEntityQuantumComputer.java From qcraft-mod with Apache License 2.0 | 4 votes |
public static void teleportPlayerRemote( EntityPlayer player, String remoteServerAddress, String remotePortalID, boolean takeItems ) { // Log the trip QCraft.log( "Sending player " + player.getDisplayName() + " to server \"" + remoteServerAddress + "\"" ); NBTTagCompound luggage = new NBTTagCompound(); if( takeItems ) { // Remove and encode the items from the players inventory we want them to take with them NBTTagList items = new NBTTagList(); InventoryPlayer playerInventory = player.inventory; for( int i = 0; i < playerInventory.getSizeInventory(); ++i ) { ItemStack stack = playerInventory.getStackInSlot( i ); if( stack != null && stack.stackSize > 0 ) { // Ignore entangled items if( stack.getItem() == Item.getItemFromBlock( QCraft.Blocks.quantumComputer ) && ItemQuantumComputer.getEntanglementFrequency( stack ) >= 0 ) { continue; } if( stack.getItem() == Item.getItemFromBlock( QCraft.Blocks.qBlock ) && ItemQBlock.getEntanglementFrequency( stack ) >= 0 ) { continue; } // Store items NBTTagCompound itemTag = new NBTTagCompound(); if (stack.getItem() == QCraft.Items.missingItem) { itemTag = stack.stackTagCompound; } else { GameRegistry.UniqueIdentifier uniqueId = GameRegistry.findUniqueIdentifierFor(stack.getItem()); String itemName = uniqueId.modId + ":" + uniqueId.name; itemTag.setString("Name", itemName); stack.writeToNBT( itemTag ); } items.appendTag( itemTag ); // Remove items playerInventory.setInventorySlotContents( i, null ); } } if( items.tagCount() > 0 ) { QCraft.log( "Removed " + items.tagCount() + " items from " + player.getDisplayName() + "'s inventory." ); playerInventory.markDirty(); luggage.setTag( "items", items ); } } // Set the destination portal ID if( remotePortalID != null ) { luggage.setString( "destinationPortal", remotePortalID ); } try { // Cryptographically sign the luggage luggage.setString( "uuid", UUID.randomUUID().toString() ); byte[] luggageData = CompressedStreamTools.compress( luggage ); byte[] luggageSignature = EncryptionRegistry.Instance.signData( luggageData ); NBTTagCompound signedLuggage = new NBTTagCompound(); signedLuggage.setByteArray( "key", EncryptionRegistry.Instance.encodePublicKey( EncryptionRegistry.Instance.getLocalKeyPair().getPublic() ) ); signedLuggage.setByteArray( "luggage", luggageData ); signedLuggage.setByteArray( "signature", luggageSignature ); // Send the player to the remote server with the luggage byte[] signedLuggageData = CompressedStreamTools.compress( signedLuggage ); QCraft.requestGoToServer( player, remoteServerAddress, signedLuggageData ); } catch( IOException e ) { throw new RuntimeException( "Error encoding inventory" ); } finally { // Prevent the player from being warped twice player.timeUntilPortal = 200; } }
Example 14
Source File: WikiHooks.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
public static IWikiProvider getWikiFor(Block block) { UniqueIdentifier mod = GameRegistry.findUniqueIdentifierFor(block); return getWikiFor(mod == null ? "" : mod.modId.toLowerCase()); }