net.minecraftforge.fml.relauncher.ReflectionHelper Java Examples

The following examples show how to use net.minecraftforge.fml.relauncher.ReflectionHelper. 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: GuiProblemScreen.java    From VanillaFix with MIT License 6 votes vote down vote up
@Override
protected void actionPerformed(GuiButton button) {
    if (button.id == 1) {
        try {
            if (hasteLink == null) {
                hasteLink = HasteUpload.uploadToHaste(ModConfig.crashes.hasteURL, "mccrash", report.getCompleteReport());
            }
            ReflectionHelper.findField(GuiScreen.class, "clickedLinkURI", "field_175286_t").set(this, new URI(hasteLink));
            mc.displayGuiScreen(new GuiConfirmOpenLink(this, hasteLink, 31102009, false));
        } catch (Throwable e) {
            log.error("Exception when crash menu button clicked:", e);
            button.displayString = I18n.format("vanillafix.gui.failed");
            button.enabled = false;
        }
    }
}
 
Example #2
Source File: Util.java    From IGW-mod with GNU General Public License v2.0 6 votes vote down vote up
public static String getModIdForEntity(Class<? extends Entity> entity){
    if(reflectionFailed) return "minecraft";
    if(entityNames == null) {
        try {
            entityNames = (HashMap<String, ModContainer>)ReflectionHelper.findField(EntityRegistry.class, "entityNames").get(EntityRegistry.instance());
        } catch(Exception e) {
            IGWLog.warning("IGW-Mod failed to perform reflection! A result of this is that wiki pages related to Entities will not be found. Report to MineMaarten please!");
            e.printStackTrace();
            reflectionFailed = true;
            return "minecraft";
        }
    }
    EntityRegistration entityReg = EntityRegistry.instance().lookupModSpawn(entity, true);
    if(entityReg == null) return "minecraft";
    ModContainer mod = entityNames.get(entityReg.getEntityName());
    if(mod == null) {
        IGWLog.info("Couldn't find the owning mod of the entity " + entityReg.getEntityName() + " even though it's registered through the EntityRegistry!");
        return "minecraft";
    } else {
        return mod.getModId().toLowerCase();
    }
}
 
Example #3
Source File: ModelErrorSuppressor.java    From AgriCraft with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onModelBakePost(ModelBakeEvent event) {
    if (supressErrors) {
        Map<ResourceLocation, Exception> modelErrors = (Map<ResourceLocation, Exception>) ReflectionHelper.getPrivateValue(ModelLoader.class, event.getModelLoader(), "loadingExceptions");
        Set<ModelResourceLocation> missingVariants = (Set<ModelResourceLocation>) ReflectionHelper.getPrivateValue(ModelLoader.class, event.getModelLoader(), "missingVariants");

        List<ResourceLocation> errored = modelErrors.keySet().stream().filter((r) -> IGNORES.contains(r.getResourceDomain())).collect(Collectors.toList());
        List<ResourceLocation> missing = missingVariants.stream().filter((r) -> IGNORES.contains(r.getResourceDomain())).collect(Collectors.toList());

        errored.forEach(modelErrors::remove);
        missing.forEach(missingVariants::remove);

        AgriCore.getLogger("agricraft").info("Suppressed {0} Model Loading Errors!", errored.size());
        AgriCore.getLogger("agricraft").info("Suppressed {0} Missing Model Variants!", missing.size());
    }
}
 
Example #4
Source File: ChunkManagerPlanet.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public ChunkManagerPlanet(long seed, WorldType default1, String str, DimensionProperties properties) {

		this.biomeCache = new BiomeCache(this);//new BiomeCacheExtended(this);
		//TODO: more biomes
		//TODO: remove rivers
		GenLayer[] agenlayer = initializeAllBiomeGenerators(seed, default1, str, properties);//GenLayer.initializeAllBiomeGenerators(seed, default1); //;
		agenlayer = getModdedBiomeGenerators(default1, seed, agenlayer);
		this.genBiomes = agenlayer[0];
		this.biomeIndexLayer = agenlayer[1];

		ReflectionHelper.setPrivateValue(BiomeProvider.class, this, this.genBiomes, "genBiomes", "field_76944_d");
		ReflectionHelper.setPrivateValue(BiomeProvider.class, this, this.biomeIndexLayer, "biomeIndexLayer", "field_76945_e");
		
		fBiomeCache = ReflectionHelper.findField(BiomeCache.class, "cache", "field_76841_d");
		fBiomeCache.setAccessible(true);

		fBiomeCacheMap = ReflectionHelper.findField(BiomeCache.class, "cacheMap", "field_76843_c");
		fBiomeCacheMap.setAccessible(true);
	}
 
