Java Code Examples for net.minecraftforge.fml.relauncher.ReflectionHelper#getPrivateValue()

The following examples show how to use net.minecraftforge.fml.relauncher.ReflectionHelper#getPrivateValue() . 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: 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 2
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 3
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 4
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 5
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 6
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);
}
 
Example 7
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 8
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 9
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;
		}
	}
}