Skip to content

Commit

Permalink
Remove a bunch more reflection (#3074)
Browse files Browse the repository at this point in the history
Co-authored-by: boubou19 <miisterunknown@gmail.com>
  • Loading branch information
Alexdoru and boubou19 authored Sep 7, 2024
1 parent ba7a419 commit 82604ea
Show file tree
Hide file tree
Showing 34 changed files with 231 additions and 925 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:BloodMagic:1.6.5:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.0:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.7.0-GTNH:dev") { transitive = false }
compileOnly rfg.deobf("curse.maven:biomes-o-plenty-220318:2499612")

compileOnly('com.github.GTNewHorizons:SC2:2.2.0:dev') {transitive=false}
compileOnly('com.github.GTNewHorizons:Binnie:2.4.1:dev') {transitive = false}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bwcrossmod/galacticgreg/MTEVoidMinerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ private void handleOutputs() {
final List<ItemStack> inputOres = this.getStoredInputs()
.stream()
.filter(GTUtility::isOre)
.collect(Collectors.toList());;
.collect(Collectors.toList());
final ItemStack output = this.nextOre();
output.stackSize = multiplier;
if (inputOres.size() == 0 || this.mBlacklist && inputOres.stream()
if (inputOres.isEmpty() || this.mBlacklist && inputOres.stream()
.noneMatch(is -> GTUtility.areStacksEqual(is, output))
|| !this.mBlacklist && inputOres.stream()
.anyMatch(is -> GTUtility.areStacksEqual(is, output)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public boolean onRunningTick(ItemStack aStack) {
if (tFluid == null) continue;
if (isFluidLocked) {
if (mLockedFluid != null) {
if (!tFluid.isFluidEqual(mLockedFluid)) continue;;
if (!tFluid.isFluidEqual(mLockedFluid)) continue;
} else {
mLockedFluid = tFluid.copy();
mLockedFluid.amount = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/GTMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class GTMod implements IGTMod {
clientSide = "gregtech.common.GTClient",
serverSide = "gregtech.common.GTServer")
public static GTProxy gregtechproxy;
public static final boolean DEBUG = Boolean.getBoolean("gt.debug");;
public static final boolean DEBUG = Boolean.getBoolean("gt.debug");

public static int MAX_IC2 = 2147483647;
public static GTAchievements achievements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
// UUID of the owner.
owner_uuid = aBaseMetaTileEntity.getOwnerUuid();

SpaceProjectManager.checkOrCreateTeam(owner_uuid);;
SpaceProjectManager.checkOrCreateTeam(owner_uuid);

tryFetchingEnergy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ private Widget makeUnitStatusWidget(LinkedPurificationUnit unit) {
.widget(
unit.metaTileEntity()
.makeSyncerWidgets())
.widget(new FakeSyncWidget.BooleanSyncer(unit::isActive, unit::setActive));;
.widget(new FakeSyncWidget.BooleanSyncer(unit::isActive, unit::setActive));

return row;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/loaders/preload/GTPreLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public static void loadConfig() {
// ore_drop_behavior
try {
GTLog.out.println("Trying to set it to: " + ConfigOreDropBehavior.setting);
GTMod.gregtechproxy.oreDropSystem = GTProxy.OreDropSystem.valueOf(ConfigOreDropBehavior.setting);;
GTMod.gregtechproxy.oreDropSystem = GTProxy.OreDropSystem.valueOf(ConfigOreDropBehavior.setting);
} catch (IllegalArgumentException e) {
GTLog.err.println(e);
GTMod.gregtechproxy.oreDropSystem = GTProxy.OreDropSystem.FortuneItem;
Expand Down
30 changes: 11 additions & 19 deletions src/main/java/gtPlusPlus/api/objects/data/AutoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public AutoMap(Map<Integer, V> defaultMapType) {

/**
* Generates an AutoMap from the List.
*
*
* @param aList - Data to be inserted into the AutoMap.
*/
public AutoMap(List<V> aList) {
mInternalMap = new LinkedHashMap<>();
mInternalNameMap = new LinkedHashMap<>();
if (aList != null && aList.size() > 0) {
if (aList != null && !aList.isEmpty()) {
for (V obj : aList) {
add(obj);
}
Expand All @@ -56,13 +56,13 @@ public AutoMap(List<V> aList) {

/**
* Generates an AutoMap from a Set.
*
*
* @param aList - Data to be inserted into the AutoMap.
*/
public AutoMap(Set<V> aList) {
mInternalMap = new LinkedHashMap<>();
mInternalNameMap = new LinkedHashMap<>();
if (aList != null && aList.size() > 0) {
if (aList != null && !aList.isEmpty()) {
for (V obj : aList) {
add(obj);
}
Expand All @@ -71,13 +71,13 @@ public AutoMap(Set<V> aList) {

/**
* Generates an AutoMap from a Collection.
*
*
* @param aList - Data to be inserted into the AutoMap.
*/
public AutoMap(Collection<V> aList) {
mInternalMap = new LinkedHashMap<>();
mInternalNameMap = new LinkedHashMap<>();
if (aList != null && aList.size() > 0) {
if (aList != null && !aList.isEmpty()) {
for (V obj : aList) {
add(obj);
}
Expand All @@ -86,13 +86,13 @@ public AutoMap(Collection<V> aList) {

/**
* Generates an AutoMap from a Array.
*
*
* @param aArray - Data to be inserted into the AutoMap.
*/
public AutoMap(V[] aArray) {
mInternalMap = new LinkedHashMap<>();
mInternalNameMap = new LinkedHashMap<>();
if (aArray != null && aArray.length > 0) {
if (aArray != null) {
for (V obj : aArray) {
add(obj);
}
Expand All @@ -107,12 +107,8 @@ public Iterator<V> iterator() {
public synchronized boolean setValue(V object) {
int mOriginalID = this.mInternalID;
put(object);
if (this.mInternalMap.get(mOriginalID)
.equals(object) || mOriginalID > this.mInternalID) {
return true;
} else {
return false;
}
return this.mInternalMap.get(mOriginalID)
.equals(object) || mOriginalID > this.mInternalID;
}

public synchronized V put(V object) {
Expand Down Expand Up @@ -168,7 +164,6 @@ public synchronized void clear() {
this.mInternalID = 0;
this.mInternalMap.clear();
this.mInternalNameMap.clear();
return;
}

@Override
Expand Down Expand Up @@ -322,7 +317,6 @@ public int indexOf(Object o) {
for (V of : mInternalMap.values()) {
if (of != o) {
aCount++;
continue;
} else {
return aCount;
}
Expand Down Expand Up @@ -353,9 +347,7 @@ public List<V> subList(int fromIndex, int toIndex) {
AutoMap<V> aNewSubList = new AutoMap<>();
for (int slot = fromIndex; slot <= toIndex; slot++) {
V obj = mInternalMap.get(slot);
if (obj == null) {
continue;
} else {
if (obj != null) {
aNewSubList.put(obj);
}
}
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/gtPlusPlus/core/block/base/BlockBaseOre.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gtPlusPlus.core.block.base;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Random;

Expand All @@ -21,7 +20,6 @@
import gregtech.GTMod;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.IIconContainer;
import gregtech.api.interfaces.ITexture;
import gregtech.api.util.GTOreDictUnificator;
import gtPlusPlus.api.interfaces.ITexturedBlock;
Expand All @@ -30,7 +28,6 @@
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.api.objects.GTPPCopiedBlockTexture;
import gtPlusPlus.xmod.gregtech.api.objects.GTPPRenderedTexture;

Expand Down Expand Up @@ -100,13 +97,6 @@ public IIcon getIcon(int ordinalSide, int aMeta) {
return Blocks.stone.getIcon(0, 0);
}

/**
* GT Texture Handler
*/

// .08 compat
public static IIconContainer[] hiddenTextureArray;

@Override
public ITexture[] getTexture(ForgeDirection side) {
return getTexture(null, side);
Expand All @@ -120,21 +110,8 @@ public ITexture[] getTexture(Block block, ForgeDirection side) {
this.blockMaterial.getRGBA());
return new ITexture[] { new GTPPCopiedBlockTexture(Blocks.stone, 0, 0), aIconSet };
}

if (hiddenTextureArray == null) {
try {
Field o = ReflectionUtils.getField(Textures.BlockIcons.class, "STONES");
if (o != null) {
hiddenTextureArray = (IIconContainer[]) o.get(Textures.BlockIcons.class);
}
if (hiddenTextureArray == null) {
hiddenTextureArray = new IIconContainer[6];
}
} catch (IllegalArgumentException | IllegalAccessException e) {
hiddenTextureArray = new IIconContainer[6];
}
}
return new ITexture[] { new GTPPRenderedTexture(hiddenTextureArray[0], new short[] { 240, 240, 240, 0 }) };
return new ITexture[] {
new GTPPRenderedTexture(Textures.BlockIcons.STONES[0], new short[] { 240, 240, 240, 0 }) };
}

@Override
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ public boolean isFocused() {
}

public boolean isBackgroundDrawingEnabled() {
Field enableBackgroundDrawing = ReflectionUtils.getField(
GuiTextField.class,
!PreloaderCore.DEV_ENVIRONMENT ? "field_146215_m" : "enableBackgroundDrawing");
if (enableBackgroundDrawing != null) {
return ReflectionUtils.getFieldValue(enableBackgroundDrawing, this);
}
return true;
return this.getEnableBackgroundDrawing();
}

public int getLineScrollOffset() {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/gtPlusPlus/core/handler/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PacketHandler {

private static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(GTPlusPlus.ID);

public static final void init() {
public static void init() {
registerMessage(PacketVolumetricFlaskGui.class, PacketVolumetricFlaskGui.class);
registerMessage(PacketVolumetricFlaskGui2.class, PacketVolumetricFlaskGui2.class);
}
Expand Down Expand Up @@ -50,45 +50,44 @@ private static void registerMessage(Class handlerClass, Class messageClass, Side
/**
* Send this message to the specified player. See {@link SimpleNetworkWrapper#sendTo(IMessage, EntityPlayerMP)}
*/
public static final void sendTo(IMessage message, EntityPlayerMP player) {
public static void sendTo(IMessage message, EntityPlayerMP player) {
INSTANCE.sendTo(message, player);
}

/**
* Send this message to everyone within a certain range of a point. See
* {@link SimpleNetworkWrapper#sendToDimension(IMessage, NetworkRegistry.TargetPoint)}
* {@link SimpleNetworkWrapper#sendToAllAround(IMessage, NetworkRegistry.TargetPoint)}
*/
public static final void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) {
public static void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) {
INSTANCE.sendToAllAround(message, point);
}

/**
* Sends a message to everyone within a certain range of the coordinates in the same dimension.
*/
public static final void sendToAllAround(IMessage message, int dimension, double x, double y, double z,
double range) {
public static void sendToAllAround(IMessage message, int dimension, double x, double y, double z, double range) {
sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, x, y, z, range));
}

/**
* Sends a message to everyone within a certain range of the player provided.
*/
public static final void sendToAllAround(IMessage message, EntityPlayer player, double range) {
public static void sendToAllAround(IMessage message, EntityPlayer player, double range) {
sendToAllAround(message, player.worldObj.provider.dimensionId, player.posX, player.posY, player.posZ, range);
}

/**
* Send this message to everyone within the supplied dimension. See
* {@link SimpleNetworkWrapper#sendToDimension(IMessage, int)}
*/
public static final void sendToDimension(IMessage message, int dimensionId) {
public static void sendToDimension(IMessage message, int dimensionId) {
INSTANCE.sendToDimension(message, dimensionId);
}

/**
* Send this message to the server. See {@link SimpleNetworkWrapper#sendToServer(IMessage)}
*/
public static final void sendToServer(IMessage message) {
public static void sendToServer(IMessage message) {
INSTANCE.sendToServer(message);
}
}
45 changes: 16 additions & 29 deletions src/main/java/gtPlusPlus/core/item/chemistry/AgriculturalChem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gtPlusPlus.core.item.chemistry;

import static gregtech.api.enums.Mods.BiomesOPlenty;
import static gregtech.api.enums.Mods.Forestry;
import static gregtech.api.enums.Mods.TinkerConstruct;
import static gregtech.api.recipe.RecipeMaps.centrifugeRecipes;
import static gregtech.api.recipe.RecipeMaps.compressorRecipes;
Expand All @@ -12,7 +11,6 @@
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.chemicalDehydratorRecipes;
import static gtPlusPlus.api.recipe.GTPPRecipeMaps.semiFluidFuels;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -23,8 +21,12 @@
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;

import forestry.core.items.ItemForestryBonemeal;
import forestry.core.items.ItemRegistryCore;
import forestry.plugins.PluginCore;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.Materials;
import gregtech.api.enums.Mods;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.TierEU;
import gregtech.api.util.GTOreDictUnificator;
Expand All @@ -37,7 +39,6 @@
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.FluidUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.plugin.agrichem.BioRecipes;
import gtPlusPlus.plugin.agrichem.item.algae.ItemAgrichemBase;
import gtPlusPlus.plugin.agrichem.item.algae.ItemAlgaeBase;
Expand Down Expand Up @@ -543,33 +544,19 @@ private static void addMiscRecipes() {
ItemStack aManureByprod = ItemUtils.getSimpleStack(dustManureByproducts, 1);

// Dehydrate Organise Fert to Normal Fert.
if (Mods.Forestry.isModLoaded()) {
ItemRegistryCore aItemRegInstance = PluginCore.items;
if (aItemRegInstance != null) {
ItemForestryBonemeal fertilizerCompound = aItemRegInstance.fertilizerCompound;
aFertForestry = ItemUtils.getSimpleStack(fertilizerCompound);

/*
* Forestry Support
*/
if (Forestry.isModLoaded()) {
Field aItemField = ReflectionUtils
.getField(ReflectionUtils.getClass("forestry.plugins.PluginCore"), "items");
try {
Object aItemRegInstance = aItemField != null ? aItemField.get(aItemField) : null;
if (aItemRegInstance != null) {
Field aFertField = ReflectionUtils.getField(aItemRegInstance.getClass(), "fertilizerCompound");
Object aItemInstance = aFertField.get(aItemRegInstance);
if (aItemInstance instanceof Item aForestryFert) {
aFertForestry = ItemUtils.getSimpleStack((Item) aItemInstance);

GTValues.RA.stdBuilder()
.itemInputs(
GTUtility.getIntegratedCircuit(11),
ItemUtils.getSimpleStack(aDustOrganicFert, 4))
.itemOutputs(ItemUtils.getSimpleStack(aForestryFert, 3), aManureByprod, aManureByprod)
.outputChances(100_00, 20_00, 20_00)
.eut(240)
.duration(20 * SECONDS)
.addTo(chemicalDehydratorRecipes);
}
}
} catch (IllegalArgumentException | IllegalAccessException e) {
GTValues.RA.stdBuilder()
.itemInputs(GTUtility.getIntegratedCircuit(11), ItemUtils.getSimpleStack(aDustOrganicFert, 4))
.itemOutputs(ItemUtils.getSimpleStack(fertilizerCompound, 3), aManureByprod, aManureByprod)
.outputChances(100_00, 20_00, 20_00)
.eut(240)
.duration(20 * SECONDS)
.addTo(chemicalDehydratorRecipes);

}
}
Expand Down
Loading

0 comments on commit 82604ea

Please sign in to comment.