diff options
6 files changed, 275 insertions, 62 deletions
diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index 76cdc56060..49b989f794 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -81,6 +81,10 @@ public class TecTech { moduleAdminErrorLogs = new IngameErrorLog(); } + playerPersistence=new PlayerPersistence("tec"); + FMLCommonHandler.instance().bus().register(playerPersistence); + MinecraftForge.EVENT_BUS.register(playerPersistence); + chunkDataHandler=new ChunkDataHandler(); FMLCommonHandler.instance().bus().register(chunkDataHandler); MinecraftForge.EVENT_BUS.register(chunkDataHandler); @@ -192,7 +196,6 @@ public class TecTech { chunkDataHandler.registerChunkMetaDataHandler(anomalyHandler=new AnomalyHandler()); - playerPersistence=new PlayerPersistence("tec"); } @Mod.EventHandler @@ -208,5 +211,6 @@ public class TecTech { @Mod.EventHandler public void onServerAboutToStart(FMLServerAboutToStartEvent aEvent) { chunkDataHandler.clearData(); + playerPersistence.clearData(); } } diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 6a8ab2d57e..c98fefcd86 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -25,8 +25,10 @@ import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.storage.IPlayerFileData; import net.minecraft.world.storage.SaveHandler; import net.minecraftforge.fluids.FluidStack; @@ -42,6 +44,7 @@ import java.util.regex.Pattern; import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE; import static gregtech.api.enums.GT_Values.E; +import static java.nio.charset.Charset.forName; /** * Created by Tec on 21.03.2017. @@ -1468,14 +1471,14 @@ public final class Util { return world.checkChunksExist(x, 0, z, x, 0, z); } - public static NBTTagCompound getPlayerData(EntityPlayer player,String extension) { + public static NBTTagCompound getPlayerData(UUID uuid1,UUID uuid2,String extension) { try { if (FMLCommonHandler.instance().getEffectiveSide().isServer()) { - if (player != null) { + if (uuid1 != null && uuid2!=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(); + String id1=uuid1.toString(); NBTTagCompound tagCompound=read(new File(dir, id1 + "."+extension)); if(tagCompound!=null){ return tagCompound; @@ -1484,7 +1487,7 @@ public final class Util { if(tagCompound!=null){ return tagCompound; } - String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes()).toString(); + String id2=uuid2.toString(); tagCompound=read(new File(dir, id2 + "."+extension)); if(tagCompound!=null){ return tagCompound; @@ -1495,9 +1498,7 @@ public final class Util { } } } - } catch (Exception var9) { - TecTech.LOGGER.fatal("Error reading data for: "+player.getCommandSenderName()); - } + } catch (Exception ignored) {} return new NBTTagCompound(); } @@ -1511,14 +1512,12 @@ public final class Util { 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(); + String id2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8"))).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()); - } + } catch (Exception ignored) {} } private static NBTTagCompound read(File file){ @@ -1557,4 +1556,16 @@ public final class Util { } } } + + public static AxisAlignedBB fromChunkCoordIntPair(ChunkCoordIntPair chunkCoordIntPair){ + int x=chunkCoordIntPair.chunkXPos<<4; + int z=chunkCoordIntPair.chunkZPos<<4; + return AxisAlignedBB.getBoundingBox(x,-128,z,x+16,512,z+16); + } + + public static AxisAlignedBB fromChunk(Chunk chunk){ + int x=chunk.xPosition<<4; + int z=chunk.zPosition<<4; + return AxisAlignedBB.getBoundingBox(x,-128,z,x+16,512,z+16); + } } diff --git a/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java b/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java index 56455a13c4..e424edd385 100644 --- a/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java +++ b/src/main/java/com/github/technus/tectech/loader/network/NetworkDispatcher.java @@ -19,5 +19,7 @@ public class NetworkDispatcher extends eu.usrv.yamcore.network.PacketDispatcher registerMessage(RotationMessage.ClientHandler.class, RotationMessage.RotationData.class); registerMessage(ChunkDataMessage.ServerHandler.class, ChunkDataMessage.ChunkDataQuery.class); registerMessage(ChunkDataMessage.ClientHandler.class, ChunkDataMessage.ChunkDataData.class); + registerMessage(PlayerDataMessage.ServerHandler.class, PlayerDataMessage.PlayerDataQuery.class); + registerMessage(PlayerDataMessage.ClientHandler.class, PlayerDataMessage.PlayerDataData.class); } } diff --git a/src/main/java/com/github/technus/tectech/loader/network/PlayerDataMessage.java b/src/main/java/com/github/technus/tectech/loader/network/PlayerDataMessage.java new file mode 100644 index 0000000000..48a21423a9 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/loader/network/PlayerDataMessage.java @@ -0,0 +1,89 @@ +package com.github.technus.tectech.loader.network; + +import com.github.technus.tectech.TecTech; +import cpw.mods.fml.common.network.ByteBufUtils; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import eu.usrv.yamcore.network.client.AbstractClientMessageHandler; +import eu.usrv.yamcore.network.server.AbstractServerMessageHandler; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; + +import java.util.UUID; + +import static java.nio.charset.Charset.forName; + +public class PlayerDataMessage implements IMessage { + NBTTagCompound data; + UUID uuid1,uuid2; + + public PlayerDataMessage(){} + + @Override + public void fromBytes(ByteBuf pBuffer) { + NBTTagCompound tag = ByteBufUtils.readTag(pBuffer); + uuid1=UUID.fromString(tag.getString("id1")); + uuid2=UUID.fromString(tag.getString("id2")); + if(tag.hasKey("data")){ + data=tag.getCompoundTag("data"); + } + } + + @Override + public void toBytes(ByteBuf pBuffer) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("id1",uuid1.toString()); + tag.setString("id2",uuid2.toString()); + if(data!=null){ + tag.setTag("data",data); + } + ByteBufUtils.writeTag(pBuffer, tag); + } + + public static class PlayerDataQuery extends PlayerDataMessage { + public PlayerDataQuery() { + } + + public PlayerDataQuery(EntityPlayer player) { + uuid1=player.getUniqueID(); + uuid2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8"))); + } + } + + public static class PlayerDataData extends PlayerDataMessage { + public PlayerDataData() { + } + + public PlayerDataData(EntityPlayer player){ + uuid1=player.getUniqueID(); + uuid2=UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8"))); + data=TecTech.playerPersistence.getDataOrSetToNewTag(player); + } + + public PlayerDataData(PlayerDataQuery query){ + uuid1=query.uuid1; + uuid2=query.uuid2; + data= TecTech.playerPersistence.getDataOrSetToNewTag(uuid1,uuid2); + } + } + + public static class ClientHandler extends AbstractClientMessageHandler<PlayerDataData> { + @Override + public IMessage handleClientMessage(EntityPlayer pPlayer, PlayerDataData pMessage, MessageContext pCtx) { + TecTech.playerPersistence.putDataOrSetToNewTag(pMessage.uuid1,pMessage.uuid2,pMessage.data); + return null; + } + } + + public static class ServerHandler extends AbstractServerMessageHandler<PlayerDataQuery> { + @Override + public IMessage handleServerMessage(EntityPlayer pPlayer, PlayerDataQuery pMessage, MessageContext pCtx) { + if(pPlayer instanceof EntityPlayerMP){ + NetworkDispatcher.INSTANCE.sendTo(new PlayerDataData(pMessage),(EntityPlayerMP) pPlayer); + } + return null; + } + } +} diff --git a/src/main/java/com/github/technus/tectech/mechanics/PlayerPersistence.java b/src/main/java/com/github/technus/tectech/mechanics/PlayerPersistence.java index db57b1e563..72416c3e0c 100644 --- a/src/main/java/com/github/technus/tectech/mechanics/PlayerPersistence.java +++ b/src/main/java/com/github/technus/tectech/mechanics/PlayerPersistence.java @@ -1,12 +1,19 @@ package com.github.technus.tectech.mechanics; import com.github.technus.tectech.Util; +import com.github.technus.tectech.loader.network.NetworkDispatcher; +import com.github.technus.tectech.loader.network.PlayerDataMessage; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.PlayerEvent; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import java.util.HashMap; import java.util.UUID; +import static java.nio.charset.Charset.forName; + public class PlayerPersistence { private final HashMap<UUID, NBTTagCompound> map=new HashMap<>(); private final String extension; @@ -15,28 +22,52 @@ public class PlayerPersistence { this.extension = extension; } - public final NBTTagCompound getData(EntityPlayer player){ - NBTTagCompound tag=map.get(player.getUniqueID()); + public NBTTagCompound getDataOrSetToNewTag(UUID uuid1, UUID uuid2){ + NBTTagCompound tag=map.get(uuid1); if(tag!=null){ return tag; } - tag=map.get(UUID.fromString(player.getCommandSenderName())); + tag=map.get(uuid2); if(tag!=null){ return tag; } - tag=Util.getPlayerData(player,extension); - if(tag!=null){ - map.put(player.getUniqueID(),tag); - map.put(UUID.fromString(player.getCommandSenderName()),tag); + tag=Util.getPlayerData(uuid1,uuid2,extension); + if(tag==null){ + tag=new NBTTagCompound(); } + map.put(uuid1,tag); + map.put(uuid2,tag); return tag; } - public final void saveData(EntityPlayer player){ - NBTTagCompound tag=map.get(player.getUniqueID()); - if(tag==null){ - tag=map.get(UUID.fromString(player.getCommandSenderName())); + public NBTTagCompound getDataOrSetToNewTag(EntityPlayer player){ + return getDataOrSetToNewTag(player.getUniqueID(),UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8")))); + } + + public void putDataOrSetToNewTag(UUID uuid1, UUID uuid2, NBTTagCompound tagCompound){ + if(tagCompound==null){ + tagCompound=new NBTTagCompound(); } - Util.savePlayerFile(player,extension,tag); + map.put(uuid1,tagCompound); + map.put(uuid2,tagCompound); + } + + public void putDataOrSetToNewTag(EntityPlayer player, NBTTagCompound tagCompound){ + putDataOrSetToNewTag(player.getUniqueID(),UUID.nameUUIDFromBytes(player.getCommandSenderName().getBytes(forName("UTF-8"))),tagCompound); + } + + public void saveData(EntityPlayer player){ + Util.savePlayerFile(player,extension,getDataOrSetToNewTag(player)); + } + + @SubscribeEvent + public void onLogin(PlayerEvent.PlayerLoggedInEvent event){ + if(event.player instanceof EntityPlayerMP){ + NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(event.player),(EntityPlayerMP)event.player); + } + } + + public void clearData() { + map.clear(); } } 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 1692037d6b..3a932ec53b 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 @@ -1,17 +1,28 @@ package com.github.technus.tectech.mechanics.anomaly; import com.github.technus.tectech.TecTech; +import com.github.technus.tectech.Util; import com.github.technus.tectech.chunkData.ChunkDataHandler; import com.github.technus.tectech.chunkData.IChunkMetaDataHandler; +import com.github.technus.tectech.loader.MainLoader; import com.github.technus.tectech.loader.network.ChunkDataMessage; import com.github.technus.tectech.loader.network.NetworkDispatcher; +import com.github.technus.tectech.loader.network.PlayerDataMessage; import com.github.technus.tectech.mechanics.elementalMatter.definitions.complex.atom.dAtomDefinition; import cpw.mods.fml.common.gameevent.TickEvent; +import gregtech.api.GregTech_API; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.Vec3; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -19,11 +30,13 @@ import net.minecraftforge.event.world.ChunkEvent; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; public class AnomalyHandler implements IChunkMetaDataHandler { private static final double SWAP_THRESHOLD = dAtomDefinition.getSomethingHeavy().getMass() * 10000D; - private static final double PER_PARTICLE=SWAP_THRESHOLD/32; - private static final String INTENSITY = "intensity"; + private static final int COUNT_DIV=32; + private static final double PER_PARTICLE=SWAP_THRESHOLD/COUNT_DIV; + private static final String INTENSITY = "intensity",SPACE_CANCER="space_cancer"; private static final int MEAN_DELAY =50; @Override @@ -64,44 +77,84 @@ public class AnomalyHandler implements IChunkMetaDataHandler { 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); + swapSomething(a, b,avg); } } } - private void swapSomething(Chunk a,Chunk b){ - for(int i=0;i<128;i++){ - int x=TecTech.RANDOM.nextInt(16); - int y=TecTech.RANDOM.nextInt(a.worldObj.getActualHeight()); - int z=TecTech.RANDOM.nextInt(16); - Block aBlock=a.getBlock(x,y,z); - Block bBlock=a.getBlock(x,y,z); - int aMeta=a.getBlockMetadata(x,y,z); - int bMeta=a.getBlockMetadata(x,y,z); - if(a.getTileEntityUnsafe(x,y,z)==null&&b.getTileEntityUnsafe(x,y,z)==null){ - a.worldObj.setBlock((a.xPosition<<4)+x,y,(a.zPosition<<4)+z,bBlock,bMeta,3); - b.worldObj.setBlock((b.xPosition<<4)+x,y,(b.zPosition<<4)+z,aBlock,aMeta,3); - }else if(a.getTileEntityUnsafe(x,y,z)==null){ - a.worldObj.setBlockToAir((a.xPosition<<4)+x,y,(a.zPosition<<4)+z); - b.worldObj.setBlock((b.xPosition<<4)+x,y,(b.zPosition<<4)+z,aBlock,aMeta,3); - }else if(b.getTileEntityUnsafe(x,y,z)==null){ - a.worldObj.setBlock((a.xPosition<<4)+x,y,(a.zPosition<<4)+z,bBlock,bMeta,3); - b.worldObj.setBlockToAir((b.xPosition<<4)+x,y,(b.zPosition<<4)+z); - }else{ - a.worldObj.setBlockToAir((a.xPosition<<4)+x,y,(a.zPosition<<4)+z); - b.worldObj.setBlockToAir((b.xPosition<<4)+x,y,(b.zPosition<<4)+z); + private void swapSomething(Chunk a,Chunk b,double avg) { + for (int i = 0; i < 64; i++) { + int x = TecTech.RANDOM.nextInt(16); + int y = TecTech.RANDOM.nextInt(a.worldObj.getActualHeight()); + int z = TecTech.RANDOM.nextInt(16); + Block aBlock = a.getBlock(x, y, z); + Block bBlock = a.getBlock(x, y, z); + int aMeta = a.getBlockMetadata(x, y, z); + int bMeta = a.getBlockMetadata(x, y, z); + if (a.getTileEntityUnsafe(x, y, z) == null && b.getTileEntityUnsafe(x, y, z) == null) { + a.worldObj.setBlock((a.xPosition << 4) + x, y, (a.zPosition << 4) + z, bBlock, bMeta, 3); + b.worldObj.setBlock((b.xPosition << 4) + x, y, (b.zPosition << 4) + z, aBlock, aMeta, 3); + } else if (a.getTileEntityUnsafe(x, y, z) == null) { + b.worldObj.setBlock((b.xPosition << 4) + x, y, (b.zPosition << 4) + z, aBlock, aMeta, 3); + a.worldObj.setBlockToAir((a.xPosition << 4) + x, y, (a.zPosition << 4) + z); + if (TecTech.RANDOM.nextBoolean()) { + a.worldObj.createExplosion(null, (a.xPosition << 4) + x + .5, y + .5, (a.zPosition << 4) + z + .5, (float) Math.log10(avg), true); + GT_Utility.sendSoundToPlayers(a.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (a.xPosition << 4) + x, y, (a.zPosition << 4) + z); + } + } else if (b.getTileEntityUnsafe(x, y, z) == null) { + a.worldObj.setBlock((a.xPosition << 4) + x, y, (a.zPosition << 4) + z, bBlock, bMeta, 3); + b.worldObj.setBlockToAir((b.xPosition << 4) + x, y, (b.zPosition << 4) + z); + if (TecTech.RANDOM.nextBoolean()) { + b.worldObj.createExplosion(null, (b.xPosition << 4) + x + .5, y + .5, (b.zPosition << 4) + z + .5, (float) Math.log10(avg), true); + GT_Utility.sendSoundToPlayers(b.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (b.xPosition << 4) + x, y, (b.zPosition << 4) + z); + } + } else { + if (TecTech.RANDOM.nextBoolean()) { + a.worldObj.setBlockToAir((a.xPosition << 4) + x, y, (a.zPosition << 4) + z); + a.worldObj.createExplosion(null, (a.xPosition << 4) + x + .5, y + .5, (a.zPosition << 4) + z + .5, (float) Math.log10(avg), true); + GT_Utility.sendSoundToPlayers(a.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (a.xPosition << 4) + x, y, (a.zPosition << 4) + z); + } + if (TecTech.RANDOM.nextBoolean()) { + b.worldObj.setBlockToAir((b.xPosition << 4) + x, y, (b.zPosition << 4) + z); + b.worldObj.createExplosion(null, (b.xPosition << 4) + x + .5, y + .5, (b.zPosition << 4) + z + .5, (float) Math.log10(avg), true); + GT_Utility.sendSoundToPlayers(b.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (b.xPosition << 4) + x, y, (b.zPosition << 4) + z); + } } } + int x = (b.xPosition - a.xPosition) << 4; + int z = (b.xPosition - a.xPosition) << 4; + List aE = a.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, Util.fromChunk(a)); + List bE = b.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, Util.fromChunk(b)); + aE.forEach(o -> { + if (TecTech.RANDOM.nextBoolean()) { + Vec3 pos = ((EntityLivingBase) o).getPosition(1); + ((EntityLivingBase) o).setPositionAndUpdate(pos.xCoord + x, pos.yCoord, pos.zCoord + z); + ((EntityLivingBase) o).attackEntityFrom(MainLoader.subspace,18); + if(o instanceof EntityPlayer){ + ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 200)); + } + } + }); + bE.forEach(o -> { + if (TecTech.RANDOM.nextBoolean()) { + Vec3 pos = ((EntityLivingBase) o).getPosition(1); + ((EntityLivingBase) o).setPositionAndUpdate(pos.xCoord - x, pos.yCoord, pos.zCoord - z); + ((EntityLivingBase) o).attackEntityFrom(MainLoader.subspace,18); + if(o instanceof EntityPlayer){ + ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.digSpeed.id, 200)); + } + } + }); } @Override public void tickPlayer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.PlayerTickEvent aEvent) { if (aEvent.side.isClient()) { - EntityClientPlayerMP player=Minecraft.getMinecraft().thePlayer; + 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++) { + for (int i = 0, badness = (int) Math.min(COUNT_DIV, compound.getDouble(INTENSITY) / PER_PARTICLE); i < badness; i++) { TecTech.proxy.em_particle(player.worldObj, player.posX - 32D + TecTech.RANDOM.nextFloat() * 64D, player.posY - 32D + TecTech.RANDOM.nextFloat() * 64D, @@ -111,7 +164,7 @@ public class AnomalyHandler implements IChunkMetaDataHandler { 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++) { + for (int i = 0, pow = (int) Math.min(32, dat.getDouble(INTENSITY) / PER_PARTICLE); i < pow; i++) { TecTech.proxy.em_particle(player.worldObj, (chunkCoordIntPair.chunkXPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D, player.posY + TecTech.RANDOM.nextFloat() * 128D - 64D, @@ -119,23 +172,46 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } }); - } - } - - @Override - public void tickServer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event) { - if(event.side.isServer()){ - + } else if (TecTech.RANDOM.nextInt(50) == 0) { + EntityPlayer player = aEvent.player; + ChunkCoordIntPair pair = new ChunkCoordIntPair(player.chunkCoordX, player.chunkCoordZ); + NBTTagCompound compound = data.get(player.worldObj.provider.dimensionId).get(pair); + NBTTagCompound playerTag = TecTech.playerPersistence.getDataOrSetToNewTag(player); + if(player.capabilities.isCreativeMode){ + playerTag.setDouble(SPACE_CANCER, 0); + }else { + if (compound != null) { + int badness = (int) Math.min(COUNT_DIV, compound.getDouble(INTENSITY) / PER_PARTICLE); + if (badness > 0) { + playerTag.setDouble(SPACE_CANCER, Math.min(2, playerTag.getDouble(SPACE_CANCER) + 9.765625E-4f * badness)); + player.attackEntityFrom(MainLoader.subspace,Math.max(1,badness/8f)); + } + } else if (playerTag.getDouble(SPACE_CANCER) > 0) { + playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-6f)); + } + } + TecTech.playerPersistence.saveData(player); + NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(player), (EntityPlayerMP) player); } } @Override public void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent aEvent) { EntityClientPlayerMP player=Minecraft.getMinecraft().thePlayer; - if(player!=null) { - player.setAngles((TecTech.RANDOM.nextFloat() - .5F)*4, (TecTech.RANDOM.nextFloat() - .5F)*4); - player.setVelocity(TecTech.RANDOM.nextFloat()*2-1,TecTech.RANDOM.nextFloat()*2-1,TecTech.RANDOM.nextFloat()*2-1); - player.setInvisible(TecTech.RANDOM.nextBoolean()); + if(player!=null && !player.capabilities.isCreativeMode) { + NBTTagCompound tagCompound=TecTech.playerPersistence.getDataOrSetToNewTag(Minecraft.getMinecraft().thePlayer); + if(tagCompound!=null) { + float cancer = tagCompound.getFloat(SPACE_CANCER); + if (cancer > 0) { + player.setAngles((TecTech.RANDOM.nextFloat() - .5F) * 4 * cancer, (TecTech.RANDOM.nextFloat() - .5F) * 4 * cancer); + player.setInvisible(TecTech.RANDOM.nextFloat() * 2 < cancer); + if (cancer > 1.9f) { + player.setVelocity((TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2, (TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2, (TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2); + } else{ + player.addVelocity((TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2, (TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2, (TecTech.RANDOM.nextFloat() - .5F) * cancer*cancer/2); + } + } + } } } |