Remove ReflectionHandler since it was only used by AbstractOptifineAccessor

This commit is contained in:
James Seibel
2023-09-23 11:51:42 -05:00
parent 03efa3c191
commit 05a16e00ad
3 changed files with 2 additions and 141 deletions
@@ -1,46 +0,0 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program 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 3.
*
* This program 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 program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.core;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
/**
* A singleton used to get variables from methods
* where they are private or potentially absent.
* Specifically the fog setting used by Optifine or the
* presence/absence of other mods.
* <p>
* This interface doesn't necessarily have to exist, but
* it makes using the singleton handler more uniform (always
* passing in interfaces), and it may be needed in the future if
* we find that reflection handlers need to be different for
* different MC versions.
*
* @author James Seibel
* @version 2022-11-24
*/
public interface IReflectionHandler extends IBindable
{
/** @return if Sodium (or a sodium like) mod is present. */
boolean sodiumPresent();
boolean optifinePresent();
}
@@ -1,88 +0,0 @@
/*
* This file is part of the Distant Horizons mod
* licensed under the GNU LGPL v3 License.
*
* Copyright (C) 2020-2023 James Seibel
*
* This program 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 3.
*
* This program 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 program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.core;
import java.lang.invoke.MethodHandles;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
import org.apache.logging.log4j.Logger;
/**
* A singleton used to determine if a class is present or
* access variables from methods where they are private
* or potentially absent. <br><br>
*
* For example: presence/absence of Optifine.
*
* @author James Seibel
* @version 2022-11-24
*/
public class ReflectionHandler implements IReflectionHandler
{
private static final Logger LOGGER = DhLoggerBuilder.getLogger(MethodHandles.lookup().lookupClass().getSimpleName());
public static final ReflectionHandler INSTANCE = new ReflectionHandler();
// populated when the methods are called the first time
private Boolean sodiumPresent = null;
private Boolean optifinePresent = false;
private ReflectionHandler() { }
//===================//
// is [mod] present? //
//===================//
@Override
public boolean optifinePresent()
{
if (this.optifinePresent == null)
{
// call the base accessor so we don't have duplicate code
this.optifinePresent = AbstractOptifineAccessor.isOptifinePresent();
}
return this.optifinePresent;
}
@Override
public boolean sodiumPresent()
{
if (this.sodiumPresent == null)
{
try
{
Class.forName("me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer");
this.sodiumPresent = true;
}
catch (ClassNotFoundException e)
{
this.sodiumPresent = false;
}
}
return this.sodiumPresent;
}
}
@@ -22,7 +22,6 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor;
import com.seibel.distanthorizons.api.enums.rendering.EFogDrawMode;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.ReflectionHandler;
import java.lang.reflect.Field;
@@ -66,11 +65,7 @@ public abstract class AbstractOptifineAccessor implements IOptifineAccessor
return null;
}
/**
* Should not be called frequently since this uses reflection calls to determine if Optifine is present. <br>
* Use {@link ReflectionHandler#optifinePresent()} instead.
*/
public static boolean isOptifinePresent() { return getOptifineFogField() != null; }
public static boolean optifinePresent() { return getOptifineFogField() != null; }
@@ -115,7 +110,7 @@ public abstract class AbstractOptifineAccessor implements IOptifineAccessor
}
}
@Override
public double getRenderResolutionMultiplier()
{
/*