Example #5
Source File: CreativeMenuHandler.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleButtons(InitGuiEvent event)
{
	if (event.getGui() instanceof GuiContainerCreative)
	{
		GuiContainerCreative gui = (GuiContainerCreative) event.getGui();

		int i = (gui.width - 136) / 2;
		int j = (gui.height - 195) / 2;
		
		List<GuiButton> buttons = event.getButtonList();
		buttons.add(salvaged = new CEXButton(355, i + 166 + 4, j + 29 + 8, 0));
		buttons.add(manufactured = new CEXButton(356, i + 166 + 4, j + 29 + 31, 1));
		
		int selectedTabIndex = ReflectionHelper.getPrivateValue(GuiContainerCreative.class, (GuiContainerCreative) gui, 2);
		if (selectedTabIndex != Cyberware.creativeTab.getTabIndex())
		{
			salvaged.visible = false;
			manufactured.visible = false;
		}
		event.setButtonList(buttons);
	}
}
 
Example #6
Source File: ItemHelper.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private static String getTabLabel(CreativeTabs tab)
{
    if (tabLabelField == null)
    {
        tabLabelField = ReflectionHelper.findField(CreativeTabs.class, "tabLabel", "field_78034_o", "o");
        tabLabelField.setAccessible(true);
    }

    try
    {
        return (String) tabLabelField.get(tab);
    } catch (IllegalAccessException e)
    {
        e.printStackTrace();
    }

    return null;
}
 
Example #7
Source File: AutoReconnectMod.java    From ForgeHax with MIT License 6 votes vote down vote up
public GuiDisconnectedOverride(
    GuiScreen screen,
    String reasonLocalizationKey,
    ITextComponent chatComp,
    String reason,
    double delay) {
  super(screen, reasonLocalizationKey, chatComp);
  parent = screen;
  message = chatComp;
  reconnectTime = System.currentTimeMillis() + (long) (delay * 1000);
  // set variable 'reason' to the previous classes value
  try {
    ReflectionHelper.setPrivateValue(
        GuiDisconnected.class,
        this,
        reason,
        "reason",
        "field_146306_a",
        "a"); // TODO: Find obbed mapping name
  } catch (Exception e) {
    Helper.printStackTrace(e);
  }
  // parse server return text and find queue pos
}
 
Example #8
Source File: RenderCyberZombie.java    From Cyberware with MIT License 5 votes vote down vote up
public RenderCyberZombie(RenderManager renderManagerIn)
{
	super(renderManagerIn);
       List<LayerRenderer<EntityZombie>> defaultLayers = ReflectionHelper.getPrivateValue(RenderZombie.class, this, 10);
       defaultLayers.add(new LayerZombieHighlight(this));
       ReflectionHelper.setPrivateValue(RenderZombie.class, this, defaultLayers, 10);
}
 
Example #9
Source File: CreativeMenuHandler.java    From Cyberware with MIT License 5 votes vote down vote up
private boolean isCorrectGui(GuiScreen gui)
{
	if (gui instanceof GuiContainerCreative)
	{
		int selectedTabIndex = ReflectionHelper.getPrivateValue(GuiContainerCreative.class, (GuiContainerCreative) gui, 2);
		if (selectedTabIndex == Cyberware.creativeTab.getTabIndex())
		{
			return true;
		}
	}
	return false;
}
 
Example #10
Source File: ARAchivements.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public static void register() {
	Method method;
	try {
		method = ReflectionHelper.findMethod(CriteriaTriggers.class, "register", "func_192118_a", ICriterionTrigger.class);
		method.setAccessible(true);
		for (int i=0; i < ARAchivements.TRIGGER_ARRAY.length; i++) {
			method.invoke(null, ARAchivements.TRIGGER_ARRAY[i]);
		} 
	} catch (Exception e) {
		
	}
}
 
