private static int SpecifiedItem(String color, int added, short[] dmgs, String[] itemId, String identifier) { for (ResourceLocation key : GameData.getItemRegistry().getKeys()) { if (key.toString().startsWith(identifier)) { int id = GameData.getItemRegistry().getId(key); Item item = Item.getItemById(id); if (item == null) { if (itemId[0].equals("minecraft") || Loader.isModLoaded(itemId[0])) Log.warn("Stumbled upon invalid entry in item registry while parsing whitelist $1, object not found: $0", key, color); continue; } getList(color).put(item, dmgs); ++added; } } return added; }
private static int SpecifiedBlock(String color, int added, short[] dmgs, String[] itemId, String identifier) { for (ResourceLocation key : GameData.getBlockRegistry().getKeys()) { if (key.toString().startsWith(identifier)) { int id = GameData.getBlockRegistry().getId(key); Block block = Block.getBlockById(id); if (block == null) { if (itemId[0].equals("minecraft") || Loader.isModLoaded(itemId[0])) Log.warn("Stumbled upon invalid entry in block registry while parsing whitelist $1, object not found: $0", key, color); continue; } getList(color).put(Item.getItemFromBlock(block), dmgs); ++added; } } return added; }
private static String catagorize(ItemStack i) { StringBuilder sb = new StringBuilder(); Item item = i.getItem(); sb.append(GameData.getItemRegistry().getNameForObject(item).getResourceDomain()); if(item instanceof ItemBlock){ if(((ItemBlock)item).getBlock() instanceof ITileEntityProvider){ sb.append("A"); } else { sb.append("B"); } } else { sb.append("I"); } sb.append(item.getUnlocalizedName()); sb.append(i.getMetadata()); return sb.toString(); }
public static @Nonnull NNList<ItemStack> getValidItems() { final NNList<ItemStack> list = new NNList<ItemStack>(); final NNList<ItemStack> sublist = new NNList<ItemStack>(); for (final Item item : GameData.getItemRegistry()) { for (CreativeTabs tab : item.getCreativeTabs()) { EnderIO.proxy.getSubItems(NullHelper.notnullM(item, "Null item in game registry"), tab, sublist); sublist.apply(new Callback<ItemStack>() { @Override public void apply(@Nonnull ItemStack stack) { if (Prep.isInvalid(stack)) { Log.error("The item " + item + " (" + item.getUnlocalizedName() + ") produces empty itemstacks in getSubItems()"); } else if (stack.getItem() == Items.AIR) { Log.error("The item " + item + " (" + item.getUnlocalizedName() + ") produces itemstacks without item in getSubItems()"); } else { list.add(stack); } } }); sublist.clear(); } } return list; }
private void loadChunk(int id, Shader shader, ExtendedBlockStorage storage) { ObjectIntIdentityMap<IBlockState> map = GameData.getBlockStateIDMap(); int[] data = new int[chunkSize*2]; for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { IBlockState state = storage.get(x, y, z); boolean fullBlock = state.isFullBlock(); boolean cube = state.isFullCube(); if (fullBlock != cube) { Log.info(state.getBlock().getUnlocalizedName() + ": " + fullBlock); } if (fullBlock) { stateSet.add(state); } int stateId = map.get(state); //TODO data[(y<<9) + (z<<5) + (x<<1)] = Block.getIdFromBlock(storage.get(x, y, z).getBlock()); } } } for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { data[(y<<9) + (z<<5) + (x<<1) + 1] = storage.getBlocklightArray().get(x, y, z); } } } IntBuffer buffer = BufferUtils.createIntBuffer(chunkSize*2); buffer.put(data); buffer.flip(); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shader.getChunkSsbo()); GL15.glBufferSubData(GL43.GL_SHADER_STORAGE_BUFFER, (id-1)*chunkSize*2*4, buffer); GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, 0); }
/** * Remap the missing item to the specified Block. * * Use this if you have renamed a Block, don't forget to handle the ItemBlock. * Existing references using the old name will point to the new one. * * @param target Block to remap to. */ public void remap(Block target) { if (type != GameRegistry.Type.BLOCK) throw new IllegalArgumentException("Can't remap an item to a block."); if (target == null) throw new NullPointerException("remap target is null"); if (GameData.getBlockRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified block %s hasn't been registered at startup.", target)); action = Action.REMAP; this.target = target; }
/** * Remap the missing item to the specified Item. * * Use this if you have renamed an Item. * Existing references using the old name will point to the new one. * * @param target Item to remap to. */ public void remap(Item target) { if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Can't remap a block to an item."); if (target == null) throw new NullPointerException("remap target is null"); if (GameData.getItemRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified item %s hasn't been registered at startup.", target)); action = Action.REMAP; this.target = target; }
/** * Gets all the integer ID for the ores that the specified item stack is registered to. * If the item stack is not linked to any ore, this will return an empty array and no new entry will be created. * * @param stack The item stack of the ore. * @return An array of ids that this ore is registered as. */ public static int[] getOreIDs(ItemStack stack) { if (stack == null || stack.getItem() == null) throw new IllegalArgumentException("Stack can not be null!"); Set<Integer> set = new HashSet<Integer>(); // HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet // IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about. // APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game. ResourceLocation registryName = stack.getItem().delegate.name(); int id; if (registryName == null) { FMLLog.log(Level.DEBUG, "Attempted to find the oreIDs for an unregistered object (%s). This won't work very well.", stack); return new int[0]; } else { id = GameData.getItemRegistry().getId(registryName); } List<Integer> ids = stackToId.get(id); if (ids != null) set.addAll(ids); ids = stackToId.get(id | ((stack.getItemDamage() + 1) << 16)); if (ids != null) set.addAll(ids); Integer[] tmp = set.toArray(new Integer[set.size()]); int[] ret = new int[tmp.length]; for (int x = 0; x < tmp.length; x++) ret[x] = tmp[x]; return ret; }
public static void rebakeMap() { //System.out.println("Baking OreDictionary:"); stackToId.clear(); for (int id = 0; id < idToStack.size(); id++) { List<ItemStack> ores = idToStack.get(id); if (ores == null) continue; for (ItemStack ore : ores) { // HACK: use the registry name's ID. It is unique and it knows about substitutions ResourceLocation name = ore.getItem().delegate.name(); int hash; if (name == null) { FMLLog.log(Level.DEBUG, "Defaulting unregistered ore dictionary entry for ore dictionary %s: type %s to -1", getOreName(id), ore.getItem().getClass()); hash = -1; } else { hash = GameData.getItemRegistry().getId(name); } if (ore.getItemDamage() != WILDCARD_VALUE) { hash |= ((ore.getItemDamage() + 1) << 16); // +1 so meta 0 is significant } List<Integer> ids = stackToId.get(hash); if (ids == null) { ids = Lists.newArrayList(); stackToId.put(hash, ids); } ids.add(id); //System.out.println(id + " " + getOreName(id) + " " + Integer.toHexString(hash) + " " + ore); } } }
protected PotionBase(String name, boolean isBadEffectIn, int liquidColorIn) { super(isBadEffectIn, liquidColorIn); this.setRegistryName(new ResourceLocation(Reference.MOD_ID,name)); GameData.getPotionRegistry().register(this); }
public void generate(Random random, int chunkX, int chunkZ, World world, OreConfig config) { Block block = GameData.getBlockRegistry().getObject(config.getBlock()); Block block2 = GameData.getBlockRegistry().getObject(config.getReplacementBlock()); if (block2 == null) { block2 = Blocks.STONE; } WorldGenMinable worldGenMinable = new WorldGenMinable(block.getDefaultState(), config.veinSize, BlockMatcher.forBlock(block2)); int xPos, yPos, zPos; for (int i = 0; i < config.veinsPerChunk; i++) { xPos = chunkX * 16 + random.nextInt(16); yPos = 10 + random.nextInt(config.maxYHeight - config.minYHeight); zPos = chunkZ * 16 + random.nextInt(16); worldGenMinable.generate(world, random, new BlockPos(xPos, yPos, zPos)); } }
@SuppressWarnings("deprecation") private static String getModNameFromItem(ItemStack stack) { try { ResourceLocation resource = GameData.getItemRegistry().getNameForObject(stack.getItem()); ModContainer mod = findModContainer(resource.getResourceDomain()); return mod == null ? "Minecraft" : mod.getName(); } catch (NullPointerException e) { return ""; } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static IBlockState createState(String block, HashMap<String, String> properties) { Block foundBlock = GameData.getBlockRegistry().getObject(new ResourceLocation(block)); ImmutableList<IBlockState> states = foundBlock.getBlockState().getValidStates(); Iterator<IBlockState> iterator = states.iterator(); while (iterator.hasNext()) { boolean isCorrectState = true; IBlockState state = iterator.next(); ImmutableMap<IProperty, Comparable> stateProps = state.getProperties(); Iterator<Entry<IProperty, Comparable>> propIterater = stateProps.entrySet().iterator(); while(propIterater.hasNext()) { Entry<IProperty, Comparable> entry = propIterater.next(); IProperty property = entry.getKey(); if(properties.containsKey(property.getName())) { if(!state.getValue(property).toString().contentEquals(properties.get(property.getName()))) { isCorrectState = false; } } } if(isCorrectState) { return state; } } GenLoaderAPI.log.log(Level.WARN, "Block: *" + block + "* with properties: *" + properties + "* was not found, resorting to block's default state"); return foundBlock.getDefaultState(); }
public WeightedBlockState(int Weight, IBlockState State) { this.weight = Weight; this.block = GameData.getBlockRegistry().getNameForObject(State.getBlock()).toString(); this.properties = BlockUtils.generateProperties(State); this.state = State; }
/** Gets the list of possible blocks that can be crafted (clientside only) */ @SideOnly(Side.CLIENT) public static List getAllEligibleItemStacks() { JointList<ItemStack> list = new JointList<ItemStack>(); if(!EBConfig.enableCreativeTabVariants) return list; // iterate through all the items Iterable<Item> allItems; allItems = GameData.getItemRegistry().typeSafeIterable(); for(Item i : allItems) { // check to make sure the mod for the item is not BL'd String modId = i.getRegistryName().getResourceDomain(); if(EBConfig.blacklistedMods.contains(modId)) continue; // get all of the exposed subitems for this item JointList<ItemStack> j = new JointList<ItemStack>(); if(i instanceof IOverrideEBSubtypes) { ((IOverrideEBSubtypes)i).getEBSubtypes(i, j); } else { i.getSubItems(i, CreativeTabs.SEARCH, j); } for(ItemStack s : j) { // check each one for eligibility ItemStack dupe = s.copy(); dupe.stackSize = 9; // the amount of blocks to hold if(isItemStackValid(s)) { if(isItemStackCraftable(s)) list.join(dupe); // add to the list } } } return list; }
private static void bindHooks() { ChestGenHooks hooks = ChestGenHooks.getInfo("Placemod"); for (ResourceLocation itemName : GameData.getItemRegistry().getKeys()) { Item item = Item.itemRegistry.getObject(itemName); int maxDmg = item.getMaxDamage(); for (int meta = 0; meta <= maxDmg; ++meta) { hooks.addItem(new WeightedRandomChestContent(new ItemStack(item, 1, meta), 1, maxChestStackSize, 256 / (1 + maxDmg))); } } hooks.setMin(minChestItems); hooks.setMax(maxChestItems); }
@Override public List<ResourceLocation> getItemVariants () { ResourceLocation location = GameData.getItemRegistry().getNameForObject(this); List<ResourceLocation> variants = new ArrayList<ResourceLocation>(); for (EnumCompDrawer type : EnumCompDrawer.values()) variants.add(new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + '_' + type.getName())); return variants; }
private void setupItemList() { String domain = domainListModel.get(domainListSelection) + ":"; FMLControlledNamespacedRegistry<Item> r1 = GameData.getItemRegistry(); cachedItems.clear(); for(Object keyobj : r1.getKeys()) { String name = keyobj.toString(); int index = name.indexOf(':'); if((index < 0 && domain.equals("minecraft:")) || name.startsWith(domain)) { String fillName = index < 0 ? name : name.substring(index + 1); Item item = r1.getObject(name); if(item.getHasSubtypes()) { List<ItemStack> itemStacks = new ArrayList<ItemStack>(); item.getSubItems(item, item.getCreativeTab(), itemStacks); int id = 0; for(ItemStack stack : itemStacks) { String indexName = String.format("%s:%03d", fillName, id++); if(checkMatches(indexName, currentFilterPattern)) { itemListModel.add(indexName); cachedItems.put(indexName, stack); } } } else { if(checkMatches(fillName, currentFilterPattern)) { itemListModel.add(fillName); cachedItems.put(fillName, new ItemStack(r1.getObject(name))); } } } } }
@SubscribeEvent public void procOnDeath(LivingDeathEvent event) { if (Settings.Abilities.canProc && event.getSource().getEntity() instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) event.getSource().getEntity(); if (!player.isEntityEqual(event.getEntity()) && isUsingProcSword(player)) { spawnParticle(player, 1.4, 1.3); spawnParticle(player, 1.4, 0.3); if (!player.worldObj.isRemote) { player.addPotionEffect(new PotionEffect(GameData.getPotionRegistry().getObjectById(5), 9)); player.addPotionEffect(new PotionEffect(GameData.getPotionRegistry().getObjectById(1), 2)); } } } }
private static int SpecifiedEntry(String color, int added, String entry, short[] dmgs, String[] itemId) { Item item = GameData.getItemRegistry().getValue(new ResourceLocation(itemId[0], itemId[1])); if (item == null) { Block block = GameData.getBlockRegistry().getValue(new ResourceLocation(itemId[0], itemId[1])); if (block == null) { if (itemId[0].equals("minecraft") || Loader.isModLoaded(itemId[0])) Log.warn("Invalid entry in whitelist $1, item not found: $0", entry, color); return added; } else item = Item.getItemFromBlock(block); } getList(color).put(item, dmgs); ++added; return added; }
private Map<String, Set<Block>> sortBlocksByModID() { Map<String, Set<Block>> modMap = new HashMap<>(); GameData.getBlockRegistry().forEach((Block b)->{ final String modid = GameData.getBlockRegistry().getNameForObject(b).getResourceDomain(); modMap.computeIfAbsent(modid, (String id)->new HashSet<Block>()); modMap.get(modid).add(b); }); return Collections.unmodifiableMap(modMap); }
/** * Writes ZSSQuest data to the tag compound * @param syncOnly True to ignore quests for which {@link IQuest#requiresSync} returns false */ public void writeToNBT(NBTTagCompound compound, boolean syncOnly) { NBTTagList questList = new NBTTagList(); for (IQuest quest : quests.values()) { if (!syncOnly || quest.requiresSync()) { questList.appendTag(QuestBase.saveToNBT(quest)); } } compound.setTag("ZssQuests", questList); ResourceLocation maskId = (borrowedMask == null ? null : (ResourceLocation) GameData.getItemRegistry().getNameForObject(borrowedMask)); if (maskId != null) { compound.setString("borrowedMask", maskId.toString()); } }
@Override public int compare(Item a, Item b) { if (itemList.containsKey(a) && itemList.containsKey(b)) { return itemList.get(a) - itemList.get(b); } else { ZSSMain.logger.warn("A mod item " + a.getUnlocalizedName() + " or " + b.getUnlocalizedName() + " is missing a comparator mapping"); return GameData.getItemRegistry().getId(a) - GameData.getItemRegistry().getId(b); } }
public static int getMaxEnchants() { if(MAX_ENCHANTS == INVALID){ try { Field field = GameData.class.getDeclaredField("MAX_ENCHANTMENT_ID"); field.setAccessible(true); MAX_ENCHANTS = (Integer) field.get(null); }catch (Exception printed){ printed.printStackTrace(); } } return MAX_ENCHANTS; }
@Nonnull @Override public List<String> getTabCompletions(MinecraftServer server, ICommandSender par1ICommandSender, String[] par2ArrayOfStr, BlockPos pos) { if(par2ArrayOfStr.length == 1) return getListOfStringsMatchingLastWord(par2ArrayOfStr, searchModes); else if(par2ArrayOfStr.length == 2) { if(par2ArrayOfStr[0].equals(searchModes[0])||par2ArrayOfStr[0].equals(searchModes[1])) return getListOfStringsMatchingLastWord(par2ArrayOfStr, getNames(WeaponRegistry.Wield.values(), true)); else if(par2ArrayOfStr[0].equals(searchModes[2]))//sensitivity return getListOfStringsMatchingLastWord(par2ArrayOfStr, operations); } else if(par2ArrayOfStr.length == 3) { if (par2ArrayOfStr[0].equals(searchModes[0]))//current return getListOfStringsMatchingLastWord(par2ArrayOfStr, server.getOnlinePlayerNames()); else if(par2ArrayOfStr[0].equals(searchModes[1]))//name return getListOfStringsMatchingLastWord(par2ArrayOfStr, GameData.getItemRegistry().getKeys()); else if (par2ArrayOfStr[0].equals(searchModes[2])) {//sensitivity if(par2ArrayOfStr[1].equals(operations[0]))//add return getListOfStringsMatchingLastWord(par2ArrayOfStr, Sets.difference(ImmutableSet.copyOf(getNames(WeaponRegistry.Sensitivity.values(), false)), sensitivities)); else if(par2ArrayOfStr[1].equals(operations[1])) {//remove return getListOfStringsMatchingLastWord(par2ArrayOfStr, sensitivities); } } } else if(par2ArrayOfStr.length == 4) { return getListOfStringsMatchingLastWord(par2ArrayOfStr, "true", "1", "false", "0"); } return super.getTabCompletions(server, par1ICommandSender, par2ArrayOfStr, pos); }
private static void register(Block block, ItemBlock itemBlock, String name) { GameRegistry.registerBlock(block.setRegistryName(name), (Class<? extends ItemBlock>) null); GameRegistry.registerItem(itemBlock.setRegistryName(name)); GameData.getBlockItemMap().put(block, itemBlock); }
public void skipItemBlock() { if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Cannot skip an item that is a block"); if (GameData.getBlockRegistry().getRaw(id) == null) throw new IllegalArgumentException("Cannot skip an ItemBlock that doesn't have a Block"); action = Action.BLOCKONLY; }
/** * Registers a ore item into the dictionary. * Raises the registerOre function in all registered handlers. * * @param name The name of the ore * @param ore The ore's ItemStack */ private static void registerOreImpl(String name, ItemStack ore) { if ("Unknown".equals(name)) return; //prevent bad IDs. if (ore == null || ore.getItem() == null) { FMLLog.bigWarning("Invalid registration attempt for an Ore Dictionary item with name %s has occurred. The registration has been denied to prevent crashes. The mod responsible for the registration needs to correct this.", name); return; //prevent bad ItemStacks. } int oreID = getOreID(name); // HACK: use the registry name's ID. It is unique and it knows about substitutions. Fallback to a -1 value (what Item.getIDForItem would have returned) in the case where the registry is not aware of the item yet // IT should be noted that -1 will fail the gate further down, if an entry already exists with value -1 for this name. This is what is broken and being warned about. // APPARENTLY it's quite common to do this. OreDictionary should be considered alongside Recipes - you can't make them properly until you've registered with the game. ResourceLocation registryName = ore.getItem().delegate.name(); int hash; if (registryName == null) { FMLLog.bigWarning("A broken ore dictionary registration with name %s has occurred. It adds an item (type: %s) which is currently unknown to the game registry. This dictionary item can only support a single value when" + " registered with ores like this, and NO I am not going to turn this spam off. Just register your ore dictionary entries after the GameRegistry.\n" + "TO USERS: YES this is a BUG in the mod "+Loader.instance().activeModContainer().getName()+" report it to them!", name, ore.getItem().getClass()); hash = -1; } else { hash = GameData.getItemRegistry().getId(registryName); } if (ore.getItemDamage() != WILDCARD_VALUE) { hash |= ((ore.getItemDamage() + 1) << 16); // +1 so 0 is significant } //Add things to the baked version, and prevent duplicates List<Integer> ids = stackToId.get(hash); if (ids != null && ids.contains(oreID)) return; if (ids == null) { ids = Lists.newArrayList(); stackToId.put(hash, ids); } ids.add(oreID); //Add to the unbaked version ore = ore.copy(); idToStack.get(oreID).add(ore); MinecraftForge.EVENT_BUS.post(new OreRegisterEvent(name, ore)); }
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws PlayerNotFoundException, NumberInvalidException { if (args.length == 0) { sender.sendMessage(new TextComponentString("Use some args!")); } else if (args[0].equals("getname")) { EntityPlayer player = (EntityPlayer) sender; if (player.getHeldItem(EnumHand.MAIN_HAND) != null) { Block block = Block.getBlockFromItem(player.getHeldItem(EnumHand.MAIN_HAND).getItem()); if (block != null && block != Blocks.AIR) { sender.sendMessage(new TextComponentString(GameData.getBlockRegistry().getNameForObject(block) + " with a meta of " + player.getHeldItem(EnumHand.MAIN_HAND).getItemDamage())); } else { ((EntityPlayer) sender).sendMessage(new TextComponentString("hold a Block!")); } } else { ((EntityPlayer) sender).sendMessage(new TextComponentString("hold an item!")); } } else if (args[0].equals("gen")) { if (args.length == 5) { EntityPlayerMP playerMP = getCommandSenderAsPlayer(sender); String configName = args[1]; String sxPos = args[2]; String szPos = args[3]; String sRadius = args[4]; int xPos; if (sxPos.equals("~")) { xPos = (int) playerMP.posX; } else { xPos = parseInt(sxPos); } int zPos; if (szPos.equals("~")) { zPos = (int) playerMP.posZ; } else { zPos = parseInt(sxPos); } int radius = parseInt(sRadius); if (radius < 1) { sender.sendMessage(new TextComponentString("The radius must be bigger than 0!")); } int chunkPosX = xPos >> 4; int chunkPosZ = zPos >> 4; if (OreHotSwap.loader.configFiles.containsKey(configName)) { for (int x = -radius; x < radius; x++) { for (int z = -radius; z < radius; z++) { ChunkCoord coord = ChunkCoord.of(x + chunkPosX, z + chunkPosZ); OreHotSwap.oreGenerator.addChunk(coord, OreHotSwap.loader.configFiles.get(configName)); } } } else { sender.sendMessage(new TextComponentString("I could not find that file!")); } } else { sender.sendMessage(new TextComponentString("Please provide the correct arguments:")); sender.sendMessage(new TextComponentString("/orehs gen <configName> <centerx> <centerz> <chunkradius>")); } } else if (args[0].equals("reload")) { try { OreHotSwap.loader.load(); sender.sendMessage(new TextComponentString("Config reloaded!")); } catch (FileNotFoundException e) { e.printStackTrace(); sender.sendMessage(new TextComponentString(e.getLocalizedMessage())); } } }
public static void processCommand(ICommandSender sender, String[] args) throws CommandException { if (args.length < 6) { sender.addChatMessage(new ChatComponentTranslation("genloader.notenoughargs")); return; } int CXmin = CommandBase.parseInt(args[1]); int CXmax = CommandBase.parseInt(args[2]); int CZmin = CommandBase.parseInt(args[3]); int CZmax = CommandBase.parseInt(args[4]); if ((CXmax - CXmin) * (CZmax - CZmin) > 25) { sender.addChatMessage(new ChatComponentTranslation("genloader.areatoolarge")); return; } String toRemove = args[5]; Block block = null; IBlockState state = null; boolean haveJunk = false; if (!toRemove.contentEquals("junk")) { if (args.length == 6) { block = GameData.getBlockRegistry().getObject(new ResourceLocation(toRemove)); } HashMap<String, String> properties = new HashMap<String, String>(); for (int i = 6; i < args.length; i = i + 2) { if (args[i] != null && args[i + 1] != null) { properties.put(args[i], args[i + 1]); } } state = BlockUtils.createState(toRemove, properties); } if (toRemove.contentEquals("junk")) { haveJunk = true; } for (int i = CXmin; i <= CXmax; i++) { for (int j = CZmin; j <= CZmax; j++) { World world = sender.getEntityWorld(); for (int k = i * 16; k < (i * 16) + 16; k++) { for (int l = j * 16; l < (j * 16) + 16; l++) { int maxheight = world.getChunkFromBlockCoords(new BlockPos(k, 0, l)).getTopFilledSegment() + 16; for (int m = 0; m < maxheight; m++) { if (haveJunk && world.getBlockState(new BlockPos(k, m, l)) != Blocks.bedrock.getDefaultState() && !GenLoaderAPI.getValuableBlockStates().contains(world.getBlockState(new BlockPos(k, m, l)))) { world.setBlockToAir(new BlockPos(k, m, l)); } if (block != null && world.getBlockState(new BlockPos(k, m, l)).getBlock() == block) { world.setBlockToAir(new BlockPos(k, m, l)); } if (world.getBlockState(new BlockPos(k, m, l)) == state) { world.setBlockToAir(new BlockPos(k, m, l)); } } } } } } }
public ParsableBlockState(IBlockState State) { this.state = State; this.block = GameData.getBlockRegistry().getNameForObject(State.getBlock()).toString(); this.properties = BlockUtils.generateProperties(State); }
public static String getName(Item it) { if (it == null) return null; ResourceLocation nameForObject = GameData.getItemRegistry().getNameForObject(it); if (nameForObject == null) return null; return nameForObject.toString(); }
public static String getName(Block b) { return GameData.getBlockRegistry().getNameForObject(b).toString(); }
public static void stopEndermanFromGriefing(){ for (Block b : GameData.getBlockItemMap().keySet()) { EntityEnderman.setCarriable(b, false); } }
public static ItemStack getItemStack(final String name, final int quantity) { ItemStack result = null; // Parse out the possible subtype from the end of the string String workingName = name; int subType = -1; if (StringUtils.countMatches(name, ":") == 2) { workingName = StringUtils.substringBeforeLast(name, ":"); final String num = StringUtils.substringAfterLast(name, ":"); if (num != null && !num.isEmpty()) { if ("*".compareTo(num) == 0) subType = OreDictionary.WILDCARD_VALUE; else { try { subType = Integer.parseInt(num); } catch (Exception e) { // It appears malformed - assume the incoming name // is // the real name and continue. ; } } } } // Check the OreDictionary first for any alias matches. Otherwise // go to the game registry to find a match. final List<ItemStack> ores = OreDictionary.getOres(workingName); if (!ores.isEmpty()) { result = ores.get(0).copy(); result.stackSize = quantity; } else { final Item i = GameData.getItemRegistry().getObject(new ResourceLocation(workingName)); if (i != null) { result = new ItemStack(i, quantity); } } // If we did have a hit on a base item, set the subtype // as needed. if (result != null && subType != -1) { result.setItemDamage(subType); } return result; }
@SuppressWarnings("unchecked") public void loadPacks() { List<ModContainer> children = new ArrayList<ModContainer>(); if (configuration.getPacks() == null) { Redux.instance.getLogger().info("No packs installed. Without packs this mod does nothing."); return; } for (Pack p : configuration.getPacks()) { if (p.getName() == null || p.getName().isEmpty() || p.getId() == null || p.getId().isEmpty()) { Redux.instance.getLogger().warn("Package found without name and/or id, skipping."); continue; } ReduxPackModContainer packContainer = new ReduxPackModContainer(p, Redux.instance); FMLCommonHandler.instance().addModToResourcePack(packContainer); children.add(packContainer); if (p.getBlocks() == null) continue; for (Block b : p.getBlocks()) { if (b.getExtendsBlock() != null && b.getReduxExtendsBlock() == null) { b.setReduxExtendsBlock(p.getBlockFromId(b.getExtendsBlock())); } ReduxBlock.blockThreadLocal.set(b); ReduxBlock mcBlock = new ReduxBlock(p, b); ReduxBlock.blockThreadLocal.remove(); Item blockItem = new ItemBlock(mcBlock); if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { FMLClientHandler.instance().getClient().getRenderItem().getItemModelMesher().register(blockItem, 0, new ModelResourceLocation(p.getId() + ":" + b.getId(), "inventory")); } try { Class<GameData> gameDataClass = GameData.class; Method mainDataGetMethod = gameDataClass.getDeclaredMethod("getMain"); mainDataGetMethod.setAccessible(true); Method registerBlockMethod = gameDataClass.getDeclaredMethod("registerBlock", net.minecraft.block.Block.class, String.class, int.class); registerBlockMethod.setAccessible(true); Method registerItemMethod = gameDataClass.getDeclaredMethod("registerItem", net.minecraft.item.Item.class, String.class, int.class); registerItemMethod.setAccessible(true); GameData gameData = (GameData) mainDataGetMethod.invoke(null); registerBlockMethod.invoke(gameData, mcBlock, p.getId() + ":" + b.getId(), -1); registerItemMethod.invoke(gameData, blockItem, p.getId() + ":" + b.getId(), -1); GameData.getBlockItemMap().put(mcBlock, blockItem); if (mcBlock.hasTileEntity(null) && mcBlock.getTileEntityClass() != null) { TileEntity.addMapping(mcBlock.getTileEntityClass(), b.getId()); } } catch (Exception e) { Redux.instance.getLogger().fatal("Error accessing FML GameData.\nRedux will not function properly!\nDid FML Update?", e); } } /* * TODO: Load the other pack components */ } FMLCommonHandler.instance().findContainerFor(Redux.instance).getMetadata().childMods = children; if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { FMLClientHandler.instance().addSpecialModEntries((ArrayList<ModContainer>) children); } }
public static Item getMinecraftItem(String name) { Item item; item = GameData.getItemRegistry().getRaw(GameData.getItemRegistry().getId(new ResourceLocation("minecraft", name))); return item; }
@Override public void onKeypress() { Minecraft minecraft = FMLClientHandler.instance().getClient(); if(minecraft.thePlayer != null) { ItemStack current = minecraft.thePlayer.getCurrentEquippedItem(); if(current != null && current.getItem() != null) { fbo.begin(); GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.pushMatrix(); GlStateManager.loadIdentity(); GlStateManager.ortho(0, 16, 16, 0, -100000.0, 100000.0); GlStateManager.matrixMode(GL11.GL_MODELVIEW); FloatBuffer matrix = GLAllocation.createDirectFloatBuffer(16); matrix.clear(); matrix.put(new float[] { 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 0f, 1f}); matrix.rewind(); //GlStateManager.multMatrix(matrix); RenderHelper.enableGUIStandardItemLighting(); GlStateManager.enableRescaleNormal(); GlStateManager.enableColorMaterial(); GlStateManager.enableLighting(); itemRenderer.func_175042_a(current, 0, 0); GlStateManager.disableLighting(); RenderHelper.disableStandardItemLighting(); GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.popMatrix(); fbo.end(); fbo.saveToFile(new File(minecraft.mcDataDir, String.format("rendered/item_%s_%d%s.png", GameData.getItemRegistry().getNameForObject(current.getItem()).toString().replace(':', '_'), current.getItemDamage(), filenameSuffix))); fbo.restoreTexture(); } } }