private void makeOurList() { if (serverListInternetField == null) { if (serverListInternetField == null) { serverListInternetField = ReflectionHelper.findField(ServerSelectionList.class, "field_148198_l", "serverListInternet"); serverListInternetField.setAccessible(true); } } try { ourList = (List<ServerListEntryPublic>) serverListInternetField.get(this); } catch (IllegalAccessException e) { CreeperHost.logger.warn("Reflection to get server list failed.", e); } }
private void setServerList(ServerList serverList) { ourSavedServerList = serverList; if (savedServerListField == null) { savedServerListField = ReflectionHelper.findField(GuiMultiplayer.class, "field_146804_i", "savedServerList"); savedServerListField.setAccessible(true); } try { savedServerListField.set(this, serverList); } catch (IllegalAccessException e) { CreeperHost.logger.error("Unable to set server list", e); } }
private void setLanServerDetector(LanServerDetector.ThreadLanServerFind detector) { ourLanServerDetector = detector; if (lanServerDetectorField == null) { lanServerDetectorField = ReflectionHelper.findField(GuiMultiplayer.class, "field_146800_B", "lanServerDetector"); lanServerDetectorField.setAccessible(true); } try { lanServerDetectorField.set(this, detector); } catch (IllegalAccessException e) { CreeperHost.logger.error("Unable to set server list", e); } }
private void setLanServerList(LanServerDetector.LanServerList detector) { ourLanServerList = detector; if (lanServerListField == null) { lanServerListField = ReflectionHelper.findField(GuiMultiplayer.class, "field_146799_A", "lanServerList"); lanServerListField.setAccessible(true); } try { lanServerListField.set(this, detector); } catch (IllegalAccessException e) { CreeperHost.logger.error("Unable to set server list", e); } }
private void setServerListSelector(ServerSelectionListPublic list) { ourServerListSelector = list; if (serverListSelectorField == null) { serverListSelectorField = ReflectionHelper.findField(GuiMultiplayer.class, "field_146803_h", "serverListSelector"); serverListSelectorField.setAccessible(true); } try { serverListSelectorField.set(this, list); } catch (IllegalAccessException e) { CreeperHost.logger.error("Unable to set server list", e); } }
public EntityRabbit(World world) { super(world); moveType = EntityRabbit.EnumMoveType.HOP; carrotTicks = 0; setSize(0.4F, 0.5F); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new EntityRabbit.RabbitJumpHelper(this), "jumpHelper", "field_70767_i"); ReflectionHelper.setPrivateValue(EntityLiving.class, this, new EntityRabbit.RabbitMoveHelper(), "moveHelper", "field_70765_h"); getNavigator().setAvoidsWater(true); // navigator.func_179678_a(2.5F); tasks.addTask(1, new EntityAISwimming(this)); tasks.addTask(1, new EntityRabbit.AIPanic(1.33D)); tasks.addTask(2, new EntityAIMate(this, 0.8D)); tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.carrot, false)); tasks.addTask(5, new EntityRabbit.AIRaidFarm()); tasks.addTask(5, new EntityAIWander(this, 0.6D)); tasks.addTask(11, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F)); tasks.addTask(4, new EntityAIAvoidEntity(this, EntityWolf.class, 16.0F, 1.33D, 1.33D)); tasks.addTask(4, new EntityAIAvoidEntity(this, EntityPlayer.class, 16.0F, 0.8D, 1.33D)); setMovementSpeed(0.0D); }
@Override public void onCollideWithPlayer(EntityPlayer player) { boolean inGround = false; try { inGround = ReflectionHelper.getPrivateValue(EntityArrow.class, this, "inGround", "field_70254_i"); } catch (Exception e) { } if (!worldObj.isRemote && inGround && arrowShake <= 0 && isEffectValid()) { boolean flag = canBePickedUp == 1 || canBePickedUp == 2 && player.capabilities.isCreativeMode; ItemStack stack = new ItemStack(ModItems.tipped_arrow); TippedArrow.setEffect(stack, Potion.potionTypes[effect.getPotionID()], effect.getDuration()); if (canBePickedUp == 1 && !player.inventory.addItemStackToInventory(stack)) flag = false; if (flag) { playSound("random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); player.onItemPickup(this, 1); setDead(); } } }
@SuppressWarnings("unchecked") public RabbitFoot() { setTextureName("rabbit_foot"); setUnlocalizedName(Utils.getUnlocalisedName("rabbit_foot")); setCreativeTab(EtFuturum.enableRabbit ? EtFuturum.creativeTab : null); if (EtFuturum.enableRabbit) try { Field f = ReflectionHelper.findField(PotionHelper.class, "potionRequirements", "field_77927_l"); f.setAccessible(true); HashMap<Integer, String> potionRequirements = (HashMap<Integer, String>) f.get(null); potionRequirements.put(Potion.jump.getId(), "0 & 1 & !2 & 3"); Field f2 = ReflectionHelper.findField(PotionHelper.class, "potionAmplifiers", "field_77928_m"); f2.setAccessible(true); HashMap<Integer, String> potionAmplifiers = (HashMap<Integer, String>) f2.get(null); potionAmplifiers.put(Potion.jump.getId(), "5"); Field f3 = ReflectionHelper.findField(Potion.class, "liquidColor", "field_76414_N"); f3.setAccessible(true); f3.set(Potion.jump, 0x22FF4C); } catch (Exception e) { } }
public BlockColor(final Block b, final String orename, final String texture) { super(b.getMaterial()); this.curMetadata = 0; this.customRecipe = null; this.customRecipeNo = 0; this.setHardness((Float)ReflectionHelper.getPrivateValue(Block.class, b, new String[] { "blockHardness", "field_149782_v" })); this.setResistance((Float)ReflectionHelper.getPrivateValue(Block.class, b, new String[] { "blockResistance", "field_149781_w" })); this.setStepSound(b.stepSound); this.setBlockTextureName(texture); this.setBlockName("extrautils:color_" + b.getUnlocalizedName().substring(5)); this.setLightLevel(b.getLightValue() / 15.0f); this.setLightOpacity(b.getLightOpacity()); this.oreName = orename; this.baseBlock = b; ExtraUtils.colorblocks.add(this); }
public void processCommand(final ICommandSender icommandsender, final String[] astring) { final File f = new File(Minecraft.getMinecraft().mcDataDir, "extrautilities_localization.txt"); final Map<String, Properties> k = (Map<String, Properties>)ReflectionHelper.getPrivateValue((Class)LanguageRegistry.class, (Object)LanguageRegistry.instance(), new String[] { "modLanguageData" }); final String lang = FMLCommonHandler.instance().getCurrentLanguage(); final Properties p = k.get(lang); String t = ""; for (final Map.Entry<Object, Object> entry : p.entrySet()) { t = t + entry.getKey() + "=" + entry.getValue() + "\n"; } try { Files.write((CharSequence)t, f, Charsets.UTF_8); LogHelper.info("Dumped Language data to " + f.getAbsolutePath(), new Object[0]); } catch (Exception exception) { exception.printStackTrace(); } }
@SuppressWarnings("rawtypes") public static void notifyPlayers(WorldServer world) { if (RorysConfig.enableSleepInDay) { if (world.getWorldTime() == RorysConfig.sleepDayTime) { world.provider.resetRainAndThunder(); Iterator iterator = world.playerEntities.iterator(); while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); entityplayer.addChatMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("message.rorysmod.sleeping.wakeup"), EnumChatFormatting.AQUA + entityplayer.getDisplayName() + EnumChatFormatting.WHITE))); } } } else { Method wakeAllPlayers = ReflectionHelper.findMethod(WorldServer.class, world, new String[] { "wakeAllPlayers", "func_73053_d" }); try { wakeAllPlayers.invoke(world, new Object[] {}); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } } }
private void doHeal(EntityLivingBase guy) { armSwing(!didSwing); // Swings arm and heals the specified person. EntityPotion potion = new EntityPotion(worldObj, this, handPotion().getItemDamage()); worldObj.spawnEntityInWorld(potion); // potion.onImpact(new MovingObjectPosition(guy)); try { final Method onImpact = ReflectionHelper.findMethod( EntityPotion.class, potion, MCP_ONIMPACT, MovingObjectPosition.class); onImpact.invoke(potion, new MovingObjectPosition(guy)); } catch (Exception e) { e.printStackTrace(); } setPathToEntity((PathEntity) null); healTime = 200; setRarePotion(rand.nextInt(4) == 0); }
public ArrayList getSheep( final World world ) { final List list = world.getEntitiesWithinAABB( EntitySheep.class, fairy.boundingBox.expand( 5D, 5D, 5D ) ); if ( list.size() < 1 ) { return null; } final ArrayList list2 = new ArrayList(); for ( int i = 0; i < list.size(); i++ ) { final EntitySheep entity1 = (EntitySheep) list.get( i ); final int fleeingTick = ReflectionHelper.getPrivateValue(EntityCreature.class, entity1, MCP_FLEEINGTICK); if ( fairy.canEntityBeSeen( entity1 ) && entity1.getHealth() > 0 && entity1.getEntityToAttack() == null && fleeingTick <= 0 && entity1.getGrowingAge() >= 0 && !entity1.getSheared() ) { list2.add( entity1 ); } } if ( list2.size() <= 0 ) { return null; } else { return list2; } }
/** * Inserts the resource pack into the game. Enabling the resource pack will * not be required, it will load automatically. * <p> * A cache of the pack zip will be kept in "resourcepack/[pack name].zip" * where "resourcepack" is a folder at the same level as the directory passed * into the constructor. */ public void inject() { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { try { if (defaultResourcePacks == null) { defaultResourcePacks = ReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getMinecraft(), "defaultResourcePacks", "field_110449_ao", "ap"); } File dest = new File(dir.getParent() + "/resourcepack/" + zip.getName()); EnderFileUtils.safeDelete(dest); FileUtils.copyFile(zip, dest); EnderFileUtils.safeDelete(zip); writeNewFile(new File(dest.getParent() + "/readme.txt"), EnderCore.lang.localize("resourcepack.readme") + "\n\n" + EnderCore.lang.localize("resourcepack.readme2")); defaultResourcePacks.add(new FileResourcePack(dest)); } catch (Exception e) { EnderCore.logger.error("Failed to inject resource pack for mod {}", modid, e); } } else { EnderCore.logger.info("Skipping resource pack, we are on a dedicated server."); } }
public static Field getField(Class<?> clazz, String... names) { try { Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { for (String fieldName : names) { if (field.getName().equalsIgnoreCase(fieldName)) { field.setAccessible(true); return field; } } } } catch (Exception e) { throw new ReflectionHelper.UnableToFindFieldException(names, e); } return null; }
public static Method getMethod(Class<?> clazz, String... names) { try { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { for (String methodName : names) { if (method.getName().equalsIgnoreCase(methodName)) { method.setAccessible(true); return method; } } } } catch (Exception e) { throw new ReflectionHelper.UnableToFindMethodException(names, e); } return null; }
public static boolean isFieldAccessible(Class<?> clazz, String... names) { try { Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { for (String fieldName : names) { if (field.getName().equalsIgnoreCase(fieldName)) { return field.isAccessible(); } } } } catch (Exception e) { throw new ReflectionHelper.UnableToFindFieldException(names, e); } return false; }
public static boolean isMethodAccessable(Class<?> clazz, String... names) { try { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { for (String methodName : names) { if (method.getName().equalsIgnoreCase(methodName)) { return method.isAccessible(); } } } } catch (Exception e) { throw new ReflectionHelper.UnableToFindMethodException(names, e); } return false; }
public SilverfishModel() { normal = new ModelSilverfish(); body = ReflectionHelper.getPrivateValue( ModelSilverfish.class, this, 0 ); wings = ReflectionHelper.getPrivateValue( ModelSilverfish.class, this, 1 ); body[ 3 ].rotateAngleX = body[ 4 ].rotateAngleX = body[ 5 ].rotateAngleX = body[ 6 ].rotateAngleX = 3.14f / 2; body[ 3 ].rotationPointZ = body[ 4 ].rotationPointZ = body[ 5 ].rotationPointZ = body[ 6 ].rotationPointZ = 0; body[ 6 ].offsetY = 0; body[ 5 ].offsetY = -0.1f; body[ 4 ].rotateAngleX *= -0.7f; body[ 4 ].offsetZ = 0.06f; body[ 4 ].offsetY = -0.2f; body[ 3 ].rotateAngleX *= -0.45f; body[ 3 ].offsetY = -0.3f; body[ 3 ].offsetZ = -0.05f; wings[ 1 ].rotateAngleX = body[ 5 ].rotateAngleX*1.4f; wings[ 1 ].rotationPointZ = body[ 5 ].rotationPointZ; wings[ 1 ].offsetY = body[ 4 ].offsetX; wings[ 1 ].offsetZ = -0.05f; }
public ChunkManagerPlanet(long seed, WorldType default1, DimensionProperties properties) { this.biomeCache = new BiomeCache(this);//new BiomeCacheExtended(this); //TODO: more biomes //TODO: remove rivers GenLayer[] agenlayer = initializeAllBiomeGenerators(seed, default1, properties);//GenLayer.initializeAllBiomeGenerators(seed, default1); //; agenlayer = getModdedBiomeGenerators(default1, seed, agenlayer); this.genBiomes = agenlayer[0]; this.biomeIndexLayer = agenlayer[1]; fBiomeCache = ReflectionHelper.findField(BiomeCache.class, "cache", "field_76841_d"); fBiomeCache.setAccessible(true); fBiomeCacheMap = ReflectionHelper.findField(BiomeCache.class, "cacheMap", "field_76843_c"); fBiomeCacheMap.setAccessible(true); }
@Override public void write(ByteBuf out) { NBTTagCompound nbt = (NBTTagCompound)ReflectionHelper.getPrivateValue(S35PacketUpdateTileEntity.class, (S35PacketUpdateTileEntity)tile.getDescriptionPacket(), "field_148860_e"); out.writeInt(((Entity)entity).worldObj.provider.dimensionId); out.writeInt(((Entity)entity).getEntityId()); out.writeInt(x); out.writeInt(y); out.writeInt(z); PacketBuffer packetBuffer = new PacketBuffer(out); try { packetBuffer.writeNBTTagCompoundToBuffer(nbt); } catch (IOException e) { e.printStackTrace(); } }
public static void init() { if (Settings.Tweaks.enableEE3Tweaks) { try { List<RecipeAludel> aludelRecipeList = ReflectionHelper.getPrivateValue(AludelRecipeManager.class, AludelRecipeManager.getInstance(), "aludelRecipes"); for (RecipeAludel recipe : aludelRecipeList) { if (recipe.getRecipeOutput().getItem().equals(alchemicalTome)) { aludelRecipeList.remove(recipe); break; } } } catch (Exception e) { e.printStackTrace(); } } }
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); Map<String, ChestGenHooks> lootTables = ReflectionHelper.getPrivateValue(ChestGenHooks.class, null, "chestInfo"); List<String> names = new ArrayList<String>(); names.addAll(lootTables.keySet()); Collections.sort(names); for (String name : names) { List<WeightedRandomChestContent> contents = ReflectionHelper.getPrivateValue(ChestGenHooks.class, lootTables.get(name), "contents"); for (WeightedRandomChestContent w : contents) { String displayName; try { displayName = w.theItemId.getDisplayName(); } catch (Exception ex) { displayName = "-"; } list.add(new String[] { name, w.theItemId.toString(), displayName, Item.itemRegistry.getNameForObject(w.theItemId.getItem()), String.valueOf(w.itemWeight) }); } } return list; }
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); Map<Class, String> classToNameMap = ReflectionHelper.getPrivateValue(TileEntity.class, null, "field_145853_j", "classToNameMap"); List<Class> classes = new ArrayList<Class>(); classes.addAll(classToNameMap.keySet()); Collections.sort(classes, new Comparator<Class>() { @Override public int compare(Class o1, Class o2) { if (o1 == null || o2 == null) { return 0; } return o1.getName().compareTo(o2.getName()); } }); for (Class clazz : classes) { if (clazz != null) { list.add(new String[] { clazz.getName(), classToNameMap.get(clazz) }); } } return list; }
@Override public Iterable<String[]> dump(int mode) { List<String[]> list = new LinkedList<String[]>(); List<Integer> ids = new ArrayList<Integer>(); ids.addAll(Arrays.asList(DimensionManager.getStaticDimensionIDs())); Collections.sort(ids); for (int id : ids) { int providerId = DimensionManager.getProviderType(id); Map<Integer, Class> providers = ReflectionHelper.getPrivateValue(DimensionManager.class, null, "providers"); Class providerClass = providers.get(providerId); list.add(new String[] { String.valueOf(id), String.valueOf(providerId), providerClass.getName() }); } return list; }
@Override public boolean itemStackMatches(ItemStack stack) { if (stack == item) return true; if (stack == null) return false; goat.func_150996_a(stack.getItem()); ReflectionHelper.setPrivateValue(ItemStack.class, goat, item.getItemDamage() == OreDictionary.WILDCARD_VALUE ? OreDictionary.WILDCARD_VALUE : stack.getItemDamage(), 5); goat.setTagCompound(item.hasTagCompound() && stack.hasTagCompound() ? (NBTTagCompound)stack.getTagCompound().copy() : null); ItemStack comp = goat; if (lenientTag && item.hasTagCompound() && comp.hasTagCompound()) { NBTTagCompound tag = comp.getTagCompound(); List<String> toRemove = Lists.newArrayList(); for (String key : (Set<String>)tag.func_150296_c()) { if (item.getTagCompound().hasKey(key)) continue; toRemove.add(key); } for (String s : toRemove) { tag.removeTag(s); } } comp.stackSize = item.stackSize; return ItemStack.areItemStacksEqual(item, comp); }
@Override protected void actionPerformed(GuiButton button) { if (!button.enabled) return; switch (button.id) { case 0: if (buttonRegenMode.enabled) preset = regenMode; break; case 3: // If going to the more options screen, hide the button. // If going back to the main screen, show the button again. boolean inMoreOptions = ReflectionHelper.getPrivateValue(GuiCreateWorld.class, this, "field_146344_y"); buttonRegenMode.visible = inMoreOptions; break; case 9: regenMode = EnumPreset.values()[(regenMode.ordinal() + 1) % EnumPreset.values().length]; buttonRegenMode.displayString = getRegenButtonString(); break; } super.actionPerformed(button); }
public static void init(){ ConfigHandler.init(DimensionGuard.config); Table<String,String,ItemStack> customStacks = ReflectionHelper.getPrivateValue(GameData.class, null, "customItemStacks"); Map<String,ItemStack> customItemStacks = new LinkedHashMap<String, ItemStack>(); for (Table.Cell<String, String,ItemStack> cell: customStacks.cellSet()) { customItemStacks.put(cell.getRowKey()+":"+cell.getColumnKey(),cell.getValue()); } addDisabledItems(true, customItemStacks); addDisabledItems(false, customItemStacks); addDisabledEntity(true); addDisabledEntity(false); }
public static int getSmallestFlowDecayTo(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int curSmallest, int fromSide) { int flowDecay = Hooks.getFlowDecayTo(flowingBlock, world, x, y, z, fromSide); if (flowDecay < 0) { return curSmallest; } else { if (flowDecay == 0) { int numAdjacentSources = ReflectionHelper.getPrivateValue(BlockDynamicLiquid.class, flowingBlock, "field_149815_a", "a"); ReflectionHelper.setPrivateValue(BlockDynamicLiquid.class, flowingBlock, numAdjacentSources+1, "field_149815_a", "a"); } if (flowDecay >= 8) { flowDecay = 0; } return curSmallest >= 0 && flowDecay >= curSmallest ? curSmallest : flowDecay; } }
@Override public int drawString(String text, int x, int y, int color, boolean dropShadow) { if (dropShadow) { Method renderString = ReflectionHelper.findMethod(FontRenderer.class, this, renderStringObfNames, String.class, int.class, int.class, int.class, boolean.class); try { renderString.invoke(this, text, x, y+1, color, true); renderString.invoke(this, text, x, y-1, color, true); renderString.invoke(this, text, x-1, y, color, true); renderString.invoke(this, text, x+1, y, color, true); } catch (Exception e) {} return super.drawString(text, x, y, color, false); } else { return super.drawString(text, x, y, color, false); } }
@Override public boolean shouldTrackWithThisEntry(IBlockAccess world, int x, int y, int z, Block block, TileEntity te){ if(tileEntityClassToNameMapping == null) { try { tileEntityClassToNameMapping = (Map)ReflectionHelper.findField(TileEntity.class, "field_145853_j", "classToNameMap").get(null); } catch(Exception e) { Log.error("[BlockTrackEntryInventory.class] Uhm reflection failed here!"); e.printStackTrace(); } } if(te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest)te; if(chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false; } return te != null && !invBlackList.contains(tileEntityClassToNameMapping.get(te.getClass())) && te instanceof IInventory && ((IInventory)te).getSizeInventory() > 0 && !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te)); }
/** * Dump ore dictionary */ public static void dumpOreDict() { Map<Integer, ItemData> idMap = ReflectionHelper.getPrivateValue(GameData.class, null, "idMap"); List<String> oreNames = Arrays.asList(OreDictionary.getOreNames()); Collections.sort(oreNames); for (String oreName : oreNames) { StringBuffer sb = new StringBuffer(); sb.append("ore: " + oreName + ": "); ArrayList<ItemStack> oreItems = OreDictionary.getOres(oreName); for (ItemStack oreItem : oreItems) { ItemData itemData = idMap.get(oreItem.itemID); String modID = itemData.getModId(); sb.append(oreItem.itemID + ":" + oreItem.getItemDamage() + "=" + modID + ", "); } System.out.println(sb); } }