forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another pass at substitutions - now capable of fixing up ItemBlock to…
… point at the right block when a block is substituted, should also handle substituting itemblocks. There's some hackery in the way we have to change the value of ItemBlock.block, but it's not too egregious in my opinion.
- Loading branch information
Showing
12 changed files
with
328 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/net/minecraftforge/fml/common/registry/FinalFieldHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Minecraft Forge | ||
* Copyright (c) 2016. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation version 2.1 | ||
* of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package net.minecraftforge.fml.common.registry; | ||
|
||
import com.google.common.base.Throwables; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* Helper class for setting final fields. | ||
*/ | ||
class FinalFieldHelper | ||
{ | ||
private static Field modifiersField; | ||
private static Object reflectionFactory; | ||
private static Method newFieldAccessor; | ||
private static Method fieldAccessorSet; | ||
static Field makeWritable(Field f) throws Exception | ||
{ | ||
if (modifiersField == null) | ||
{ | ||
Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory"); | ||
reflectionFactory = getReflectionFactory.invoke(null); | ||
newFieldAccessor = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("newFieldAccessor", Field.class, boolean.class); | ||
fieldAccessorSet = Class.forName("sun.reflect.FieldAccessor").getDeclaredMethod("set", Object.class, Object.class); | ||
modifiersField = Field.class.getDeclaredField("modifiers"); | ||
modifiersField.setAccessible(true); | ||
} | ||
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); | ||
return f; | ||
} | ||
|
||
|
||
static void setField(Field field, Object instance, Object thing) throws Exception | ||
{ | ||
Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false); | ||
fieldAccessorSet.invoke(fieldAccessor, instance, thing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.