diff options
Diffstat (limited to 'src/main/java/gregtech/api/objects')
7 files changed, 75 insertions, 80 deletions
diff --git a/src/main/java/gregtech/api/objects/GT_ChunkManager.java b/src/main/java/gregtech/api/objects/GT_ChunkManager.java index dd87c8c72e..14baaddd3d 100644 --- a/src/main/java/gregtech/api/objects/GT_ChunkManager.java +++ b/src/main/java/gregtech/api/objects/GT_ChunkManager.java @@ -21,7 +21,9 @@ import gregtech.api.interfaces.IChunkLoader; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Log; -// This class handles re-initializing chunks after a server restart +/** + * Handles re-initialization of chunks after a server restart. + */ public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback, ForgeChunkManager.PlayerOrderedLoadingCallback { @@ -30,17 +32,25 @@ public class GT_ChunkManager public static void init() { ForgeChunkManager.setForcedChunkLoadingCallback(GT_Mod.instance, instance); - // MinecraftForge.EVENT_BUS.register(instance); } @Override public void ticketsLoaded(List<Ticket> tickets, World world) {} - // Determine if tickets should be kept. Based on if the ticket is a machine or working chunk ticket. Working chunk - // tickets are tossed - // and re-created when the machine re-activates. Machine tickets are kept only if the config - // alwaysReloadChunkloaders is true. Otherwise - // machine chunks are tossed and re-created only when the machine re-activates, similar to a Passive Anchor. + /** + * Determines if tickets should be kept. Based on if the ticket is a machine or a working-chunk ticket. + * Working-chunk tickets are tossed and recreated when the machine reactivates. + * Machine tickets are kept only if the config {@code alwaysReloadChunkloaders} is true. + * Otherwise, machine chunks are tossed and recreated only when the machine reactivates, + * similarly to a Passive Anchor. + * + * @param tickets The tickets that you will want to select from. + * The list is immutable and cannot be manipulated directly. Copy it first. + * @param world The world + * @param maxTicketCount The maximum number of tickets that will be allowed. + * @return list of tickets + */ + @Override public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) { List<Ticket> validTickets = new ArrayList<>(); @@ -54,8 +64,7 @@ public class GT_ChunkManager .getInteger("OwnerZ"); if (y > 0) { TileEntity tile = world.getTileEntity(x, y, z); - if (tile != null && tile instanceof IGregTechTileEntity - && ((IGregTechTileEntity) tile).isAllowedToWork()) { + if (tile instanceof IGregTechTileEntity && ((IGregTechTileEntity) tile).isAllowedToWork()) { ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(x >> 4, z >> 4)); if (!registeredTickets.containsKey(tile)) { registeredTickets.put(tile, ticket); @@ -72,19 +81,32 @@ public class GT_ChunkManager return validTickets; } - // Determine if player tickets should be kept. This is where a ticket list per player would be created and - // maintained. When - // a player join event occurs, their name/UUID/whatevs is compared against tickets on this list and those tickets - // reactivated. - // Since that info would be maintained/dealt with on a per-player startup, the list returned back to Forge is empty. + /** + * Determines if player tickets should be kept. This is where a ticket list per-player would be created and + * maintained. When a player joins, an event occurs, their name/UUID/etc is compared against tickets on this list + * and those tickets are reactivated. + * Since that info would be maintained/dealt with on a per-player startup, the list returned back to Forge is empty. + * + * @param tickets The tickets that you will want to select from. + * The list is immutable and cannot be manipulated directly. Copy it first. + * @param world The world + * @return the list of string-ticket paris + */ @Override public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world) { // Not currently used, so just return an empty list. return ArrayListMultimap.create(); } - // Request a chunk to be loaded for this machine - // may pass null chunk to load just the machine itself, if "alwaysReloadChunkloaders" is enabled in config + /** + * Requests a chunk to be loaded for this machine. May pass a {@code null} chunk to load just the machine itself if + * {@code alwaysReloadChunkloaders} is enabled in config. + * + * @param owner owner of the TileEntity + * @param chunkXZ chunk coordinates + * @param player player + * @return if the chunk was loaded successfully + */ public static boolean requestPlayerChunkLoad(TileEntity owner, ChunkCoordIntPair chunkXZ, String player) { if (!GT_Values.enableChunkloaders) return false; if (!GT_Values.alwaysReloadChunkloaders && chunkXZ == null) return false; @@ -122,6 +144,7 @@ public class GT_ChunkManager return true; } + @SuppressWarnings("UnusedReturnValue") public static boolean requestChunkLoad(TileEntity owner, ChunkCoordIntPair chunkXZ) { return requestPlayerChunkLoad(owner, chunkXZ, ""); } diff --git a/src/main/java/gregtech/api/objects/GT_FluidStack.java b/src/main/java/gregtech/api/objects/GT_FluidStack.java index f0a6dae8e5..5a017fd590 100644 --- a/src/main/java/gregtech/api/objects/GT_FluidStack.java +++ b/src/main/java/gregtech/api/objects/GT_FluidStack.java @@ -2,16 +2,12 @@ package gregtech.api.objects; import java.util.Collection; import java.util.Collections; -import java.util.Map; import java.util.WeakHashMap; -import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import gregtech.api.GregTech_API; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_Utility; /** * Because Forge fucked this one up royally. @@ -20,7 +16,6 @@ public class GT_FluidStack extends FluidStack { private static final Collection<GT_FluidStack> sAllFluidStacks = Collections .newSetFromMap(new WeakHashMap<>(10000)); - private static volatile boolean lock = false; private final Fluid mFluid; public GT_FluidStack(Fluid aFluid, int aAmount) { @@ -35,46 +30,8 @@ public class GT_FluidStack extends FluidStack { this(aFluid.getFluid(), aFluid.amount); } - public static final synchronized void fixAllThoseFuckingFluidIDs() { - if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) { - try { - while (lock) { - Thread.sleep(1); - } - } catch (InterruptedException e) {} - lock = true; - for (GT_FluidStack tFluid : sAllFluidStacks) tFluid.fixFluidIDForFucksSake(); - try { - for (Map<Fluid, ?> tMap : GregTech_API.sFluidMappings) GT_Utility.reMap(tMap); - } catch (Throwable e) { - e.printStackTrace(GT_Log.err); - } - lock = false; - } - } - - public final void fixFluidIDForFucksSake() { - if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) { - int fluidID; - try { - fluidID = this.getFluid() - .getID(); - } catch (Throwable e) { - System.err.println(e); - } - try { - fluidID = mFluid.getID(); - } catch (Throwable e) { - fluidID = -1; - } - } - } - @Override public FluidStack copy() { - if (ForgeVersion.getBuildVersion() < 1355 && ForgeVersion.getRevisionVersion() < 4) { - fixFluidIDForFucksSake(); - } return new GT_FluidStack(this); } diff --git a/src/main/java/gregtech/api/objects/GT_HashSet.java b/src/main/java/gregtech/api/objects/GT_HashSet.java index 6442631035..d42f194e5d 100644 --- a/src/main/java/gregtech/api/objects/GT_HashSet.java +++ b/src/main/java/gregtech/api/objects/GT_HashSet.java @@ -1,6 +1,11 @@ package gregtech.api.objects; -import java.util.*; +import java.util.AbstractSet; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; import net.minecraft.item.ItemStack; @@ -42,6 +47,7 @@ public class GT_HashSet<E extends GT_ItemStack> extends AbstractSet<E> { return map; } + @SuppressWarnings("unchecked") // The downcasting below will throw ClassCastException unless E is GT_ItemStack. @Override public Iterator<E> iterator() { return (Iterator<E>) map.keySet() diff --git a/src/main/java/gregtech/api/objects/GT_ItemStack.java b/src/main/java/gregtech/api/objects/GT_ItemStack.java index 27e79a3e96..1273b7111d 100644 --- a/src/main/java/gregtech/api/objects/GT_ItemStack.java +++ b/src/main/java/gregtech/api/objects/GT_ItemStack.java @@ -7,6 +7,10 @@ import net.minecraft.item.ItemStack; import gregtech.api.enums.GT_Values; import gregtech.api.util.GT_Utility; +/** + * An optimization of {@link ItemStack} to have a better {@code hashcode} and {@code equals} in order to improve + * {@code HashMap} and {@code Set} performance + */ public class GT_ItemStack { public final Item mItem; diff --git a/src/main/java/gregtech/api/objects/ItemData.java b/src/main/java/gregtech/api/objects/ItemData.java index c6a04bbb7e..779e45ac8b 100644 --- a/src/main/java/gregtech/api/objects/ItemData.java +++ b/src/main/java/gregtech/api/objects/ItemData.java @@ -1,6 +1,8 @@ package gregtech.api.objects; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import net.minecraft.item.ItemStack; @@ -115,8 +117,6 @@ public class ItemData { @Override public String toString() { if (mPrefix == null || mMaterial == null || mMaterial.mMaterial == null) return ""; - return String.valueOf( - new StringBuilder().append(mPrefix.name()) - .append(mMaterial.mMaterial.mName)); + return String.valueOf(mPrefix.name() + mMaterial.mMaterial.mName); } } diff --git a/src/main/java/gregtech/api/objects/ObjMap.java b/src/main/java/gregtech/api/objects/ObjMap.java index bb15aab0d7..badc673464 100644 --- a/src/main/java/gregtech/api/objects/ObjMap.java +++ b/src/main/java/gregtech/api/objects/ObjMap.java @@ -191,7 +191,7 @@ public class ObjMap<K, V> { return key.hashCode() & m_mask; } - /** Taken from FastUtil implementation */ + /* Taken from FastUtil implementation */ /** * Return the least power of two greater than or equal to the specified value. diff --git a/src/main/java/gregtech/api/objects/XSTR.java b/src/main/java/gregtech/api/objects/XSTR.java index 1ce5273e7e..33823d3ebd 100644 --- a/src/main/java/gregtech/api/objects/XSTR.java +++ b/src/main/java/gregtech/api/objects/XSTR.java @@ -1,29 +1,33 @@ package gregtech.api.objects; +import java.util.Random; +import java.util.concurrent.atomic.AtomicLong; + +/* + * TODO: Check the validity of the algorithm. + * There is a claim that this particular implementation is not faithful to the articles it links, skewing the + * distribution. + */ /** + * XSTR - Xorshift ThermiteRandom Modified by Bogdan-G 03.06.2016 version 0.0.4 + * <p> * A subclass of java.util.random that implements the Xorshift random number generator - * + * <p> * - it is 30% faster than the generator from Java's library - it produces random sequences of higher quality than * java.util.Random - this class also provides a clone() function - * + * <p> * Usage: XSRandom rand = new XSRandom(); //Instantiation x = rand.nextInt(); //pull a random number - * + * <p> * To use the class in legacy code, you may also instantiate an XSRandom object and assign it to a java.util.Random * object: java.util.Random rand = new XSRandom(); - * + * <p> * for an explanation of the algorithm, see http://demesos.blogspot.com/2011/09/pseudo-random-number-generators.html * * @author Wilfried Elmenreich University of Klagenfurt/Lakeside Labs http://www.elmenreich.tk - * + * <p> * This code is released under the GNU Lesser General Public License Version 3 * http://www.gnu.org/licenses/lgpl-3.0.txt */ -import java.util.Random; -import java.util.concurrent.atomic.AtomicLong; - -/** - * XSTR - Xorshift ThermiteRandom Modified by Bogdan-G 03.06.2016 version 0.0.4 - */ public class XSTR extends Random { private static final long serialVersionUID = 6208727693524452904L; @@ -118,11 +122,12 @@ public class XSTR extends Random { } /** - * Implementation of George Marsaglia's elegant Xorshift random generator 30% faster and better quality than the - * built-in java.util.random see also see http://www.javamex.com/tutorials/random_numbers/xorshift.shtml + * Implementation of George Marsaglia's Xorshift random generator that is 30% faster and better quality than the + * built-in java.util.random. * - * @param nbits - * @return + * @param nbits number of bits to shift the result for + * @return a random integer + * @see <a href="https://www.javamex.com/tutorials/random_numbers/xorshift.shtml">the Xorshift article</a> */ @Override public int next(int nbits) { |