Example #11
Source File: PacketStorageTileUpdate.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = (NBTTagCompound)ReflectionHelper.getPrivateValue(SPacketUpdateTileEntity.class, (SPacketUpdateTileEntity)tile.getUpdatePacket(), "field_148860_e");


	out.writeInt(((Entity)entity).world.provider.getDimension());
	out.writeInt(((Entity)entity).getEntityId());
	out.writeInt(x);
	out.writeInt(y);
	out.writeInt(z);

	PacketBuffer packetBuffer = new PacketBuffer(out);
	packetBuffer.writeCompoundTag(nbt);
}
 
Example #12
Source File: ItemUpgrade.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public ItemUpgrade(int num) {
	super(num);
	setMaxStackSize(1);
	
	walkSpeed = ReflectionHelper.findField(net.minecraft.entity.player.PlayerCapabilities.class, "walkSpeed", "field_75097_g");
	walkSpeed.setAccessible(true);
}
 
Example #13
Source File: YUNoMakeGoodMap.java    From YUNoMakeGoodMap with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT) //Modders should never do this, im just lazy, and I KNOW what im doing.
public void onOpenGui(GuiOpenEvent e)
{
    //If we're opening the new world screen from the world selection, default to void world.
    if (e.getGui() instanceof GuiCreateWorld && Minecraft.getMinecraft().currentScreen instanceof GuiWorldSelection)
    {
        //Auto-select void world.
        GuiCreateWorld cw = (GuiCreateWorld)e.getGui();
        ReflectionHelper.setPrivateValue(GuiCreateWorld.class, cw, worldType.getId(),
                "field_146331_K", "selectedIndex");
    }
}
 
Example #14
Source File: EntityConcussionCreeper.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public EntityConcussionCreeper(World world) {
  super(world);
  try {
    fTimeSinceIgnited = ReflectionHelper.findField(EntityCreeper.class, "timeSinceIgnited", "field_70833_d");
    fFuseTime = ReflectionHelper.findField(EntityCreeper.class, "fuseTime", "field_82225_f");
  } catch (Exception e) {
    Log.error("Could not create ender creeper  logic as fields not found");
  }
}
 
Example #15
Source File: ItemMuscleUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();

	ItemStack test = new ItemStack(this, 1, 0);
	int rank = CyberwareAPI.getCyberwareRank(e, test);
	if (!event.isCanceled() && e instanceof EntityPlayer && (rank > 1) && EnableDisableHelper.isEnabled(CyberwareAPI.getCyberware(e, test)) && getLastBoostSpeed(e))
	{
		EntityPlayer p = (EntityPlayer) e;
		if (event.getSource() instanceof EntityDamageSource && !(event.getSource() instanceof EntityDamageSourceIndirect))
		{
			EntityDamageSource source = (EntityDamageSource) event.getSource();
			Entity attacker = source.getEntity();
			int lastAttacked = ReflectionHelper.getPrivateValue(CombatTracker.class, p.getCombatTracker(), 2);
			
			if (p.ticksExisted - lastAttacked > 120)
			{
				ItemStack weapon = p.getHeldItemMainhand();
				int loc = -1;
				if (weapon != null)
				{
					if (p.getItemInUseCount() > 0 || weapon.getItem() instanceof ItemSword || weapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, weapon).containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
					{
						loc = p.inventory.currentItem;
					}
				}
				
				if (loc == -1)
				{
					double mostDamage = 0F;
					
					for (int i = 0; i < 10; i++)
					{
						if (i != p.inventory.currentItem)
						{
							ItemStack potentialWeapon = p.inventory.mainInventory[i];
							if (potentialWeapon != null)
							{
								Multimap<String, AttributeModifier> modifiers = potentialWeapon.getItem().getAttributeModifiers(EntityEquipmentSlot.MAINHAND, potentialWeapon);
								if (modifiers.containsKey(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()))
								{
									double damage = modifiers.get(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName()).iterator().next().getAmount();
									
									if (damage > mostDamage || loc == -1)
									{
										mostDamage = damage;
										loc = i;
									}
								}
							}
						}
					}
				}
				
				if (loc != -1)
				{
					//System.out.println("LOC " + loc);

					p.inventory.currentItem = loc;

		
					CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) p);
					
					WorldServer world = (WorldServer) p.worldObj;
					
					for (EntityPlayer trackingPlayer : world.getEntityTracker().getTrackingPlayers(p))
					{
						CyberwarePacketHandler.INSTANCE.sendTo(new SwitchHeldItemAndRotationPacket(loc, p.getEntityId(), rank > 2 ? attacker.getEntityId() : -1), (EntityPlayerMP) trackingPlayer);
					}
					
				}
			}

		}

	}
}
 
