diff options
Diffstat (limited to 'src/main/java/gregtech/api/objects')
25 files changed, 644 insertions, 484 deletions
diff --git a/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java b/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java index ad51d307fe..1fe4536085 100644 --- a/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java +++ b/src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java @@ -6,18 +6,31 @@ import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -@Optional.Interface(iface = "appeng.api.storage.IExternalStorageHandler", modid = "appliedenergistics2", striprefs = true) +@Optional.Interface( + iface = "appeng.api.storage.IExternalStorageHandler", + modid = "appliedenergistics2", + striprefs = true) public class AE2DigitalChestHandler implements appeng.api.storage.IExternalStorageHandler { @Override @Optional.Method(modid = "appliedenergistics2") - public boolean canHandle(final TileEntity te, final ForgeDirection d, final appeng.api.storage.StorageChannel chan, final appeng.api.networking.security.BaseActionSource mySrc) { - return chan == appeng.api.storage.StorageChannel.ITEMS && te instanceof BaseMetaTileEntity && ((BaseMetaTileEntity) te).getMetaTileEntity() instanceof GT_MetaTileEntity_DigitalChestBase; + public boolean canHandle( + final TileEntity te, + final ForgeDirection d, + final appeng.api.storage.StorageChannel chan, + final appeng.api.networking.security.BaseActionSource mySrc) { + return chan == appeng.api.storage.StorageChannel.ITEMS + && te instanceof BaseMetaTileEntity + && ((BaseMetaTileEntity) te).getMetaTileEntity() instanceof GT_MetaTileEntity_DigitalChestBase; } @Override @Optional.Method(modid = "appliedenergistics2") - public appeng.api.storage.IMEInventory getInventory(final TileEntity te, final ForgeDirection d, final appeng.api.storage.StorageChannel chan, final appeng.api.networking.security.BaseActionSource src) { + public appeng.api.storage.IMEInventory getInventory( + final TileEntity te, + final ForgeDirection d, + final appeng.api.storage.StorageChannel chan, + final appeng.api.networking.security.BaseActionSource src) { if (chan == appeng.api.storage.StorageChannel.ITEMS) { return ((GT_MetaTileEntity_DigitalChestBase) (((BaseMetaTileEntity) te).getMetaTileEntity())); } diff --git a/src/main/java/gregtech/api/objects/CollectorUtils.java b/src/main/java/gregtech/api/objects/CollectorUtils.java index 3f89ad0773..41ca5e1e05 100644 --- a/src/main/java/gregtech/api/objects/CollectorUtils.java +++ b/src/main/java/gregtech/api/objects/CollectorUtils.java @@ -20,10 +20,13 @@ public class CollectorUtils { * @return a merge function which always throw {@code IllegalStateException} */ public static <T> BinaryOperator<T> throwingMerger() { - return (u,v) -> { throw new IllegalStateException(String.format("Duplicate key %s", u)); }; + return (u, v) -> { + throw new IllegalStateException(String.format("Duplicate key %s", u)); + }; } - public static <K, V, E extends Map.Entry<K, V>, M extends Map<K, V>> Collector<E, ?, M> entriesToMap(Supplier<M> mapSupplier) { + public static <K, V, E extends Map.Entry<K, V>, M extends Map<K, V>> Collector<E, ?, M> entriesToMap( + Supplier<M> mapSupplier) { return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, CollectorUtils.throwingMerger(), mapSupplier); } } diff --git a/src/main/java/gregtech/api/objects/ElementStack.java b/src/main/java/gregtech/api/objects/ElementStack.java index d241276103..29f043188c 100644 --- a/src/main/java/gregtech/api/objects/ElementStack.java +++ b/src/main/java/gregtech/api/objects/ElementStack.java @@ -17,7 +17,11 @@ public class ElementStack implements Cloneable { @Override public ElementStack clone() { - try { return (ElementStack) super.clone(); } catch (Exception e) { return new ElementStack(mElement, mAmount); } + try { + return (ElementStack) super.clone(); + } catch (Exception e) { + return new ElementStack(mElement, mAmount); + } } @Override @@ -26,7 +30,10 @@ public class ElementStack implements Cloneable { if (aObject == null) return false; if (aObject instanceof Element) return aObject == mElement; if (aObject instanceof ElementStack) - return ((ElementStack) aObject).mElement == mElement && (mAmount < 0 || ((ElementStack) aObject).mAmount < 0 || ((ElementStack) aObject).mAmount == mAmount); + return ((ElementStack) aObject).mElement == mElement + && (mAmount < 0 + || ((ElementStack) aObject).mAmount < 0 + || ((ElementStack) aObject).mAmount == mAmount); return false; } diff --git a/src/main/java/gregtech/api/objects/GT_ArrayList.java b/src/main/java/gregtech/api/objects/GT_ArrayList.java index a9efd8d0a0..fe6bd4a214 100644 --- a/src/main/java/gregtech/api/objects/GT_ArrayList.java +++ b/src/main/java/gregtech/api/objects/GT_ArrayList.java @@ -1,7 +1,6 @@ package gregtech.api.objects; import com.google.common.collect.Collections2; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -21,13 +20,27 @@ public class GT_ArrayList<E> extends ArrayList<E> { public GT_ArrayList(boolean aAllowNulls, E... aArray) { super(Arrays.asList(aArray)); mAllowNulls = aAllowNulls; - if (!mAllowNulls) {size_sS=size(); for (int i = 0; i < size_sS; i++) if (get(i) == null) {remove(i--);size_sS=size();}} + if (!mAllowNulls) { + size_sS = size(); + for (int i = 0; i < size_sS; i++) + if (get(i) == null) { + remove(i--); + size_sS = size(); + } + } } public GT_ArrayList(boolean aAllowNulls, Collection<? extends E> aList) { super(aList); mAllowNulls = aAllowNulls; - if (!mAllowNulls) {size_sS=size(); for (int i = 0; i < size_sS; i++) if (get(i) == null) {remove(i--);size_sS=size();}} + if (!mAllowNulls) { + size_sS = size(); + for (int i = 0; i < size_sS; i++) + if (get(i) == null) { + remove(i--); + size_sS = size(); + } + } } @Override diff --git a/src/main/java/gregtech/api/objects/GT_ChunkManager.java b/src/main/java/gregtech/api/objects/GT_ChunkManager.java index 2f1d2c3381..e06834fe1f 100644 --- a/src/main/java/gregtech/api/objects/GT_ChunkManager.java +++ b/src/main/java/gregtech/api/objects/GT_ChunkManager.java @@ -1,12 +1,16 @@ package gregtech.api.objects; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.interfaces.IChunkLoader; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Log; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.ChunkCoordIntPair; @@ -14,27 +18,24 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - // This class handles re-initializing chunks after a server restart -public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback, ForgeChunkManager.PlayerOrderedLoadingCallback { +public class GT_ChunkManager + implements ForgeChunkManager.OrderedLoadingCallback, ForgeChunkManager.PlayerOrderedLoadingCallback { private Map<TileEntity, Ticket> registeredTickets = new HashMap<>(); public static GT_ChunkManager instance = new GT_ChunkManager(); public static void init() { ForgeChunkManager.setForcedChunkLoadingCallback(GT_Mod.instance, instance); - //MinecraftForge.EVENT_BUS.register(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 + // 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. @Override public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) { @@ -46,23 +47,30 @@ public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback int z = ticket.getModData().getInteger("OwnerZ"); if (y > 0) { TileEntity tile = world.getTileEntity(x, y, z); - if (tile != null && tile instanceof IGregTechTileEntity && ((IGregTechTileEntity)tile).isAllowedToWork()) { + if (tile != null + && tile instanceof IGregTechTileEntity + && ((IGregTechTileEntity) tile).isAllowedToWork()) { ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(x >> 4, z >> 4)); if (!registeredTickets.containsKey(tile)) { registeredTickets.put(tile, ticket); - if (((IGregTechTileEntity)tile).getMetaTileEntity() instanceof IChunkLoader) - ForgeChunkManager.forceChunk(ticket, ((IChunkLoader)((IGregTechTileEntity)tile).getMetaTileEntity()).getActiveChunk()); + if (((IGregTechTileEntity) tile).getMetaTileEntity() instanceof IChunkLoader) + ForgeChunkManager.forceChunk( + ticket, + ((IChunkLoader) ((IGregTechTileEntity) tile).getMetaTileEntity()) + .getActiveChunk()); validTickets.add(ticket); } } } } } - return validTickets ; + 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. + // 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. @Override public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world) { @@ -73,27 +81,29 @@ public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback // 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 public static boolean requestPlayerChunkLoad(TileEntity owner, ChunkCoordIntPair chunkXZ, String player) { - if (!GT_Values.enableChunkloaders) - return false; - if (!GT_Values.alwaysReloadChunkloaders && chunkXZ == null) - return false; + if (!GT_Values.enableChunkloaders) return false; + if (!GT_Values.alwaysReloadChunkloaders && chunkXZ == null) return false; if (GT_Values.debugChunkloaders && chunkXZ != null) - GT_Log.out.println("GT_ChunkManager: Chunk request: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); + GT_Log.out.println( + "GT_ChunkManager: Chunk request: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); if (instance.registeredTickets.containsKey(owner)) { ForgeChunkManager.forceChunk(instance.registeredTickets.get(owner), chunkXZ); } else { Ticket ticket; if (player.equals("")) - ticket = ForgeChunkManager.requestTicket(GT_Mod.instance, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); + ticket = ForgeChunkManager.requestTicket( + GT_Mod.instance, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); else - ticket = ForgeChunkManager.requestPlayerTicket(GT_Mod.instance, player, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); + ticket = ForgeChunkManager.requestPlayerTicket( + GT_Mod.instance, player, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); if (ticket == null) { if (GT_Values.debugChunkloaders) GT_Log.out.println("GT_ChunkManager: ForgeChunkManager.requestTicket failed"); return false; } if (GT_Values.debugChunkloaders) - GT_Log.out.println("GT_ChunkManager: ticket issued for machine at: (" + owner.xCoord + ", " + owner.yCoord + ", " + owner.zCoord + ")" ); + GT_Log.out.println("GT_ChunkManager: ticket issued for machine at: (" + owner.xCoord + ", " + + owner.yCoord + ", " + owner.zCoord + ")"); NBTTagCompound tag = ticket.getModData(); tag.setInteger("OwnerX", owner.xCoord); tag.setInteger("OwnerY", owner.yCoord); @@ -111,25 +121,26 @@ public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback } public static void releaseChunk(TileEntity owner, ChunkCoordIntPair chunkXZ) { - if (!GT_Values.enableChunkloaders) - return; + if (!GT_Values.enableChunkloaders) return; Ticket ticket = instance.registeredTickets.get(owner); if (ticket != null) { if (GT_Values.debugChunkloaders) - GT_Log.out.println("GT_ChunkManager: Chunk release: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); + GT_Log.out.println( + "GT_ChunkManager: Chunk release: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); ForgeChunkManager.unforceChunk(ticket, chunkXZ); } } public static void releaseTicket(TileEntity owner) { - if (!GT_Values.enableChunkloaders) - return; + if (!GT_Values.enableChunkloaders) return; Ticket ticket = instance.registeredTickets.get(owner); if (ticket != null) { if (GT_Values.debugChunkloaders) { - GT_Log.out.println("GT_ChunkManager: ticket released by machine at: (" + owner.xCoord + ", " + owner.yCoord + ", " + owner.zCoord + ")" ); + GT_Log.out.println("GT_ChunkManager: ticket released by machine at: (" + owner.xCoord + ", " + + owner.yCoord + ", " + owner.zCoord + ")"); for (ChunkCoordIntPair chunk : ticket.getChunkList()) - GT_Log.out.println("GT_ChunkManager: Chunk release: (" + chunk.chunkXPos + ", " + chunk.chunkZPos + ")"); + GT_Log.out.println( + "GT_ChunkManager: Chunk release: (" + chunk.chunkXPos + ", " + chunk.chunkZPos + ")"); } ForgeChunkManager.releaseTicket(ticket); instance.registeredTickets.remove(owner); @@ -139,9 +150,9 @@ public class GT_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback public static void printTickets() { GT_Log.out.println("GT_ChunkManager: Start forced chunks dump:"); instance.registeredTickets.forEach((machine, ticket) -> { - GT_Log.out.print("GT_ChunkManager: Chunks forced by the machine at (" + machine.xCoord + ", " + machine.yCoord + ", " + machine.zCoord + ")"); - if (ticket.isPlayerTicket()) - GT_Log.out.print(" Owner: " + ticket.getPlayerName()); + GT_Log.out.print("GT_ChunkManager: Chunks forced by the machine at (" + machine.xCoord + ", " + + machine.yCoord + ", " + machine.zCoord + ")"); + if (ticket.isPlayerTicket()) GT_Log.out.print(" Owner: " + ticket.getPlayerName()); GT_Log.out.print(" :"); for (ChunkCoordIntPair c : ticket.getChunkList()) { GT_Log.out.print("("); diff --git a/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java b/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java index 317cc04066..cfecc9d736 100644 --- a/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java +++ b/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java @@ -4,14 +4,14 @@ import gregtech.api.enums.Dyes; import gregtech.api.interfaces.ITexture; import net.minecraft.block.Block; - /** * @deprecated Replaced by the {@link gregtech.api.render.TextureFactory} API. */ @Deprecated public class GT_CopiedBlockTexture extends gregtech.common.render.GT_CopiedBlockTexture implements ITexture { // Backwards Compat - @Deprecated public short[] mRGBa; + @Deprecated + public short[] mRGBa; public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa, boolean aAllowAlpha) { super(aBlock, aSide, aMeta, aRGBa, aAllowAlpha); diff --git a/src/main/java/gregtech/api/objects/GT_Cover_Default.java b/src/main/java/gregtech/api/objects/GT_Cover_Default.java index 79db764449..a975de9759 100644 --- a/src/main/java/gregtech/api/objects/GT_Cover_Default.java +++ b/src/main/java/gregtech/api/objects/GT_Cover_Default.java @@ -20,9 +20,22 @@ public class GT_Cover_Default extends GT_CoverBehavior { } @Override - public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + public int onCoverScrewdriverclick( + byte aSide, + int aCoverID, + int aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer, + float aX, + float aY, + float aZ) { aCoverVariable = ((aCoverVariable + 1) & 15); - GT_Utility.sendChatToPlayer(aPlayer, ((aCoverVariable & 1) != 0 ? GT_Utility.trans("128", "Redstone ") : "") + ((aCoverVariable & 2) != 0 ? GT_Utility.trans("129", "Energy ") : "") + ((aCoverVariable & 4) != 0 ? GT_Utility.trans("130", "Fluids ") : "") + ((aCoverVariable & 8) != 0 ? GT_Utility.trans("131", "Items ") : "")); + GT_Utility.sendChatToPlayer( + aPlayer, + ((aCoverVariable & 1) != 0 ? GT_Utility.trans("128", "Redstone ") : "") + + ((aCoverVariable & 2) != 0 ? GT_Utility.trans("129", "Energy ") : "") + + ((aCoverVariable & 4) != 0 ? GT_Utility.trans("130", "Fluids ") : "") + + ((aCoverVariable & 8) != 0 ? GT_Utility.trans("131", "Items ") : "")); return aCoverVariable; } diff --git a/src/main/java/gregtech/api/objects/GT_Cover_None.java b/src/main/java/gregtech/api/objects/GT_Cover_None.java index 073b51511d..dac48449d1 100644 --- a/src/main/java/gregtech/api/objects/GT_Cover_None.java +++ b/src/main/java/gregtech/api/objects/GT_Cover_None.java @@ -1,5 +1,7 @@ package gregtech.api.objects; +import static gregtech.api.enums.GT_Values.E; + import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.ISerializableObject; @@ -8,15 +10,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; -import static gregtech.api.enums.GT_Values.E; - public class GT_Cover_None extends GT_CoverBehavior { /** * This is the Dummy, if there is no Cover */ - public GT_Cover_None() { - } + public GT_Cover_None() {} @Override public float getBlastProofLevel(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { @@ -69,22 +68,33 @@ public class GT_Cover_None extends GT_CoverBehavior { } @Override - public boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + public boolean manipulatesSidedRedstoneOutput( + byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return false; } @Override - public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + public boolean onCoverRightclick( + byte aSide, + int aCoverID, + int aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer, + float aX, + float aY, + float aZ) { return false; } @Override - public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { + public boolean onCoverRemoval( + byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { return true; } @Override - public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + public int doCoverThings( + byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { return 0; } @@ -94,132 +104,214 @@ public class GT_Cover_None extends GT_CoverBehavior { } @Override - protected boolean isRedstoneSensitiveImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected boolean isRedstoneSensitiveImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + long aTimer) { return false; } @Override - protected ISerializableObject.LegacyCoverData doCoverThingsImpl(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, long aTimer) { + protected ISerializableObject.LegacyCoverData doCoverThingsImpl( + byte aSide, + byte aInputRedstone, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + long aTimer) { return aCoverVariable; } @Override - protected boolean onCoverRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + protected boolean onCoverRightClickImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer, + float aX, + float aY, + float aZ) { return false; } @Override - protected ISerializableObject.LegacyCoverData onCoverScrewdriverClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + protected ISerializableObject.LegacyCoverData onCoverScrewdriverClickImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer, + float aX, + float aY, + float aZ) { return aCoverVariable; } @Override - protected boolean onCoverShiftRightClickImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { + protected boolean onCoverShiftRightClickImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer) { return false; } @Override - protected Object getClientGUIImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { + protected Object getClientGUIImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + EntityPlayer aPlayer, + World aWorld) { return null; } @Override - protected boolean onCoverRemovalImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, boolean aForced) { + protected boolean onCoverRemovalImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity, + boolean aForced) { return true; } @Override - protected String getDescriptionImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected String getDescriptionImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return E; } @Override - protected float getBlastProofLevelImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected float getBlastProofLevelImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return 10.0F; } @Override - protected boolean letsRedstoneGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoInImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsRedstoneGoOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsRedstoneGoOutImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsFibreGoInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsFibreGoInImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsFibreGoOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsFibreGoOutImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsEnergyInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyInImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsEnergyOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean letsEnergyOutImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean letsFluidInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + protected boolean letsFluidInImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + Fluid aFluid, + ICoverable aTileEntity) { return true; } @Override - protected boolean letsFluidOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + protected boolean letsFluidOutImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + Fluid aFluid, + ICoverable aTileEntity) { return true; } @Override - protected boolean letsItemsInImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsInImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + int aSlot, + ICoverable aTileEntity) { return true; } @Override - protected boolean letsItemsOutImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, int aSlot, ICoverable aTileEntity) { + protected boolean letsItemsOutImpl( + byte aSide, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + int aSlot, + ICoverable aTileEntity) { return true; } @Override - protected boolean isGUIClickableImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean isGUIClickableImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return true; } @Override - protected boolean manipulatesSidedRedstoneOutputImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean manipulatesSidedRedstoneOutputImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return false; } @Override - protected boolean alwaysLookConnectedImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected boolean alwaysLookConnectedImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return false; } @Override - protected byte getRedstoneInputImpl(byte aSide, byte aInputRedstone, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected byte getRedstoneInputImpl( + byte aSide, + byte aInputRedstone, + int aCoverID, + ISerializableObject.LegacyCoverData aCoverVariable, + ICoverable aTileEntity) { return aInputRedstone; } @Override - protected int getTickRateImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected int getTickRateImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return 0; } @Override - protected byte getLensColorImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected byte getLensColorImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return -1; } @Override - protected ItemStack getDropImpl(byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { + protected ItemStack getDropImpl( + byte aSide, int aCoverID, ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { return null; } } diff --git a/src/main/java/gregtech/api/objects/GT_Fluid.java b/src/main/java/gregtech/api/objects/GT_Fluid.java index 4f5c2a3ca2..52b58d38cc 100644 --- a/src/main/java/gregtech/api/objects/GT_Fluid.java +++ b/src/main/java/gregtech/api/objects/GT_Fluid.java @@ -1,10 +1,10 @@ package gregtech.api.objects; +import static gregtech.api.enums.GT_Values.RES_PATH_BLOCK; + import gregtech.api.GregTech_API; import net.minecraftforge.fluids.Fluid; -import static gregtech.api.enums.GT_Values.RES_PATH_BLOCK; - public class GT_Fluid extends Fluid implements Runnable { public final String mTextureName; private final short[] mRGBa; @@ -18,7 +18,9 @@ public class GT_Fluid extends Fluid implements Runnable { @Override public int getColor() { - return (Math.max(0, Math.min(255, mRGBa[0])) << 16) | (Math.max(0, Math.min(255, mRGBa[1])) << 8) | Math.max(0, Math.min(255, mRGBa[2])); + return (Math.max(0, Math.min(255, mRGBa[0])) << 16) + | (Math.max(0, Math.min(255, mRGBa[1])) << 8) + | Math.max(0, Math.min(255, mRGBa[2])); } @Override diff --git a/src/main/java/gregtech/api/objects/GT_FluidStack.java b/src/main/java/gregtech/api/objects/GT_FluidStack.java index 8771b504cf..8f796430e5 100644 --- a/src/main/java/gregtech/api/objects/GT_FluidStack.java +++ b/src/main/java/gregtech/api/objects/GT_FluidStack.java @@ -3,27 +3,29 @@ package gregtech.api.objects; import gregtech.api.GregTech_API; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; -import net.minecraftforge.common.ForgeVersion; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; - 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; /** * Because Forge fucked this one up royally. */ public class GT_FluidStack extends FluidStack { - private static final Collection<GT_FluidStack> sAllFluidStacks = Collections.newSetFromMap(new WeakHashMap<>(10000)); + private static final Collection<GT_FluidStack> sAllFluidStacks = + Collections.newSetFromMap(new WeakHashMap<>(10000)); private static volatile boolean lock = false; private Fluid mFluid; public GT_FluidStack(Fluid aFluid, int aAmount) { super(aFluid, aAmount); mFluid = aFluid; - if(!GregTech_API.mServerStarted){sAllFluidStacks.add(this);} + if (!GregTech_API.mServerStarted) { + sAllFluidStacks.add(this); + } } public GT_FluidStack(FluidStack aFluid) { @@ -35,13 +37,16 @@ public class GT_FluidStack extends FluidStack { try { while (lock) { Thread.sleep(1); - }} catch (InterruptedException e) {} + } + } 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);} + for (Map<Fluid, ?> tMap : GregTech_API.sFluidMappings) GT_Utility.reMap(tMap); + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + } lock = false; } } @@ -72,6 +77,7 @@ public class GT_FluidStack extends FluidStack { @Override public String toString() { - return String.format("GT_FluidStack: %s x %s, ID:%s", this.amount, this.getFluid().getName(), this.getFluidID()); + return String.format( + "GT_FluidStack: %s x %s, ID:%s", this.amount, this.getFluid().getName(), this.getFluidID()); } } diff --git a/src/main/java/gregtech/api/objects/GT_HashSet.java b/src/main/java/gregtech/api/objects/GT_HashSet.java index c0a8e3994d..01c4b00995 100644 --- a/src/main/java/gregtech/api/objects/GT_HashSet.java +++ b/src/main/java/gregtech/api/objects/GT_HashSet.java @@ -2,9 +2,8 @@ package gregtech.api.objects; import gregtech.api.GregTech_API; import gregtech.api.util.GT_Utility; -import net.minecraft.item.ItemStack; - import java.util.*; +import net.minecraft.item.ItemStack; public class GT_HashSet<E extends GT_ItemStack> extends AbstractSet<E> { private static final Object OBJECT = new Object(); diff --git a/src/main/java/gregtech/api/objects/GT_ItemStack.java b/src/main/java/gregtech/api/objects/GT_ItemStack.java index 3e25454fa1..a6c892c4f9 100644 --- a/src/main/java/gregtech/api/objects/GT_ItemStack.java +++ b/src/main/java/gregtech/api/objects/GT_ItemStack.java @@ -22,7 +22,10 @@ public class GT_ItemStack { } public GT_ItemStack(ItemStack aStack, boolean wildcard) { - this(aStack == null ? null : aStack.getItem(), aStack == null ? 0 : aStack.stackSize, aStack == null ? 0 : wildcard ? GT_Values.W : Items.feather.getDamage(aStack)); + this( + aStack == null ? null : aStack.getItem(), + aStack == null ? 0 : aStack.stackSize, + aStack == null ? 0 : wildcard ? GT_Values.W : Items.feather.getDamage(aStack)); } public GT_ItemStack(int aHashCode) { diff --git a/src/main/java/gregtech/api/objects/GT_MultiTexture.java b/src/main/java/gregtech/api/objects/GT_MultiTexture.java index 51ab7615b4..82df899135 100644 --- a/src/main/java/gregtech/api/objects/GT_MultiTexture.java +++ b/src/main/java/gregtech/api/objects/GT_MultiTexture.java @@ -5,7 +5,7 @@ import gregtech.api.interfaces.ITexture; /** * <p>Lets Multiple ITextures Render overlay over each other.<</p> * <p>I should have done this much earlier...</p> - * @deprecated Replaced by the {@link gregtech.api.render.TextureFactory} API. + * @deprecated Replaced by the {@link gregtech.api.render.TextureFactory} API. */ @Deprecated public class GT_MultiTexture extends gregtech.common.render.GT_MultiTexture implements ITexture { diff --git a/src/main/java/gregtech/api/objects/GT_RenderedTexture.java b/src/main/java/gregtech/api/objects/GT_RenderedTexture.java index 1f123274f4..4c17afde17 100644 --- a/src/main/java/gregtech/api/objects/GT_RenderedTexture.java +++ b/src/main/java/gregtech/api/objects/GT_RenderedTexture.java @@ -6,8 +6,10 @@ import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; @Deprecated -public class GT_RenderedTexture extends gregtech.common.render.GT_RenderedTexture implements ITexture, IColorModulationContainer { - @Deprecated public short[] mRGBa; +public class GT_RenderedTexture extends gregtech.common.render.GT_RenderedTexture + implements ITexture, IColorModulationContainer { + @Deprecated + public short[] mRGBa; public GT_RenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean aAllowAlpha) { super(aIcon, aRGBa, aAllowAlpha, false, true, false); diff --git a/src/main/java/gregtech/api/objects/GT_SidedTexture.java b/src/main/java/gregtech/api/objects/GT_SidedTexture.java index 3c699a3f4b..25b941e968 100644 --- a/src/main/java/gregtech/api/objects/GT_SidedTexture.java +++ b/src/main/java/gregtech/api/objects/GT_SidedTexture.java @@ -9,21 +9,44 @@ import gregtech.api.interfaces.ITexture; * @deprecated Replaced by the {@link gregtech.api.render.TextureFactory} API. */ @Deprecated -public class GT_SidedTexture extends gregtech.common.render.GT_SidedTexture implements ITexture, IColorModulationContainer { - @Deprecated public short[] mRGBa; +public class GT_SidedTexture extends gregtech.common.render.GT_SidedTexture + implements ITexture, IColorModulationContainer { + @Deprecated + public short[] mRGBa; - public GT_SidedTexture(IIconContainer aIcon0, IIconContainer aIcon1, IIconContainer aIcon2, IIconContainer aIcon3, IIconContainer aIcon4, IIconContainer aIcon5, short[] aRGBa, boolean aAllowAlpha) { + public GT_SidedTexture( + IIconContainer aIcon0, + IIconContainer aIcon1, + IIconContainer aIcon2, + IIconContainer aIcon3, + IIconContainer aIcon4, + IIconContainer aIcon5, + short[] aRGBa, + boolean aAllowAlpha) { super(aIcon0, aIcon1, aIcon2, aIcon3, aIcon4, aIcon5, aRGBa, aAllowAlpha); // Backwards Compat GT_SidedTexture.this.mRGBa = aRGBa; } - public GT_SidedTexture(IIconContainer aIcon0, IIconContainer aIcon1, IIconContainer aIcon2, IIconContainer aIcon3, IIconContainer aIcon4, IIconContainer aIcon5, short[] aRGBa) { + public GT_SidedTexture( + IIconContainer aIcon0, + IIconContainer aIcon1, + IIconContainer aIcon2, + IIconContainer aIcon3, + IIconContainer aIcon4, + IIconContainer aIcon5, + short[] aRGBa) { this(aIcon0, aIcon1, aIcon2, aIcon3, aIcon4, aIcon5, aRGBa, true); } - public GT_SidedTexture(IIconContainer aIcon0, IIconContainer aIcon1, IIconContainer aIcon2, IIconContainer aIcon3, IIconContainer aIcon4, IIconContainer aIcon5) { + public GT_SidedTexture( + IIconContainer aIcon0, + IIconContainer aIcon1, + IIconContainer aIcon2, + IIconContainer aIcon3, + IIconContainer aIcon4, + IIconContainer aIcon5) { this(aIcon0, aIcon1, aIcon2, aIcon3, aIcon4, aIcon5, Dyes._NULL.mRGBa); } diff --git a/src/main/java/gregtech/api/objects/GT_StdRenderedTexture.java b/src/main/java/gregtech/api/objects/GT_StdRenderedTexture.java index 0dd405c792..3966b060a3 100644 --- a/src/main/java/gregtech/api/objects/GT_StdRenderedTexture.java +++ b/src/main/java/gregtech/api/objects/GT_StdRenderedTexture.java @@ -15,7 +15,7 @@ import net.minecraftforge.common.util.ForgeDirection; * @deprecated Replaced by the {@link gregtech.api.render.TextureFactory} API. */ @Deprecated -public class GT_StdRenderedTexture extends GT_RenderedTexture{ +public class GT_StdRenderedTexture extends GT_RenderedTexture { @SuppressWarnings("unused") public GT_StdRenderedTexture(IIconContainer aIcon, short[] aRGBa, boolean aAllowAlpha) { @@ -34,8 +34,7 @@ public class GT_StdRenderedTexture extends GT_RenderedTexture{ @Override public void renderYNeg(RenderBlocks aRenderer, Block aBlock, int aX, int aY, int aZ) { LightingHelper lighting = new LightingHelper(aRenderer); - lighting.setupLightingYNeg(aBlock, aX, aY, aZ) - .setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); + lighting.setupLightingYNeg(aBlock, aX, aY, aZ).setupColor(ForgeDirection.DOWN.ordinal(), mRGBa); aRenderer.renderFaceYNeg(aBlock, aX, aY, aZ, mIconContainer.getIcon()); if (mIconContainer.getOverlayIcon() != null) { lighting.setupColor(ForgeDirection.DOWN.ordinal(), 0xffffff); diff --git a/src/main/java/gregtech/api/objects/GT_UO_Dimension.java b/src/main/java/gregtech/api/objects/GT_UO_Dimension.java index 0d05e6d229..f449478860 100644 --- a/src/main/java/gregtech/api/objects/GT_UO_Dimension.java +++ b/src/main/java/gregtech/api/objects/GT_UO_Dimension.java @@ -2,48 +2,47 @@ package gregtech.api.objects; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import net.minecraftforge.common.config.ConfigCategory; - import java.util.Random; +import net.minecraftforge.common.config.ConfigCategory; public class GT_UO_Dimension { - private BiMap<String, GT_UO_Fluid> fFluids; - private int maxChance; - public String Dimension = "null"; + private BiMap<String, GT_UO_Fluid> fFluids; + private int maxChance; + public String Dimension = "null"; + + public GT_UO_Dimension(ConfigCategory aConfigCategory) { // TODO CONFIGURE + fFluids = HashBiMap.create(); + if (aConfigCategory.containsKey("Dimension")) { + aConfigCategory.get("Dimension").comment = "Dimension ID or Class Name"; + Dimension = aConfigCategory.get("Dimension").getString(); + } + maxChance = 0; + // GT_FML_LOGGER.info("GT UO "+aConfigCategory.getName()+" Dimension:"+Dimension); + for (int i = 0; i < aConfigCategory.getChildren().size(); i++) { + GT_UO_Fluid fluid = new GT_UO_Fluid( + (ConfigCategory) aConfigCategory.getChildren().toArray()[i]); + fFluids.put(fluid.Registry, fluid); + maxChance += fluid.Chance; + } + } - public GT_UO_Dimension(ConfigCategory aConfigCategory) {//TODO CONFIGURE - fFluids = HashBiMap.create(); - if (aConfigCategory.containsKey("Dimension")) - { - aConfigCategory.get("Dimension").comment = "Dimension ID or Class Name"; - Dimension = aConfigCategory.get("Dimension").getString(); - } - maxChance = 0; - //GT_FML_LOGGER.info("GT UO "+aConfigCategory.getName()+" Dimension:"+Dimension); - for (int i = 0 ; i < aConfigCategory.getChildren().size(); i++) { - GT_UO_Fluid fluid = new GT_UO_Fluid((ConfigCategory)aConfigCategory.getChildren().toArray()[i]); - fFluids.put(fluid.Registry, fluid); - maxChance += fluid.Chance; - } - } - - public GT_UO_Fluid getRandomFluid (Random aRandom) { - int random = aRandom.nextInt(1000); - for (BiMap.Entry<String, GT_UO_Fluid> fl : fFluids.entrySet()) { - int chance = fl.getValue().Chance*1000/maxChance; - if (random<=chance) return fl.getValue(); - //GT_FML_LOGGER.info("GT UO "+fl.getValue().Registry+" Chance:"+chance+" Random:"+random); - random-=chance; - } - return null; - } + public GT_UO_Fluid getRandomFluid(Random aRandom) { + int random = aRandom.nextInt(1000); + for (BiMap.Entry<String, GT_UO_Fluid> fl : fFluids.entrySet()) { + int chance = fl.getValue().Chance * 1000 / maxChance; + if (random <= chance) return fl.getValue(); + // GT_FML_LOGGER.info("GT UO "+fl.getValue().Registry+" Chance:"+chance+" Random:"+random); + random -= chance; + } + return null; + } - public String getUOFluidKey(GT_UO_Fluid uoFluid) { - return fFluids.inverse().get(uoFluid); - } + public String getUOFluidKey(GT_UO_Fluid uoFluid) { + return fFluids.inverse().get(uoFluid); + } - public GT_UO_Fluid getUOFluid(String key) { - return fFluids.get(key); - } + public GT_UO_Fluid getUOFluid(String key) { + return fFluids.get(key); + } } diff --git a/src/main/java/gregtech/api/objects/GT_UO_DimensionList.java b/src/main/java/gregtech/api/objects/GT_UO_DimensionList.java index a2cd2354d8..44b56938b4 100644 --- a/src/main/java/gregtech/api/objects/GT_UO_DimensionList.java +++ b/src/main/java/gregtech/api/objects/GT_UO_DimensionList.java @@ -8,74 +8,85 @@ import net.minecraftforge.common.config.Configuration; public class GT_UO_DimensionList { - private Configuration fConfig; - private String fCategory; - private BiMap<String, GT_UO_Dimension> fDimensionList; + private Configuration fConfig; + private String fCategory; + private BiMap<String, GT_UO_Dimension> fDimensionList; - public int[] blackList =new int[0]; - - public GT_UO_DimensionList() { - fDimensionList = HashBiMap.create(); - } + public int[] blackList = new int[0]; - public GT_UO_Dimension GetDimension(int aDimension) { - if(CheckBlackList(aDimension)) return null; - if (fDimensionList.containsKey(Integer.toString(aDimension))) - return fDimensionList.get(Integer.toString(aDimension)); - for (BiMap.Entry <String, GT_UO_Dimension> dl : fDimensionList.entrySet()) - if (DimensionManager.getProvider(aDimension).getClass().getName().contains(dl.getValue().Dimension)) - return dl.getValue(); - return fDimensionList.get("Default"); - } + public GT_UO_DimensionList() { + fDimensionList = HashBiMap.create(); + } - private boolean CheckBlackList(int aDimensionId){ - try { - return java.util.Arrays.binarySearch(blackList, aDimensionId) >= 0; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - public void SetConfigValues(String aDimensionName, String aDimension, String aName, String aRegistry, int aMinAmount, int aMaxAmount, int aChance, int aDecreasePerOperationAmount) { - String Category = fCategory+"."+aDimensionName; - fConfig.get(Category, "Dimension", aDimension).getString(); - Category+="."+aName; - fConfig.get(Category, "Registry", aRegistry).getString(); - fConfig.get(Category, "MinAmount", aMinAmount).getInt(aMinAmount); - fConfig.get(Category, "MaxAmount", aMaxAmount).getInt(aMaxAmount); - fConfig.get(Category, "Chance", aChance).getInt(aChance); - fConfig.get(Category, "DecreasePerOperationAmount", aDecreasePerOperationAmount).getInt(aDecreasePerOperationAmount); - //IT IS IN BUCKETS!!! - } - - public void SetDafultValues() { - SetConfigValues("Overworld", "0", "gas_natural_gas", "gas_natural_gas", 0, 700, 20, 7); - SetConfigValues("Overworld", "0", "liquid_light_oil", "liquid_light_oil", 0, 650, 20, 6); - SetConfigValues("Overworld", "0", "liquid_medium_oil", "liquid_medium_oil", 0, 600, 20, 5); - SetConfigValues("Overworld", "0", "liquid_heavy_oil", "liquid_heavy_oil", 0, 550, 20, 4); - SetConfigValues("Overworld", "0", "oil", "oil", 0, 600, 20, 5); - SetConfigValues("Moon", "Moon", "helium-3", "helium-3", 24, 128, 100, 1); - } - - public void getConfig(Configuration aConfig, String aCategory) { - fCategory=aCategory; - fConfig = aConfig; - if (!fConfig.hasCategory(fCategory)) - SetDafultValues(); + public GT_UO_Dimension GetDimension(int aDimension) { + if (CheckBlackList(aDimension)) return null; + if (fDimensionList.containsKey(Integer.toString(aDimension))) + return fDimensionList.get(Integer.toString(aDimension)); + for (BiMap.Entry<String, GT_UO_Dimension> dl : fDimensionList.entrySet()) + if (DimensionManager.getProvider(aDimension).getClass().getName().contains(dl.getValue().Dimension)) + return dl.getValue(); + return fDimensionList.get("Default"); + } - fConfig.setCategoryComment(fCategory, "Config Underground Fluids (Delete this Category for regenerate)"); - fConfig.setCategoryComment(fCategory+".Default", "Set Default Generating (Use this Category for Default settings)"); - fConfig.setCategoryComment(fCategory+".Overworld", "Set Overworld Generating"); - fConfig.setCategoryComment(fCategory+".Moon", "Set Moon Generating"); - - blackList = new int[]{-1,1}; - blackList = aConfig.get(fCategory, "DimBlackList", blackList, "Dimension IDs Black List").getIntList(); - java.util.Arrays.sort(blackList); - - for (int i = 0 ; i < fConfig.getCategory(fCategory).getChildren().size(); i++) { - GT_UO_Dimension Dimension = new GT_UO_Dimension((ConfigCategory)fConfig.getCategory(fCategory).getChildren().toArray()[i]); - fDimensionList.put(Dimension.Dimension, Dimension); - } - } + private boolean CheckBlackList(int aDimensionId) { + try { + return java.util.Arrays.binarySearch(blackList, aDimensionId) >= 0; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public void SetConfigValues( + String aDimensionName, + String aDimension, + String aName, + String aRegistry, + int aMinAmount, + int aMaxAmount, + int aChance, + int aDecreasePerOperationAmount) { + String Category = fCategory + "." + aDimensionName; + fConfig.get(Category, "Dimension", aDimension).getString(); + Category += "." + aName; + fConfig.get(Category, "Registry", aRegistry).getString(); + fConfig.get(Category, "MinAmount", aMinAmount).getInt(aMinAmount); + fConfig.get(Category, "MaxAmount", aMaxAmount).getInt(aMaxAmount); + fConfig.get(Category, "Chance", aChance).getInt(aChance); + fConfig.get(Category, "DecreasePerOperationAmount", aDecreasePerOperationAmount) + .getInt(aDecreasePerOperationAmount); + // IT IS IN BUCKETS!!! + } + + public void SetDafultValues() { + SetConfigValues("Overworld", "0", "gas_natural_gas", "gas_natural_gas", 0, 700, 20, 7); + SetConfigValues("Overworld", "0", "liquid_light_oil", "liquid_light_oil", 0, 650, 20, 6); + SetConfigValues("Overworld", "0", "liquid_medium_oil", "liquid_medium_oil", 0, 600, 20, 5); + SetConfigValues("Overworld", "0", "liquid_heavy_oil", "liquid_heavy_oil", 0, 550, 20, 4); + SetConfigValues("Overworld", "0", "oil", "oil", 0, 600, 20, 5); + SetConfigValues("Moon", "Moon", "helium-3", "helium-3", 24, 128, 100, 1); + } + + public void getConfig(Configuration aConfig, String aCategory) { + fCategory = aCategory; + fConfig = aConfig; + if (!fConfig.hasCategory(fCategory)) SetDafultValues(); + + fConfig.setCategoryComment(fCategory, "Config Underground Fluids (Delete this Category for regenerate)"); + fConfig.setCategoryComment( + fCategory + ".Default", "Set Default Generating (Use this Category for Default settings)"); + fConfig.setCategoryComment(fCategory + ".Overworld", "Set Overworld Generating"); + fConfig.setCategoryComment(fCategory + ".Moon", "Set Moon Generating"); + + blackList = new int[] {-1, 1}; + blackList = aConfig.get(fCategory, "DimBlackList", blackList, "Dimension IDs Black List") + .getIntList(); + java.util.Arrays.sort(blackList); + + for (int i = 0; i < fConfig.getCategory(fCategory).getChildren().size(); i++) { + GT_UO_Dimension Dimension = new GT_UO_Dimension((ConfigCategory) + fConfig.getCategory(fCategory).getChildren().toArray()[i]); + fDimensionList.put(Dimension.Dimension, Dimension); + } + } } diff --git a/src/main/java/gregtech/api/objects/GT_UO_Fluid.java b/src/main/java/gregtech/api/objects/GT_UO_Fluid.java index d06772dc1e..36f98d6cae 100644 --- a/src/main/java/gregtech/api/objects/GT_UO_Fluid.java +++ b/src/main/java/gregtech/api/objects/GT_UO_Fluid.java @@ -1,61 +1,61 @@ package gregtech.api.objects; +import static gregtech.common.GT_UndergroundOil.DIVIDER; + +import java.util.Random; import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -import java.util.Random; +public class GT_UO_Fluid { + public String Registry = "null"; + public int MaxAmount = 0; + public int MinAmount = 0; + public int Chance = 0; + public int DecreasePerOperationAmount = 5; -import static gregtech.common.GT_UndergroundOil.DIVIDER; + public GT_UO_Fluid(ConfigCategory aConfigCategory) { // TODO CONFIGURE + if (aConfigCategory.containsKey("Registry")) { + aConfigCategory.get("Registry").comment = "Fluid registry name"; + Registry = aConfigCategory.get("Registry").getString(); + } + if (aConfigCategory.containsKey("MaxAmount")) { + aConfigCategory.get("MaxAmount").comment = + "Max amount generation (per operation, sets the VeinData) 80000 MAX"; + MaxAmount = aConfigCategory.get("MaxAmount").getInt(0); + } + if (aConfigCategory.containsKey("MinAmount")) { + aConfigCategory.get("MinAmount").comment = "Min amount generation (per operation, sets the VeinData) 0 MIN"; + MinAmount = aConfigCategory.get("MinAmount").getInt(0); + } + if (aConfigCategory.containsKey("Chance")) { + aConfigCategory.get("Chance").comment = + "Chance generating (weighted chance!, there will be a fluid in chunk always!)"; + Chance = aConfigCategory.get("Chance").getInt(0); + } + if (aConfigCategory.containsKey("DecreasePerOperationAmount")) { + aConfigCategory.get("DecreasePerOperationAmount").comment = + "Decrease per operation (actual fluid gained works like (Litre)VeinData/5000)"; + DecreasePerOperationAmount = + aConfigCategory.get("DecreasePerOperationAmount").getInt(5); + } + // GT_FML_LOGGER.info("GT UO "+aConfigCategory.getName()+" Fluid:"+Registry+" Max:"+MaxAmount+" + // Min:"+MinAmount+" Chance:"+Chance); + } -public class GT_UO_Fluid { - public String Registry = "null"; - public int MaxAmount = 0; - public int MinAmount = 0; - public int Chance = 0; - public int DecreasePerOperationAmount = 5; + public Fluid getFluid() { + try { + return FluidRegistry.getFluid(this.Registry); + } catch (Exception e) { + return null; + } + } - public GT_UO_Fluid(ConfigCategory aConfigCategory) {//TODO CONFIGURE - if (aConfigCategory.containsKey("Registry")) - { - aConfigCategory.get("Registry").comment = "Fluid registry name"; - Registry = aConfigCategory.get("Registry").getString(); - } - if (aConfigCategory.containsKey("MaxAmount")) - { - aConfigCategory.get("MaxAmount").comment = "Max amount generation (per operation, sets the VeinData) 80000 MAX"; - MaxAmount = aConfigCategory.get("MaxAmount").getInt(0); - } - if (aConfigCategory.containsKey("MinAmount")) - { - aConfigCategory.get("MinAmount").comment = "Min amount generation (per operation, sets the VeinData) 0 MIN"; - MinAmount = aConfigCategory.get("MinAmount").getInt(0); - } - if (aConfigCategory.containsKey("Chance")) - { - aConfigCategory.get("Chance").comment = "Chance generating (weighted chance!, there will be a fluid in chunk always!)"; - Chance = aConfigCategory.get("Chance").getInt(0); - } - if (aConfigCategory.containsKey("DecreasePerOperationAmount")) - { - aConfigCategory.get("DecreasePerOperationAmount").comment = "Decrease per operation (actual fluid gained works like (Litre)VeinData/5000)"; - DecreasePerOperationAmount = aConfigCategory.get("DecreasePerOperationAmount").getInt(5); - } - //GT_FML_LOGGER.info("GT UO "+aConfigCategory.getName()+" Fluid:"+Registry+" Max:"+MaxAmount+" Min:"+MinAmount+" Chance:"+Chance); - } - - public Fluid getFluid(){ - try { - return FluidRegistry.getFluid(this.Registry); - } catch (Exception e) { - return null; - } - } - - public int getRandomAmount(Random aRandom){//generates some random ass number that correlates to extraction speeds - int div = (int)Math.floor(Math.pow((MaxAmount-MinAmount)*100.d*DIVIDER, 0.2d)); - int min = (int)Math.floor(Math.pow(MinAmount*100.d*DIVIDER, 0.2d)); - double amount = min+aRandom.nextInt(div)+aRandom.nextDouble(); - return (int) (Math.pow(amount, 5) / 100);//reverses the computation above - } + public int getRandomAmount( + Random aRandom) { // generates some random ass number that correlates to extraction speeds + int div = (int) Math.floor(Math.pow((MaxAmount - MinAmount) * 100.d * DIVIDER, 0.2d)); + int min = (int) Math.floor(Math.pow(MinAmount * 100.d * DIVIDER, 0.2d)); + double amount = min + aRandom.nextInt(div) + aRandom.nextDouble(); + return (int) (Math.pow(amount, 5) / 100); // reverses the computation above + } } diff --git a/src/main/java/gregtech/api/objects/ItemData.java b/src/main/java/gregtech/api/objects/ItemData.java index ce77d222aa..cf3c2b5c14 100644 --- a/src/main/java/gregtech/api/objects/ItemData.java +++ b/src/main/java/gregtech/api/objects/ItemData.java @@ -2,9 +2,8 @@ package gregtech.api.objects; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; -import net.minecraft.item.ItemStack; - import java.util.*; +import net.minecraft.item.ItemStack; public class ItemData { private static final MaterialStack[] EMPTY_MATERIALSTACK_ARRAY = new MaterialStack[0]; @@ -20,7 +19,9 @@ public class ItemData { mPrefix = aPrefix; mMaterial = aMaterial == null ? null : new MaterialStack(aMaterial, aPrefix.mMaterialAmount); mBlackListed = aBlackListed; - mByProducts = aPrefix.mSecondaryMaterial == null || aPrefix.mSecondaryMaterial.mMaterial == null ? EMPTY_MATERIALSTACK_ARRAY : new MaterialStack[]{aPrefix.mSecondaryMaterial.clone()}; + mByProducts = aPrefix.mSecondaryMaterial == null || aPrefix.mSecondaryMaterial.mMaterial == null + ? EMPTY_MATERIALSTACK_ARRAY + : new MaterialStack[] {aPrefix.mSecondaryMaterial.clone()}; } public ItemData(OrePrefixes aPrefix, Materials aMaterial) { @@ -34,7 +35,8 @@ public class ItemData { if (aByProducts == null) { mByProducts = EMPTY_MATERIALSTACK_ARRAY; } else { - MaterialStack[] tByProducts = aByProducts.length < 1 ? EMPTY_MATERIALSTACK_ARRAY : new MaterialStack[aByProducts.length]; + MaterialStack[] tByProducts = + aByProducts.length < 1 ? EMPTY_MATERIALSTACK_ARRAY : new MaterialStack[aByProducts.length]; int j = 0; for (int i = 0; i < aByProducts.length; i++) if (aByProducts[i] != null && aByProducts[i].mMaterial != null) diff --git a/src/main/java/gregtech/api/objects/MaterialStack.java b/src/main/java/gregtech/api/objects/MaterialStack.java index e4c135cc73..3e68105f0e 100644 --- a/src/main/java/gregtech/api/objects/MaterialStack.java +++ b/src/main/java/gregtech/api/objects/MaterialStack.java @@ -18,7 +18,11 @@ public class MaterialStack implements Cloneable { @Override public MaterialStack clone() { - try { return (MaterialStack) super.clone(); } catch (Exception e) { return new MaterialStack(mMaterial, mAmount); } + try { + return (MaterialStack) super.clone(); + } catch (Exception e) { + return new MaterialStack(mMaterial, mAmount); + } } @Override @@ -27,34 +31,38 @@ public class MaterialStack implements Cloneable { if (aObject == null) return false; if (aObject instanceof Materials) return aObject == mMaterial; if (aObject instanceof MaterialStack) - return ((MaterialStack) aObject).mMaterial == mMaterial && (mAmount < 0 || ((MaterialStack) aObject).mAmount < 0 || ((MaterialStack) aObject).mAmount == mAmount); + return ((MaterialStack) aObject).mMaterial == mMaterial + && (mAmount < 0 + || ((MaterialStack) aObject).mAmount < 0 + || ((MaterialStack) aObject).mAmount == mAmount); return false; } @Override public String toString() { - String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = ""; - if (mAmount > 1) { - temp4 = GT_Utility.toSubscript(mAmount); - - if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) { + String temp1 = "", temp2 = mMaterial.getToolTip(true), temp3 = "", temp4 = ""; + if (mAmount > 1) { + temp4 = GT_Utility.toSubscript(mAmount); + + if (mMaterial.mMaterialList.size() > 1 || isMaterialListComplex(this)) { temp1 = "("; temp3 = ")"; - } - } - return String.valueOf(new StringBuilder().append(temp1).append(temp2).append(temp3).append(temp4)); + } + } + return String.valueOf( + new StringBuilder().append(temp1).append(temp2).append(temp3).append(temp4)); } - private boolean isMaterialListComplex(MaterialStack materialStack){ - if (materialStack.mMaterial.mMaterialList.size() > 1) { - return true; - } - if (materialStack.mMaterial.mMaterialList.size() == 0) { - return false; - } - return isMaterialListComplex(materialStack.mMaterial.mMaterialList.get(0)); + private boolean isMaterialListComplex(MaterialStack materialStack) { + if (materialStack.mMaterial.mMaterialList.size() > 1) { + return true; + } + if (materialStack.mMaterial.mMaterialList.size() == 0) { + return false; + } + return isMaterialListComplex(materialStack.mMaterial.mMaterialList.get(0)); } - + @Override public int hashCode() { return mMaterial.hashCode(); diff --git a/src/main/java/gregtech/api/objects/ObjMap.java b/src/main/java/gregtech/api/objects/ObjMap.java index 0db6083cfe..0a3b3a8fbe 100644 --- a/src/main/java/gregtech/api/objects/ObjMap.java +++ b/src/main/java/gregtech/api/objects/ObjMap.java @@ -5,8 +5,7 @@ import java.util.Arrays; /** * Object-2-object map based on IntIntMap4a */ -public class ObjMap<K, V> -{ +public class ObjMap<K, V> { private static final Object FREE_KEY = new Object(); private static final Object REMOVED_KEY = new Object(); @@ -15,6 +14,7 @@ public class ObjMap<K, V> /** Value for the null key (if inserted into a map) */ private Object m_nullValue; + private boolean m_hasNull; /** Fill factor, must be between (0 and 1) */ @@ -28,159 +28,120 @@ public class ObjMap<K, V> /** Mask to wrap the actual array pointer */ private int m_mask2; - public ObjMap( final int size, final float fillFactor ) - { - if ( fillFactor <= 0 || fillFactor >= 1 ) - throw new IllegalArgumentException( "FillFactor must be in (0, 1)" ); - if ( size <= 0 ) - throw new IllegalArgumentException( "Size must be positive!" ); + public ObjMap(final int size, final float fillFactor) { + if (fillFactor <= 0 || fillFactor >= 1) throw new IllegalArgumentException("FillFactor must be in (0, 1)"); + if (size <= 0) throw new IllegalArgumentException("Size must be positive!"); final int capacity = arraySize(size, fillFactor); m_mask = capacity - 1; m_mask2 = capacity * 2 - 1; m_fillFactor = fillFactor; m_data = new Object[capacity * 2]; - Arrays.fill( m_data, FREE_KEY ); + Arrays.fill(m_data, FREE_KEY); m_threshold = (int) (capacity * fillFactor); } @SuppressWarnings("unchecked") - public V get( final K key ) - { - if ( key == null ) - return (V) m_nullValue; //we null it on remove, so safe not to check a flag here + public V get(final K key) { + if (key == null) return (V) m_nullValue; // we null it on remove, so safe not to check a flag here int ptr = (key.hashCode() & m_mask) << 1; - Object k = m_data[ ptr ]; + Object k = m_data[ptr]; - if ( k == FREE_KEY ) - return null; //end of chain already - if ( k.equals( key ) ) //we check FREE and REMOVED prior to this call - return (V) m_data[ ptr + 1 ]; - while ( true ) - { - ptr = (ptr + 2) & m_mask2; //that's next index - k = m_data[ ptr ]; - if ( k == FREE_KEY ) - return null; - if ( k.equals( key ) ) - return (V) m_data[ ptr + 1 ]; + if (k == FREE_KEY) return null; // end of chain already + if (k.equals(key)) // we check FREE and REMOVED prior to this call + return (V) m_data[ptr + 1]; + while (true) { + ptr = (ptr + 2) & m_mask2; // that's next index + k = m_data[ptr]; + if (k == FREE_KEY) return null; + if (k.equals(key)) return (V) m_data[ptr + 1]; } } @SuppressWarnings("unchecked") - public V put( final K key, final V value ) - { - if ( key == null ) - return insertNullKey(value); + public V put(final K key, final V value) { + if (key == null) return insertNullKey(value); int ptr = getStartIndex(key) << 1; Object k = m_data[ptr]; - if ( k == FREE_KEY ) //end of chain already + if (k == FREE_KEY) // end of chain already { - m_data[ ptr ] = key; - m_data[ ptr + 1 ] = value; - if ( m_size >= m_threshold ) - rehash( m_data.length * 2 ); //size is set inside - else - ++m_size; + m_data[ptr] = key; + m_data[ptr + 1] = value; + if (m_size >= m_threshold) rehash(m_data.length * 2); // size is set inside + else ++m_size; return null; - } - else if ( k.equals( key ) ) //we check FREE and REMOVED prior to this call + } else if (k.equals(key)) // we check FREE and REMOVED prior to this call { - final Object ret = m_data[ ptr + 1 ]; - m_data[ ptr + 1 ] = value; + final Object ret = m_data[ptr + 1]; + m_data[ptr + 1] = value; return (V) ret; } int firstRemoved = -1; - if ( k == REMOVED_KEY ) - firstRemoved = ptr; //we may find a key later - - while ( true ) - { - ptr = ( ptr + 2 ) & m_mask2; //that's next index calculation - k = m_data[ ptr ]; - if ( k == FREE_KEY ) - { - if ( firstRemoved != -1 ) - ptr = firstRemoved; - m_data[ ptr ] = key; - m_data[ ptr + 1 ] = value; - if ( m_size >= m_threshold ) - rehash( m_data.length * 2 ); //size is set inside - else - ++m_size; + if (k == REMOVED_KEY) firstRemoved = ptr; // we may find a key later + + while (true) { + ptr = (ptr + 2) & m_mask2; // that's next index calculation + k = m_data[ptr]; + if (k == FREE_KEY) { + if (firstRemoved != -1) ptr = firstRemoved; + m_data[ptr] = key; + m_data[ptr + 1] = value; + if (m_size >= m_threshold) rehash(m_data.length * 2); // size is set inside + else ++m_size; return null; - } - else if ( k.equals( key ) ) - { - final Object ret = m_data[ ptr + 1 ]; - m_data[ ptr + 1 ] = value; + } else if (k.equals(key)) { + final Object ret = m_data[ptr + 1]; + m_data[ptr + 1] = value; return (V) ret; - } - else if ( k == REMOVED_KEY ) - { - if ( firstRemoved == -1 ) - firstRemoved = ptr; + } else if (k == REMOVED_KEY) { + if (firstRemoved == -1) firstRemoved = ptr; } } } @SuppressWarnings("unchecked") - public V remove( final K key ) - { - if ( key == null ) - return removeNullKey(); + public V remove(final K key) { + if (key == null) return removeNullKey(); int ptr = getStartIndex(key) << 1; - Object k = m_data[ ptr ]; - if ( k == FREE_KEY ) - return null; //end of chain already - else if ( k.equals( key ) ) //we check FREE and REMOVED prior to this call + Object k = m_data[ptr]; + if (k == FREE_KEY) return null; // end of chain already + else if (k.equals(key)) // we check FREE and REMOVED prior to this call { --m_size; - if ( m_data[ ( ptr + 2 ) & m_mask2 ] == FREE_KEY ) - m_data[ ptr ] = FREE_KEY; - else - m_data[ ptr ] = REMOVED_KEY; - final V ret = (V) m_data[ ptr + 1 ]; - m_data[ ptr + 1 ] = null; + if (m_data[(ptr + 2) & m_mask2] == FREE_KEY) m_data[ptr] = FREE_KEY; + else m_data[ptr] = REMOVED_KEY; + final V ret = (V) m_data[ptr + 1]; + m_data[ptr + 1] = null; return ret; } - while ( true ) - { - ptr = ( ptr + 2 ) & m_mask2; //that's next index calculation - k = m_data[ ptr ]; - if ( k == FREE_KEY ) - return null; - else if ( k.equals( key ) ) - { + while (true) { + ptr = (ptr + 2) & m_mask2; // that's next index calculation + k = m_data[ptr]; + if (k == FREE_KEY) return null; + else if (k.equals(key)) { --m_size; - if ( m_data[ ( ptr + 2 ) & m_mask2 ] == FREE_KEY ) - m_data[ ptr ] = FREE_KEY; - else - m_data[ ptr ] = REMOVED_KEY; - final V ret = (V) m_data[ ptr + 1 ]; - m_data[ ptr + 1 ] = null; + if (m_data[(ptr + 2) & m_mask2] == FREE_KEY) m_data[ptr] = FREE_KEY; + else m_data[ptr] = REMOVED_KEY; + final V ret = (V) m_data[ptr + 1]; + m_data[ptr + 1] = null; return ret; } } } @SuppressWarnings("unchecked") - private V insertNullKey(final V value) - { - if ( m_hasNull ) - { + private V insertNullKey(final V value) { + if (m_hasNull) { final Object ret = m_nullValue; m_nullValue = value; return (V) ret; - } - else - { + } else { m_nullValue = value; ++m_size; return null; @@ -188,94 +149,87 @@ public class ObjMap<K, V> } @SuppressWarnings("unchecked") - private V removeNullKey() - { - if ( m_hasNull ) - { + private V removeNullKey() { + if (m_hasNull) { final Object ret = m_nullValue; m_nullValue = null; m_hasNull = false; --m_size; return (V) ret; - } - else - { + } else { return null; } } - public int size() - { + public int size() { return m_size; } @SuppressWarnings("unchecked") - private void rehash( final int newCapacity ) - { - m_threshold = (int) (newCapacity/2 * m_fillFactor); - m_mask = newCapacity/2 - 1; + private void rehash(final int newCapacity) { + m_threshold = (int) (newCapacity / 2 * m_fillFactor); + m_mask = newCapacity / 2 - 1; m_mask2 = newCapacity - 1; final int oldCapacity = m_data.length; final Object[] oldData = m_data; - m_data = new Object[ newCapacity ]; - Arrays.fill( m_data, FREE_KEY ); + m_data = new Object[newCapacity]; + Arrays.fill(m_data, FREE_KEY); m_size = m_hasNull ? 1 : 0; - for ( int i = 0; i < oldCapacity; i += 2 ) { - final Object oldKey = oldData[ i ]; - if( oldKey != FREE_KEY && oldKey != REMOVED_KEY ) - put( (K)oldKey, (V)oldData[ i + 1 ]); + for (int i = 0; i < oldCapacity; i += 2) { + final Object oldKey = oldData[i]; + if (oldKey != FREE_KEY && oldKey != REMOVED_KEY) put((K) oldKey, (V) oldData[i + 1]); } } - public int getStartIndex( final Object key ) - { - //key is not null here + public int getStartIndex(final Object key) { + // key is not null here return key.hashCode() & m_mask; } - + /** Taken from FastUtil implementation */ /** Return the least power of two greater than or equal to the specified value. - * - * <p>Note that this function will return 1 when the argument is 0. - * - * @param x a long integer smaller than or equal to 2<sup>62</sup>. - * @return the least power of two greater than or equal to the specified value. - */ - public static long nextPowerOfTwo( long x ) { - if ( x == 0 ) return 1; - x--; - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; - return ( x | x >> 32 ) + 1; - } + * + * <p>Note that this function will return 1 when the argument is 0. + * + * @param x a long integer smaller than or equal to 2<sup>62</sup>. + * @return the least power of two greater than or equal to the specified value. + */ + public static long nextPowerOfTwo(long x) { + if (x == 0) return 1; + x--; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + return (x | x >> 32) + 1; + } /** Returns the least power of two smaller than or equal to 2<sup>30</sup> and larger than or equal to <code>Math.ceil( expected / f )</code>. - * - * @param expected the expected number of elements in a hash table. - * @param f the load factor. - * @return the minimum possible size for a backing array. - * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. - */ - public static int arraySize( final int expected, final float f ) { - final long s = Math.max( 2, nextPowerOfTwo( (long)Math.ceil( expected / f ) ) ); - if ( s > (1 << 30) ) throw new IllegalArgumentException( "Too large (" + expected + " expected elements with load factor " + f + ")" ); - return (int)s; - } - - //taken from FastUtil + * + * @param expected the expected number of elements in a hash table. + * @param f the load factor. + * @return the minimum possible size for a backing array. + * @throws IllegalArgumentException if the necessary size is larger than 2<sup>30</sup>. + */ + public static int arraySize(final int expected, final float f) { + final long s = Math.max(2, nextPowerOfTwo((long) Math.ceil(expected / f))); + if (s > (1 << 30)) + throw new IllegalArgumentException( + "Too large (" + expected + " expected elements with load factor " + f + ")"); + return (int) s; + } + + // taken from FastUtil private static final int INT_PHI = 0x9E3779B9; - public static int phiMix( final int x ) { - final int h = x * INT_PHI; - return h ^ (h >> 16); -} - + public static int phiMix(final int x) { + final int h = x * INT_PHI; + return h ^ (h >> 16); + } } diff --git a/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java index cb9e7d4d83..60a5c13d74 100644 --- a/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java +++ b/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java @@ -1,16 +1,15 @@ package gregtech.api.objects; +import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes; + import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler; -import net.minecraft.item.ItemStack; - import java.util.Collections; import java.util.LinkedList; import java.util.Optional; import java.util.Queue; - -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes; +import net.minecraft.item.ItemStack; public class ReverseShapedRecipe { private static Queue<ReverseShapedRecipe> reverseRecipes = new LinkedList<>(); @@ -30,11 +29,11 @@ public class ReverseShapedRecipe { public static void runReverseRecipes() { for (ReverseShapedRecipe x : reverseRecipes) { Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapedRecipe(x.aResult, x.aRecipe); - if (!recipeOptional.isPresent()) - continue; + if (!recipeOptional.isPresent()) continue; GT_Recipe recipe = recipeOptional.get(); ItemStack[] replacement = new ItemStack[recipe.mOutputs.length]; - GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs)); + GT_MetaTileEntity_Disassembler.handleRecipeTransformation( + recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs)); recipe.mOutputs = replacement; sDisassemblerRecipes.add(recipe); diff --git a/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java index 1c5e27d246..6593dc60d8 100644 --- a/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java +++ b/src/main/java/gregtech/api/objects/ReverseShapelessRecipe.java @@ -1,16 +1,15 @@ package gregtech.api.objects; +import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes; + import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler; -import net.minecraft.item.ItemStack; - import java.util.Collections; import java.util.LinkedList; import java.util.Optional; import java.util.Queue; - -import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes; +import net.minecraft.item.ItemStack; public class ReverseShapelessRecipe { private static Queue<ReverseShapelessRecipe> reverseRecipes = new LinkedList<>(); @@ -30,11 +29,11 @@ public class ReverseShapelessRecipe { public static void runReverseRecipes() { for (ReverseShapelessRecipe x : reverseRecipes) { Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapelessRecipe(x.aResult, x.aRecipe); - if (!recipeOptional.isPresent()) - continue; + if (!recipeOptional.isPresent()) continue; GT_Recipe recipe = recipeOptional.get(); ItemStack[] replacement = new ItemStack[recipe.mOutputs.length]; - GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs)); + GT_MetaTileEntity_Disassembler.handleRecipeTransformation( + recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs)); recipe.mOutputs = replacement; sDisassemblerRecipes.add(recipe); diff --git a/src/main/java/gregtech/api/objects/XSTR.java b/src/main/java/gregtech/api/objects/XSTR.java index a2c4906345..b5ed4a00b4 100644 --- a/src/main/java/gregtech/api/objects/XSTR.java +++ b/src/main/java/gregtech/api/objects/XSTR.java @@ -23,7 +23,6 @@ package gregtech.api.objects; * 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; @@ -41,21 +40,21 @@ public class XSTR extends Random { private static final long GAMMA = 0x9e3779b97f4a7c15L; private static final int PROBE_INCREMENT = 0x9e3779b9; private static final long SEEDER_INCREMENT = 0xbb67ae8584caa73bL; - private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53) - private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24) + private static final double DOUBLE_UNIT = 0x1.0p-53; // 1.0 / (1L << 53) + private static final float FLOAT_UNIT = 0x1.0p-24f; // 1.0f / (1 << 24) private static final AtomicLong seedUniquifier = new AtomicLong(8682522807148012L); - public static final XSTR XSTR_INSTANCE=new XSTR(){ + public static final XSTR XSTR_INSTANCE = new XSTR() { @Override public synchronized void setSeed(long seed) { - if(!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) + if (!Thread.currentThread().getStackTrace()[2].getClassName().equals(Random.class.getName())) throw new NoSuchMethodError("This is meant to be shared!, leave seed state alone!"); } }; /* - MODIFIED BY: Robotia - Modification: Implemented Random class seed generator - */ + MODIFIED BY: Robotia + Modification: Implemented Random class seed generator + */ /** * Creates a new pseudo random number generator. The seed is initialized to * the current time, as if by @@ -68,7 +67,7 @@ public class XSTR extends Random { private static long seedUniquifier() { // L'Ecuyer, "Tables of Linear Congruential Generators of // Different Sizes and Good Lattice Structure", 1999 - for (;;) { + for (; ; ) { long current = seedUniquifier.get(); long next = current * 181783497276652981L; if (seedUniquifier.compareAndSet(current, next)) { @@ -86,6 +85,7 @@ public class XSTR extends Random { public XSTR(long seed) { this.seed = seed; } + @Override public boolean nextBoolean() { return next(1) != 0; @@ -93,7 +93,7 @@ public class XSTR extends Random { @Override public double nextDouble() { - return (((long)(next(26)) << 27) + next(27)) * DOUBLE_UNIT; + return (((long) (next(26)) << 27) + next(27)) * DOUBLE_UNIT; } /** * Returns the current state of the seed, can be used to clone the object @@ -142,8 +142,10 @@ public class XSTR extends Random { x &= ((1L << nbits) - 1); return (int) x; } + boolean haveNextNextGaussian = false; double nextNextGaussian = 0; + @Override public synchronized double nextGaussian() { // See Knuth, ACP, Section 3.4.1 Algorithm C. @@ -157,7 +159,7 @@ public class XSTR extends Random { v2 = 2 * nextDouble() - 1; // between -1 and 1 s = v1 * v1 + v2 * v2; } while (s >= 1 || s == 0); - double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s)/s); + double multiplier = StrictMath.sqrt(-2 * StrictMath.log(s) / s); nextNextGaussian = v2 * multiplier; haveNextNextGaussian = true; return v1 * multiplier; @@ -220,9 +222,9 @@ public class XSTR extends Random { */ @Override public int nextInt(int bound) { - //if (bound <= 0) { - //throw new RuntimeException("BadBound"); - //} + // if (bound <= 0) { + // throw new RuntimeException("BadBound"); + // } /*int r = next(31); int m = bound - 1; @@ -236,7 +238,7 @@ public class XSTR extends Random { ; } return r;*/ - //speedup, new nextInt ~+40% + // speedup, new nextInt ~+40% last = seed ^ (seed << 21); last ^= (last >>> 35); last ^= (last << 4); @@ -244,6 +246,7 @@ public class XSTR extends Random { int out = (int) last % bound; return (out < 0) ? -out : out; } + @Override public int nextInt() { return next(32); @@ -257,15 +260,14 @@ public class XSTR extends Random { @Override public long nextLong() { // it's okay that the bottom word remains signed. - return ((long)(next(32)) << 32) + next(32); + return ((long) (next(32)) << 32) + next(32); } @Override public void nextBytes(byte[] bytes_arr) { for (int iba = 0, lenba = bytes_arr.length; iba < lenba; ) - for (int rndba = nextInt(), - nba = Math.min(lenba - iba, Integer.SIZE/Byte.SIZE); - nba-- > 0; rndba >>= Byte.SIZE) - bytes_arr[iba++] = (byte)rndba; + for (int rndba = nextInt(), nba = Math.min(lenba - iba, Integer.SIZE / Byte.SIZE); + nba-- > 0; + rndba >>= Byte.SIZE) bytes_arr[iba++] = (byte) rndba; } } |