From 1febaef9d798cce07687ed3a7723e5b9619e9ede Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 15 Jul 2019 08:12:28 +0200 Subject: Pollution! --- .../tectech/chunkData/ChunkDataHandler.java | 63 +++++---- .../tectech/chunkData/IChunkMetaDataHandler.java | 3 - .../tectech/loader/thing/MachineLoader.java | 1 + .../tectech/mechanics/anomaly/AnomalyHandler.java | 69 ++++----- .../technus/tectech/thing/CustomItemList.java | 2 +- .../GT_MetaTileEntity_Hatch_OverflowElemental.java | 8 +- .../base/GT_MetaTileEntity_MultiblockBase_EM.java | 4 +- .../pipe/GT_MetaTileEntity_Pipe_Data.java | 2 +- .../single/GT_MetaTileEntity_DebugPollutor.java | 156 +++++++++++++++++++++ .../single/gui/GT_Container_DebugPollutor.java | 145 +++++++++++++++++++ .../single/gui/GT_GUIContainer_DebugPollutor.java | 31 ++++ 11 files changed, 409 insertions(+), 75 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java create mode 100644 src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DebugPollutor.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java index f7b3895a80..c924099375 100644 --- a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java +++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java @@ -130,38 +130,39 @@ public class ChunkDataHandler { 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 work; - if(epoch==0){ - int per=data.dirtyBoys.size()/cycle; - int mod=data.dirtyBoys.size()%cycle; - Iterator 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 { + ChunkHashMap data = dimensionWiseMetaChunkData + .get(chunkMetaDataHandler.getTagName()).get(dim); + int cycle = chunkMetaDataHandler.pushPayloadSpreadPeriod(); + int epoch = (int) (aEvent.world.getTotalWorldTime() % cycle); + ArrayList work; + if (epoch == 0) { + int per = data.dirtyBoys.size() / cycle; + int mod = data.dirtyBoys.size() % cycle; + Iterator 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(); } - data.dirtyBoys.clear(); - } - work=data.workLoad.get(epoch); - chunkMetaDataHandler.pushPayload(dim,work); - work.clear(); - }); - worldHandlers.forEach(chunkMetaDataHandler -> - chunkMetaDataHandler.tickWorld( - dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + work = data.workLoad.get(epoch); + chunkMetaDataHandler.pushPayload(dim, work); + work.clear(); + }); + worldHandlers.forEach(chunkMetaDataHandler -> + chunkMetaDataHandler.tickWorld( + dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent)); + } } @SubscribeEvent @@ -196,7 +197,7 @@ public class ChunkDataHandler { clientSyncHandlers.add(handler); } } catch (NoSuchMethodException e) { - throw new RuntimeException("Cannot register common event handlers!"); + throw new RuntimeException("Cannot register common event handlers!",e); } if(FMLCommonHandler.instance().getEffectiveSide().isServer()) { try { @@ -204,7 +205,7 @@ public class ChunkDataHandler { worldHandlers.add(handler); } } catch (NoSuchMethodException e) { - throw new RuntimeException("Cannot register client event handlers!"); + throw new RuntimeException("Cannot register server event handlers!",e); } } if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { @@ -216,7 +217,7 @@ public class ChunkDataHandler { renderHandlers.add(handler); } } catch (NoSuchMethodException e) { - throw new RuntimeException("Cannot register client event handlers!"); + throw new RuntimeException("Cannot register client event handlers!",e); } } } diff --git a/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java index b904f09f33..920d09c26a 100644 --- a/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java +++ b/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java @@ -16,9 +16,7 @@ public interface IChunkMetaDataHandler { NBTTagCompound createData(); @SideOnly(Side.CLIENT) default void requestData(ChunkEvent.Load aEvent){} - @SideOnly(Side.SERVER) default void pushData(int world, ChunkCoordIntPair chunk){} - @SideOnly(Side.SERVER) default void pushPayload(int world, ArrayList chunk){ chunk.forEach(chunkCoordIntPair -> pushData(world,chunkCoordIntPair)); } @@ -30,7 +28,6 @@ public interface IChunkMetaDataHandler { @SideOnly(Side.CLIENT) default void tickClient(HashMap data, TickEvent.ClientTickEvent aEvent){} default void tickServer(HashMap data, TickEvent.ServerTickEvent event){} - @SideOnly(Side.SERVER) default void tickWorld(HashMap data, TickEvent.WorldTickEvent aEvent){} default void tickPlayer(HashMap data, TickEvent.PlayerTickEvent aEvent){} } diff --git a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java index e734a4f8a3..e9fe5cfb19 100644 --- a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java @@ -595,6 +595,7 @@ public class MachineLoader implements Runnable { // =================================================================================================== // Debug Stuff // =================================================================================================== + Machine_DebugPollutor.set(new GT_MetaTileEntity_DebugPollutor(15495,"debug.tt.pollutor","Debug Pollution Generator",15).getStackForm(1)); hatch_CreativeData.set(new GT_MetaTileEntity_Hatch_CreativeData(15496,"debug.tt.data","Debug Data Hatch",15).getStackForm(1)); hatch_CreativeMaitenance.set(new GT_MetaTileEntity_Hatch_CreativeMaintenance(15497, "debug.tt.maintenance", "Debug Maintenance Hatch", 15).getStackForm(1L)); Machine_DebugGenny.set(new GT_MetaTileEntity_DebugPowerGenerator(15498, "debug.tt.genny", "Debug Power Generator", 15).getStackForm(1L)); diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index f45d3a5df5..c52ffc185f 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -20,7 +20,7 @@ import java.util.HashMap; public class AnomalyHandler implements IChunkMetaDataHandler { private static final double SWAP_THRESHOLD = dAtomDefinition.getSomethingHeavy().getMass() * 10000D; - private static final double PER_PARTICLE=SWAP_THRESHOLD/64; + private static final double PER_PARTICLE=SWAP_THRESHOLD/32; private static final String INTENSITY = "intensity"; private static final int MEAN_DELAY =50; @@ -42,27 +42,27 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickWorld(HashMap data, TickEvent.WorldTickEvent aEvent) { - if(TecTech.RANDOM.nextInt(MEAN_DELAY)==0) { - int dim=aEvent.world.provider.dimensionId; - ArrayList worldDataArrayList =new ArrayList<>(1024); - data.get(dim).forEach((chunkCoordIntPair, compound) -> { - if (compound.getDouble(INTENSITY) >= SWAP_THRESHOLD) { - Chunk chunk=aEvent.world.getChunkFromChunkCoords(chunkCoordIntPair.chunkXPos,chunkCoordIntPair.chunkZPos); - if(chunk.isChunkLoaded){ - worldDataArrayList.add(chunk); - } + if (TecTech.RANDOM.nextInt(MEAN_DELAY) == 0) { + int dim = aEvent.world.provider.dimensionId; + ArrayList worldDataArrayList = new ArrayList<>(1024); + data.get(dim).forEach((chunkCoordIntPair, compound) -> { + if (compound.getDouble(INTENSITY) >= SWAP_THRESHOLD) { + Chunk chunk = aEvent.world.getChunkFromChunkCoords(chunkCoordIntPair.chunkXPos, chunkCoordIntPair.chunkZPos); + if (chunk.isChunkLoaded) { + worldDataArrayList.add(chunk); } - }); - if(worldDataArrayList.size()>=2) { - Chunk a = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); - Chunk b = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); - data.get(dim).get(a.getChunkCoordIntPair()).setDouble(INTENSITY,SWAP_THRESHOLD*TecTech.RANDOM.nextFloat()*0.25F); - data.get(dim).get(b.getChunkCoordIntPair()).setDouble(INTENSITY,SWAP_THRESHOLD*TecTech.RANDOM.nextFloat()*0.25F); - data.get(dim).markForTransmissionToClient(a.getChunkCoordIntPair()); - data.get(dim).markForTransmissionToClient(b.getChunkCoordIntPair()); - swapSomething(a,b); } + }); + if (worldDataArrayList.size() >= 2) { + Chunk a = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); + Chunk b = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); + data.get(dim).get(a.getChunkCoordIntPair()).setDouble(INTENSITY, SWAP_THRESHOLD * TecTech.RANDOM.nextFloat() * 0.25F); + data.get(dim).get(b.getChunkCoordIntPair()).setDouble(INTENSITY, SWAP_THRESHOLD * TecTech.RANDOM.nextFloat() * 0.25F); + data.get(dim).markForTransmissionToClient(a.getChunkCoordIntPair()); + data.get(dim).markForTransmissionToClient(b.getChunkCoordIntPair()); + swapSomething(a, b); } + } } private void swapSomething(Chunk a,Chunk b){ @@ -97,27 +97,29 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickPlayer(HashMap data, TickEvent.PlayerTickEvent aEvent) { - ChunkCoordIntPair pair=new ChunkCoordIntPair(aEvent.player.chunkCoordX,aEvent.player.chunkCoordZ); - NBTTagCompound compound=data.get(aEvent.player.worldObj.provider.dimensionId).get(pair); - if(compound!=null) { - double intensity = compound.getDouble(INTENSITY); - if (aEvent.side.isClient()) { - for (int i = 0; i < intensity / PER_PARTICLE; i++) { + if (aEvent.side.isClient()) { + ChunkCoordIntPair pair = new ChunkCoordIntPair(aEvent.player.chunkCoordX, aEvent.player.chunkCoordZ); + NBTTagCompound compound = data.get(aEvent.player.worldObj.provider.dimensionId).get(pair); + if (compound != null) { + for (int i = 0, pow = (int)Math.min(32,compound.getDouble(INTENSITY) / PER_PARTICLE); i < pow; i++) { TecTech.proxy.em_particle(aEvent.player.worldObj, aEvent.player.posX - 32D + TecTech.RANDOM.nextFloat() * 64D, aEvent.player.posY - 32D + TecTech.RANDOM.nextFloat() * 64D, aEvent.player.posZ - 32D + TecTech.RANDOM.nextFloat() * 64D); } } + + data.get(aEvent.player.worldObj.provider.dimensionId).forEach((chunkCoordIntPair, dat) -> { + if (Math.abs(chunkCoordIntPair.getCenterXPos() - aEvent.player.posX) + Math.abs(chunkCoordIntPair.getCenterZPosition() - aEvent.player.posZ) < 256) { + for (int i = 0, pow = (int)Math.min(32,dat.getDouble(INTENSITY) / PER_PARTICLE); i < pow; i++) { + TecTech.proxy.em_particle(aEvent.player.worldObj, + (chunkCoordIntPair.chunkXPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D, + aEvent.player.posY + TecTech.RANDOM.nextFloat() * 128D - 64D, + (chunkCoordIntPair.chunkZPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D); + } + } + }); } - data.get(aEvent.player.worldObj.provider.dimensionId).forEach((chunkCoordIntPair, dat) -> { - for (int i = 0,pow=(int)(dat.getDouble(INTENSITY)/PER_PARTICLE); i < pow; i++) { - TecTech.proxy.em_particle(aEvent.player.worldObj, - (chunkCoordIntPair.chunkXPos<<4)+TecTech.RANDOM.nextFloat() * 48D-16D, - aEvent.player.posY+TecTech.RANDOM.nextFloat() * 128D-64D, - (chunkCoordIntPair.chunkZPos<<4)+TecTech.RANDOM.nextFloat() * 48D-16D); - } - }); } @Override @@ -147,6 +149,7 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } public void addAnomaly(int world, ChunkCoordIntPair chunk, double amount) { + amount=Math.abs(amount); NBTTagCompound old = TecTech.chunkDataHandler.getChunkData(this, world, chunk); if (old == null) { NBTTagCompound data = new NBTTagCompound(); diff --git a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java index 14f1bd1296..cd3d1cccd8 100644 --- a/src/main/java/com/github/technus/tectech/thing/CustomItemList.java +++ b/src/main/java/com/github/technus/tectech/thing/CustomItemList.java @@ -28,7 +28,7 @@ public enum CustomItemList implements IItemContainer { Machine_BuckConverter_IV,Machine_BuckConverter_LuV,Machine_BuckConverter_ZPM, Machine_BuckConverter_UV,Machine_BuckConverter_UHV,Machine_BuckConverter_UEV, Machine_BuckConverter_UIV,Machine_BuckConverter_UMV, Machine_BuckConverter_UXV, - Machine_DebugWriter,Machine_DebugGenny,UnusedStuff, + Machine_DebugWriter,Machine_DebugGenny,UnusedStuff, Machine_DebugPollutor, EMpipe, DATApipe, LASERpipe, rack_Hatch, holder_Hatch, capacitor_Hatch, eM_dynamomulti4_IV, eM_dynamomulti16_IV, eM_dynamomulti64_IV, diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java index e3dc732c99..18eb8b8c72 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/hatch/GT_MetaTileEntity_Hatch_OverflowElemental.java @@ -38,8 +38,8 @@ import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Mult public class GT_MetaTileEntity_Hatch_OverflowElemental extends GT_MetaTileEntity_Hatch { private static Textures.BlockIcons.CustomIcon EM_T_SIDES; private static Textures.BlockIcons.CustomIcon EM_T_ACTIVE; - private static Textures.BlockIcons.CustomIcon MufflerEM; - private static Textures.BlockIcons.CustomIcon MufflerEMidle; + public static Textures.BlockIcons.CustomIcon MufflerEM; + public static Textures.BlockIcons.CustomIcon MufflerEMidle; private float overflowMatter; public final float overflowMax; private final float overflowDisperse; @@ -159,8 +159,8 @@ public class GT_MetaTileEntity_Hatch_OverflowElemental extends GT_MetaTileEntity aBaseMetaTileEntity.getWorld().updateLightByType(EnumSkyBlock.Block, aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getZCoord()); } } - } else if (aBaseMetaTileEntity.isClientSide() && getBaseMetaTileEntity().isActive()) { - TecTech.proxy.em_particle(getBaseMetaTileEntity(), getBaseMetaTileEntity().getFrontFacing()); + } else if (aBaseMetaTileEntity.isClientSide() && aBaseMetaTileEntity.isActive()) { + TecTech.proxy.em_particle(aBaseMetaTileEntity, aBaseMetaTileEntity.getFrontFacing()); } super.onPostTick(aBaseMetaTileEntity, aTick); //DOES NOT CHECK FOR TOO MUCH, it is done only while putting stuff in (OPTIMIZATION!!!) diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java index 2ba49d0849..90e69c4fb7 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/base/GT_MetaTileEntity_MultiblockBase_EM.java @@ -1307,8 +1307,8 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt eOutputData.clear(); eInputData.clear(); - if (getBaseMetaTileEntity() instanceof BaseTileEntity) { - ((BaseTileEntity) getBaseMetaTileEntity()).ignoreUnloadedChunks = mMachine; + if (aBaseMetaTileEntity instanceof BaseTileEntity) { + ((BaseTileEntity) aBaseMetaTileEntity).ignoreUnloadedChunks = mMachine; } mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/GT_MetaTileEntity_Pipe_Data.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/GT_MetaTileEntity_Pipe_Data.java index 4badeb2d7c..3331430cb9 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/GT_MetaTileEntity_Pipe_Data.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/pipe/GT_MetaTileEntity_Pipe_Data.java @@ -108,7 +108,7 @@ public class GT_MetaTileEntity_Pipe_Data extends MetaPipeEntity implements IConn @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { - if(getBaseMetaTileEntity().isClientSide()){ + if(aBaseMetaTileEntity.isClientSide()){ NetworkDispatcher.INSTANCE.sendToServer(new PipeActivityMessage.PipeActivityQuery(this)); } onPostTick(aBaseMetaTileEntity, 31); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java new file mode 100644 index 0000000000..d3b6b3aff8 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java @@ -0,0 +1,156 @@ +package com.github.technus.tectech.thing.metaTileEntity.single; + +import com.github.technus.tectech.CommonValues; +import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; +import com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_OverflowElemental; +import com.github.technus.tectech.thing.metaTileEntity.single.gui.GT_Container_DebugPollutor; +import com.github.technus.tectech.thing.metaTileEntity.single.gui.GT_GUIContainer_DebugPollutor; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.common.GT_Pollution; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; + +import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; + +/** + * Created by Tec on 23.03.2017. + */ +public class GT_MetaTileEntity_DebugPollutor extends GT_MetaTileEntity_TieredMachineBlock { + private static GT_RenderedTexture POLLUTOR; + public int pollution=0; + public float anomaly=0; + + public GT_MetaTileEntity_DebugPollutor(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 0, "Shit genny broke!"); + Util.setTier(aTier,this); + } + + public GT_MetaTileEntity_DebugPollutor(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 0, aDescription, aTextures); + Util.setTier(aTier,this); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_DebugPollutor(mName, mTier, mDescription, mTextures); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister aBlockIconRegister) { + super.registerIcons(aBlockIconRegister); + POLLUTOR = new GT_RenderedTexture(new Textures.BlockIcons.CustomIcon("iconsets/POLLUTOR")); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return new ITexture[]{MACHINE_CASINGS[mTier][aColorIndex + 1], aSide != aFacing ? aActive? new GT_RenderedTexture(GT_MetaTileEntity_Hatch_OverflowElemental.MufflerEM): new GT_RenderedTexture(GT_MetaTileEntity_Hatch_OverflowElemental.MufflerEMidle) : POLLUTOR}; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + return null; + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_Container_DebugPollutor(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_DebugPollutor(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { + return false; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("ePollution",pollution); + aNBT.setFloat("eAnomaly",anomaly); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + pollution=aNBT.getInteger("ePollution"); + anomaly=aNBT.getFloat("eAnomaly"); + getBaseMetaTileEntity().setActive(anomaly>0||pollution>0); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + aBaseMetaTileEntity.setActive(anomaly>0||pollution>0); + if (anomaly > 0) { + TecTech.anomalyHandler.addAnomaly(aBaseMetaTileEntity,anomaly); + } + if (pollution > 0) { + GT_Pollution.addPollution(aBaseMetaTileEntity, pollution); + } + } else if (aBaseMetaTileEntity.isClientSide() && aBaseMetaTileEntity.isActive()) { + for(byte i=0;i<6;i++){ + if(i!=aBaseMetaTileEntity.getFrontFacing()){ + TecTech.proxy.em_particle(aBaseMetaTileEntity, i); + } + } + } + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public String[] getDescription() { + return new String[]{ + CommonValues.TEC_MARK_GENERAL, mDescription, + EnumChatFormatting.BLUE + "Infinite Producer/Consumer", + EnumChatFormatting.BLUE + "Since i wanted one..." + }; + } + + @Override + public boolean isElectric() { + return false; + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java new file mode 100644 index 0000000000..8db50abd96 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java @@ -0,0 +1,145 @@ +package com.github.technus.tectech.thing.metaTileEntity.single.gui; + +import com.github.technus.tectech.Util; +import com.github.technus.tectech.thing.metaTileEntity.single.GT_MetaTileEntity_DebugPollutor; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.gui.GT_ContainerMetaTile_Machine; +import gregtech.api.gui.GT_Slot_Holo; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class GT_Container_DebugPollutor + extends GT_ContainerMetaTile_Machine { + public int pollution =0; + public float anomaly =0; + + public GT_Container_DebugPollutor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(aInventoryPlayer, aTileEntity); + } + + @Override + public void addSlots(InventoryPlayer aInventoryPlayer) { + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 5, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 23, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 41, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 59, false, false, 1)); + + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 5, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 23, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 41, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 59, false, false, 1)); + + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 5, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 23, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 41, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 59, false, false, 1)); + + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 5, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 23, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 41, false, false, 1)); + addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 59, false, false, 1)); + } + + @Override + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (aSlotIndex < 0) { + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + Slot tSlot = (Slot) inventorySlots.get(aSlotIndex); + if (tSlot != null && mTileEntity.getMetaTileEntity() != null) { + GT_MetaTileEntity_DebugPollutor dpg = (GT_MetaTileEntity_DebugPollutor) mTileEntity.getMetaTileEntity(); + switch (aSlotIndex) { + case 0: + dpg.pollution -= aShifthold == 1 ? 512 : 64; + break; + case 1: + dpg.pollution /= aShifthold == 1 ? 512 : 64; + break; + case 2: + dpg.anomaly -= aShifthold == 1 ? 512 : 64; + break; + case 3: + dpg.anomaly /= aShifthold == 1 ? 512 : 64; + break; + case 4: + dpg.pollution -= aShifthold == 1 ? 16 : 1; + break; + case 5: + dpg.pollution /= aShifthold == 1 ? 16 : 2; + break; + case 6: + dpg.anomaly -= aShifthold == 1 ? 16 : 1; + break; + case 7: + dpg.anomaly /= aShifthold == 1 ? 16 : 2; + break; + case 8: + dpg.pollution += aShifthold == 1 ? 512 : 64; + break; + case 9: + dpg.pollution *= aShifthold == 1 ? 512 : 64; + break; + case 10: + dpg.anomaly += aShifthold == 1 ? 512 : 64; + break; + case 11: + dpg.anomaly *= aShifthold == 1 ? 512 : 64; + break; + case 12: + dpg.pollution += aShifthold == 1 ? 16 : 1; + break; + case 13: + dpg.pollution *= aShifthold == 1 ? 16 : 2; + break; + case 14: + dpg.anomaly += aShifthold == 1 ? 16 : 1; + break; + case 15: + dpg.anomaly *= aShifthold == 1 ? 16 : 2; + break; + default: return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + return null; + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) { + return; + } + + GT_MetaTileEntity_DebugPollutor dpg = (GT_MetaTileEntity_DebugPollutor) mTileEntity.getMetaTileEntity(); + pollution =dpg.pollution; + anomaly =dpg.anomaly; + + for (Object crafter : crafters) { + ICrafting var1 = (ICrafting) crafter; + Util.sendInteger(pollution,this,var1,100); + Util.sendFloat(anomaly,this,var1,102); + } + } + + @Override + @SideOnly(Side.CLIENT) + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 100: + case 101: + pollution = Util.receiveInteger(pollution,100,par1,par2); + break; + case 102: + case 103: + anomaly = Util.receiveFloat(anomaly,102,par1,par2); + break; + } + } +} diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DebugPollutor.java new file mode 100644 index 0000000000..39c67f1b50 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_GUIContainer_DebugPollutor.java @@ -0,0 +1,31 @@ +package com.github.technus.tectech.thing.metaTileEntity.single.gui; + +import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.InventoryPlayer; + +import static gregtech.api.enums.GT_Values.RES_PATH_GUI; + +public class GT_GUIContainer_DebugPollutor extends GT_GUIContainerMetaTile_Machine { + public GT_GUIContainer_DebugPollutor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(new GT_Container_DebugPollutor(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "Teleporter.png"); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + fontRendererObj.drawString("Pollutor", 46, 8, 16448255); + if (mContainer != null) { + GT_Container_DebugPollutor dpg = (GT_Container_DebugPollutor) mContainer; + fontRendererObj.drawString("Pollution: " + dpg.pollution, 46, 24, 16448255); + fontRendererObj.drawString("Anomaly: " + dpg.anomaly, 46, 32, 16448255); + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + super.drawGuiContainerBackgroundLayer(par1, par2, par3); + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + } +} -- cgit From 2e6cad60a78241c08596ae5a722862dd08583f48 Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 15 Jul 2019 09:10:26 +0200 Subject: Tweaking numbers --- .../tectech/chunkData/ChunkDataHandler.java | 28 ++++++++++------------ .../tectech/chunkData/IChunkMetaDataHandler.java | 2 +- .../tectech/mechanics/anomaly/AnomalyHandler.java | 8 ++++--- .../single/GT_MetaTileEntity_DebugPollutor.java | 28 ++++++++++++++++++++++ .../single/gui/GT_Container_DebugPollutor.java | 7 +++++- 5 files changed, 53 insertions(+), 20 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java index c924099375..191011d959 100644 --- a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java +++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java @@ -18,7 +18,8 @@ public class ChunkDataHandler { private final HashMap> dimensionWiseChunkData=new HashMap<>(); private final HashMap> dimensionWiseMetaChunkData=new HashMap<>(); private final HashMap metaDataHandlerHashMap =new HashMap<>(); - private final ArrayList clientSyncHandlers =new ArrayList<>(); + private final ArrayList pushSyncHandlers =new ArrayList<>(); + private final ArrayList pullSyncHandlers =new ArrayList<>(); private final ArrayList serverHandlers=new ArrayList<>(); private final ArrayList worldHandlers=new ArrayList<>(); private final ArrayList playerHandlers=new ArrayList<>(); @@ -95,13 +96,13 @@ public class ChunkDataHandler { @SideOnly(Side.CLIENT) @SubscribeEvent public void onLoadChunk(ChunkEvent.Load aEvent){ - clientSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.requestData(aEvent)); + pullSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.pullData(aEvent)); } @SideOnly(Side.CLIENT) @SubscribeEvent public void onUnLoadChunk(ChunkEvent.Unload aEvent){ - clientSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData + pushSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData .get(chunkMetaDataHandler.getTagName()) .get(aEvent.world.provider.dimensionId) .remove(aEvent.getChunk().getChunkCoordIntPair())); @@ -134,7 +135,7 @@ public class ChunkDataHandler { public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) { if(aEvent.side.isServer()) { int dim = aEvent.world.provider.dimensionId; - clientSyncHandlers.forEach(chunkMetaDataHandler -> { + pushSyncHandlers.forEach(chunkMetaDataHandler -> { ChunkHashMap data = dimensionWiseMetaChunkData .get(chunkMetaDataHandler.getTagName()).get(dim); int cycle = chunkMetaDataHandler.pushPayloadSpreadPeriod(); @@ -193,23 +194,20 @@ public class ChunkDataHandler { 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); + if (clazz.getMethod("pushData", int.class, ChunkCoordIntPair.class).getDeclaringClass()!=IChunkMetaDataHandler.class) { + pushSyncHandlers.add(handler); + } + if(clazz.getMethod("tickWorld", HashMap.class, TickEvent.WorldTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){ + worldHandlers.add(handler); } } catch (NoSuchMethodException e) { throw new RuntimeException("Cannot register common event handlers!",e); } - 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 server event handlers!",e); - } - } if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { try { + if (clazz.getMethod("pullData", ChunkEvent.Load.class).getDeclaringClass() != IChunkMetaDataHandler.class) { + pullSyncHandlers.add(handler); + } if (clazz.getMethod("tickClient", HashMap.class, TickEvent.ClientTickEvent.class).getDeclaringClass() != IChunkMetaDataHandler.class) { clientHandlers.add(handler); } diff --git a/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java index 920d09c26a..b5c79a4628 100644 --- a/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java +++ b/src/main/java/com/github/technus/tectech/chunkData/IChunkMetaDataHandler.java @@ -15,7 +15,7 @@ public interface IChunkMetaDataHandler { void mergeData(NBTTagCompound target, NBTTagCompound loadedData); NBTTagCompound createData(); @SideOnly(Side.CLIENT) - default void requestData(ChunkEvent.Load aEvent){} + default void pullData(ChunkEvent.Load aEvent){} default void pushData(int world, ChunkCoordIntPair chunk){} default void pushPayload(int world, ArrayList chunk){ chunk.forEach(chunkCoordIntPair -> pushData(world,chunkCoordIntPair)); diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index c52ffc185f..3100fd38fe 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -56,8 +56,10 @@ public class AnomalyHandler implements IChunkMetaDataHandler { if (worldDataArrayList.size() >= 2) { Chunk a = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); Chunk b = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); - data.get(dim).get(a.getChunkCoordIntPair()).setDouble(INTENSITY, SWAP_THRESHOLD * TecTech.RANDOM.nextFloat() * 0.25F); - data.get(dim).get(b.getChunkCoordIntPair()).setDouble(INTENSITY, SWAP_THRESHOLD * TecTech.RANDOM.nextFloat() * 0.25F); + double avg=.5* (data.get(dim).get(a.getChunkCoordIntPair()).getDouble(INTENSITY)+ + data.get(dim).get(b.getChunkCoordIntPair()).getDouble(INTENSITY)); + data.get(dim).get(a.getChunkCoordIntPair()).setDouble(INTENSITY, Math.min(SWAP_THRESHOLD,avg * (TecTech.RANDOM.nextFloat()+.5F) * 0.5F)); + data.get(dim).get(b.getChunkCoordIntPair()).setDouble(INTENSITY, Math.min(SWAP_THRESHOLD,avg * (TecTech.RANDOM.nextFloat()+.5F) * 0.5F)); data.get(dim).markForTransmissionToClient(a.getChunkCoordIntPair()); data.get(dim).markForTransmissionToClient(b.getChunkCoordIntPair()); swapSomething(a, b); @@ -123,7 +125,7 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } @Override - public void requestData(ChunkEvent.Load aEvent) { + public void pullData(ChunkEvent.Load aEvent) { NetworkDispatcher.INSTANCE.sendToServer(new ChunkDataMessage.ChunkDataQuery(aEvent, this)); } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java index d3b6b3aff8..ab68393dee 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DebugPollutor.java @@ -21,6 +21,8 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; @@ -116,6 +118,7 @@ public class GT_MetaTileEntity_DebugPollutor extends GT_MetaTileEntity_TieredMac for(byte i=0;i<6;i++){ if(i!=aBaseMetaTileEntity.getFrontFacing()){ TecTech.proxy.em_particle(aBaseMetaTileEntity, i); + pollutionParticles(aBaseMetaTileEntity.getWorld(),"largesmoke",i); } } } @@ -153,4 +156,29 @@ public class GT_MetaTileEntity_DebugPollutor extends GT_MetaTileEntity_TieredMac public boolean isElectric() { return false; } + + @SideOnly(Side.CLIENT) + public void pollutionParticles(World aWorld, String name,byte face) { + IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity(); + ForgeDirection aDir = ForgeDirection.getOrientation(face); + float xPos = aDir.offsetX * 0.76F + aMuffler.getXCoord() + 0.25F; + float yPos = aDir.offsetY * 0.76F + aMuffler.getYCoord() + 0.25F; + float zPos = aDir.offsetZ * 0.76F + aMuffler.getZCoord() + 0.25F; + + float ySpd = aDir.offsetY * 0.1F + 0.2F + 0.1F * TecTech.RANDOM.nextFloat(); + float xSpd; + float zSpd; + + if (aDir.offsetY == -1) { + float temp = TecTech.RANDOM.nextFloat() * 2 * (float) Math.PI; + xSpd = (float) Math.sin(temp) * 0.1F; + zSpd = (float) Math.cos(temp) * 0.1F; + } else { + xSpd = aDir.offsetX * (0.1F + 0.2F * TecTech.RANDOM.nextFloat()); + zSpd = aDir.offsetZ * (0.1F + 0.2F * TecTech.RANDOM.nextFloat()); + } + aWorld.spawnParticle(name, xPos + TecTech.RANDOM.nextFloat() * 0.5F, yPos + TecTech.RANDOM.nextFloat() * 0.5F, zPos + TecTech.RANDOM.nextFloat() * 0.5F, xSpd, ySpd, zSpd); + aWorld.spawnParticle(name, xPos + TecTech.RANDOM.nextFloat() * 0.5F, yPos + TecTech.RANDOM.nextFloat() * 0.5F, zPos + TecTech.RANDOM.nextFloat() * 0.5F, xSpd, ySpd, zSpd); + aWorld.spawnParticle(name, xPos + TecTech.RANDOM.nextFloat() * 0.5F, yPos + TecTech.RANDOM.nextFloat() * 0.5F, zPos + TecTech.RANDOM.nextFloat() * 0.5F, xSpd, ySpd, zSpd); + } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java index 8db50abd96..3374d874d4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/gui/GT_Container_DebugPollutor.java @@ -104,6 +104,11 @@ public class GT_Container_DebugPollutor break; default: return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); } + if(dpg.anomaly==Float.POSITIVE_INFINITY){ + dpg.anomaly=Float.MAX_VALUE; + }else if (dpg.anomaly==Float.NEGATIVE_INFINITY){ + dpg.anomaly=-Float.MAX_VALUE; + } return null; } return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); @@ -119,7 +124,7 @@ public class GT_Container_DebugPollutor GT_MetaTileEntity_DebugPollutor dpg = (GT_MetaTileEntity_DebugPollutor) mTileEntity.getMetaTileEntity(); pollution =dpg.pollution; anomaly =dpg.anomaly; - + for (Object crafter : crafters) { ICrafting var1 = (ICrafting) crafter; Util.sendInteger(pollution,this,var1,100); -- cgit From 150f34aebae02b71ffc6eba115c3910c69f37885 Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 15 Jul 2019 09:39:39 +0200 Subject: Use properlist --- .../java/com/github/technus/tectech/chunkData/ChunkDataHandler.java | 2 +- .../com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java index 191011d959..108e762af0 100644 --- a/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java +++ b/src/main/java/com/github/technus/tectech/chunkData/ChunkDataHandler.java @@ -102,7 +102,7 @@ public class ChunkDataHandler { @SideOnly(Side.CLIENT) @SubscribeEvent public void onUnLoadChunk(ChunkEvent.Unload aEvent){ - pushSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData + pullSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData .get(chunkMetaDataHandler.getTagName()) .get(aEvent.world.provider.dimensionId) .remove(aEvent.getChunk().getChunkCoordIntPair())); diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index 3100fd38fe..df6bfa7801 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -92,11 +92,6 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } - @Override - public void tickServer(HashMap data, TickEvent.ServerTickEvent event) { - - } - @Override public void tickPlayer(HashMap data, TickEvent.PlayerTickEvent aEvent) { if (aEvent.side.isClient()) { -- cgit From cf618db325bceec9b90887ec2b37db800ea7704f Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 15 Jul 2019 09:54:07 +0200 Subject: Spawn particles only around ThePlayer not all --- .../tectech/mechanics/anomaly/AnomalyHandler.java | 65 ++++++++++++++++++---- 1 file changed, 55 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java index df6bfa7801..ce79c42003 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java @@ -6,17 +6,31 @@ import com.github.technus.tectech.chunkData.IChunkMetaDataHandler; import com.github.technus.tectech.loader.network.ChunkDataMessage; import com.github.technus.tectech.loader.network.NetworkDispatcher; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.atom.dAtomDefinition; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; +import crazypants.util.BaublesUtil; +import crazypants.util.GalacticraftUtil; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.event.entity.player.PlayerDropsEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.world.ChunkEvent; import java.util.ArrayList; import java.util.HashMap; +import java.util.ListIterator; public class AnomalyHandler implements IChunkMetaDataHandler { private static final double SWAP_THRESHOLD = dAtomDefinition.getSomethingHeavy().getMass() * 10000D; @@ -95,23 +109,24 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickPlayer(HashMap data, TickEvent.PlayerTickEvent aEvent) { if (aEvent.side.isClient()) { - ChunkCoordIntPair pair = new ChunkCoordIntPair(aEvent.player.chunkCoordX, aEvent.player.chunkCoordZ); - NBTTagCompound compound = data.get(aEvent.player.worldObj.provider.dimensionId).get(pair); + EntityClientPlayerMP player=Minecraft.getMinecraft().thePlayer; + ChunkCoordIntPair pair = new ChunkCoordIntPair(player.chunkCoordX, player.chunkCoordZ); + NBTTagCompound compound = data.get(player.worldObj.provider.dimensionId).get(pair); if (compound != null) { for (int i = 0, pow = (int)Math.min(32,compound.getDouble(INTENSITY) / PER_PARTICLE); i < pow; i++) { - TecTech.proxy.em_particle(aEvent.player.worldObj, - aEvent.player.posX - 32D + TecTech.RANDOM.nextFloat() * 64D, - aEvent.player.posY - 32D + TecTech.RANDOM.nextFloat() * 64D, - aEvent.player.posZ - 32D + TecTech.RANDOM.nextFloat() * 64D); + TecTech.proxy.em_particle(player.worldObj, + player.posX - 32D + TecTech.RANDOM.nextFloat() * 64D, + player.posY - 32D + TecTech.RANDOM.nextFloat() * 64D, + player.posZ - 32D + TecTech.RANDOM.nextFloat() * 64D); } } - data.get(aEvent.player.worldObj.provider.dimensionId).forEach((chunkCoordIntPair, dat) -> { - if (Math.abs(chunkCoordIntPair.getCenterXPos() - aEvent.player.posX) + Math.abs(chunkCoordIntPair.getCenterZPosition() - aEvent.player.posZ) < 256) { + data.get(player.worldObj.provider.dimensionId).forEach((chunkCoordIntPair, dat) -> { + if (Math.abs(chunkCoordIntPair.getCenterXPos() - player.posX) + Math.abs(chunkCoordIntPair.getCenterZPosition() - player.posZ) < 256) { for (int i = 0, pow = (int)Math.min(32,dat.getDouble(INTENSITY) / PER_PARTICLE); i < pow; i++) { - TecTech.proxy.em_particle(aEvent.player.worldObj, + TecTech.proxy.em_particle(player.worldObj, (chunkCoordIntPair.chunkXPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D, - aEvent.player.posY + TecTech.RANDOM.nextFloat() * 128D - 64D, + player.posY + TecTech.RANDOM.nextFloat() * 128D - 64D, (chunkCoordIntPair.chunkZPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D); } } @@ -119,6 +134,13 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } + @Override + public void tickServer(HashMap data, TickEvent.ServerTickEvent event) { + if(event.side.isServer()){ + + } + } + @Override public void pullData(ChunkEvent.Load aEvent) { NetworkDispatcher.INSTANCE.sendToServer(new ChunkDataMessage.ChunkDataQuery(aEvent, this)); @@ -157,4 +179,27 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } TecTech.chunkDataHandler.getChunkData(this, world).markForTransmissionToClient(chunk); } + + @SubscribeEvent + public void onPlayerClone(PlayerEvent.Clone evt) { + if (evt.wasDeath && !evt.isCanceled()) { + if (evt.original != null && evt.entityPlayer != null && !(evt.entityPlayer instanceof FakePlayer)) { + int i; + ItemStack item; + for (i = 0; i < evt.original.field_71071_by.field_70462_a.length; ++i) { + item = evt.original.field_71071_by.field_70462_a[i]; + if (this.isSoulBound(item) && this.addToPlayerInventory(evt.entityPlayer, item)) { + evt.original.field_71071_by.field_70462_a[i] = null; + } + } + + for (i = 0; i < evt.original.field_71071_by.field_70460_b.length; ++i) { + item = evt.original.field_71071_by.field_70460_b[i]; + if (this.isSoulBound(item) && this.addToPlayerInventory(evt.entityPlayer, item)) { + evt.original.field_71071_by.field_70460_b[i] = null; + } + } + } + } + } } -- cgit From 99462bdb945778faf1ddf41a59040cfe2c4840d7 Mon Sep 17 00:00:00 2001 From: Tec Date: Mon, 15 Jul 2019 11:19:30 +0200 Subject: Implement player data persistence --- .../java/com/github/technus/tectech/TecTech.java | 4 + src/main/java/com/github/technus/tectech/Util.java | 100 +++++++++++++++++++++ .../tectech/mechanics/PlayerPersistence.java | 42 +++++++++ .../tectech/mechanics/anomaly/AnomalyHandler.java | 45 +++------- 4 files changed, 156 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/github/technus/tectech/mechanics/PlayerPersistence.java (limited to 'src/main/java') diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index 9d3273f10e..76cdc56060 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -4,6 +4,7 @@ import com.github.technus.tectech.loader.MainLoader; 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.PlayerPersistence; import com.github.technus.tectech.mechanics.anomaly.AnomalyHandler; import com.github.technus.tectech.chunkData.ChunkDataHandler; import com.github.technus.tectech.mechanics.elementalMatter.core.commands.GiveEM; @@ -44,6 +45,7 @@ public class TecTech { public static ChunkDataHandler chunkDataHandler; public static AnomalyHandler anomalyHandler; + public static PlayerPersistence playerPersistence; /** * For Loader.isModLoaded checks during the runtime @@ -189,6 +191,8 @@ public class TecTech { MainLoader.postLoad(); chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler()); + + playerPersistence=new PlayerPersistence("tec"); } @Mod.EventHandler diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 53e9627187..6a8ab2d57e 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -3,6 +3,8 @@ 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.IHatchAdder; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -12,19 +14,27 @@ import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; +import net.minecraft.world.storage.IPlayerFileData; +import net.minecraft.world.storage.SaveHandler; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.lang.reflect.Field; import java.util.*; import java.util.regex.Matcher; @@ -1457,4 +1467,94 @@ public final class Util { int z=chunk.getCenterZPosition(); return world.checkChunksExist(x, 0, z, x, 0, z); } + + public static NBTTagCompound getPlayerData(EntityPlayer player,String extension) { + try { + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + if (player != null) { + IPlayerFileData playerNBTManagerObj = MinecraftServer.getServer().worldServerForDimension(0).getSaveHandler().getSaveHandler(); + SaveHandler sh = (SaveHandler)playerNBTManagerObj; + File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, new String[]{"playersDirectory", "field_75771_c"}); + String id1=player.getUniqueID().toString(); + NBTTagCompound tagCompound=read(new File(dir, id1 + "."+extension)); + if(tagCompound!=null){ + return tagCompound; + } + tagCompound=readBackup(new File(dir, id1 + "."+extension+"_bak")); + if(tagCompound!=null){ + return tagCompound; + } + String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes()).toString(); + tagCompound=read(new File(dir, id2 + "."+extension)); + if(tagCompound!=null){ + return tagCompound; + } + tagCompound=readBackup(new File(dir, id2 + "."+extension+"_bak")); + if(tagCompound!=null){ + return tagCompound; + } + } + } + } catch (Exception var9) { + TecTech.LOGGER.fatal("Error reading data for: "+player.getCommandSenderName()); + } + return new NBTTagCompound(); + } + + public static void savePlayerFile(EntityPlayer player,String extension, NBTTagCompound data) { + try { + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { + if (player != null) { + IPlayerFileData playerNBTManagerObj = MinecraftServer.getServer().worldServerForDimension(0).getSaveHandler().getSaveHandler(); + SaveHandler sh = (SaveHandler)playerNBTManagerObj; + File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, new String[]{"playersDirectory", "field_75771_c"}); + String id1=player.getUniqueID().toString(); + write(new File(dir, id1 + "."+extension),data); + write(new File(dir, id1 + "."+extension+"_bak"),data); + String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes()).toString(); + write(new File(dir, id2 + "."+extension),data); + write(new File(dir, id2 + "."+extension+"_bak"),data); + } + } + } catch (Exception var10) { + TecTech.LOGGER.fatal("Error saving data for: "+player.getCommandSenderName()); + } + } + + private static NBTTagCompound read(File file){ + if (file != null && file.exists()) { + try(FileInputStream fileInputStream= new FileInputStream(file)) { + return CompressedStreamTools.readCompressed(fileInputStream); + } catch (Exception var9) { + TecTech.LOGGER.error("Cannot read NBT File: "+file.getAbsolutePath()); +