Example #16
Source File: ItemBrainUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void handleHurt(LivingAttackEvent event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 4)) && isMatrixWorking(e))
	{

		if (!e.worldObj.isRemote && event.getSource() instanceof EntityDamageSource)
		{
			Entity attacker = ((EntityDamageSource) event.getSource()).getSourceOfDamage();
			if (e instanceof EntityPlayer)
			{
				String str = e.getEntityId() + " " + e.ticksExisted + " " + attacker.getEntityId();
				if (lastHits.contains(str))
				{
					return;
				}
				else
				{
					lastHits.add(str);
				}
			}
			
			boolean armor = false;
			for (ItemStack stack : e.getArmorInventoryList())
			{
				if (stack != null && stack.getItem() instanceof ItemArmor)
				{
					if (((ItemArmor) stack.getItem()).getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST) > 4)
					{
						return;
					}
				}
				else if (stack != null && stack.getItem() instanceof ISpecialArmor)
				{
					if (((ISpecialArmor) stack.getItem()).getProperties(e, stack, event.getSource(), event.getAmount(), 1).AbsorbRatio * 25D > 4)
					{
						return;
					}
				}
				
				if (stack != null)
				{
					armor = true;
				}
				
			}
			

			if (!((float) e.hurtResistantTime > (float) e.maxHurtResistantTime / 2.0F))
               {
				Random random = e.getRNG();
				if (random.nextFloat() < (armor ? LibConstants.DODGE_ARMOR : LibConstants.DODGE_NO_ARMOR))
				{
					event.setCanceled(true);
					e.hurtResistantTime = e.maxHurtResistantTime;
					e.hurtTime = e.maxHurtTime = 10;
					ReflectionHelper.setPrivateValue(EntityLivingBase.class, e, 9999F, 46);
					
					CyberwarePacketHandler.INSTANCE.sendToAllAround(new DodgePacket(e.getEntityId()), new TargetPoint(e.worldObj.provider.getDimension(), e.posX, e.posY, e.posZ, 50));
				}
			}
		}
	}
}
 
