diff options
| author | Tec <daniel112092@gmail.com> | 2019-07-15 06:17:38 +0200 |
|---|---|---|
| committer | Tec <daniel112092@gmail.com> | 2019-07-15 06:17:38 +0200 |
| commit | e739e0df9802d2d139c1b3241746af80eef0f4b4 (patch) | |
| tree | cda2615fc57c8d41ff149d57fc304c4db31c4a87 /src/main/java | |
| parent | 41e8623f77b750efc531d7c545094991f6ade55a (diff) | |
| parent | c3388bf4fb0acad4ebdda64d178453edcc3cfeb8 (diff) | |
| download | GT5-Unofficial-e739e0df9802d2d139c1b3241746af80eef0f4b4.tar.gz GT5-Unofficial-e739e0df9802d2d139c1b3241746af80eef0f4b4.tar.bz2 GT5-Unofficial-e739e0df9802d2d139c1b3241746af80eef0f4b4.zip | |
Merge branch 'betterParametrizers' into BassAddons
# Conflicts:
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_microwave.java
# src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java
Diffstat (limited to 'src/main/java')
58 files changed, 1010 insertions, 565 deletions
diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index 5383b9cf62..9d3273f10e 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -5,21 +5,20 @@ import com.github.technus.tectech.loader.TecTechConfig; import com.github.technus.tectech.mechanics.ConvertFloat; import com.github.technus.tectech.mechanics.ConvertInteger; import com.github.technus.tectech.mechanics.anomaly.AnomalyHandler; -import com.github.technus.tectech.mechanics.chunkData.ChunkDataHandler; +import com.github.technus.tectech.chunkData.ChunkDataHandler; import com.github.technus.tectech.mechanics.elementalMatter.core.commands.GiveEM; import com.github.technus.tectech.mechanics.elementalMatter.core.commands.ListEM; import com.github.technus.tectech.proxy.CommonProxy; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.event.*; import eu.usrv.yamcore.auxiliary.IngameErrorLog; import eu.usrv.yamcore.auxiliary.LogHelper; import gregtech.GT_Mod; import gregtech.common.GT_Proxy; +import net.minecraftforge.common.MinecraftForge; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -80,6 +79,10 @@ public class TecTech { moduleAdminErrorLogs = new IngameErrorLog(); } + chunkDataHandler=new ChunkDataHandler(); + FMLCommonHandler.instance().bus().register(chunkDataHandler); + MinecraftForge.EVENT_BUS.register(chunkDataHandler); + MainLoader.preLoad(); } @@ -90,10 +93,10 @@ public class TecTech { if(configTecTech.DISABLE_MATERIAL_LOADING_FFS){ try { - Field field= GT_Proxy.class.getDeclaredField("mEvents"); - field.setAccessible(true); Field modifiersField = Field.class.getDeclaredField( "modifiers" ); modifiersField.setAccessible( true ); + Field field= GT_Proxy.class.getDeclaredField("mEvents"); + field.setAccessible(true); modifiersField.setInt( field, field.getModifiers() & ~Modifier.FINAL ); field.set(GT_Mod.gregtechproxy, new Collection() { @Override @@ -184,7 +187,7 @@ public class TecTech { @Mod.EventHandler public void PostLoad(FMLPostInitializationEvent PostEvent) { MainLoader.postLoad(); - chunkDataHandler=new ChunkDataHandler(); + chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler()); } @@ -199,7 +202,7 @@ public class TecTech { } @Mod.EventHandler - public void onServerStarting(FMLServerStartingEvent aEvent) { - chunkDataHandler.onServerStarting(); + public void onServerAboutToStart(FMLServerAboutToStartEvent aEvent) { + chunkDataHandler.clearData(); } } diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index e333e70137..53e9627187 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -2,7 +2,7 @@ package com.github.technus.tectech; import com.github.technus.tectech.thing.casing.TT_Container_Casings; import com.github.technus.tectech.thing.metaTileEntity.IFrontRotation; -import com.github.technus.tectech.thing.metaTileEntity.multi.base.HatchAdder; +import com.github.technus.tectech.thing.metaTileEntity.multi.base.IHatchAdder; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -20,6 +20,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.StringUtils; @@ -395,7 +396,7 @@ public final class Util { String[][] structure,//0-9 casing, +- air no air, A... ignore 'A'-CHAR-1 blocks Block[] blockType,//use numbers 0-9 for casing types byte[] blockMeta,//use numbers 0-9 for casing types - HatchAdder[] addingMethods, + IHatchAdder[] addingMethods, short[] casingTextures, Block[] blockTypeFallback,//use numbers 0-9 for casing types byte[] blockMetaFallback,//use numbers 0-9 for casing types @@ -1450,4 +1451,10 @@ public final class Util { } return Double.toString(value); } + + public static boolean checkChunkExist(World world, ChunkCoordIntPair chunk){ + int x=chunk.getCenterXPos(); + int z=chunk.getCenterZPosition(); + return world.checkChunksExist(x, 0, z, x, 0, z); + } } diff --git a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java new file mode 100644 index 0000000000..f7b3895a80 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java @@ -0,0 +1,364 @@ +package com.github.technus.tectech.chunkData; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraftforge.event.world.ChunkDataEvent; +import net.minecraftforge.event.world.ChunkEvent; +import net.minecraftforge.event.world.WorldEvent; + +import java.util.*; + +public class ChunkDataHandler { + private final String BASE_TAG_NAME ="TecTechData"; + private final HashMap<Integer,HashMap<ChunkCoordIntPair, NBTChunk>> dimensionWiseChunkData=new HashMap<>(); + private final HashMap<String,HashMap<Integer,ChunkHashMap >> dimensionWiseMetaChunkData=new HashMap<>(); + private final HashMap<String, IChunkMetaDataHandler> metaDataHandlerHashMap =new HashMap<>(); + private final ArrayList<IChunkMetaDataHandler> clientSyncHandlers =new ArrayList<>(); + private final ArrayList<IChunkMetaDataHandler> serverHandlers=new ArrayList<>(); + private final ArrayList<IChunkMetaDataHandler> worldHandlers=new ArrayList<>(); + private final ArrayList<IChunkMetaDataHandler> playerHandlers=new ArrayList<>(); + private final ArrayList<IChunkMetaDataHandler> clientHandlers=new ArrayList<>(); + private final ArrayList<IChunkMetaDataHandler> renderHandlers=new ArrayList<>(); + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event){ + int dim=event.world.provider.dimensionId; + dimensionWiseChunkData.computeIfAbsent(dim, m->{ + HashMap<ChunkCoordIntPair, NBTChunk> map = new HashMap<>(); + for (Map.Entry<String,IChunkMetaDataHandler> meta : metaDataHandlerHashMap.entrySet()) { + dimensionWiseMetaChunkData.get(meta.getKey()).put(dim, new ChunkHashMap(meta.getValue(), map)); + } + return map; + }); + } + + @SubscribeEvent + public void handleChunkSaveEvent(ChunkDataEvent.Save event) { + HashMap<ChunkCoordIntPair, NBTChunk> dimensionData = dimensionWiseChunkData.get(event.world.provider.dimensionId); + NBTChunk chunkData = dimensionData != null ? dimensionData.get(event.getChunk().getChunkCoordIntPair()) : null; + if (chunkData == null) { + event.getData().removeTag(BASE_TAG_NAME); + } else { + chunkData.isLoaded = true; + event.getData().setTag(BASE_TAG_NAME, chunkData.data); + } + } + + @SubscribeEvent + public void handleChunkLoadEvent(ChunkDataEvent.Load event) { + NBTTagCompound loadedTag = event.getData().getCompoundTag(BASE_TAG_NAME); + if (loadedTag.hasNoTags()) { + return; + } + int dimId = event.world.provider.dimensionId; + HashMap<ChunkCoordIntPair, NBTChunk> dimensionMemory = dimensionWiseChunkData.get(dimId); + ChunkCoordIntPair chunkCoordIntPair = event.getChunk().getChunkCoordIntPair(); + Set<String> loadedKeys = loadedTag.func_150296_c(); + NBTChunk chunkMemory = dimensionMemory.get(chunkCoordIntPair); + if (chunkMemory == null) { + chunkMemory = new NBTChunk(loadedTag, true); + dimensionMemory.put(chunkCoordIntPair, chunkMemory); + for (String s : loadedKeys) { + dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, loadedTag.getCompoundTag(s)); + } + } else if (!chunkMemory.isLoaded) { + chunkMemory.isLoaded = true; + + Set<String> tagsDuplicated = new HashSet(loadedKeys); + tagsDuplicated.retainAll(chunkMemory.data.func_150296_c()); + + if (tagsDuplicated.isEmpty()) { + for (String s : loadedKeys) { + NBTTagCompound tag = loadedTag.getCompoundTag(s); + chunkMemory.data.setTag(s, tag); + dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, tag); + } + } else { + for (String s : loadedKeys) { + NBTTagCompound memory = chunkMemory.data.getCompoundTag(s); + if (tagsDuplicated.contains(s)) { + metaDataHandlerHashMap.get(s).mergeData(memory, loadedTag.getCompoundTag(s)); + } else { + chunkMemory.data.setTag(s, loadedTag.getCompoundTag(s)); + dimensionWiseMetaChunkData.get(s).get(dimId).putLoaded(chunkCoordIntPair, memory); + } + } + } + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void onLoadChunk(ChunkEvent.Load aEvent){ + clientSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.requestData(aEvent)); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void onUnLoadChunk(ChunkEvent.Unload aEvent){ + clientSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData + .get(chunkMetaDataHandler.getTagName()) + .get(aEvent.world.provider.dimensionId) + .remove(aEvent.getChunk().getChunkCoordIntPair())); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void onClientTickEvent(TickEvent.ClientTickEvent aEvent) { + clientHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickClient( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void onRenderTickEvent(TickEvent.RenderTickEvent aEvent) { + renderHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickRender( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } + + @SubscribeEvent + public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) { + serverHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickServer( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } + + @SideOnly(Side.SERVER) + @SubscribeEvent + public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) { + int dim=aEvent.world.provider.dimensionId; + clientSyncHandlers.forEach(chunkMetaDataHandler -> { + ChunkHashMap data=dimensionWiseMetaChunkData + .get(chunkMetaDataHandler.getTagName()).get(dim); + int cycle=chunkMetaDataHandler.pushPayloadSpreadPeriod(); + int epoch=(int)(aEvent.world.getTotalWorldTime()%cycle); + ArrayList<ChunkCoordIntPair> work; + if(epoch==0){ + int per=data.dirtyBoys.size()/cycle; + int mod=data.dirtyBoys.size()%cycle; + Iterator<ChunkCoordIntPair> iter=data.dirtyBoys.iterator(); + for (int periodWork = 0; periodWork < cycle; periodWork++) { + work=data.workLoad.get(periodWork); + for (int i = 0; i < per; i++) { + work.add(iter.next()); + } + if(periodWork<mod){ + work.add(iter.next()); + } + } + data.dirtyBoys.clear(); + } + work=data.workLoad.get(epoch); + chunkMetaDataHandler.pushPayload(dim,work); + work.clear(); + }); + worldHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickWorld( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } + + @SubscribeEvent + public void onPlayerTickEvent(TickEvent.PlayerTickEvent aEvent) { + playerHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickPlayer( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } + + + public void clearData() { + dimensionWiseChunkData.clear(); + dimensionWiseMetaChunkData.forEach((k,v)->v.clear()); + } + + public IChunkMetaDataHandler getChunkMetaDataHandler(String s){ + return metaDataHandlerHashMap.get(s); + } + + public void registerChunkMetaDataHandler(IChunkMetaDataHandler handler){ + metaDataHandlerHashMap.put(handler.getTagName(),handler); + dimensionWiseMetaChunkData.put(handler.getTagName(),new HashMap<>()); + Class clazz=handler.getClass(); + try { + if(clazz.getMethod("tickServer", HashMap.class, TickEvent.ServerTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){ + serverHandlers.add(handler); + } + if(clazz.getMethod("tickPlayer", HashMap.class, TickEvent.PlayerTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){ + playerHandlers.add(handler); + } + if (clazz.getMethod("requestData", ChunkEvent.Load.class).getDeclaringClass() != IChunkMetaDataHandler.class) { + clientSyncHandlers.add(handler); + } + } catch (NoSuchMethodException e) { + throw new RuntimeException("Cannot register common event handlers!"); + } + if(FMLCommonHandler.instance().getEffectiveSide().isServer()) { + try { + if(clazz.getMethod("tickWorld", HashMap.class, TickEvent.WorldTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){ + worldHandlers.add(handler); + } + } catch (NoSuchMethodException e) { + throw new RuntimeException("Cannot register client event handlers!"); + } + } + if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { + try { + if (clazz.getMethod("tickClient", HashMap.class, TickEvent.ClientTickEvent.class).getDeclaringClass() != IChunkMetaDataHandler.class) { + clientHandlers.add(handler); + } + if (clazz.getMethod("tickRender", HashMap.class, TickEvent.RenderTickEvent.class).getDeclaringClass() != IChunkMetaDataHandler.class) { + renderHandlers.add(handler); + } + } catch (NoSuchMethodException e) { + throw new RuntimeException("Cannot register client event handlers!"); + } + } + } + + public NBTTagCompound removeChunkData(IChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){ + return dimensionWiseMetaChunkData.get(handler.getTagName()).get(world).remove(chunk); + } + + public NBTTagCompound getChunkData(IChunkMetaDataHandler handler, int world, ChunkCoordIntPair chunk){ |
