diff options
7 files changed, 258 insertions, 141 deletions
diff --git a/gradle.properties b/gradle.properties index 3d49d30e98..7b41df262e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ forgeVersion = 10.13.4.1614 # restart Minecraft in development. Choose this dependent on your mod: # Do you need consistent player progressing (for example Thaumcraft)? -> Select a name # Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty -developmentEnvironmentUserName = "Developer" +developmentEnvironmentUserName = "" # Define a source file of your project with: # public static final String VERSION = "GRADLETOKEN_VERSION"; diff --git a/src/main/java/com/github/technus/tectech/TecTech.java b/src/main/java/com/github/technus/tectech/TecTech.java index 1248437e30..c281304205 100644 --- a/src/main/java/com/github/technus/tectech/TecTech.java +++ b/src/main/java/com/github/technus/tectech/TecTech.java @@ -7,6 +7,7 @@ import com.github.technus.tectech.loader.gui.CreativeTabEM; 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.anomaly.MassCommand; import com.github.technus.tectech.mechanics.commands.ConvertFloat; import com.github.technus.tectech.mechanics.commands.ConvertInteger; import com.github.technus.tectech.mechanics.data.ChunkDataHandler; @@ -221,6 +222,7 @@ public class TecTech { pEvent.registerServerCommand(new EMGive()); pEvent.registerServerCommand(new CancerCommand()); pEvent.registerServerCommand(new ChargeCommand()); + pEvent.registerServerCommand(new MassCommand()); } } diff --git a/src/main/java/com/github/technus/tectech/loader/MainLoader.java b/src/main/java/com/github/technus/tectech/loader/MainLoader.java index 3b99cd987b..2a1bd59357 100644 --- a/src/main/java/com/github/technus/tectech/loader/MainLoader.java +++ b/src/main/java/com/github/technus/tectech/loader/MainLoader.java @@ -50,28 +50,29 @@ import static com.github.technus.tectech.TecTech.creativeTabTecTech; import static gregtech.api.enums.GT_Values.W; public final class MainLoader { - public static DamageSource microwaving, elementalPollution,subspace; + public static DamageSource microwaving, elementalPollution, subspace; - private MainLoader(){} + private MainLoader() { + } - public static void staticLoad(){ - for(int i=0;i<16;i++){ - GT_Values.V[i]=V[i]; - GT_Values.VN[i]=VN[i]; - GT_Values.VOLTAGE_NAMES[i]=VOLTAGE_NAMES[i]; + public static void staticLoad() { + for (int i = 0; i < 16; i++) { + GT_Values.V[i] = V[i]; + GT_Values.VN[i] = VN[i]; + GT_Values.VOLTAGE_NAMES[i] = VOLTAGE_NAMES[i]; } new ComponentLoader(); } - public static void preLoad(){ - creativeTabTecTech =new CreativeTabTecTech("TecTech"); - creativeTabEM =new CreativeTabEM("EM"); + public static void preLoad() { + creativeTabTecTech = new CreativeTabTecTech("TecTech"); + creativeTabEM = new CreativeTabEM("EM"); //set expanded texture arrays for tiers try { Textures.run(); - }catch (Throwable t){ - LOGGER.error("Loading textures...",t); + } catch (Throwable t) { + LOGGER.error("Loading textures...", t); } } @@ -107,9 +108,9 @@ public final class MainLoader { LOGGER.info("Entities registered"); progressBarLoad.step("Add damage types"); - microwaving =new DamageSource("microwaving").setDamageBypassesArmor(); - elementalPollution =new DamageSource("elementalPollution").setDamageBypassesArmor(); - subspace =new DamageSource("subspace").setDamageBypassesArmor().setDamageIsAbsolute(); + microwaving = new DamageSource("microwaving").setDamageBypassesArmor(); + elementalPollution = new DamageSource("elementalPollution").setDamageBypassesArmor(); + subspace = new DamageSource("subspace").setDamageBypassesArmor().setDamageIsAbsolute(); LOGGER.info("Damage types addition Done"); progressBarLoad.step("Register Packet Dispatcher"); @@ -128,16 +129,16 @@ public final class MainLoader { ProgressManager.ProgressBar progressBarPostLoad = ProgressManager.push("TecTech Post Loader", 4); progressBarPostLoad.step("Dreamcraft Compatibility"); - if(Loader.isModLoaded(Reference.DREAMCRAFT)){ + if (Loader.isModLoaded(Reference.DREAMCRAFT)) { try { Class<?> clazz = Class.forName("com.dreammaster.gthandler.casings.GT_Container_CasingsNH"); - TT_Container_Casings.sBlockCasingsNH = (Block)clazz.getField("sBlockCasingsNH").get(null); + TT_Container_Casings.sBlockCasingsNH = (Block) clazz.getField("sBlockCasingsNH").get(null); - if(TT_Container_Casings.sBlockCasingsNH==null){ + if (TT_Container_Casings.sBlockCasingsNH == null) { throw new NullPointerException("sBlockCasingsNH Is not set at this time"); } - }catch (Exception e){ - throw new Error("Unable to get NH casings",e); + } catch (Exception e) { + throw new Error("Unable to get NH casings", e); } } @@ -171,19 +172,19 @@ public final class MainLoader { } private static void registerExtraHazmats() { - ItemStack EMT_iqC=GT_ModHandler.getModItem("EMT","itemArmorQuantumChestplate",1,W); - ItemStack GRAVI_gC=GT_ModHandler.getModItem("GraviSuite","graviChestPlate",1,W); - ItemStack GRAVI_anC=GT_ModHandler.getModItem("GraviSuite", "advNanoChestPlate", 1, W); + ItemStack EMT_iqC = GT_ModHandler.getModItem("EMT", "itemArmorQuantumChestplate", 1, W); + ItemStack GRAVI_gC = GT_ModHandler.getModItem("GraviSuite", "graviChestPlate", 1, W); + ItemStack GRAVI_anC = GT_ModHandler.getModItem("GraviSuite", "advNanoChestPlate", 1, W); - ItemStack IC2_qH=GT_ModHandler.getIC2Item("quantumHelmet", 1L, W); - ItemStack IC2_qC=GT_ModHandler.getIC2Item("quantumBodyarmor", 1L, W); - ItemStack IC2_qL=GT_ModHandler.getIC2Item("quantumLeggings", 1L, W); - ItemStack IC2_qB=GT_ModHandler.getIC2Item("quantumBoots", 1L, W); + ItemStack IC2_qH = GT_ModHandler.getIC2Item("quantumHelmet", 1L, W); + ItemStack IC2_qC = GT_ModHandler.getIC2Item("quantumBodyarmor", 1L, W); + ItemStack IC2_qL = GT_ModHandler.getIC2Item("quantumLeggings", 1L, W); + ItemStack IC2_qB = GT_ModHandler.getIC2Item("quantumBoots", 1L, W); - ItemStack IC2_nH=GT_ModHandler.getIC2Item("nanoHelmet", 1L, W); - ItemStack IC2_nC=GT_ModHandler.getIC2Item("nanoBodyarmor", 1L, W); - ItemStack IC2_nL=GT_ModHandler.getIC2Item("nanoLeggings", 1L, W); - ItemStack IC2_nB=GT_ModHandler.getIC2Item("nanoBoots", 1L, W); + ItemStack IC2_nH = GT_ModHandler.getIC2Item("nanoHelmet", 1L, W); + ItemStack IC2_nC = GT_ModHandler.getIC2Item("nanoBodyarmor", 1L, W); + ItemStack IC2_nL = GT_ModHandler.getIC2Item("nanoLeggings", 1L, W); + ItemStack IC2_nB = GT_ModHandler.getIC2Item("nanoBoots", 1L, W); GregTech_API.sFrostHazmatList.add(EMT_iqC); GregTech_API.sFrostHazmatList.add(GRAVI_gC); @@ -205,7 +206,7 @@ public final class MainLoader { GregTech_API.sBioHazmatList.add(IC2_qC); GregTech_API.sBioHazmatList.add(IC2_qL); GregTech_API.sBioHazmatList.add(IC2_qB); - + GregTech_API.sBioHazmatList.add(GRAVI_anC); GregTech_API.sBioHazmatList.add(IC2_nH); GregTech_API.sBioHazmatList.add(IC2_nC); @@ -218,7 +219,7 @@ public final class MainLoader { GregTech_API.sGasHazmatList.add(IC2_qC); GregTech_API.sGasHazmatList.add(IC2_qL); GregTech_API.sGasHazmatList.add(IC2_qB); - + GregTech_API.sGasHazmatList.add(GRAVI_anC); GregTech_API.sGasHazmatList.add(IC2_nH); GregTech_API.sGasHazmatList.add(IC2_nC); @@ -238,13 +239,13 @@ public final class MainLoader { GregTech_API.sElectroHazmatList.add(IC2_qC); GregTech_API.sElectroHazmatList.add(IC2_qL); GregTech_API.sElectroHazmatList.add(IC2_qB); - + //todo add GC GS stuff } public static void addAfterGregTechPostLoadRunner() { GregTech_API.sAfterGTPostload.add(() -> { - if(TecTech.configTecTech.NERF_FUSION) { + if (TecTech.configTecTech.NERF_FUSION) { FixBrokenFusionRecipes(); } GT_MetaTileEntity_EM_collider.setValues(getFuelValue(Materials.Helium.getPlasma(125))); @@ -306,7 +307,7 @@ public final class MainLoader { public static int getFuelValue(FluidStack aLiquid) { if (aLiquid == null || GT_Recipe.GT_Recipe_Map.sTurbineFuels == null) return 0; - FluidStack tLiquid; + FluidStack tLiquid; Collection<GT_Recipe> tRecipeList = GT_Recipe.GT_Recipe_Map.sPlasmaFuels.mRecipeList; if (tRecipeList != null) for (GT_Recipe tFuel : tRecipeList) if ((tLiquid = GT_Utility.getFluidForFilledItem(tFuel.getRepresentativeInput(0), true)) != null) @@ -314,8 +315,8 @@ public final class MainLoader { return 0; } - private static void fixBlocks(){ - HashSet<String> modIDs=new HashSet<>(Arrays.asList( + private static void fixBlocks() { + HashSet<String> modIDs = new HashSet<>(Arrays.asList( "minecraft", "IC2", "gregtech", @@ -346,8 +347,8 @@ public final class MainLoader { "utilityworlds", Reference.MODID )); - for(Block block : GameData.getBlockRegistry().typeSafeIterable()) { - GameRegistry.UniqueIdentifier uniqueIdentifier=GameRegistry.findUniqueIdentifierFor(block); + for (Block block : GameData.getBlockRegistry().typeSafeIterable()) { + GameRegistry.UniqueIdentifier uniqueIdentifier = GameRegistry.findUniqueIdentifierFor(block); if (uniqueIdentifier != null) { if (block.blockHardness < 0 || modIDs.contains(uniqueIdentifier.modId)) { continue; 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 2ca1349489..a61490b162 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 @@ -33,21 +33,23 @@ import java.util.Map; import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMTransformationRegistry.EM_COUNT_PER_MATERIAL_AMOUNT; import static com.github.technus.tectech.mechanics.elementalMatter.core.transformations.EMTransformationRegistry.EM_COUNT_PER_MATERIAL_AMOUNT_DIMINISHED; +import static com.github.technus.tectech.util.Util.crossProduct3D; +import static com.github.technus.tectech.util.Util.normalize3D; public class AnomalyHandler implements IChunkMetaDataHandler { private static final double SWAP_THRESHOLD = EMAtomDefinition.getSomethingHeavy().getMass() * 1000D * EM_COUNT_PER_MATERIAL_AMOUNT_DIMINISHED;//can be const as it is computed later... - 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", SPACE_CHARGE ="space_charge", SPACE_MASS="space_mass"; - private static final int MEAN_DELAY =50; - private static final double CANCER_EFFECTIVENESS = 1/ EM_COUNT_PER_MATERIAL_AMOUNT; - private static final double GRAVITY_EFFECTIVENESS =1; - private static final double CHARGE_EFFECTIVENESS = 10/ EM_COUNT_PER_MATERIAL_AMOUNT; - private static final double CHARGE_EXPLOSIVENESS = 5/ EM_COUNT_PER_MATERIAL_AMOUNT; - - private boolean fixMe=false; - private final List<EntityPlayer> playersWithCharge = new ArrayList<>(); - private final ArrayList<Chunk> worldDataArrayList = new ArrayList<>(512); + 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", SPACE_CHARGE = "space_charge", SPACE_MASS = "space_mass"; + private static final int MEAN_DELAY = 50; + private static final double CANCER_EFFECTIVENESS = 1 / EM_COUNT_PER_MATERIAL_AMOUNT; + private static final double MASS_EFFECTIVENESS = 1 / EM_COUNT_PER_MATERIAL_AMOUNT; + private static final double CHARGE_EFFECTIVENESS = 10 / EM_COUNT_PER_MATERIAL_AMOUNT; + private static final double CHARGE_EXPLOSIVENESS = 5 / EM_COUNT_PER_MATERIAL_AMOUNT; + + private boolean fixMe = false; + private final List<EntityPlayer> playersWithCharge = new ArrayList<>(); + private final ArrayList<Chunk> worldDataArrayList = new ArrayList<>(512); @Override public String getTagName() { @@ -68,7 +70,7 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickWorld(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.WorldTickEvent aEvent) { if (TecTech.RANDOM.nextInt(MEAN_DELAY) == 0) { - int dim = aEvent.world.provider.dimensionId; + int dim = aEvent.world.provider.dimensionId; ChunkDataHandler.ChunkHashMap chunkHashMap = data.get(dim); chunkHashMap.forEach((chunkCoordIntPair, compound) -> { if (compound.getDouble(INTENSITY) > SWAP_THRESHOLD) { @@ -79,17 +81,17 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } }); if (worldDataArrayList.size() >= 2) { - Chunk a = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); - Chunk b = worldDataArrayList.get(TecTech.RANDOM.nextInt(worldDataArrayList.size())); + Chunk a = worldDataArrayList.remove(TecTech.RANDOM.nextInt(worldDataArrayList.size())); + Chunk b = worldDataArrayList.get(TecTech.RANDOM.nextInt(worldDataArrayList.size())); ChunkCoordIntPair aCoords = a.getChunkCoordIntPair(); ChunkCoordIntPair bCoords = b.getChunkCoordIntPair(); double newValue = (chunkHashMap.get(aCoords).getDouble(INTENSITY) + - chunkHashMap.get(bCoords).getDouble(INTENSITY))/2-SWAP_THRESHOLD/8; - float split=TecTech.RANDOM.nextFloat(); + chunkHashMap.get(bCoords).getDouble(INTENSITY)) / 2 - SWAP_THRESHOLD / 8; + float split = TecTech.RANDOM.nextFloat(); chunkHashMap.get(aCoords).setDouble(INTENSITY, newValue * split); - chunkHashMap.get(bCoords).setDouble(INTENSITY, newValue * (1-split)); + chunkHashMap.get(bCoords).setDouble(INTENSITY, newValue * (1 - split)); chunkHashMap.markForTransmissionToClient(aCoords); chunkHashMap.markForTransmissionToClient(bCoords); swapSomething(a, b, newValue); @@ -111,20 +113,20 @@ public class AnomalyHandler implements IChunkMetaDataHandler { if (other == player) { continue outer; } - double field = getCharge(player); + double field = getCharge(player); double absDifference = Math.abs(field - fieldOther); if (absDifference != 0) { if (player.getDistanceSqToEntity(other) < 1) { double avg = (fieldOther + field) / 2; //addAnomaly(other.worldObj.provider.dimensionId, new ChunkCoordIntPair(other.chunkCoordX, other.chunkCoordZ), Math.min(SWAP_THRESHOLD, PER_PARTICLE * absDifference)); - if(TecTech.configTecTech.BOOM_ENABLE){ - other.worldObj.createExplosion(other, other.posX, other.posY, other.posZ,(float) Math.min(CHARGE_EXPLOSIVENESS * absDifference, 25), true); + if (TecTech.configTecTech.BOOM_ENABLE) { + other.worldObj.createExplosion(other, other.posX, other.posY, other.posZ, (float) Math.min(CHARGE_EXPLOSIVENESS * absDifference, 25), true); player.worldObj.createExplosion(player, player.posX, player.posY, player.posZ, (float) Math.min(CHARGE_EXPLOSIVENESS * absDifference, 25), true); } - GT_Utility.sendSoundToPlayers(other.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (int)other.posX, (int)other.posY, (int)other.posZ); - GT_Utility.sendSoundToPlayers(player.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (int)player.posX, (int)player.posY, (int)player.posZ); - setCharge(player,avg); - setCharge(other,avg); + GT_Utility.sendSoundToPlayers(other.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (int) other.posX, (int) other.posY, (int) other.posZ); + GT_Utility.sendSoundToPlayers(player.worldObj, GregTech_API.sSoundList.get(209), 1.0F, -1, (int) player.posX, (int) player.posY, (int) player.posZ); + setCharge(player, avg); + setCharge(other, avg); } } } @@ -133,16 +135,16 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } - private void swapSomething(Chunk a,Chunk b,double mass) { - float explosionPower=(float) Math.log(mass/ EM_COUNT_PER_MATERIAL_AMOUNT); - for (int i = 0; i < Math.min((int)explosionPower,64); i++) { - int x = TecTech.RANDOM.nextInt(16); - int y = TecTech.RANDOM.nextInt(a.worldObj.getActualHeight()); - int z = TecTech.RANDOM.nextInt(16); + private void swapSomething(Chunk a, Chunk b, double mass) { + float explosionPower = (float) Math.log(mass / EM_COUNT_PER_MATERIAL_AMOUNT); + for (int i = 0; i < Math.min((int) explosionPower, 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); + 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); @@ -156,19 +158,19 @@ public class AnomalyHandler implements IChunkMetaDataHandler { 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.configTecTech.BOOM_ENABLE){ + if (TecTech.configTecTech.BOOM_ENABLE) { if (TecTech.RANDOM.nextBoolean()) { - a.worldObj.createExplosion(null, (a.xPosition << 4) + x + .5, y + .5, (a.zPosition << 4) + z + .5, explosionPower*TecTech.RANDOM.nextFloat(), true); + a.worldObj.createExplosion(null, (a.xPosition << 4) + x + .5, y + .5, (a.zPosition << 4) + z + .5, explosionPower * TecTech.RANDOM.nextFloat(), 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, explosionPower*TecTech.RANDOM.nextFloat(), true); + b.worldObj.createExplosion(null, (b.xPosition << 4) + x + .5, y + .5, (b.zPosition << 4) + z + .5, explosionPower * TecTech.RANDOM.nextFloat(), 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; + int x = (b.xPosition - a.xPosition) << 4; + int z = (b.xPosition - a.xPosition) << 4; List<EntityLivingBase> aE = a.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, Util.fromChunk(a)); List<EntityLivingBase> bE = b.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, Util.fromChunk(b)); for (EntityLivingBase entityLivingBase : aE) { @@ -220,9 +222,9 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickPlayer(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.PlayerTickEvent aEvent) { if (aEvent.side.isClient()) { - EntityPlayer player = TecTech.proxy.getPlayer(); - ChunkCoordIntPair pair = new ChunkCoordIntPair(player.chunkCoordX, player.chunkCoordZ); - NBTTagCompound compound = data.get(player.worldObj.provider.dimensionId).get(pair); + EntityPlayer player = TecTech.proxy.getPlayer(); + 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, badness = (int) Math.min(COUNT_DIV, compound.getDouble(INTENSITY) / PER_PARTICLE); i < badness; i++) { TecTech.proxy.em_particle(player.worldObj, @@ -245,18 +247,18 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } } 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); - boolean saveRequired = false; + 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); + boolean saveRequired = false; if (!player.capabilities.isCreativeMode) { - double cancer=getCancer(player); + double cancer = getCancer(player); 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, cancer + 9.765625E-4f * badness)); - player.attackEntityFrom(MainLoader.subspace,Math.max(1,badness/8f)); + player.attackEntityFrom(MainLoader.subspace, Math.max(1, badness / 8f)); saveRequired = true; } } else if (playerTag.getDouble(SPACE_CANCER) > 0 && !player.isDead) { @@ -276,14 +278,14 @@ public class AnomalyHandler implements IChunkMetaDataHandler { @Override public void tickRender(HashMap<Integer, ChunkDataHandler.ChunkHashMap> data, TickEvent.RenderTickEvent aEvent) { - EntityPlayer player=TecTech.proxy.getPlayer(); - if(player!=null) { - if(!player.capabilities.isCreativeMode) { - double cancer = getCancer(player)*CANCER_EFFECTIVENESS; + EntityPlayer player = TecTech.proxy.getPlayer(); + if (player != null) { + if (!player.capabilities.isCreativeMode) { + double cancer = getCancer(player) * CANCER_EFFECTIVENESS; if (cancer > 0) { player.setInvisible(fixMe = TecTech.RANDOM.nextFloat() * 2 < cancer); player.setAngles((TecTech.RANDOM.nextFloat() - .5F) * 36 * (float) cancer, (TecTech.RANDOM.nextFloat() - .5F) * 36 * (float) cancer); - cancer*=cancer/2F; + 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 { @@ -292,23 +294,22 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } double charge = getCharge(player); - if(charge!=0) { + if (charge != 0) { for (Object o : player.worldObj.playerEntities) { if (o instanceof EntityPlayer && !((EntityPlayer) o).capabilities.isCreativeMode) { - EntityPlayer otherPlayer=(EntityPlayer)o; - double chargeOther = getCharge(otherPlayer); + EntityPlayer otherPlayer = (EntityPlayer) o; + double chargeOther = getCharge(otherPlayer); if (chargeOther != 0 && player != o) { double reaction = chargeOther * charge; - if (reaction !=0) { + 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); - effect=-effect; - otherPlayer.addVelocity(effect * dX, effect * dY, effect * dZ); + double dX = (player.posX - otherPlayer.posX) * effect; + double dY = (player.posY - otherPlayer.posY) * effect; + double dZ = (player.posZ - otherPlayer.posZ) * effect; + player.addVelocity(dX, dY, dZ); + otherPlayer.addVelocity(-dX, -dY, -dZ); } } } @@ -316,35 +317,38 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } } - float mass=TecTech.playerPersistence.getDataOrSetToNewTag(player).getFloat(SPACE_MASS); - if(mass!=0) { + double mass = getMass(player); + if (mass != 0) { for (Object o : player.worldObj.playerEntities) { if (o instanceof EntityPlayer && !((EntityPlayer) o).capabilities.isCreativeMode) { - EntityPlayer otherPlayer=(EntityPlayer)o; - float massOther = TecTech.playerPersistence.getDataOrSetToNewTag(otherPlayer).getFloat(SPACE_MASS); + EntityPlayer otherPlayer = (EntityPlayer) o; + double massOther = getMass(otherPlayer); if (massOther != 0 && player != o) { - float reaction = massOther * mass; - if (reaction !=0) { + double reaction = massOther * mass; + if (reaction != 0) { double distanceSq = otherPlayer.getDistanceSqToEntity(player); if (distanceSq >= 1) { - double effect = GRAVITY_EFFECTIVENESS * reaction / (distanceSq * distanceSq * distanceSq); - double dX = player.posX - otherPlayer.posX; - double dY = player.posY - otherPlayer.posY; - double dZ = player.posZ - otherPlayer.posZ; - otherPlayer.addVelocity(effect * dX, effect * dY, effect * dZ); - effect=-effect; - player.addVelocity(effect * dX, effect * dY, effect * dZ); + double effect = MASS_EFFECTIVENESS * reaction / (distanceSq * distanceSq * distanceSq); + double effect1 = effect / mass; + double effect2 = effect / massOther; + double[] dPos = new double[]{player.posX - otherPlayer.posX, player.posY - otherPlayer.posY, player.posZ - otherPlayer.posZ}; + double[] vel = new double[]{player.motionX, player.motionY, player.motionZ}; + double[] out = new double[3]; + crossProduct3D(dPos, vel, out); + crossProduct3D(out, dPos, vel); + normalize3D(vel,out); + player.addVelocity(effect1 * out[0], effect1 * out[1], effect1 * out[2]); + otherPlayer.addVelocity(effect2 * -out[0], effect2 * -out[1], effect2 * -out[2]); } } } } } - } } - if (fixMe){ + if (fixMe) { player.setInvisible(false); - fixMe=false; + fixMe = false; } } } @@ -365,14 +369,14 @@ public class AnomalyHandler implements IChunkMetaDataHandler { } public void addAnomaly(IGregTechTileEntity gtTile, double amount) { - addAnomaly(gtTile.getWorld(),gtTile.getXCoord(),gtTile.getZCoord(),amount); + addAnomaly(gtTile.getWorld(), gtTile.getXCoord(), gtTile.getZCoord(), amount); } public void addAnomaly(TileEntity tileEntity, double amount) { - addAnomaly(tileEntity.getWorldObj(),tileEntity.xCoord,tileEntity.zCoord,amount); + addAnomaly(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.zCoord, amount); } - public void addAnomaly(World w,int x,int z, double amount) { + public void addAnomaly(World w, int x, int z, double amount) { if (!w.isRemote) { addAnomaly(w.provider.dimensionId, new ChunkCoordIntPair( @@ -394,43 +398,55 @@ public class AnomalyHandler implements IChunkMetaDataHandler { TecTech.chunkDataHandler.getChunkData(this, world).markForTransmissionToClient(chunk); } - public double getCharge(EntityPlayer player){ - return getDouble(player,SPACE_CHARGE); + public double getCharge(EntityPlayer player) { + return getDouble(player, SPACE_CHARGE); + } + + public void setCharge(EntityPlayer player, double amount) { + setDouble(player, SPACE_CHARGE, amount); + } + + public void addCharge(EntityPlayer player, double amount) { + addDouble(player, SPACE_CHARGE, amount); + } + + public double getMass(EntityPlayer player) { + return getDouble(player, SPACE_MASS); } - public void setCharge(EntityPlayer player, double amount){ - setDouble(player,SPACE_CHARGE,amount); + public void setMass(EntityPlayer player, double amount) { + setDouble(player, SPACE_MASS, amount); } - public void addCharge(EntityPlayer player, double amount){ - addDouble(player,SPACE_CHARGE,amount); + public void addMass(EntityPlayer player, double amount) { + addDouble(player, SPACE_MASS, amount); } - public double getCancer(EntityPlayer player){ - return getDouble(player,SPACE_CANCER); + public double getCancer(EntityPlayer player) { + return getDouble(player, SPACE_CANCER); } - public void setCancer(EntityPlayer player, double amount){ - setDouble(player,SPACE_CANCER,amount); + public void setCancer(EntityPlayer player, double amount) { + setDouble(player, SPACE_CANCER, amount); } - public void addCancer(EntityPlayer player, double amount){ - addDouble(player,SPACE_CANCER,amount); + public void addCancer(EntityPlayer player, double amount) { + addDouble(player, SPACE_CANCER, amount); } - public double getDouble(EntityPlayer player,String name){ + public double getDouble(EntityPlayer player, String name) { return TecTech.playerPersistence.getDataOrSetToNewTag(player).getDouble(name); } - public void setDouble(EntityPlayer player,String name, double amount){ + public void setDouble(EntityPlayer player, String name, double amount) { TecTech.playerPersistence.getDataOrSetToNewTag(player).setDouble(name, amount); TecTech.playerPersistence.saveData(player); NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player)); } - public void addDouble(EntityPlayer player,String name, double amount){ + public void addDouble(EntityPlayer player, String name, double amount) { NBTTagCompound data = TecTech.playerPersistence.getDataOrSetToNewTag(player); - data.setDouble(name, amount+data.getDouble(name)); + data.setDouble(name, amount + data.getDouble(name)); TecTech.playerPersistence.saveData(player); NetworkDispatcher.INSTANCE.sendToAll(new PlayerDataMessage.PlayerDataData(player)); } diff --git a/src/main/java/com/github/technus/tectech/mechanics/anomaly/MassCommand.java b/src/main/java/com/github/technus/tectech/mechanics/anomaly/MassCommand.java new file mode 100644 index 0000000000..3d0ade5082 --- /dev/null +++ b/src/main/java/com/github/technus/tectech/mechanics/anomaly/MassCommand.java @@ -0,0 +1,77 @@ +package com.github.technus.tectech.mechanics.anomaly; + +import com.github.technus.tectech.TecTech; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.ChatComponentText; + +import java.util.ArrayList; +import java.util.List; + +public class MassCommand implements ICommand { + ArrayList<String> aliases=new ArrayList<>(); + + public MassCommand(){ + aliases.add("mass_EM"); + aliases.add("mass"); + } + + @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; + if(player.capabilities.isCreativeMode){ + sender.addChatMessage(new ChatComponentText("Doesn't really work in creative mode!")); + }else { + TecTech.anomalyHandler.setMass(player,amount); + sender.addChatMessage(new ChatComponentText("Mass 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 "mass_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/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 2a04af23d1..8b55c16831 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 @@ -27,8 +27,6 @@ import net.minecraft.world.EnumSkyBlock; import net.minecraftforge.common.util.ForgeDirection; import org.apache.commons.lang3.reflect.FieldUtils; -import java.util.Locale; - import static com.github.technus.tectech.loader.MainLoader.elementalPollution; import static com.github.technus.tectech.util.CommonValues.DISPERSE_AT; import static com.github.technus.tectech.util.CommonValues.V; @@ -188,6 +186,9 @@ public class GT_MetaTileEntity_Hatch_OverflowElemental extends GT_MetaTileEntity ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.confusion.id, 1, (int) (damagingFactor * 20))); ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.wither.id, 2, (int) (damagingFactor * 15))); ((EntityLivingBase) entity).attackEntityFrom(elementalPollution, damagingFactor); + if(entity instanceof EntityPlayer) { + TecTech.anomalyHandler.addMass((EntityPlayer) entity,overflowDisperse); + } } } diff --git a/src/main/java/com/github/technus/tectech/util/Util.java b/src/main/java/com/github/technus/tectech/util/Util.java index 78522a2ae8..489246e061 100644 --- a/src/main/java/com/github/technus/tectech/util/Util.java +++ b/src/main/java/com/github/technus/tectech/util/Util.java @@ -573,4 +573,24 @@ public final class Util { } return stringBuilder.toString(); } + + public static double getMagnitude3D(double in[]) + { + return Math.sqrt(in[0]*in[0]+in[1]*in[1]+in[2]*in[2]); + } + + public static void normalize3D(double in[], double out[]) + { + double mag=getMagnitude3D(in); + out[0]=in[0]/mag; + out[1]=in[1]/mag; + out[2]=in[2]/mag; + } + + public static void crossProduct3D(double inA[], double inB[], double out[]) + { + out[0] = inA[1] * inB[2] - inA[2] * inB[1]; + out[1] = inA[2] * inB[0] - inA[0] * inB[2]; + out[2] = inA[0] * inB[1] - inA[1] * inB[0]; + } } |