Java Code Examples for cpw.mods.fml.common.registry.GameRegistry#UniqueIdentifier

The following examples show how to use cpw.mods.fml.common.registry.GameRegistry#UniqueIdentifier . 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 vote down vote up
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: CustomToolTips.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
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 3
Source File: CustomFuels.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: ItemInHandInfoCommand.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: BiomesOPlenty.java    From GardenCollection with MIT License 5 votes vote down vote up
@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 6
Source File: BiomesOPlenty.java    From GardenCollection with MIT License 5 votes vote down vote up
@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 7
Source File: RadioHatchCompat.java    From bartworks with MIT License 4 votes vote down vote up
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 8
Source File: TooltipEventHandler.java    From bartworks with MIT License 4 votes vote down vote up
@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 9
Source File: TileEntityQuantumComputer.java    From qcraft-mod with Apache License 2.0 4 votes vote down vote up
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 10
Source File: UniqueMetaIdentifier.java    From GardenCollection with MIT License 4 votes vote down vote up
public GameRegistry.UniqueIdentifier getUniqueIdentifier () {
    if (cachedUID == null)
        cachedUID = new GameRegistry.UniqueIdentifier(modId + ":" + name);
    return cachedUID;
}
 
Example 11
Source File: IUniqueID.java    From GardenCollection with MIT License 2 votes vote down vote up
/**
 * Gets the Forge {@link cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier} representation of the unique ID, which doesn't carry the mod ID.
 */
GameRegistry.UniqueIdentifier getUniqueIdentifier ();
 
Example 12
Source File: IUniqueID.java    From GardenCollection with MIT License 2 votes vote down vote up
/**
 * Gets the Forge {@link GameRegistry.UniqueIdentifier} representation of the unique ID, which doesn't carry the mod ID.
 */
GameRegistry.UniqueIdentifier getUniqueIdentifier ();