aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/api')
-rw-r--r--src/Java/gtPlusPlus/api/analytics/AnalyticsLoggingPlugin.java39
-rw-r--r--src/Java/gtPlusPlus/api/analytics/BlockingFlush.java67
-rw-r--r--src/Java/gtPlusPlus/api/analytics/SegmentAnalytics.java271
-rw-r--r--src/Java/gtPlusPlus/api/analytics/SegmentHelper.java81
-rw-r--r--src/Java/gtPlusPlus/api/damage/BaseCustomDamageSource.java22
-rw-r--r--src/Java/gtPlusPlus/api/damage/DamageTeslaTower.java2
-rw-r--r--src/Java/gtPlusPlus/api/enums/Quality.java62
-rw-r--r--src/Java/gtPlusPlus/api/helpers/MaterialHelper.java (renamed from src/Java/gtPlusPlus/api/objects/MaterialHelper.java)8
-rw-r--r--src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java3
-rw-r--r--src/Java/gtPlusPlus/api/interfaces/IGregtechPower.java147
-rw-r--r--src/Java/gtPlusPlus/api/interfaces/IPlugin.java6
-rw-r--r--src/Java/gtPlusPlus/api/interfaces/ITexturedBlock.java3
-rw-r--r--src/Java/gtPlusPlus/api/objects/Logger.java1
-rw-r--r--src/Java/gtPlusPlus/api/objects/data/AutoMap.java84
-rw-r--r--src/Java/gtPlusPlus/api/objects/data/Pair.java27
-rw-r--r--src/Java/gtPlusPlus/api/objects/data/Quad.java33
-rw-r--r--src/Java/gtPlusPlus/api/objects/data/Triplet.java27
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java222
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java (renamed from src/Java/gtPlusPlus/api/objects/ChunkManager.java)30
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java (renamed from src/Java/gtPlusPlus/api/objects/DimChunkPos.java)3
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/FluidGT6.java31
-rw-r--r--src/Java/gtPlusPlus/api/objects/minecraft/GenericStack.java (renamed from src/Java/gtPlusPlus/api/objects/GenericStack.java)3
-rw-r--r--src/Java/gtPlusPlus/api/objects/random/CSPRNG_DO_NOT_USE.java (renamed from src/Java/gtPlusPlus/api/objects/CSPRNG_DO_NOT_USE.java)2
-rw-r--r--src/Java/gtPlusPlus/api/objects/random/UUIDGenerator.java449
-rw-r--r--src/Java/gtPlusPlus/api/objects/random/XSTR.java (renamed from src/Java/gtPlusPlus/api/objects/XSTR.java)2
-rw-r--r--src/Java/gtPlusPlus/api/plugin/Sample_Plugin.java32
26 files changed, 1143 insertions, 514 deletions
diff --git a/src/Java/gtPlusPlus/api/analytics/AnalyticsLoggingPlugin.java b/src/Java/gtPlusPlus/api/analytics/AnalyticsLoggingPlugin.java
deleted file mode 100644
index 2423eaa65c..0000000000
--- a/src/Java/gtPlusPlus/api/analytics/AnalyticsLoggingPlugin.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package gtPlusPlus.api.analytics;
-
-import com.segment.analytics.Analytics;
-import com.segment.analytics.Callback;
-import com.segment.analytics.Log;
-import com.segment.analytics.Plugin;
-import com.segment.analytics.messages.Message;
-
-import gtPlusPlus.api.objects.Logger;
-
-/**
- * A {@link Plugin} implementation that redirects client logs to standard output and logs callback
- * events.
- */
-public class AnalyticsLoggingPlugin implements Plugin {
- @Override public void configure(Analytics.Builder builder) {
- builder.log(new Log() {
- @Override public void print(Level level, String format, Object... args) {
- Logger.WARNING(level + ":\t" + String.format(format, args));
- }
-
- @Override public void print(Level level, Throwable error, String format, Object... args) {
- Logger.WARNING(level + ":\t" + String.format(format, args));
- //Utils.LOG_WARNING(error);
- }
- });
-
- builder.callback(new Callback() {
- @Override public void success(Message message) {
- Logger.WARNING("Uploaded " + message);
- }
-
- @Override public void failure(Message message, Throwable throwable) {
- Logger.WARNING("Could not upload " + message);
- //Utils.LOG_WARNING(throwable);
- }
- });
- }
-} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/analytics/BlockingFlush.java b/src/Java/gtPlusPlus/api/analytics/BlockingFlush.java
deleted file mode 100644
index dddb37fefb..0000000000
--- a/src/Java/gtPlusPlus/api/analytics/BlockingFlush.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package gtPlusPlus.api.analytics;
-
-import com.segment.analytics.Analytics;
-import com.segment.analytics.Callback;
-import com.segment.analytics.MessageTransformer;
-import com.segment.analytics.Plugin;
-import com.segment.analytics.messages.Message;
-import com.segment.analytics.messages.MessageBuilder;
-import java.util.concurrent.Phaser;
-
-/**
- * The {@link Analytics} class doesn't come with a blocking {@link Analytics#flush()} implementation
- * out of the box. It's trivial to build one using a {@link Phaser} that monitors requests and is
- * able to block until they're uploaded.
- *
- * <pre><code>
- * BlockingFlush mBlockingFlush = BlockingFlush.create();
- * Analytics mHelper = Analytics.builder(writeKey)
- * .plugin(mBlockingFlush)
- * .build();
- *
- * // Do some work.
- *
- * mHelper.flush(); // Trigger a flush.
- * mBlockingFlush.block(); // Block until the flush completes.
- * mHelper.shutdown(); // Shut down after the flush is complete.
- * </code></pre>
- */
-public class BlockingFlush {
-
- public static BlockingFlush create() {
- return new BlockingFlush();
- }
-
- BlockingFlush() {
- this.phaser = new Phaser(1);
- }
-
- final Phaser phaser;
-
- public Plugin plugin() {
- return new Plugin() {
- @Override public void configure(Analytics.Builder builder) {
- builder.messageTransformer(new MessageTransformer() {
- @Override public boolean transform(MessageBuilder builder) {
- phaser.register();
- return true;
- }
- });
-
- builder.callback(new Callback() {
- @Override public void success(Message message) {
- phaser.arrive();
- }
-
- @Override public void failure(Message message, Throwable throwable) {
- phaser.arrive();
- }
- });
- }
- };
- }
-
- public void block() {
- phaser.arriveAndAwaitAdvance();
- }
-} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/analytics/SegmentAnalytics.java b/src/Java/gtPlusPlus/api/analytics/SegmentAnalytics.java
deleted file mode 100644
index c4ef82b9ef..0000000000
--- a/src/Java/gtPlusPlus/api/analytics/SegmentAnalytics.java
+++ /dev/null
@@ -1,271 +0,0 @@
-package gtPlusPlus.api.analytics;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Phaser;
-
-import com.mojang.authlib.GameProfile;
-import com.segment.analytics.Analytics;
-
-import gtPlusPlus.api.objects.Logger;
-import gtPlusPlus.core.lib.CORE;
-import gtPlusPlus.core.lib.LoadedMods;
-import gtPlusPlus.core.util.Utils;
-import gtPlusPlus.core.util.player.PlayerUtils;
-import gtPlusPlus.core.util.uuid.UUIDGenerator;
-import gtPlusPlus.core.util.uuid.UUIDUtils;
-import ic2.core.IC2;
-import net.minecraft.entity.player.EntityPlayer;
-
-public class SegmentAnalytics {
-
- //Globally Enabled
- public static boolean isEnabled = true;
-
- //Analytics Map with IDs
- public static final Map<Integer, SegmentAnalytics> sAnalyticsMasterList = new ConcurrentHashMap<Integer, SegmentAnalytics>();
- //ID count
- private static int sAnalyticsMapID = 0;
-
- //Analytics Player Mapping
- public static final Map<UUID, Integer> sAnalyticsToPlayermap = new ConcurrentHashMap<UUID, Integer>();
-
- //Set some Vars
- final BlockingFlush mBlockingFlush;
- final SegmentHelper mHelper;
- final UUIDGenerator mUuidGenerator;
-
- public final GameProfile mLocalProfile;
- public final String mLocalName;
- public final UUID mUUID;
- public final String mUserName;
- public final String mAnonymousId;
- protected Map<String, Object> mProperties = new LinkedHashMap<>();
- final protected Phaser mPhaser;
-
- //Build a new instance of this class
- public SegmentAnalytics(EntityPlayer mPlayer){
- LOG("Initializing Segment for "+mPlayer.getDisplayName());
-
- //Give this Object an ID
- int currentID = sAnalyticsMapID;
- sAnalyticsMapID++;
-
- //Map this Object to it's ID and a Player UUID.
- sAnalyticsMasterList.put(currentID, this);
- sAnalyticsToPlayermap.put(mPlayer.getUniqueID(), currentID);
-
- //Create a Phaser
- this.mPhaser = new Phaser(1);
-
- //Set vars for player
- this.mLocalProfile = mPlayer.getGameProfile();
- this.mLocalName = mLocalProfile.getName();
- this.mUUID = PlayerUtils.getPlayersUUIDByName(mLocalName);
- this.mUserName = mUUID.toString();
- this.mAnonymousId = getStringForm(generateIdForSession());
-
- //Create a new UUID generator.
- this.mUuidGenerator = new UUIDGenerator();
-
- //Use Segment Analytics instead of plain Google Analytics.
- this.mBlockingFlush = BlockingFlush.create();
- this.mHelper = SegmentHelper.getInstance();
- initTimer(mPlayer);
- }
-
- //Sets vars and stops Analytics running if the player profile is invalid.
- private boolean canProcess(){
- //Invalid Player Profile
- if (mLocalProfile == null || !isEnabled){
- return false;
- }
- if (mLocalName == null || mUUID == null || mUserName == null || mAnonymousId == null){
- //LOG("One player var remained null, returning false.");
- return false;
- }
- if (mLocalName != null && mUUID != null && mUserName != null && mAnonymousId != null){
- //LOG("All player vars are ok, returning true.");
- return true;
- }
- LOG("Something went wrong, returning false.");
- return false;
- }
-
-
- public void submitInitData(EntityPlayer mPlayer){
- if (!canProcess()){
- return;
- }
- mProperties = new LinkedHashMap<>();
- mProperties.put("username", mLocalName);
- mProperties.put("gt_version", Utils.getGregtechVersionAsString());
- if (LoadedMods.IndustrialCraft2){
- mProperties.put("ic2_version", IC2.VERSION);
- }
- mProperties.put("country_code", CORE.USER_COUNTRY);
- mProperties.put("gtnh", CORE.GTNH);
-
- LOG("Created new Data packet, queued for submission.");
-
- //Old Code, now passed to Helper Class
- /*mHelper.enqueue(IdentifyMessage.builder()
- .userId(mUserName) //Save Username as UUID, for future sessions to attach to.
- .traits(mProperties)
- //.anonymousId(mAnonymousId) //Save Random Session UUID
- );*/
-
- mHelper.addUser(this.mUserName, mProperties);
-
- if (CORE.GTNH){
- mHelper.groupUser("GT:NewHorizons", this.mUserName);
- }
- else {
- mHelper.groupUser("GT:Vanilla", this.mUserName);
- }
-
- }
-
- public void submitTrackingData(String aActionPerformed){
- submitTrackingData(aActionPerformed, null);
- }
-
- public void submitTrackingData(String aActionPerformed, Object aObject){
- if (!canProcess()){
- return;
- }
-
- Map<String, Object> properties = new LinkedHashMap<>();
- properties.put("blockType", aObject);
- String mObjectAsString = "Unknown";
-
- if (aObject != null){
- mObjectAsString = aObject.toString();
- }
-
- LOG("Queued submission of data for event "+aActionPerformed+". This was performed on "+mObjectAsString+".");
-
- mHelper.trackUser(this.mUserName, aActionPerformed, properties);
-
- //Old Code, now passed to Helper Class
- /*mHelper.enqueue(TrackMessage.builder(aActionPerformed) //
- .userId(mUserName) // Save Username as UUID, for future sessions to attach to.
- .properties(mProperties) //Save Stats
- //.anonymousId(mAnonymousId) //Save Random Session UUID
- );
- flushData();
- */
- }
-
- public void flushData(){
- getAnalyticObject().flush();
- }
-
- public void flushDataFinal(){
- LOG("Flushing all data from Queue to Segment Analytics database.");
- getAnalyticObject().flush();
- mBlockingFlush.block();
- mPhaser.arriveAndAwaitAdvance();
- getAnalyticObject().shutdown();
- /*try {
- this.finalize();
- }
- catch (Throwable e) {
- Utils.LOG_INFO("Could not finalize Analytics Object.");
- }*/
- }
-
- public UUID generateIdForSession(){
- return UUIDUtils.getUUIDFromBytes(generateUUID());
- }
-
- private final byte[] generateUUID(){
- byte[] mUUID;
-
- if (this.mUuidGenerator != null){
- try {
- if ((mUUID = mUuidGenerator.next(4)) != null){
- LOG("Generated Type 4 UUID for Session ID.");
- return mUUID;
- }
- else if ((mUUID = mUuidGenerator.next(1)) != null){
- LOG("Generated Type 1 UUID for Session ID.");
- return mUUID;
- }
- }
- catch (Throwable t){
- t.printStackTrace();
- }
- }
-
- LOG("Generated Type 3 UUID for Session ID.");
- return UUIDUtils.getBytesFromUUID(UUID.randomUUID());
-
- }
-
- public final String getStringForm(UUID mID){
- return mID.toString();
- }
-
- // Non-Dev Comments
- public static void LOG(final String s) {
- if (CORE.DEBUG){
- Logger.getLogger().info("[Analytics] "+s);
- }
- }
-
- public static SegmentAnalytics getAnalyticsForPlayer(EntityPlayer mPlayer){
- try {
- if (mPlayer != null){
- if (SegmentAnalytics.sAnalyticsToPlayermap.containsKey(mPlayer.getUniqueID())){
- int ID = sAnalyticsToPlayermap.get(mPlayer.getUniqueID());
- return SegmentAnalytics.sAnalyticsMasterList.get(ID);
- }
- else {
- LOG("Map does not contain Player.");
- }
- }
- else {
- LOG("Invalid Player.");
- }
- }
- catch (Throwable t){
- t.printStackTrace();
- }
- return null;
- }
-
- public final Analytics getAnalyticObject() {
- return mHelper.getAnalyticsClient();
- }
-
- public final Map<String, Object> getPlayerProperties(){
- return this.mProperties;
- }
-
-
- public Timer initTimer(EntityPlayer mPlayer) {
- Timer timer;
- timer = new Timer();
- timer.schedule(new initPlayer(mPlayer), 2 * 1000);
- return timer;
- }
-
- //Timer Task for notifying the player.
- class initPlayer extends TimerTask {
- final EntityPlayer aPlayer;
- public initPlayer(EntityPlayer mPlayer) {
- this.aPlayer = mPlayer;
- }
- @Override
- public void run() {
- //Let us submit a doorknock to Segment to let them know who this is.
- submitInitData(aPlayer);
- }
- }
-
-}
diff --git a/src/Java/gtPlusPlus/api/analytics/SegmentHelper.java b/src/Java/gtPlusPlus/api/analytics/SegmentHelper.java
deleted file mode 100644
index 6e264fe1d2..0000000000
--- a/src/Java/gtPlusPlus/api/analytics/SegmentHelper.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package gtPlusPlus.api.analytics;
-
-import com.segment.analytics.Analytics;
-import com.segment.analytics.Callback;
-import com.segment.analytics.messages.Message;
-import com.segment.analytics.messages.TrackMessage;
-import com.segment.analytics.messages.*;
-import java.util.Map;
-
-public class SegmentHelper implements Callback {
-
- /**
- * Credits to Author: FLAMINSAGANAKI/Theodore Mavrakis
- * http://domisydev.com/2015/11/05/using-segment-analytics-in-your-java-servlet/
- */
-
- private static final String writeKey = "EDOWl9peleGlUqe1ZwTqKDyuTMFhyT4k";
- private static volatile SegmentHelper segment = new SegmentHelper();
- private Analytics analytics;
-
- public SegmentHelper(){
- try{
- this.analytics = Analytics.builder(writeKey).callback(this).build();
- }catch(Exception e){
- SegmentAnalytics.LOG("exception while creating Analytics : " + e);
- }
- }
-
- public static SegmentHelper getInstance(){
- return segment;
- }
-
- public Analytics getAnalyticsClient(){
- return segment.analytics;
- }
-
- public void success(Message message) {
- SegmentAnalytics.LOG("Successfully uploaded " + message);
- }
-
- public void failure(Message message, Throwable throwable) {
- SegmentAnalytics.LOG("Could not upload " + message);
- }
-
- public void addUser(String user_id, Map<String, Object> properties) {
- try {
- this.analytics.enqueue(IdentifyMessage.builder().userId(user_id).traits(properties));
- //trackUser(user_id, "Logged In", properties);
- } catch (Exception e) {
- SegmentAnalytics.LOG("Exception in addUser() - " + e);
- }
- }
-
- public void trackUser(String user_id, String description, Map<String, Object> properties) {
- try {
- this.analytics.enqueue(TrackMessage.builder(description).userId(user_id).properties(properties));
- } catch (Exception e) {
- SegmentAnalytics.LOG("Exception in trackUser() - " + e);
- }
- }
-
- public void trackUser(String user_id, String description) {
- try {
- this.analytics.enqueue(TrackMessage.builder(description).userId(user_id));
- } catch (Exception e) {
- SegmentAnalytics.LOG("Exception in trackUser() - " + e);
- }
- }
-
- public void groupUser(String group_id, String user_id) {
- try {
- this.analytics.enqueue(GroupMessage.builder(group_id).userId(user_id));
- } catch (Exception e) {
- SegmentAnalytics.LOG("Exception in groupUser() - " + e);
- }
- }
-
- public static void main(String[] args){
-
- }
-} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/damage/BaseCustomDamageSource.java b/src/Java/gtPlusPlus/api/damage/BaseCustomDamageSource.java
deleted file mode 100644
index 24348988d6..0000000000
--- a/src/Java/gtPlusPlus/api/damage/BaseCustomDamageSource.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package gtPlusPlus.api.damage;
-
-import net.minecraft.entity.Entity;
-import net.minecraft.util.EntityDamageSourceIndirect;
-
-public class BaseCustomDamageSource extends EntityDamageSourceIndirect {
-
- public BaseCustomDamageSource(String name, Entity transmitter, Entity indirectSource) {
- super(name, transmitter, indirectSource);
- this.setDifficultyScaled();
- }
-
- /**
- * Return whether this damage source will have its damage amount scaled based on the current difficulty.
- */
- public boolean isDifficultyScaled()
- {
- return true;
- }
-
-
-} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/damage/DamageTeslaTower.java b/src/Java/gtPlusPlus/api/damage/DamageTeslaTower.java
index ada2ba5c3d..f35c9cbc6b 100644
--- a/src/Java/gtPlusPlus/api/damage/DamageTeslaTower.java
+++ b/src/Java/gtPlusPlus/api/damage/DamageTeslaTower.java
@@ -5,6 +5,8 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
+import gtPlusPlus.core.world.damage.BaseCustomDamageSource;
+
public class DamageTeslaTower extends BaseCustomDamageSource{
public DamageTeslaTower(Entity transmitter) {
diff --git a/src/Java/gtPlusPlus/api/enums/Quality.java b/src/Java/gtPlusPlus/api/enums/Quality.java
new file mode 100644
index 0000000000..050f335b5e
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/enums/Quality.java
@@ -0,0 +1,62 @@
+package gtPlusPlus.api.enums;
+
+import net.minecraft.util.EnumChatFormatting;
+
+import gtPlusPlus.core.util.math.MathUtils;
+
+public enum Quality {
+
+ // Magic Blue
+ // Rare Yellow
+ // Set Green
+ // Unique Gold/Purple
+ // Trade-off Brown
+
+ POOR("Poor", EnumChatFormatting.GRAY), COMMON("Common", EnumChatFormatting.WHITE), UNCOMMON("Uncommon",
+ EnumChatFormatting.DARK_GREEN), MAGIC("Magic", EnumChatFormatting.BLUE), RARE("Rare",
+ EnumChatFormatting.YELLOW), UNIQUE("Unique", EnumChatFormatting.GOLD), ARTIFACT("Artifact",
+ EnumChatFormatting.AQUA), SET("Set Piece", EnumChatFormatting.GREEN), TRADEOFF("Trade-off",
+ EnumChatFormatting.DARK_RED), EPIC("Epic", EnumChatFormatting.LIGHT_PURPLE);
+
+ private String LOOT;
+ private EnumChatFormatting COLOUR;
+
+ private Quality(final String lootTier, final EnumChatFormatting tooltipColour) {
+ this.LOOT = lootTier;
+ this.COLOUR = tooltipColour;
+ }
+
+ public String getQuality() {
+ return this.LOOT;
+ }
+
+ protected EnumChatFormatting getColour() {
+ return this.COLOUR;
+ }
+
+ public String formatted() {
+ return this.COLOUR + this.LOOT;
+ }
+
+ public static Quality getRandomQuality() {
+ final int lootChance = MathUtils.randInt(0, 100);
+ if (lootChance <= 10) {
+ return Quality.POOR;
+ } else if (lootChance <= 45) {
+ return Quality.COMMON;
+ } else if (lootChance <= 65) {
+ return Quality.UNCOMMON;
+ } else if (lootChance <= 82) {
+ return Quality.MAGIC;
+ } else if (lootChance <= 92) {
+ return Quality.EPIC;
+ } else if (lootChance <= 97) {
+ return Quality.RARE;
+ } else if (lootChance <= 99) {
+ return Quality.ARTIFACT;
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/api/objects/MaterialHelper.java b/src/Java/gtPlusPlus/api/helpers/MaterialHelper.java
index d63ab7a15a..0acee40a0f 100644
--- a/src/Java/gtPlusPlus/api/objects/MaterialHelper.java
+++ b/src/Java/gtPlusPlus/api/helpers/MaterialHelper.java
@@ -1,10 +1,12 @@
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.helpers;
+
+import net.minecraft.item.ItemStack;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
+
import gtPlusPlus.core.material.Material;
-import gtPlusPlus.core.util.item.ItemUtils;
-import net.minecraft.item.ItemStack;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
public class MaterialHelper {
diff --git a/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java b/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java
index ca2d80de53..5ab90d47ce 100644
--- a/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java
+++ b/src/Java/gtPlusPlus/api/interfaces/IEntityCatcher.java
@@ -1,10 +1,11 @@
package gtPlusPlus.api.interfaces;
-import gtPlusPlus.core.util.array.BlockPos;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
+import gtPlusPlus.api.objects.minecraft.BlockPos;
+
public interface IEntityCatcher {
public boolean hasEntity(ItemStack aStack);
diff --git a/src/Java/gtPlusPlus/api/interfaces/IGregtechPower.java b/src/Java/gtPlusPlus/api/interfaces/IGregtechPower.java
new file mode 100644
index 0000000000..5f624e7a8c
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/interfaces/IGregtechPower.java
@@ -0,0 +1,147 @@
+package gtPlusPlus.api.interfaces;
+
+import net.minecraft.block.Block;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+
+import gregtech.api.interfaces.IDescribable;
+import gregtech.api.interfaces.tileentity.*;
+
+import gtPlusPlus.core.tileentities.base.TilePoweredGT;
+
+public abstract interface IGregtechPower extends IGearEnergyTileEntity, ITurnable, IGregTechDeviceInformation, IDescribable, IBasicEnergyContainer {
+
+ @Override
+ public String[] getDescription();
+
+ @Override
+ default boolean isUniversalEnergyStored(long p0) {
+ return false;
+ }
+
+ @Override
+ public long getOutputAmperage();
+
+ @Override
+ public long getOutputVoltage();
+
+ @Override
+ public long getInputAmperage();
+
+ @Override
+ public long getInputVoltage();
+
+ @Override
+ public boolean decreaseStoredEnergyUnits(long p0, boolean p1);
+
+ @Override
+ public boolean increaseStoredEnergyUnits(long p0, boolean p1);
+
+ @Override
+ public boolean drainEnergyUnits(byte p0, long p1, long p2);
+
+ @Override
+ public long getAverageElectricInput();
+
+ @Override
+ public long getAverageElectricOutput();
+
+ @Override
+ public long getStoredEU();
+
+ @Override
+ public long getEUCapacity();
+
+ @Override
+ public long getStoredSteam();
+
+ @Override
+ public long getSteamCapacity();
+
+ @Override
+ public boolean increaseStoredSteam(long p0, boolean p1);
+
+ @Override
+ public Block getBlockAtSide(byte p0);
+
+ @Override
+ public Block getBlockAtSideAndDistance(byte p0, int p1);
+
+ @Override
+ public Block getBlockOffset(int p0, int p1, int p2);
+
+
+ @Override
+ public TileEntity getTileEntity(int p0, int p1, int p2);
+
+ @Override
+ public TileEntity getTileEntityAtSide(byte p0);
+
+ @Override
+ public TileEntity getTileEntityAtSideAndDistance(byte p0, int p1);
+
+ @Override
+ public TileEntity getTileEntityOffset(int p0, int p1, int p2);
+
+ @Override
+ public World getWorld();
+
+ @Override
+ public int getXCoord();
+
+ @Override
+ public short getYCoord();
+
+ @Override
+ public int getZCoord();
+
+ @Override
+ public boolean isClientSide();
+
+ @Override
+ public boolean isDead();
+
+ @Override
+ public boolean isInvalidTileEntity();
+
+ @Override
+ public boolean isServerSide();
+
+ @Override
+ public void readFromNBT(NBTTagCompound p0);
+
+ @Override
+ public void writeToNBT(NBTTagCompound p0);
+
+ @Override
+ public boolean acceptsRotationalEnergy(byte p0);
+
+ @Override
+ public boolean injectRotationalEnergy(byte p0, long p1, long p2);
+
+ @Override
+ public long injectEnergyUnits(byte p0, long p1, long p2);
+
+ @Override
+ public boolean inputEnergyFrom(byte p0);
+
+ @Override
+ public boolean outputsEnergyTo(byte p0);
+
+ @Override
+ public String[] getInfoData();
+
+ @Override
+ default public boolean isGivingInformation() {
+ return true;
+ }
+
+ boolean onPreTick(TilePoweredGT tilePoweredGT, long mTickTimer2);
+
+ boolean onTick(TilePoweredGT iGregTechTileEntity, long mTickTimer2);
+
+ boolean onPostTick(TilePoweredGT iGregTechTileEntity, long mTickTimer2);
+
+
+}
diff --git a/src/Java/gtPlusPlus/api/interfaces/IPlugin.java b/src/Java/gtPlusPlus/api/interfaces/IPlugin.java
index 3ac960eaf2..99c71a5823 100644
--- a/src/Java/gtPlusPlus/api/interfaces/IPlugin.java
+++ b/src/Java/gtPlusPlus/api/interfaces/IPlugin.java
@@ -1,12 +1,6 @@
package gtPlusPlus.api.interfaces;
-import gtPlusPlus.plugin.manager.Core_Manager;
-
public interface IPlugin {
-
- public default void register() {
- Core_Manager.registerPlugin(this);
- }
public String getPluginName();
diff --git a/src/Java/gtPlusPlus/api/interfaces/ITexturedBlock.java b/src/Java/gtPlusPlus/api/interfaces/ITexturedBlock.java
index 3a4b8f188c..47e692bffb 100644
--- a/src/Java/gtPlusPlus/api/interfaces/ITexturedBlock.java
+++ b/src/Java/gtPlusPlus/api/interfaces/ITexturedBlock.java
@@ -1,8 +1,9 @@
package gtPlusPlus.api.interfaces;
+import net.minecraft.block.Block;
+
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.ITexturedTileEntity;
-import net.minecraft.block.Block;
public interface ITexturedBlock extends ITexturedTileEntity{
diff --git a/src/Java/gtPlusPlus/api/objects/Logger.java b/src/Java/gtPlusPlus/api/objects/Logger.java
index 1ecdaa9e86..2c50f0c15e 100644
--- a/src/Java/gtPlusPlus/api/objects/Logger.java
+++ b/src/Java/gtPlusPlus/api/objects/Logger.java
@@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
+
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.proxy.ClientProxy;
diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java
new file mode 100644
index 0000000000..e5b5ded0ad
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java
@@ -0,0 +1,84 @@
+package gtPlusPlus.api.objects.data;
+
+import java.io.Serializable;
+import java.util.*;
+
+public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable {
+
+ /**
+ * The Internal Map
+ */
+ private Map<Integer, V> mInternalMap = new HashMap<Integer, V>();
+
+ /**
+ * The Internal ID
+ */
+ private int mInternalID = 0;
+ private static final long serialVersionUID = 3771412318075131790L;
+
+ @Override
+ public Iterator<V> iterator() {
+ return values().iterator();
+ }
+
+ public synchronized boolean setValue(V object){
+ int mOriginalID = this.mInternalID;
+ put(object);
+ if (this.mInternalMap.get(mOriginalID).equals(object) || mOriginalID > this.mInternalID){
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ public synchronized V put(V object){
+ return set(object);
+ }
+
+ public synchronized V set(V object){
+ return mInternalMap.put(mInternalID++, object);
+ }
+
+ public synchronized V get(int id){
+ return mInternalMap.get(id);
+ }
+
+ public synchronized Collection<V> values(){
+ return mInternalMap.values();
+ }
+
+ public synchronized int size(){
+ return mInternalMap.size();
+ }
+
+ public synchronized int hashCode(){
+ return mInternalMap.hashCode();
+ }
+
+ public synchronized boolean containsKey(int key){
+ return mInternalMap.containsKey(key);
+ }
+
+ public synchronized boolean containsValue(V value){
+ return mInternalMap.containsValue(value);
+ }
+
+ public synchronized boolean isEmpty(){
+ return mInternalMap.isEmpty();
+ }
+
+ public synchronized boolean clear(){
+ this.mInternalID = 0;
+ this.mInternalMap.clear();
+ return true;
+ }
+
+ public synchronized V[] toArray() {
+ Collection<V> col = this.mInternalMap.values();
+ @SuppressWarnings("unchecked")
+ V[] val = (V[]) col.toArray();
+ return val;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/api/objects/data/Pair.java b/src/Java/gtPlusPlus/api/objects/data/Pair.java
new file mode 100644
index 0000000000..6ab781cf1e
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/data/Pair.java
@@ -0,0 +1,27 @@
+package gtPlusPlus.api.objects.data;
+
+import java.io.Serializable;
+
+public class Pair<K,V> implements Serializable {
+
+ /**
+ * SVUID
+ */
+ private static final long serialVersionUID = 1250550491092812443L;
+ private final K key;
+ private final V value;
+
+ public Pair(final K key, final V value){
+ this.key = key;
+ this.value = value;
+ }
+
+ final public K getKey(){
+ return this.key;
+ }
+
+ final public V getValue(){
+ return this.value;
+ }
+
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/objects/data/Quad.java b/src/Java/gtPlusPlus/api/objects/data/Quad.java
new file mode 100644
index 0000000000..01c62e95e6
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/data/Quad.java
@@ -0,0 +1,33 @@
+package gtPlusPlus.api.objects.data;
+
+public class Quad<K,V,C,R> {
+
+ private final K key;
+ private final V value;
+ private final C value2;
+ private final R value3;
+
+ public Quad(final K key, final V value, final C value2, final R value3){
+ this.key = key;
+ this.value = value;
+ this.value2 = value2;
+ this.value3 = value3;
+ }
+
+ final public K getKey(){
+ return this.key;
+ }
+
+ final public V getValue_1(){
+ return this.value;
+ }
+
+ final public C getValue_2(){
+ return this.value2;
+ }
+
+ final public R getValue_3(){
+ return this.value3;
+ }
+
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/objects/data/Triplet.java b/src/Java/gtPlusPlus/api/objects/data/Triplet.java
new file mode 100644
index 0000000000..affb03d868
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/data/Triplet.java
@@ -0,0 +1,27 @@
+package gtPlusPlus.api.objects.data;
+
+public class Triplet<K,V,C> {
+
+ private final K key;
+ private final V value;
+ private final C count;
+
+ public Triplet(final K key, final V value, final C value2){
+ this.key = key;
+ this.value = value;
+ this.count = value2;
+ }
+
+ final public K getValue_1(){
+ return this.key;
+ }
+
+ final public V getValue_2(){
+ return this.value;
+ }
+
+ final public C getValue_3(){
+ return this.count;
+ }
+
+} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java
new file mode 100644
index 0000000000..5f0d3a2117
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java
@@ -0,0 +1,222 @@
+package gtPlusPlus.api.objects.minecraft;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.minecraft.block.Block;
+import net.minecraft.world.World;
+
+import gtPlusPlus.api.objects.data.AutoMap;
+import net.minecraftforge.common.DimensionManager;
+
+public class BlockPos implements Serializable{
+
+ private static final long serialVersionUID = -7271947491316682006L;
+ public final int xPos;
+ public final int yPos;
+ public final int zPos;
+ public final int dim;
+ public final World world;
+
+ public BlockPos(int x, int y, int z){
+ this(x, y, z, 0);
+ }
+
+ public BlockPos(int x, int y, int z, int dim){
+ this.xPos = x;
+ this.yPos = y;
+ this.zPos = z;
+ this.dim = dim;
+ this.world = DimensionManager.getWorld(dim);
+ }
+
+ public BlockPos(int x, int y, int z, World dim){
+ this.xPos = x;
+ this.yPos = y;
+ this.zPos = z;
+ this.dim = dim.provider.dimensionId;
+ this.world = dim;
+ }
+
+ public String getLocationString() {
+ return "[X: "+this.xPos+"][Y: "+this.yPos+"][Z: "+this.zPos+"][Dim: "+this.dim+"]";
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash += (13 * this.xPos);
+ hash += (19 * this.yPos);
+ hash += (31 * this.zPos);
+ hash += (17 * this.dim);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (other == this) {
+ return true;
+ }
+ if(!(other instanceof BlockPos)) {
+ return false;
+ }
+ BlockPos otherPoint = (BlockPos)other;
+ return this.xPos == otherPoint.xPos && this.yPos == otherPoint.yPos && this.zPos == otherPoint.zPos && this.dim == otherPoint.dim;
+ }
+
+ public int distanceFrom(BlockPos target) {
+ if (target.dim != this.dim) {
+ return Short.MIN_VALUE;
+ }
+ return distanceFrom(target.xPos, target.yPos, target.zPos);
+ }
+
+ /**
+ *
+ * @param x X coordinate of target.
+ * @param y Y coordinate of target.
+ * @param z Z coordinate of target.
+ * @return square of distance
+ */
+ public int distanceFrom(int x, int y, int z) {
+ int distanceX = this.xPos - x;
+ int distanceY = this.yPos - y;
+ int distanceZ = this.zPos - z;
+ return distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ;
+ }
+
+ public boolean isWithinRange(BlockPos target, int range) {
+ if (target.dim != this.dim) {
+ return false;
+ }
+ return isWithinRange(target.xPos, target.yPos, target.zPos, range);
+ }
+
+ public boolean isWithinRange(int x, int y, int z, int range) {
+ return distanceFrom(x, y, z) <= (range * range);
+ }
+
+
+ public BlockPos getUp() {
+ return new BlockPos(this.xPos, this.yPos+1, this.zPos, this.dim);
+ }
+
+ public BlockPos getDown() {
+ return new BlockPos(this.xPos, this.yPos-1, this.zPos, this.dim);
+ }
+
+ public BlockPos getXPos() {
+ return new BlockPos(this.xPos+1, this.yPos, this.zPos, this.dim);
+ }
+
+ public BlockPos getXNeg() {
+ return new BlockPos(this.xPos-1, this.yPos, this.zPos, this.dim);
+ }
+
+ public BlockPos getZPos() {
+ return new BlockPos(this.xPos, this.yPos, this.zPos+1, this.dim);
+ }
+
+ public BlockPos getZNeg() {
+ return new BlockPos(this.xPos, this.yPos, this.zPos-1, this.dim);
+ }
+
+ public AutoMap<BlockPos> getSurroundingBlocks(){
+ AutoMap<BlockPos> sides = new AutoMap<BlockPos>();
+ sides.put(getUp());
+ sides.put(getDown());
+ sides.put(getXPos());
+ sides.put(getXNeg());
+ sides.put(getZPos());
+ sides.put(getZNeg());
+ return sides;
+ }
+
+ public Block getBlockAtPos() {
+ return getBlockAtPos(this);
+ }
+
+ public Block getBlockAtPos(BlockPos pos) {
+ return getBlockAtPos(world, pos);
+ }
+
+ public Block getBlockAtPos(World world, BlockPos pos) {
+ return world.getBlock(pos.xPos, pos.yPos, pos.zPos);
+ }
+
+ public int getMetaAtPos() {
+ return getMetaAtPos(this);
+ }
+
+ public int getMetaAtPos(BlockPos pos) {
+ return getMetaAtPos(world, pos);
+ }
+
+ public int getMetaAtPos(World world, BlockPos pos) {
+ return world.getBlockMetadata(pos.xPos, pos.yPos, pos.zPos);
+ }
+
+ public boolean hasSimilarNeighbour() {
+ return hasSimilarNeighbour(false);
+ }
+
+ /**
+ * @param strict - Does this check Meta Data?
+ * @return - Does this block have a neighbour that is the same?
+ */
+ public boolean hasSimilarNeighbour(boolean strict) {
+ for (BlockPos g : getSurroundingBlocks().values()) {
+ if (getBlockAtPos(g) == getBlockAtPos()) {
+ if (!strict) {
+ return true;
+ }
+ else {
+ if (getMetaAtPos() == getMetaAtPos(g)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public AutoMap<BlockPos> getSimilarNeighbour() {
+ return getSimilarNeighbour(false);
+ }
+
+ /**
+ * @param strict - Does this check Meta Data?
+ * @return - Does this block have a neighbour that is the same?
+ */
+ public AutoMap<BlockPos> getSimilarNeighbour(boolean strict) {
+ AutoMap<BlockPos> sides = new AutoMap<BlockPos>();
+ for (BlockPos g : getSurroundingBlocks().values()) {
+ if (getBlockAtPos(g) == getBlockAtPos()) {
+ if (!strict) {
+ sides.put(g);
+ }
+ else {
+ if (getMetaAtPos() == getMetaAtPos(g)) {
+ sides.put(g);
+ }
+ }
+ }
+ }
+ return sides;
+ }
+
+ public Set<BlockPos> getValidNeighboursAndSelf(){
+ AutoMap<BlockPos> h = getSimilarNeighbour(true);
+ h.put(this);
+ Set<BlockPos> result = new HashSet<BlockPos>();
+ for (BlockPos f : h.values()) {
+ result.add(f);
+ }
+ return result;
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/api/objects/ChunkManager.java b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java
index 0bace04bf8..82f3adfc9e 100644
--- a/src/Java/gtPlusPlus/api/objects/ChunkManager.java
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java
@@ -6,33 +6,27 @@
* permission unless otherwise specified on the
* license page at http://railcraft.info/wiki/info:license.
*/
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.objects.minecraft;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
-import cpw.mods.fml.common.eventhandler.SubscribeEvent;
-import gtPlusPlus.GTplusplus;
-import gtPlusPlus.core.util.array.BlockPos;
-import gtPlusPlus.core.util.array.Triplet;
-import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ConcurrentHashMap;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
-import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.entity.Entity;
+import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
+
+import gtPlusPlus.GTplusplus;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.Triplet;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader;
import net.minecraftforge.common.ForgeChunkManager;
-import net.minecraftforge.common.ForgeChunkManager.LoadingCallback;
-import net.minecraftforge.common.ForgeChunkManager.OrderedLoadingCallback;
-import net.minecraftforge.common.ForgeChunkManager.Ticket;
-import net.minecraftforge.common.ForgeChunkManager.Type;
+import net.minecraftforge.common.ForgeChunkManager.*;
import net.minecraftforge.event.entity.EntityEvent;
/**
diff --git a/src/Java/gtPlusPlus/api/objects/DimChunkPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java
index bea0a4ec3b..010e522a14 100644
--- a/src/Java/gtPlusPlus/api/objects/DimChunkPos.java
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/DimChunkPos.java
@@ -1,6 +1,5 @@
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.objects.minecraft;
-import gtPlusPlus.core.util.array.BlockPos;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/FluidGT6.java b/src/Java/gtPlusPlus/api/objects/minecraft/FluidGT6.java
new file mode 100644
index 0000000000..2535046792
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/FluidGT6.java
@@ -0,0 +1,31 @@
+package gtPlusPlus.api.objects.minecraft;
+
+import gregtech.api.GregTech_API;
+
+import gtPlusPlus.core.lib.CORE;
+import net.minecraftforge.fluids.Fluid;
+
+public class FluidGT6 extends Fluid implements Runnable
+{
+ private final short[] mRGBa;
+ public final String mTextureName;
+
+ public FluidGT6(final String aName, final String aTextureName, final short[] aRGBa) {
+ super(aName);
+ this.mRGBa = aRGBa;
+ this.mTextureName = aTextureName;
+ if (GregTech_API.sGTBlockIconload != null) {
+ GregTech_API.sGTBlockIconload.add(this);
+ }
+ }
+
+ @Override
+ public int getColor() {
+ return (Math.max(0, Math.min(255, this.mRGBa[0])) << 16) | (Math.max(0, Math.min(255, this.mRGBa[1])) << 8) | Math.max(0, Math.min(255, this.mRGBa[2]));
+ }
+
+ @Override
+ public void run() {
+ this.setIcons(GregTech_API.sBlockIcons.registerIcon(CORE.MODID+ ":" + "fluids/fluid." + this.mTextureName));
+ }
+}
diff --git a/src/Java/gtPlusPlus/api/objects/GenericStack.java b/src/Java/gtPlusPlus/api/objects/minecraft/GenericStack.java
index b3bc94364f..9c1b231961 100644
--- a/src/Java/gtPlusPlus/api/objects/GenericStack.java
+++ b/src/Java/gtPlusPlus/api/objects/minecraft/GenericStack.java
@@ -1,6 +1,7 @@
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.objects.minecraft;
import net.minecraft.item.ItemStack;
+
import net.minecraftforge.fluids.FluidStack;
public class GenericStack {
diff --git a/src/Java/gtPlusPlus/api/objects/CSPRNG_DO_NOT_USE.java b/src/Java/gtPlusPlus/api/objects/random/CSPRNG_DO_NOT_USE.java
index 19200846ca..b2dc984456 100644
--- a/src/Java/gtPlusPlus/api/objects/CSPRNG_DO_NOT_USE.java
+++ b/src/Java/gtPlusPlus/api/objects/random/CSPRNG_DO_NOT_USE.java
@@ -33,7 +33,7 @@
* http://www.opensource.org/licenses/bsd-license.php
*/
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.objects.random;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
diff --git a/src/Java/gtPlusPlus/api/objects/random/UUIDGenerator.java b/src/Java/gtPlusPlus/api/objects/random/UUIDGenerator.java
new file mode 100644
index 0000000000..fec92368f8
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/objects/random/UUIDGenerator.java
@@ -0,0 +1,449 @@
+package gtPlusPlus.api.objects.random;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ *
+ * Implement modified version of Apache's OpenJPA UUID generator.
+ * This UUID generator is paired with a Blum-Blum-Shub random number generator
+ * which in itself is seeded by custom SecureRandom.
+ *
+ * The UUID generator class has been converted from a static factory to an instanced factory.
+ *
+ */
+
+//========================================= APACHE BLOCK =========================================
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * UUID value generator. Type 1 generator is based on the time-based generator
+ * in the Apache Commons Id project: http://jakarta.apache.org/commons/sandbox
+ * /id/uuid.html The type 4 generator uses the standard Java UUID generator.
+ *
+ * The type 1 code has been vastly simplified and modified to replace the
+ * ethernet address of the host machine with the IP, since we do not want to
+ * require native libs and Java cannot access the MAC address directly.
+ *
+ * In spirit, implements the IETF UUID draft specification, found here:<br />
+ * http://www1.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-uuids-guids-01
+ * .txt
+ *
+ * @author Abe White, Kevin Sutter
+ * @since 0.3.3
+ */
+public class UUIDGenerator {
+
+ // supported UUID types
+ public static final int TYPE1 = 1;
+ public static final int TYPE4 = 4;
+ // indexes within the uuid array for certain boundaries
+ private static final byte IDX_TIME_HI = 6;
+ private static final byte IDX_TYPE = 6; // multiplexed
+ private static final byte IDX_TIME_MID = 4;
+ private static final byte IDX_TIME_LO = 0;
+ private static final byte IDX_TIME_SEQ = 8;
+ private static final byte IDX_VARIATION = 8; // multiplexed
+ // indexes and lengths within the timestamp for certain boundaries
+ private static final byte TS_TIME_LO_IDX = 4;
+ private static final byte TS_TIME_LO_LEN = 4;
+ private static final byte TS_TIME_MID_IDX = 2;
+ private static final byte TS_TIME_MID_LEN = 2;
+ private static final byte TS_TIME_HI_IDX = 0;
+ private static final byte TS_TIME_HI_LEN = 2;
+ // offset to move from 1/1/1970, which is 0-time for Java, to gregorian
+ // 0-time 10/15/1582, and multiplier to go from 100nsec to msec units
+ private static final long GREG_OFFSET = 0xB1D069B5400L;
+ private static final long MILLI_MULT = 10000L;
+ // type of UUID -- time based
+ private final static byte TYPE_TIME_BASED = 0x10;
+ // random number generator used to reduce conflicts with other JVMs, and
+ // hasher for strings.
+ private Random RANDOM;
+ // 4-byte IP address + 2 random bytes to compensate for the fact that
+ // the MAC address is usually 6 bytes
+ private byte[] IP;
+ // counter is initialized to 0 and is incremented for each uuid request
+ // within the same timestamp window.
+ private int _counter;
+ // current timestamp (used to detect multiple uuid requests within same
+ // timestamp)
+ private long _currentMillis;
+ // last used millis time, and a semi-random sequence that gets reset
+ // when it overflows
+ private long _lastMillis = 0L;
+ private static final int MAX_14BIT = 0x3FFF;
+ private short _seq = 0;
+ private boolean type1Initialized = false; /*
+ * Initializer for type 1 UUIDs. Creates random generator and genenerates
+ * the node portion of the UUID using the IP address.
+ */
+ private synchronized void initializeForType1() {
+ if (type1Initialized == true) {
+ return;
+ }
+ // note that secure random is very slow the first time
+ // it is used; consider switching to a standard random
+ RANDOM = CSPRNG_DO_NOT_USE.generate();
+ _seq = (short) RANDOM.nextInt(MAX_14BIT);
+
+ byte[] ip = null;
+ try {
+ ip = InetAddress.getLocalHost().getAddress();
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ IP = new byte[6];
+ RANDOM.nextBytes(IP);
+ //OPENJPA-2055: account for the fact that 'getAddress'
+ //may return an IPv6 address which is 16 bytes wide.
+ for( int i = 0 ; i < ip.length; ++i ) {
+ IP[2+(i%4)] ^= ip[i];
+ }
+ type1Initialized = true;
+ }
+ /**
+ * Return a unique UUID value.
+ */
+ public byte[] next(int type) {
+ if (type == TYPE4) {
+ return createType4();
+ }
+ return createType1();
+ }
+ /*
+ * Creates a type 1 UUID
+ */
+ public byte[] createType1() {
+ if (type1Initialized == false) {
+ initializeForType1();
+ }
+ // set ip addr
+ byte[] uuid = new byte[16];
+ System.arraycopy(IP, 0, uuid, 10, IP.length);
+ // Set time info. Have to do this processing within a synchronized
+ // block because of the statics...
+ long now = 0;
+ synchronized (UUIDGenerator.class) {
+ // Get the time to use for this uuid. This method has the side
+ // effect of modifying the clock sequence, as well.
+ now = getTime();
+ // Insert the resulting clock sequence into the uuid
+ uuid[IDX_TIME_SEQ] = (byte) ((_seq & 0x3F00) >>> 8);
+ uuid[IDX_VARIATION] |= 0x80;
+ uuid[IDX_TIME_SEQ+1] = (byte) (_seq & 0xFF);
+ }
+ // have to break up time because bytes are spread through uuid
+ byte[] timeBytes = Bytes.toBytes(now);
+ // Copy time low
+ System.arraycopy(timeBytes, TS_TIME_LO_IDX, uuid, IDX_TIME_LO,
+ TS_TIME_LO_LEN);
+ // Copy time mid
+ System.arraycopy(timeBytes, TS_TIME_MID_IDX, uuid, IDX_TIME_MID,
+ TS_TIME_MID_LEN);
+ // Copy time hi
+ System.arraycopy(timeBytes, TS_TIME_HI_IDX, uuid, IDX_TIME_HI,
+ TS_TIME_HI_LEN);
+ //Set version (time-based)
+ uuid[IDX_TYPE] |= TYPE_TIME_BASED; // 0001 0000
+ return uuid;
+ }
+ /*
+ * Creates a type 4 UUID
+ */
+ private byte[] createType4() {
+ UUID type4 = UUID.randomUUID();
+ byte[] uuid = new byte[16];
+ longToBytes(type4.getMostSignificantBits(), uuid, 0);
+ longToBytes(type4.getLeastSignificantBits(), uuid, 8);
+ return uuid;
+ }
+ /*
+ * Converts a long to byte values, setting them in a byte array
+ * at a given starting position.
+ */
+ private void longToBytes(long longVal, byte[] buf, int sPos) {
+ sPos += 7;
+ for(int i = 0; i < 8; i++)
+ buf[sPos-i] = (byte)(longVal >>> (i * 8));
+ }
+
+ /**
+ * Return the next unique uuid value as a 16-character string.
+ */
+ public String nextString(int type) {
+ byte[] bytes = next(type);
+ try {
+ return new String(bytes, "ISO-8859-1");
+ } catch (Exception e) {
+ return new String(bytes);
+ }
+ }
+ /**
+ * Return the next unique uuid value as a 32-character hex string.
+ */
+ public String nextHex(int type) {
+ return Base16Encoder.encode(next(type));
+ }
+ /**
+ * Get the timestamp to be used for this uuid. Must be called from
+ * a synchronized block.
+ *
+ * @return long timestamp
+ */
+ // package-visibility for testing
+ private long getTime() {
+ if (RANDOM == null)
+ initializeForType1();
+ long newTime = getUUIDTime();
+ if (newTime <= _lastMillis) {
+ incrementSequence();
+ newTime = getUUIDTime();
+ }
+ _lastMillis = newTime;
+ return newTime;
+ }
+ /**
+ * Gets the appropriately modified timestamep for the UUID. Must be called
+ * from a synchronized block.
+ *
+ * @return long timestamp in 100ns intervals since the Gregorian change
+ * offset
+ */
+ private long getUUIDTime() {
+ if (_currentMillis != System.currentTimeMillis()) {
+ _currentMillis = System.currentTimeMillis();
+ _counter = 0; // reset counter
+ }
+ // check to see if we have created too many uuid's for this timestamp
+ if (_counter + 1 >= MILLI_MULT) {
+ // Original algorithm threw exception. Seemed like overkill.
+ // Let's just increment the timestamp instead and start over...
+ _currentMillis++;
+ _counter = 0;
+ }
+ // calculate time as current millis plus offset times 100 ns ticks
+ long currentTime = (_currentMillis + GREG_OFFSET) * MILLI_MULT;
+ // return the uuid time plus the artificial tick counter incremented
+ return currentTime + _counter++;
+ }
+ /**
+ * Increments the clock sequence for this uuid. Must be called from a
+ * synchronized block.
+ */
+ private void incrementSequence() {
+ // increment, but if it's greater than its 14-bits, reset it
+ if (++_seq > MAX_14BIT) {
+ _seq = (short) RANDOM.nextInt(MAX_14BIT); // semi-random
+ }
+ }
+
+ //Add Dependant classes internally
+
+ /**
+ * This class came from the Apache Commons Id sandbox project in support
+ * of the UUIDGenerator implementation.
+ *
+ * <p>Static methods for managing byte arrays (all methods follow Big
+ * Endian order where most significant bits are in front).</p>
+ */
+ public static final class Bytes {
+ /**
+ * <p>Hide constructor in utility class.</p>
+ */
+ private Bytes() {
+ }
+ /**
+ * Appends two bytes array into one.
+ *
+ * @param a A byte[].
+ * @param b A byte[].
+ * @return A byte[].
+ */
+ public static byte[] append(byte[] a, byte[] b) {
+ byte[] z = new byte[a.length + b.length];
+ System.arraycopy(a, 0, z, 0, a.length);
+ System.arraycopy(b, 0, z, a.length, b.length);
+ return z;
+ }
+ /**
+ * Returns a 8-byte array built from a long.
+ *
+ * @param n The number to convert.
+ * @return A byte[].
+ */
+ public static byte[] toBytes(long n) {
+ return toBytes(n, new byte[8]);
+ }
+ /**
+ * Build a 8-byte array from a long. No check is performed on the
+ * array length.
+ *
+ * @param n The number to convert.
+ * @param b The array to fill.
+ * @return A byte[].
+ */
+ public static byte[] toBytes(long n, byte[] b) {
+ b[7] = (byte) (n);
+ n >>>= 8;
+ b[6] = (byte) (n);
+ n >>>= 8;
+ b[5] = (byte) (n);
+ n >>>= 8;
+ b[4] = (byte) (n);
+ n >>>= 8;
+ b[3] = (byte) (n);
+ n >>>= 8;
+ b[2] = (byte) (n);
+ n >>>= 8;
+ b[1] = (byte) (n);
+ n >>>= 8;
+ b[0] = (byte) (n);
+
+ return b;
+ }
+ /**
+ * Build a long from first 8 bytes of the array.
+ *
+ * @param b The byte[] to convert.
+ * @return A long.
+ */
+ public static long toLong(byte[] b) {
+ return ((((long) b[7]) & 0xFF)
+ + ((((long) b[6]) & 0xFF) << 8)
+ + ((((long) b[5]) & 0xFF) << 16)
+ + ((((long) b[4]) & 0xFF) << 24)
+ + ((((long) b[3]) & 0xFF) << 32)
+ + ((((long) b[2]) & 0xFF) << 40)
+ + ((((long) b[1]) & 0xFF) << 48)
+ + ((((long) b[0]) & 0xFF) << 56));
+ }
+ /**
+ * Compares two byte arrays for equality.
+ *
+ * @param a A byte[].
+ * @param b A byte[].
+ * @return True if the arrays have identical contents.
+ */
+ public static boolean areEqual(byte[] a, byte[] b) {
+ int aLength = a.length;
+ if (aLength != b.length) {
+ return false;
+ }
+ for (int i = 0; i < aLength; i++) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ /**
+ * <p>Compares two byte arrays as specified by <code>Comparable</code>.
+ *
+ * @param lhs - left hand value in the comparison operation.
+ * @param rhs - right hand value in the comparison operation.
+ * @return a negative integer, zero, or a positive integer as
+ * <code>lhs</code> is less than, equal to, or greater than
+ * <code>rhs</code>.
+ */
+ public static int compareTo(byte[] lhs, byte[] rhs) {
+ if (lhs == rhs) {
+ return 0;
+ }
+ if (lhs == null) {
+ return -1;
+ }
+ if (rhs == null) {
+ return +1;
+ }
+ if (lhs.length != rhs.length) {
+ return ((lhs.length < rhs.length) ? -1 : +1);
+ }
+ for (int i = 0; i < lhs.length; i++) {
+ if (lhs[i] < rhs[i]) {
+ return -1;
+ } else if (lhs[i] > rhs[i]) {
+ return 1;
+ }
+ }
+ return 0;
+ }
+ /**
+ * Build a short from first 2 bytes of the array.
+ *
+ * @param b The byte[] to convert.
+ * @return A short.
+ */
+ public static short toShort(byte[] b) {
+ return (short) ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8));
+ }
+ }
+ /**
+ * Base 16 encoder.
+ *
+ * @author Marc Prud'hommeaux
+ */
+ public static final class Base16Encoder {
+
+ private final static char[] HEX = new char[]{
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+ /**
+ * Convert bytes to a base16 string.
+ */
+ public static String encode(byte[] byteArray) {
+ StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
+ for (int i = 0; i < byteArray.length; i++)
+ for (int j = 1; j >= 0; j--)
+ hexBuffer.append(HEX[(byteArray[i] >> (j * 4)) & 0xF]);
+ return hexBuffer.toString();
+ }
+ /**
+ * Convert a base16 string into a byte array.
+ */
+ public static byte[] decode(String s) {
+ int len = s.length();
+ byte[] r = new byte[len / 2];
+ for (int i = 0; i < r.length; i++) {
+ int digit1 = s.charAt(i * 2), digit2 = s.charAt(i * 2 + 1);
+ if (digit1 >= '0' && digit1 <= '9')
+ digit1 -= '0';
+ else if (digit1 >= 'A' && digit1 <= 'F')
+ digit1 -= 'A' - 10;
+ if (digit2 >= '0' && digit2 <= '9')
+ digit2 -= '0';
+ else if (digit2 >= 'A' && digit2 <= 'F')
+ digit2 -= 'A' - 10;
+
+ r[i] = (byte) ((digit1 << 4) + digit2);
+ }
+ return r;
+ }
+ }
+
+
+
+}
+
+//========================================= APACHE BLOCK =========================================
+
diff --git a/src/Java/gtPlusPlus/api/objects/XSTR.java b/src/Java/gtPlusPlus/api/objects/random/XSTR.java
index 3ff0792f6e..7f83df52c4 100644
--- a/src/Java/gtPlusPlus/api/objects/XSTR.java
+++ b/src/Java/gtPlusPlus/api/objects/random/XSTR.java
@@ -1,4 +1,4 @@
-package gtPlusPlus.api.objects;
+package gtPlusPlus.api.objects.random;
/**
* A subclass of java.util.random that implements the Xorshift random number
* generator
diff --git a/src/Java/gtPlusPlus/api/plugin/Sample_Plugin.java b/src/Java/gtPlusPlus/api/plugin/Sample_Plugin.java
new file mode 100644
index 0000000000..d2959df58d
--- /dev/null
+++ b/src/Java/gtPlusPlus/api/plugin/Sample_Plugin.java
@@ -0,0 +1,32 @@
+package gtPlusPlus.api.plugin;
+
+import gtPlusPlus.api.interfaces.IPlugin;
+import gtPlusPlus.plugin.manager.Core_Manager;
+
+public final class Sample_Plugin implements IPlugin {
+
+ public Sample_Plugin() {
+ Core_Manager.registerPlugin(this); //This must be called, else it won't load.
+ }
+
+ @Override
+ public boolean preInit() {
+ return true;
+ }
+
+ @Override
+ public boolean init() {
+ return true;
+ }
+
+ @Override
+ public boolean postInit() {
+ return true;
+ }
+
+ @Override
+ public String getPluginName() {
+ return "Sample Plugin";
+ }
+
+}