aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTec <daniel112092@gmail.com>2019-07-16 23:49:27 +0200
committerTec <daniel112092@gmail.com>2019-07-16 23:49:27 +0200
commitec335befdb0c2e03a33f4fbf42587b5585cf3796 (patch)
treee2a3278936c60726d92a7ad5e0ed8ab55861eb1a
parent0989424cca10758930071d0846070e521f856957 (diff)
downloadGT5-Unofficial-ec335befdb0c2e03a33f4fbf42587b5585cf3796.tar.gz
GT5-Unofficial-ec335befdb0c2e03a33f4fbf42587b5585cf3796.tar.bz2
GT5-Unofficial-ec335befdb0c2e03a33f4fbf42587b5585cf3796.zip
It should work now.
-rw-r--r--src/main/java/com/github/technus/tectech/TecTech.java2
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/AnomalyHandler.java179
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/CancerCommand.java1
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/anomaly/ChargeCommand.java85
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/data/ChunkDataHandler.java70
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/data/IChunkMetaDataHandler.java15
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/data/PlayerPersistence.java11
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/ClientProxy.java4
-rw-r--r--src/main/java/com/github/technus/tectech/proxy/CommonProxy.java4
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java3
10 files changed, 280 insertions, 94 deletions
diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java
index 264c8dd797..f998a9017b 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.anomaly.AnomalyHandler;
import com.github.technus.tectech.mechanics.anomaly.CancerCommand;
+import com.github.technus.tectech.mechanics.anomaly.ChargeCommand;
import com.github.technus.tectech.mechanics.commands.ConvertFloat;
import com.github.technus.tectech.mechanics.commands.ConvertInteger;
import com.github.technus.tectech.mechanics.data.ChunkDataHandler;
@@ -207,6 +208,7 @@ public class TecTech {
if(DEBUG_MODE) {
pEvent.registerServerCommand(new GiveEM());
pEvent.registerServerCommand(new CancerCommand());
+ pEvent.registerServerCommand(new ChargeCommand());
}
}
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 4eb2cc45a2..2f65fc05a1 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,6 @@ 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;
@@ -34,10 +33,14 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
public static final double SWAP_THRESHOLD = dAtomDefinition.getSomethingHeavy().getMass() * 10000D;
public static final int COUNT_DIV=32;
public static final double PER_PARTICLE=SWAP_THRESHOLD/COUNT_DIV;
- public static final String INTENSITY = "intensity",SPACE_CANCER="space_cancer";
+ public static final String INTENSITY = "intensity",SPACE_CANCER="space_cancer", SPACE_CHARGE ="space_charge";
public static final int MEAN_DELAY =50;
+ private static final float CHARGE_EFFECTIVENESS = 10;
+ private static final float CHARGE_EXPLOSIVENESS = 5;
private boolean fixMe=false;
+ private final ArrayList<EntityPlayer> playersWithCharge = new ArrayList<>();
+ private final ArrayList<Chunk> worldDataArrayList = new ArrayList<>(512);
@Override
public String getTagName() {
@@ -59,7 +62,6 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
public void tickWorld(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.WorldTickEvent aEvent) {
if (TecTech.RANDOM.nextInt(MEAN_DELAY) == 0) {
int dim = aEvent.world.provider.dimensionId;
- ArrayList<Chunk> 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);
@@ -71,18 +73,55 @@ 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()));
- 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));
+ 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,avg);
+ swapSomething(a, b, (float) Math.min(Math.log10(avg-5), 20));
}
+ worldDataArrayList.clear();
+ }
+ for (Object o : aEvent.world.playerEntities) {
+ if (o instanceof EntityPlayer && !((EntityPlayer) o).capabilities.isCreativeMode) {
+ float charge = TecTech.playerPersistence.getDataOrSetToNewTag((EntityPlayer) o).getFloat(SPACE_CHARGE);
+ if (charge != 0) {
+ playersWithCharge.add((EntityPlayer) o);
+ }
+ }
+ }
+ if (playersWithCharge.size() > 0) {
+ outer:
+ for (EntityPlayer other : playersWithCharge) {
+ float fieldOther = TecTech.playerPersistence.getDataOrSetToNewTag(other).getFloat(SPACE_CHARGE);
+ for (EntityPlayer player : playersWithCharge) {
+ if (other == player) {
+ continue outer;
+ }
+ float field = TecTech.playerPersistence.getDataOrSetToNewTag(player).getFloat(SPACE_CHARGE);
+ float difference = Math.abs(field - fieldOther);
+ if (difference != 0) {
+ if (player.getDistanceSqToEntity(other) < 1) {
+ float avg = (fieldOther + field) / 2;
+ addAnomaly(other.worldObj.provider.dimensionId, new ChunkCoordIntPair(other.chunkCoordX, other.chunkCoordZ), Math.min(SWAP_THRESHOLD, PER_PARTICLE * difference));
+ other.worldObj.createExplosion(other, other.posX, other.posY, other.posZ, Math.min(CHARGE_EXPLOSIVENESS * difference, 25), true);
+ player.worldObj.createExplosion(player, player.posX, player.posY, player.posZ, Math.min(CHARGE_EXPLOSIVENESS * difference, 25), true);
+ TecTech.playerPersistence.getDataOrSetToNewTag(player).setFloat(SPACE_CHARGE, avg);
+ TecTech.playerPersistence.getDataOrSetToNewTag(other).setFloat(SPACE_CHARGE, avg);
+ TecTech.playerPersistence.saveData(player);
+ TecTech.playerPersistence.saveData(other);
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player));
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(other));
+ }
+ }
+ }
+ }
+ playersWithCharge.clear();
}
}
- private void swapSomething(Chunk a,Chunk b,double avg) {
+ private void swapSomething(Chunk a,Chunk b,float power) {
for (int i = 0; i < 64; i++) {
int x = TecTech.RANDOM.nextInt(16);
int y = TecTech.RANDOM.nextInt(a.worldObj.getActualHeight());
@@ -97,51 +136,68 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
} 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);
- }
+ a.worldObj.setBlockToAir((a.xPosition << 4) + x, y, (a.zPosition << 4) + z);
+ b.worldObj.setBlockToAir((b.xPosition << 4) + x, y, (b.zPosition << 4) + z);
+ }
+ if (TecTech.RANDOM.nextBoolean()) {
+ a.worldObj.createExplosion(null, (a.xPosition << 4) + x + .5, y + .5, (a.zPosition << 4) + z + .5, power, 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.createExplosion(null, (b.xPosition << 4) + x + .5, y + .5, (b.zPosition << 4) + z + .5, power, 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));
+ List<EntityLivingBase> aE = a.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, Util.fromChunk(a));
+ List<EntityLivingBase> 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);
+ o.setPositionAndUpdate(o.posX + x, o.posY, o.posZ + z);
+ o.attackEntityFrom(MainLoader.subspace,8+TecTech.RANDOM.nextInt(8));
if(o instanceof EntityPlayer){
- ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 200));
+ EntityPlayer player=((EntityPlayer) o);
+ if(!player.capabilities.isCreativeMode) {
+ player.addPotionEffect(new PotionEffect(Potion.hunger.id, 1200));
+ player.addPotionEffect(new PotionEffect(Potion.weakness.id, 1000));
+ player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 800));
+ player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 600));
+ player.addPotionEffect(new PotionEffect(Potion.confusion.id, 400));
+ player.addPotionEffect(new PotionEffect(Potion.poison.id, 200));
+ player.addPotionEffect(new PotionEffect(Potion.blindness.id, 100));
+ player.addPotionEffect(new PotionEffect(Potion.wither.id, 60));
+ TecTech.playerPersistence.getDataOrSetToNewTag(player).setFloat(SPACE_CHARGE,
+ TecTech.playerPersistence.getDataOrSetToNewTag(player).getFloat(SPACE_CHARGE)-(float)Math.abs(TecTech.RANDOM.nextGaussian()));
+ TecTech.playerPersistence.saveData(player);
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player));
+ }
}
}
});
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);
+ o.setPositionAndUpdate(o.posX - x, o.posY, o.posZ - z);
+ o.attackEntityFrom(MainLoader.subspace,8+TecTech.RANDOM.nextInt(8));
if(o instanceof EntityPlayer){
- ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.digSpeed.id, 200));
+ EntityPlayer player=((EntityPlayer) o);
+ if(!player.capabilities.isCreativeMode) {
+ player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 800));
+ player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 600));
+ player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 400));
+ player.addPotionEffect(new PotionEffect(Potion.jump.id, 200));
+ player.addPotionEffect(new PotionEffect(Potion.resistance.id, 100));
+ player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 60));
+ TecTech.playerPersistence.getDataOrSetToNewTag(player).setFloat(SPACE_CHARGE,
+ TecTech.playerPersistence.getDataOrSetToNewTag(player).getFloat(SPACE_CHARGE)+(float)Math.abs(TecTech.RANDOM.nextGaussian()));
+
+ TecTech.playerPersistence.saveData(player);
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player));
+ }
}
}
});
@@ -156,9 +212,9 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
if (compound != null) {
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,
- player.posZ - 32D + TecTech.RANDOM.nextFloat() * 64D);
+ player.posX + TecTech.RANDOM.nextGaussian() * 64D,
+ player.posY + TecTech.RANDOM.nextGaussian() * 64D,
+ player.posZ + TecTech.RANDOM.nextGaussian() * 64D);
}
}
@@ -166,9 +222,9 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
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(player.worldObj,
- (chunkCoordIntPair.chunkXPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D,
+ chunkCoordIntPair.getCenterXPos() + TecTech.RANDOM.nextGaussian() * 32D,
player.posY + TecTech.RANDOM.nextFloat() * 128D - 64D,
- (chunkCoordIntPair.chunkZPos << 4) + TecTech.RANDOM.nextFloat() * 48D - 16D);
+ chunkCoordIntPair.getCenterZPosition() + TecTech.RANDOM.nextGaussian() * 32D);
}
}
});
@@ -186,7 +242,7 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
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) {
+ } else if (playerTag.getDouble(SPACE_CANCER) > 0 && !player.isDead) {
playerTag.setDouble(SPACE_CANCER, Math.max(0, playerTag.getDouble(SPACE_CANCER) - 7.6293945E-6f));
}
}
@@ -204,12 +260,37 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
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(fixMe = 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);
+ player.setAngles((TecTech.RANDOM.nextFloat() - .5F) * 36 * cancer, (TecTech.RANDOM.nextFloat() - .5F) * 36 * cancer);
+ cancer*=cancer/2F;
+ if (cancer > 1.75f) {
+ player.setVelocity((TecTech.RANDOM.nextFloat() - .5F) * cancer, (TecTech.RANDOM.nextFloat() - .5F) * cancer, (TecTech.RANDOM.nextFloat() - .5F) * cancer);
} else {
- player.addVelocity((TecTech.RANDOM.nextFloat() - .5F) * cancer * cancer / 2, (TecTech.RANDOM.nextFloat() - .5F) * cancer * cancer / 2, (TecTech.RANDOM.nextFloat() - .5F) * cancer * cancer / 2);
+ player.addVelocity((TecTech.RANDOM.nextFloat() - .5F) * cancer, (TecTech.RANDOM.nextFloat() - .5F) * cancer, (TecTech.RANDOM.nextFloat() - .5F) * cancer);
+ }
+ }
+ }
+
+ float charge = TecTech.playerPersistence.getDataOrSetToNewTag(player).getFloat(SPACE_CHARGE);
+ if(charge!=0) {
+ for (Object o : player.worldObj.playerEntities) {
+ if (o instanceof EntityPlayer && !((EntityPlayer) o).capabilities.isCreativeMode) {
+ EntityPlayer otherPlayer=(EntityPlayer)o;
+ float chargeOther = TecTech.playerPersistence.getDataOrSetToNewTag(otherPlayer).getFloat(SPACE_CHARGE);
+ if (chargeOther != 0 && player != o) {
+ float reaction = chargeOther * charge;
+ if (reaction !=0) {
+ double distanceSq = otherPlayer.getDistanceSqToEntity(player);
+ if (distanceSq >= 1) {
+ double effect = CHARGE_EFFECTIVENESS * reaction / (distanceSq * distanceSq * distanceSq);
+ double dX = player.posX - otherPlayer.posX;
+ double dY = player.posY - otherPlayer.posY;
+ double dZ = player.posZ - otherPlayer.posZ;
+ player.addVelocity(effect * dX, effect * dY, effect * dZ);
+ otherPlayer.addVelocity(-effect * dX, -effect * dY, -effect * dZ);
+ }
+ }
+ }
}
}
}
@@ -227,8 +308,8 @@ public class AnomalyHandler implements IChunkMetaDataHandler {
}
@Override
- public void pushData(int world, ChunkCoordIntPair chunk) {
- NetworkDispatcher.INSTANCE.sendToDimension(new ChunkDataMessage.ChunkDataData(world, chunk, this), world);
+ public void pushData(World world, ChunkCoordIntPair chunk) {
+ NetworkDispatcher.INSTANCE.sendToDimension(new ChunkDataMessage.ChunkDataData(world.provider.dimensionId, chunk, this), world.provider.dimensionId);
}
@Override
diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/CancerCommand.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/CancerCommand.java
index c19cca64d5..a153671a59 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/anomaly/CancerCommand.java
+++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/CancerCommand.java
@@ -46,6 +46,7 @@ public class CancerCommand implements ICommand {
playerTag.setDouble(SPACE_CANCER, amount);
TecTech.playerPersistence.saveData(player);
NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(player), player);
+ sender.addChatMessage(new ChatComponentText("Cancer set to: "+amount));
}
}
}
diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/ChargeCommand.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/ChargeCommand.java
new file mode 100644
index 0000000000..da365a92f8
--- /dev/null
+++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/ChargeCommand.java
@@ -0,0 +1,85 @@
+package com.github.technus.tectech.mechanics.anomaly;
+
+import com.github.technus.tectech.TecTech;
+import com.github.technus.tectech.loader.NetworkDispatcher;
+import com.github.technus.tectech.mechanics.data.PlayerDataMessage;
+import net.minecraft.command.ICommand;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.ChatComponentText;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.github.technus.tectech.mechanics.anomaly.AnomalyHandler.SPACE_CHARGE;
+
+public class ChargeCommand implements ICommand {
+ ArrayList<String> aliases=new ArrayList<>();
+
+ public ChargeCommand(){
+ aliases.add("charge_EM");
+ aliases.add("charge");
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) {
+ if (sender instanceof EntityPlayerMP && !sender.getEntityWorld().isRemote) {
+ double amount;
+ try {
+ amount = Double.parseDouble(args[0]);
+ }catch (NumberFormatException e){
+ sender.addChatMessage(new ChatComponentText("Cannot parse amount!"));
+ return;
+ }
+ EntityPlayerMP player=(EntityPlayerMP)sender;
+ NBTTagCompound playerTag = TecTech.playerPersistence.getDataOrSetToNewTag(player);
+ if(player.capabilities.isCreativeMode){
+ sender.addChatMessage(new ChatComponentText("Doesn't really work in creative mode!"));
+ }else {
+ playerTag.setDouble(SPACE_CHARGE, amount);
+ TecTech.playerPersistence.saveData(player);
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player));
+ sender.addChatMessage(new ChatComponentText("Charge set to: "+amount));
+ }
+ }
+ }
+
+ @Override
+ public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
+ return false;
+ }
+
+ @Override
+ public List<String> getCommandAliases() {
+ return aliases;
+ }
+
+ @Override
+ public String getCommandName() {
+ return aliases.get(0);
+ }
+
+ @Override
+ public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
+ return null;
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender p_71518_1_) {
+ return "charge_EM [Amount]";
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if(o instanceof ICommand){
+ return getCommandName().compareTo(((ICommand) o).getCommandName());
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand(ICommandSender sender) {
+ return true;
+ }
+}
diff --git a/src/main/java/com/github/technus/tectech/mechanics/data/ChunkDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/data/ChunkDataHandler.java
index 8109db9b86..0d0af5b390 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/data/ChunkDataHandler.java
+++ b/src/main/java/com/github/technus/tectech/mechanics/data/ChunkDataHandler.java
@@ -8,6 +8,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.World;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
@@ -97,13 +98,15 @@ public class ChunkDataHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onLoadChunk(ChunkEvent.Load aEvent){
- pullSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.pullData(aEvent));
+ if(aEvent.world.isRemote && !Minecraft.getMinecraft().isSingleplayer()) {//we already have the data!
+ pullSyncHandlers.forEach(chunkMetaDataHandler -> chunkMetaDataHandler.pullData(aEvent));
+ }
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
- public void onUnLoadChunk(ChunkEvent.Unload aEvent){
- if(aEvent.world.isRemote && !Minecraft.getMinecraft().isSingleplayer()) {
+ public void onUnloadChunk(ChunkEvent.Unload aEvent){
+ if(aEvent.world.isRemote && !Minecraft.getMinecraft().isSingleplayer()) {//we need all data if running local server!
pullSyncHandlers.forEach(chunkMetaDataHandler -> dimensionWiseMetaChunkData
.get(chunkMetaDataHandler.getTagName())
.get(aEvent.world.provider.dimensionId)
@@ -134,39 +137,38 @@ public class ChunkDataHandler {
dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
}
+ //Ticks only on server side (but must be present for client server)
@SubscribeEvent
public void onWorldTickEvent(TickEvent.WorldTickEvent aEvent) {
- if(aEvent.side.isServer()) {
- int dim = aEvent.world.provider.dimensionId;
- pushSyncHandlers.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());
- }
+ int dim = aEvent.world.provider.dimensionId;
+ pushSyncHandlers.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));
- }
+ data.dirtyBoys.clear();
+ }
+ work = data.workLoad.get(epoch);
+ chunkMetaDataHandler.pushPayload(aEvent.world, work);
+ work.clear();
+ });
+ worldHandlers.forEach(chunkMetaDataHandler ->
+ chunkMetaDataHandler.tickWorld(
+ dimensionWiseMetaChunkData.get(chunkMetaDataHandler.getTagName()), aEvent));
}
@SubscribeEvent
@@ -197,7 +199,7 @@ public class ChunkDataHandler {
if(clazz.getMethod("tickPlayer", HashMap.class, TickEvent.PlayerTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){
playerHandlers.add(handler);
}
- if (clazz.getMethod("pushData", int.class, ChunkCoordIntPair.class).getDeclaringClass()!=IChunkMetaDataHandler.class) {
+ if (clazz.getMethod("pushData", World.class, ChunkCoordIntPair.class).getDeclaringClass()!=IChunkMetaDataHandler.class) {
pushSyncHandlers.add(handler);
}
if(clazz.getMethod("tickWorld", HashMap.class, TickEvent.WorldTickEvent.class).getDeclaringClass()!= IChunkMetaDataHandler.class){
@@ -206,7 +208,7 @@ public class ChunkDataHandler {
} catch (NoSuchMethodException e) {
throw new RuntimeException("Cannot register common event handlers!",e);
}
- if(FMLCommonHandler.instance().getEffectiveSide().isClient()) {
+ if(FMLCommonHandler.instance().getSide().isClient()) {
try {
if (clazz.getMethod("pullData", ChunkEvent.Load.class).getDeclaringClass() != IChunkMetaDataHandler.class) {
pullSyncHandlers.add(handler);
diff --git a/src/main/java/com/github/technus/tectech/mechanics/data/IChunkMetaDataHandler.java b/src/main/java/com/github/technus/tectech/mechanics/data/IChunkMetaDataHandler.java
index a8f5e013c5..0be1fec517 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/data/IChunkMetaDataHandler.java
+++ b/src/main/java/com/github/technus/tectech/mechanics/data/IChunkMetaDataHandler.java
@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.World;
import net.minecraftforge.event.world.ChunkEvent;
import java.util.ArrayList;
@@ -16,19 +17,19 @@ public interface IChunkMetaDataHandler {
NBTTagCompound createData();
@SideOnly(Side.CLIENT)
default void pullData(ChunkEvent.Load aEvent){}
- default void pushData(int world, ChunkCoordIntPair chunk){}
- default void pushPayload(int world, ArrayList<ChunkCoordIntPair> chunk){
+ default void pushData(World world, ChunkCoordIntPair chunk){}
+ default void pushPayload(World world, ArrayList<ChunkCoordIntPair> chunk){
chunk.forEach(chunkCoordIntPair -> pushData(world,chunkCoordIntPair));
}
default int pushPayloadSpreadPeriod(){
- return 20;
+ return 20;//must be a constant!
}
@SideOnly(Side.CLIENT)
- default void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent aEvent){}
+ default void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent event){}
@SideOnly(Side.CLIENT)
- default void tickClient(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ClientTickEvent aEvent){}
+ default void tickClient(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ClientTickEvent event){}
default void tickServer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.ServerTickEvent event){}
- default void tickWorld(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.WorldTickEvent aEvent){}
- default void tickPlayer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.PlayerTickEvent aEvent){}
+ default void tickWorld(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.WorldTickEvent event){}
+ default void tickPlayer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.PlayerTickEvent event){}
}
diff --git a/src/main/java/com/github/technus/tectech/mechanics/data/PlayerPersistence.java b/src/main/java/com/github/technus/tectech/mechanics/data/PlayerPersistence.java
index 9282001c9a..0a829de3e9 100644
--- a/src/main/java/com/github/technus/tectech/mechanics/data/PlayerPersistence.java
+++ b/src/main/java/com/github/technus/tectech/mechanics/data/PlayerPersistence.java
@@ -7,6 +7,8 @@ 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 net.minecraft.server.MinecraftServer;
+import net.minecraft.world.WorldServer;
import java.util.HashMap;
import java.util.UUID;
@@ -61,8 +63,13 @@ public class PlayerPersistence {
@SubscribeEvent
public void onLogin(PlayerEvent.PlayerLoggedInEvent event){
- if(event.player instanceof EntityPlayerMP){
- NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData(event.player),(EntityPlayerMP)event.player);
+ if(!event.player.worldObj.isRemote){
+ for (WorldServer worldServer : MinecraftServer.getServer().worldServers) {
+ for (Object playerEntity : worldServer.playerEntities) {
+ NetworkDispatcher.INSTANCE.sendTo(new PlayerDataMessage.PlayerDataData((EntityPlayer) playerEntity),(EntityPlayerMP) event.player);
+ }
+ }
+ NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(event.player));
}
}
diff --git a/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java b/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
index d66cc8bf82..5ab81d8283 100644
--- a/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
+++ b/src/main/java/com/github/technus/tectech/proxy/ClientProxy.java
@@ -144,4 +144,8 @@ public class ClientProxy extends CommonProxy {
public EntityClientPlayerMP getPlayer(){
return Minecraft.getMinecraft().thePlayer;
}
+
+ public boolean isThePlayer(EntityPlayer player){
+ return getPlayer()==player;
+ }
}
diff --git a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
index 6f5f367d7f..59d2b95150 100644
--- a/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
+++ b/src/main/java/com/github/technus/tectech/proxy/CommonProxy.java
@@ -85,4 +85,8 @@ public class CommonProxy implements IGuiHandler {
public EntityPlayer getPlayer(){
return null;
}
+
+ public boolean isThePlayer(EntityPlayer player){
+ return false;
+ }
}
diff --git a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java
index f63f35e7f8..33f0d34ad5 100644
--- a/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java
+++ b/src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java
@@ -10,7 +10,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_ElectricBlastFurnace;
import net.minecraft.block.Block;
-import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
@@ -63,7 +62,7 @@ public final class ConstructableTriggerItem extends Item {
}
}
return true;
- }else if (aPlayer instanceof EntityClientPlayerMP){//particles and text client side
+ }else if (TecTech.proxy.isThePlayer(aPlayer)){//particles and text client side
//if ((!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode)) {
if(tTileEntity instanceof IGregTechTileEntity) {
IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();