Effects of Marx discharges on entities:

Damage for thos close to the discharge, tinnitus for those further out
Also added a nice bang for discharges (it is from a cap bank rather than a Marx though)
This commit is contained in:
malte0811 2017-06-16 22:04:30 +02:00
parent d65621a0b5
commit 143311aecf
12 changed files with 255 additions and 21 deletions

View file

@ -56,10 +56,10 @@ minecraft {
}
repositories {
maven {
name 'ic2'
url 'http://maven.ic2.player.to/'
}
//maven {
// name 'ic2'
// url 'http://maven.ic2.player.to/'
//}
maven {
name 'jared maven'
url 'http://blamejared.com/maven'
@ -68,7 +68,7 @@ repositories {
dependencies {
// deobfCompile "net.industrial-craft:industrialcraft-2:2.7.+:api"
// deobfCompile "blusunrize:ImmersiveEngineering:0.11-+:deobf"
deobfCompile "blusunrize:ImmersiveEngineering:0.11-+:deobf"
}
jar {

View file

@ -20,6 +20,7 @@ package malte0811.industrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
@ -47,6 +48,8 @@ public class CommonProxy implements IGuiHandler {
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
}
public void startTinnitus() {
}
@Override
public Container getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@ -76,4 +79,6 @@ public class CommonProxy implements IGuiHandler {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
public void playMarxBang(TileEntityMarx tileEntityMarx, Vec3d vec3d, float energy) {}
}

View file

@ -0,0 +1,32 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
import net.minecraft.util.DamageSource;
public class IWDamageSources {
public static class MarxDamage extends DamageSource {
public MarxDamage() {
super("industrialwires.marx");
setDamageBypassesArmor();
}
}
public static final MarxDamage dmg_marx = new MarxDamage();
public static final DamageSource dmg_jacobs = new DamageSource("industrialwires.jacobs_ladder");
}

View file

@ -0,0 +1,54 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
public class IWPotions {
public static PotionTinnitus tinnitus;
public static void init() {
tinnitus = new PotionTinnitus();
}
static class PotionTinnitus extends Potion {
protected PotionTinnitus() {
super(true, 0xffff0000);
REGISTRY.register(-1, new ResourceLocation(IndustrialWires.MODID, "tinnitus"), this);
}
@Override
public boolean isReady(int duration, int amplifier) {
return true;
}
@Override
public void performEffect(@Nonnull EntityLivingBase affected, int amp) {
if (affected.getEntityWorld().isRemote) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.player==affected) {
IndustrialWires.proxy.startTinnitus();
}
}
}
}
}

View file

@ -110,6 +110,8 @@ public class IndustrialWires {
throw new IllegalStateException("No IC2 wires registered");
}
MultiblockHandler.registerMultiblock(new MultiblockMarx());
IWPotions.init();
proxy.preInit();
}

View file

@ -26,6 +26,7 @@ import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IWDamageSources;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.IHasDummyBlocksIW;
@ -43,7 +44,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@ -329,7 +333,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
private void hurtEntity(Entity e) {
e.attackEntityFrom(new DamageSource("industrialwires.jacobs_ladder"), IWConfig.HVStuff.jacobsBaseDmg * (size.ordinal() + 1));
e.attackEntityFrom(IWDamageSources.dmg_jacobs, IWConfig.HVStuff.jacobsBaseDmg * (size.ordinal() + 1));
}
public boolean onActivated(EntityPlayer player, EnumHand hand) {

View file

@ -31,6 +31,8 @@ import blusunrize.immersiveengineering.common.blocks.metal.*;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.IIC2Connector;
import malte0811.industrialWires.IWDamageSources;
import malte0811.industrialWires.IWPotions;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.ISyncReceiver;
@ -43,10 +45,14 @@ import malte0811.industrialWires.util.MiscUtils;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
@ -61,6 +67,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
@ -105,6 +112,11 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
out.setInteger(STAGES, stageCount);
out.setBoolean(HAS_CONN, hasConnection);
storage.writeToNbt(out, ENERGY_TAG);
NBTTagList voltages = new NBTTagList();
for (int i = 0;i<stageCount;i++) {
voltages.appendTag(new NBTTagDouble(capVoltages[i]));
}
out.setTag(CAP_VOLTAGES, voltages);
}
@Override
@ -195,20 +207,10 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
}
} else if (state==FiringState.NEXT_TICK) {
state = FiringState.FIRE;
if (!world.isRemote) {
//calculate energy
double energyStored = 0;
//TODO handle high cap voltage differences
for (int i = 0;i<stageCount;i++) {
energyStored += capVoltages[i]*capVoltages[i]/cReciproke;
capVoltages[i] = 0;
}
net.updateValues();
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
IndustrialWires.packetHandler.sendToDimension(new MessageTileSyncIW(this, data), world.provider.getDimension());
if (world.isRemote) {
IndustrialWires.proxy.playMarxBang(this, getMiddle(), dischargeData.energy/(stageCount*250*250));
} else {
dischargingMarxes.add(this);//TODO deal with breaking during discharges
fire();
}
}
if (!world.isRemote&&type== IWProperties.MarxType.BOTTOM) {
@ -244,6 +246,64 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
}
}
private void fire() {
if (!world.isRemote) {
//calculate energy
double energyStored = 0;
//TODO handle high cap voltage differences
for (int i = 0;i<stageCount;i++) {
energyStored += capVoltages[i]*capVoltages[i]/cReciproke;
capVoltages[i] = 0;
}
net.updateValues();
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
IndustrialWires.packetHandler.sendToDimension(new MessageTileSyncIW(this, data), world.provider.getDimension());
Vec3d v0 = getMiddle();
AxisAlignedBB aabb = new AxisAlignedBB(v0, v0);
aabb = aabb.expand(0, stageCount/2-1,0);
final double sqrtStages = Math.sqrt(stageCount);
aabb = aabb.expandXyz(5*sqrtStages);
List<EntityLivingBase> fools = world.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
double energyNormed = energyStored/(stageCount*250*250);
double damageDistSqu = .5*energyNormed*sqrtStages;
double tinnitusDistSqu = 3*energyNormed*sqrtStages;
damageDistSqu *= damageDistSqu;
tinnitusDistSqu *= tinnitusDistSqu;
for (EntityLivingBase entity:fools) {
double y;
if (entity.posY<pos.getY()+1) {
y = pos.getY()+1;
} else if (entity.posY>pos.getY()+stageCount-2) {
y = pos.getY()+stageCount-2;
} else {
y = entity.posY;
}
double distSqu = entity.getDistanceSq(v0.xCoord, y, v0.zCoord);
if (distSqu<=damageDistSqu) {
//TODO damage entity
float dmg = (float) (10*stageCount*(1-distSqu/damageDistSqu));
entity.attackEntityFrom(IWDamageSources.dmg_marx, dmg);
}
if (distSqu<=tinnitusDistSqu && entity instanceof EntityPlayer) {
ItemStack helmet = ((EntityPlayer) entity).inventory.armorInventory.get(3);
boolean earMuff = helmet.getItem()==IEContent.itemEarmuffs;
if (!earMuff&&helmet.hasTagCompound()) {
earMuff = helmet.getTagCompound().hasKey("IE:Earmuffs");
}
if (!earMuff) {//TODO they work on other helmets, don't they?
//TODO 13kHz
double multipl = Math.min(5, Math.sqrt(stageCount));
int duration = (int) (20*20*(1+multipl*(1-distSqu/tinnitusDistSqu)));
entity.addPotionEffect(new PotionEffect(IWPotions.tinnitus, duration));
}
}
}
} else {
dischargingMarxes.add(this);//TODO deal with breaking during discharges
}
}
@Override
public Vec3i getSize() {
return new Vec3i(stageCount, 8, 2);
@ -502,6 +562,12 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
return stageCount;
}
public Vec3d getMiddle() {
double middleY = pos.getY()+(stageCount)/2D;
Vec3i electrodXZ = MiscUtils.offset(pos, facing, mirrored, 1, 4, 0);
return new Vec3d(electrodXZ.getX()+.5, middleY, electrodXZ.getZ()+.5);
}
public enum FiringState {
CHARGING,
NEXT_TICK,

View file

@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableMap;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.CommonProxy;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IWPotions;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
@ -49,6 +50,7 @@ import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.MovingSound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.block.model.ModelBakery;
@ -60,6 +62,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@ -69,6 +72,7 @@ import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import java.util.Arrays;
import java.util.Locale;
import java.util.Random;
import java.util.WeakHashMap;
@ -253,6 +257,49 @@ public class ClientProxy extends CommonProxy {
);
}
private static ISound tinnitus;
@Override
public void startTinnitus() {
final Minecraft mc = Minecraft.getMinecraft();
if (tinnitus==null) {
tinnitus = new MovingSound(new SoundEvent(new ResourceLocation(IndustrialWires.MODID, "tinnitus")), SoundCategory.PLAYERS) {
@Override
public void update() {
if (mc.player.getActivePotionEffect(IWPotions.tinnitus)==null) {
donePlaying = true;
}
}
@Override
public float getXPosF() {
return (float) mc.player.posX;
}
@Override
public float getYPosF() {
return (float) mc.player.posY;
}
@Override
public float getZPosF() {
return (float) mc.player.posZ;
}
@Override
public boolean canRepeat() {
return true;
}
};
int oldLength = Config.IEConfig.Tools.earDefenders_SoundBlacklist.length;
Config.IEConfig.Tools.earDefenders_SoundBlacklist =
Arrays.copyOf(Config.IEConfig.Tools.earDefenders_SoundBlacklist, oldLength+1);
Config.IEConfig.Tools.earDefenders_SoundBlacklist[oldLength] = tinnitus.getSoundLocation().toString();
}
if (!mc.getSoundHandler().isSoundPlaying(tinnitus)) {
mc.getSoundHandler().playSound(tinnitus);
}
}
@Override
public World getClientWorld() {
return Minecraft.getMinecraft().world;
@ -262,6 +309,7 @@ public class ClientProxy extends CommonProxy {
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
private static ResourceLocation marxBang = new ResourceLocation(IndustrialWires.MODID, "marx_bang");
@Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
@ -288,6 +336,13 @@ public class ClientProxy extends CommonProxy {
playingSounds.put(te.getPos(), sound);
}
@Override
public void playMarxBang(TileEntityMarx te, Vec3d pos, float energy) {
PositionedSoundRecord sound = new PositionedSoundRecord(marxBang, SoundCategory.BLOCKS, 5*energy, 1, false, 0, ISound.AttenuationType.LINEAR, (float) pos.xCoord, (float) pos.yCoord, (float) pos.zCoord);
ClientUtils.mc().getSoundHandler().playSound(sound);
playingSounds.put(te.getPos(), sound);
}
@Override
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == 0) {
@ -311,4 +366,5 @@ public class ClientProxy extends CommonProxy {
}
return null;
}
}

View file

@ -80,6 +80,7 @@ industrialwires.chat.tooLong=This coil does not contain enough wire for this con
industrialwires.chat.stackSize=Linking is only possible with a stack of size 1
death.attack.industrialwires.jacobs_ladder=%1$s was electrocuted by a Jacob's Ladder
death.attack.industrialwires.marx=%1$s was struck by lightning produced by a Marx generator
itemGroup.industrialwires=Industrial Wires

View file

@ -19,5 +19,19 @@
"sounds": [
"industrialwires:jacobs_ladder/end"
]
},
"tinnitus": {
"category": "player",
"subtitle": "industrialwires.subtitle.tinnitus",
"sounds": [
"industrialwires:tinnitus"
]
},
"marx_bang": {
"category": "block",
"subtitle": "industrialwires.subtitle.marx_bang",
"sounds": [
"industrialwires:marx_bang"
]
}
}
}