aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/GT_Proxy.java
diff options
context:
space:
mode:
authorJohannes Gäßler <updrn@student.kit.edu>2017-06-15 12:28:14 +0200
committerJohannes Gäßler <updrn@student.kit.edu>2017-06-15 12:28:14 +0200
commit34474480f73ca5ab1c711d73bdb4bd809673e063 (patch)
tree794ef12002b88e2f01b5f6d76c9c1f9b62a48961 /src/main/java/gregtech/common/GT_Proxy.java
parentc3f2b2b49dc3911a377fd062908d4df78bd3e58d (diff)
parent08c75fd813a4b48ba7a6b58391767161791c96e7 (diff)
downloadGT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.tar.gz
GT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.tar.bz2
GT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.zip
Merge remote-tracking branch 'origin/unstable' into ChemistryUpdate
Conflicts: src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java src/main/java/gregtech/loaders/load/GT_FuelLoader.java src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java
Diffstat (limited to 'src/main/java/gregtech/common/GT_Proxy.java')
-rw-r--r--src/main/java/gregtech/common/GT_Proxy.java152
1 files changed, 115 insertions, 37 deletions
diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java
index c60a0bdb13..f0706e7d69 100644
--- a/src/main/java/gregtech/common/GT_Proxy.java
+++ b/src/main/java/gregtech/common/GT_Proxy.java
@@ -6,6 +6,8 @@ import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.ProgressManager;
import cpw.mods.fml.common.eventhandler.Event.Result;
+import cpw.mods.fml.common.eventhandler.EventBus;
+import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
@@ -22,6 +24,7 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.items.GT_MetaGenerated_Item;
import gregtech.api.items.GT_MetaGenerated_Tool;
+import gregtech.api.net.GT_Packet_Pollution;
import gregtech.api.objects.GT_Fluid;
import gregtech.api.objects.GT_FluidStack;
import gregtech.api.objects.GT_UO_DimensionList;
@@ -36,6 +39,7 @@ import gregtech.common.items.armor.gui.ContainerElectricArmor1;
import gregtech.common.items.armor.gui.GuiElectricArmor1;
import gregtech.common.items.armor.gui.GuiModularArmor;
import gregtech.common.items.armor.gui.InventoryArmor;
+import gregtech.common.tools.GT_Tool;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
@@ -44,6 +48,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -55,20 +60,24 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
+import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraft.world.gen.feature.WorldGenMinable;
+import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
+import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.terraingen.OreGenEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ChunkDataEvent;
+import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
@@ -193,11 +202,13 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
public boolean mEnableAllMaterials = false;
public boolean mEnableAllComponents = false;
public boolean mAddGTRecipesToIC2Machines = true;
+ public boolean mEnableCleanroom = true;
public boolean mLowGravProcessing = false;
public boolean mAprilFool = false;
public boolean mCropNeedBlock = true;
public boolean mReenableSimplifiedChemicalRecipes = false;
public boolean mAMHInteraction = true;
+ public boolean mForceFreeFace = false;
public GT_Proxy() {
GameRegistry.registerFuelHandler(this);
@@ -498,6 +509,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
break;
}
}
+ GT_LanguageManager.writePlaceholderStrings();
}
public static long tBits = GT_ModHandler.RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS | GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.ONLY_ADD_IF_RESULT_IS_NOT_NULL | GT_ModHandler.RecipeBits.NOT_REMOVABLE;
@@ -582,6 +594,9 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
}
}
} catch (Throwable e) {e.printStackTrace(GT_Log.err);}
+
+ dimensionWiseChunkData.clear();//!!! IMPORTANT for map switching...
+ dimensionWisePollution.clear();//!!! IMPORTANT for map switching...
}
public void onServerStarted() {
@@ -1247,8 +1262,8 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
}
}
}
- if(aEvent.world.provider.dimensionId==0)
- GT_Pollution.onWorldTick(aEvent.world, (int) (aEvent.world.getTotalWorldTime() % 1200));
+
+ GT_Pollution.onWorldTick(aEvent);
}
}
@@ -1260,7 +1275,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
aEvent.player.setGameType(GameType.ADVENTURE);
aEvent.player.capabilities.allowEdit = false;
if (this.mAxeWhenAdventure) {
- GT_Utility.sendChatToPlayer(aEvent.player, "It's dangerous to go alone! Take this.");
+ GT_Utility.sendChatToPlayer(aEvent.player, GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_097", "It's dangerous to go alone! Take this.", false));
aEvent.player.worldObj.spawnEntityInWorld(new EntityItem(aEvent.player.worldObj, aEvent.player.posX, aEvent.player.posY,
aEvent.player.posZ, GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(GT_MetaGenerated_Tool_01.AXE, 1, Materials.Flint, Materials.Wood, null)));
}
@@ -1313,6 +1328,11 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
aEvent.player.addExhaustion(Math.max(1.0F, tCount / 666.6F));
}
}
+ if (aEvent.player.ticksExisted % 10 == 0) {
+ int tPollution = 0;
+ tPollution = GT_Pollution.getPollution(new ChunkCoordIntPair(aEvent.player.chunkCoordX,aEvent.player.chunkCoordZ), aEvent.player.dimension);
+ if(aEvent.player instanceof EntityPlayerMP)GT_Values.NW.sendToPlayer(new GT_Packet_Pollution(tPollution), (EntityPlayerMP) aEvent.player);
+ }
}
}
@@ -1719,48 +1739,106 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
ProgressManager.pop(progressBar);
}
- public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<ChunkPosition, int[]>(5000);
+ public static final HashMap<Integer,HashMap<ChunkCoordIntPair,int []>> dimensionWiseChunkData = new HashMap<>(16);//stores chunk data that is loaded/saved
+ public static final HashMap<Integer,GT_Pollution> dimensionWisePollution = new HashMap<>(16);//stores GT_Polluttors objects
+ public static final byte GTOIL=3,GTOILFLUID=2,GTPOLLUTION=1,GTMETADATA=0,NOT_LOADED=0,LOADED=1;//consts
+ //@Deprecated
+ //public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<>(0);
+
+ private static final byte oilVer=(byte)20;//non zero plz
+
+ //TO get default's fast
+ public static int[] getDefaultChunkDataOnCreation(){
+ return new int[]{NOT_LOADED,0,-1,-1};
+ }
+ public static int[] getDefaultChunkDataOnLoad(){
+ return new int[]{LOADED,0,-1,-1};
+ }
@SubscribeEvent
- public void handleChunkSaveEvent(ChunkDataEvent.Save event)
- {
- ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,event.getChunk().worldObj.provider.dimensionId,event.getChunk().zPosition);
- if(chunkData.containsKey(tPos)){
- int[] tInts = chunkData.get(tPos);
- if(tInts.length>0){event.getData().setInteger("GTOIL", tInts[0]);}
- if(tInts.length>1){event.getData().setInteger("GTPOLLUTION", tInts[1]);}
- if(tInts.length>2){event.getData().setInteger("GTOILFLUID", tInts[2]);}
- }
+ public void handleChunkSaveEvent(ChunkDataEvent.Save event) {//ALWAYS SAVE FROM THE HASH MAP DATA
+ HashMap<ChunkCoordIntPair,int []> chunkData=dimensionWiseChunkData.get(event.world.provider.dimensionId);
+ if(chunkData==null) return;//no dim info stored
+
+ int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair());
+ if(tInts==null) return;//no chunk data stored
+ //assuming len of this array 4
+ if(tInts[3]>=0)event.getData().setInteger("GTOIL", tInts[GTOIL]);
+ else event.getData().removeTag("GTOIL");
+ if(tInts[2]>=0)event.getData().setInteger("GTOILFLUID", tInts[GTOILFLUID]);
+ else event.getData().removeTag("GTOILFLUID");
+ if(tInts[1]>0)event.getData().setInteger("GTPOLLUTION", tInts[GTPOLLUTION]);
+ else event.getData().removeTag("GTPOLLUTION");
+ event.getData().setByte("GTOILVER", oilVer);//version mark
}
@SubscribeEvent
- public void handleChunkLoadEvent(ChunkDataEvent.Load event)
- {
- int tOil = 0;
- int tOilFluid = 0;
- int tPollution = 0;
-
- ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,event.getChunk().worldObj.provider.dimensionId,event.getChunk().zPosition);
- int[] tData = new int[0];
- if(chunkData.containsKey(tPos)){
- tData = chunkData.get(tPos);
- chunkData.remove(tPos);
- if(tData.length>0)
- tOil = tData[0];
- if(tData.length>1)
- tPollution = tData[1];
- if(tData.length>2)
- tOilFluid = tData[2];
+ public void handleChunkLoadEvent(ChunkDataEvent.Load event) {
+ final int worldID=event.world.provider.dimensionId;
+ HashMap<ChunkCoordIntPair, int[]> chunkData = dimensionWiseChunkData.get(worldID);
+ if (chunkData == null){
+ chunkData=new HashMap<>(1024);
+ dimensionWiseChunkData.put(worldID, chunkData);
}
+ if (dimensionWisePollution.get(worldID) == null)
+ dimensionWisePollution.put(worldID, new GT_Pollution(event.world));
+
+ int[] tInts = chunkData.get(event.getChunk().getChunkCoordIntPair());
+ if (tInts == null) {
+ //NOT LOADED and NOT PROCESSED by pollution algorithms
+ //regular load
+ tInts = getDefaultChunkDataOnLoad();
+
+ if (event.getData().getByte("GTOILVER") == oilVer) {
+ if (event.getData().hasKey("GTOIL"))
+ tInts[GTOIL] = event.getData().getInteger("GTOIL");
+ if (event.getData().hasKey("GTOILFLUID"))
+ tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID");
+ }
- if(tOil==0&&event.getData().hasKey("GTOIL"))
- tOil = event.getData().getInteger("GTOIL");
- if(tPollution==0&&event.getData().hasKey("GTPOLLUTION"))
- tPollution = event.getData().getInteger("GTPOLLUTION");
- if(tOilFluid==0&&event.getData().hasKey("GTOILFLUID"))
- tOilFluid = event.getData().getInteger("GTOILFLUID");
+ tInts[GTPOLLUTION] = event.getData().getInteger("GTPOLLUTION");//Defaults to 0
- chunkData.put(tPos, new int[]{tOil,tPollution,tOilFluid});
+ //store in HASH MAP if has useful data
+ if (tInts[GTPOLLUTION] > 0 || tInts[GTOIL] >= 0 || tInts[GTOILFLUID] >= 0)
+ chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts);
+ } else if (tInts[GTMETADATA] == NOT_LOADED) {//was NOT loaded from chunk save game data
+ //NOT LOADED but generated
+ //append load
+ if (event.getData().getByte("GTOILVER") == oilVer) {
+ if (tInts[GTOIL] < 0 && event.getData().hasKey("GTOIL"))//if was not yet initialized
+ tInts[GTOIL] = event.getData().getInteger("GTOIL");
+
+ if (tInts[GTOILFLUID] < 0 && event.getData().hasKey("GTOILFLUID"))//if was not yet initialized
+ tInts[GTOILFLUID] = event.getData().getInteger("GTOILFLUID");
+ } else {
+ tInts[GTOIL] = -1;
+ tInts[GTOILFLUID] = -1;
+ }
+
+ tInts[GTPOLLUTION] += event.getData().getInteger("GTPOLLUTION");//Defaults to 0, add stored pollution to data
+ tInts[GTMETADATA] = LOADED;//mark as = loaded
+ //store in HASHMAP
+
+ chunkData.put(event.getChunk().getChunkCoordIntPair(), tInts);
+ }//else if(tInts[0]==1){
+ ////Already loaded chunk data
+ ////DO NOTHING - this chunk data was already loaded and stored in hash map
+ //}
+ }
+
+ @SubscribeEvent
+ public void onBlockBreakSpeedEvent(PlayerEvent.BreakSpeed aEvent)
+ {
+ if (aEvent.newSpeed > 0.0F)
+ {
+ if (aEvent.entityPlayer != null)
+ {
+ ItemStack aStack = aEvent.entityPlayer.getCurrentEquippedItem();
+ if ((aStack != null) && ((aStack.getItem() instanceof GT_MetaGenerated_Tool))) {
+ aEvent.newSpeed = ((GT_MetaGenerated_Tool)aStack.getItem()).onBlockBreakSpeedEvent(aEvent.newSpeed, aStack, aEvent.entityPlayer, aEvent.block, aEvent.x, aEvent.y, aEvent.z, (byte)aEvent.metadata, aEvent);
+ }
+ }
+ }
}
public static class OreDictEventContainer {