Example #17
Source File: EssentialsMissingHandlerClient.java    From Cyberware with MIT License 4 votes vote down vote up
private void renderItemInFirstPerson(float partialTicks)
{
	ItemRenderer ir = mc.getItemRenderer();
	AbstractClientPlayer abstractclientplayer = mc.thePlayer;
	float f = abstractclientplayer.getSwingProgress(partialTicks);
	EnumHand enumhand = (EnumHand)Objects.firstNonNull(abstractclientplayer.swingingHand, EnumHand.MAIN_HAND);
	float f1 = abstractclientplayer.prevRotationPitch + (abstractclientplayer.rotationPitch - abstractclientplayer.prevRotationPitch) * partialTicks;
	float f2 = abstractclientplayer.prevRotationYaw + (abstractclientplayer.rotationYaw - abstractclientplayer.prevRotationYaw) * partialTicks;
	boolean flag = true;
	boolean flag1 = true;

	if (abstractclientplayer.isHandActive())
	{
		ItemStack itemstack = abstractclientplayer.getActiveItemStack();

		if (itemstack != null && itemstack.getItem() == Items.BOW) //Forge: Data watcher can desync and cause this to NPE...
		{
			EnumHand enumhand1 = abstractclientplayer.getActiveHand();
			flag = enumhand1 == EnumHand.MAIN_HAND;
			flag1 = !flag;
		}
	}

	rotateArroundXAndY(f1, f2);
	setLightmap();
	rotateArm(partialTicks);
	GlStateManager.enableRescaleNormal();

	ItemStack itemStackMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 3);
	ItemStack itemStackOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 4);
	float equippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 5);
	float prevEquippedProgressMainHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 6);
	float equippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 7);
	float prevEquippedProgressOffHand = ReflectionHelper.getPrivateValue(ItemRenderer.class, ir, 8);

	RenderCyberlimbHand.INSTANCE.itemStackMainHand = itemStackMainHand;
	RenderCyberlimbHand.INSTANCE.itemStackOffHand = itemStackOffHand;

	if (flag && !missingSecondArm)
	{
		float f3 = enumhand == EnumHand.MAIN_HAND ? f : 0.0F;
		float f5 = 1.0F - (prevEquippedProgressMainHand + (equippedProgressMainHand - prevEquippedProgressMainHand) * partialTicks);
		RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft;
		RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight;
		RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.MAIN_HAND, f3, itemStackMainHand, f5);
	}

	if (flag1 && !missingArm)
	{
		float f4 = enumhand == EnumHand.OFF_HAND ? f : 0.0F;
		float f6 = 1.0F - (prevEquippedProgressOffHand + (equippedProgressOffHand - prevEquippedProgressOffHand) * partialTicks);
		RenderCyberlimbHand.INSTANCE.leftRobot = hasRoboLeft;
		RenderCyberlimbHand.INSTANCE.rightRobot = hasRoboRight;
		RenderCyberlimbHand.INSTANCE.renderItemInFirstPerson(abstractclientplayer, partialTicks, f1, EnumHand.OFF_HAND, f4, itemStackOffHand, f6);
	}

	GlStateManager.disableRescaleNormal();
	RenderHelper.disableStandardItemLighting();
}
 
Example #18
Source File: CreativeMenuHandler.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleCreativeInventory(BackgroundDrawnEvent event)
{
	if (event.getGui() instanceof GuiContainerCreative)
	{
		int selectedTabIndex = ReflectionHelper.getPrivateValue(GuiContainerCreative.class, (GuiContainerCreative) event.getGui(), 2);

		if (selectedTabIndex == Cyberware.creativeTab.getTabIndex())
		{
			GuiContainerCreative gui = (GuiContainerCreative) event.getGui();
			int i = (gui.width - 136) / 2;
			int j = (gui.height - 195) / 2;
			
			int xSize = 29;
			int ySize = 129;
			
			int xOffset = 0;
			boolean hasVisibleEffect = false;
			for(PotionEffect potioneffect : mc.thePlayer.getActivePotionEffects())
			{
				Potion potion = potioneffect.getPotion();
				if(potion.shouldRender(potioneffect)) {
					hasVisibleEffect = true; break;
				}
			}
			if (!this.mc.thePlayer.getActivePotionEffects().isEmpty() && hasVisibleEffect)
			{
				xOffset = 59;
			}
			salvaged.xPosition = salvaged.baseX + xOffset;
			manufactured.xPosition = manufactured.baseX + xOffset;

			
			GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
			this.mc.getTextureManager().bindTexture(CEX_GUI_TEXTURES);
			gui.drawTexturedModalRect(i + 166 + xOffset, j + 29, 0, 0, xSize, ySize);
			
			salvaged.visible = true;
			manufactured.visible = true;
		}
		else
		{
			salvaged.visible = false;
			manufactured.visible = false;
		}
	}
}
 
Example #19
Source File: ItemJetpack.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public ItemJetpack() {
	flySpeed = ReflectionHelper.findField(net.minecraft.entity.player.PlayerCapabilities.class, "flySpeed", "field_75096_f");
	flySpeed.setAccessible(true);
}
 
Example #20
Source File: GTUtility.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static BiomeDictionary.Type getBiomeTypeTagByName(String name) {
    Map<String, BiomeDictionary.Type> byName = ReflectionHelper.getPrivateValue(BiomeDictionary.Type.class, null, "byName");
    return byName.get(name);
}