Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Cable Damage Update #6

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/ja13/eau/EAU.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class EAU {
public final static String URL = "https://eau.ja13.org";
public final static String UPDATE_URL = "https://github.com/jrddunbr/EAU/releases";
public final static String SRC_URL = "https://github.com/jrddunbr/EAU";
public final static String[] AUTHORS = {"jrddunbr"};
public final static String[] AUTHORS = {"jrddunbr","Omega Haxors"};
public static final String channelName = "EAU";

// The instance of your mod that Forge uses.
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/ja13/eau/misc/Coordonate.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ja13.eau.misc

import cpw.mods.fml.common.FMLCommonHandler
import org.ja13.eau.node.NodeBlockEntity
import net.minecraft.block.Block
import net.minecraft.entity.Entity
import net.minecraft.nbt.NBTTagCompound
Expand All @@ -10,6 +9,7 @@ import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.Vec3
import net.minecraft.world.World
import net.minecraftforge.common.DimensionManager
import javax.vecmath.Vector3d
OmegaHaxors marked this conversation as resolved.
Show resolved Hide resolved

class Coordonate : INBTTReady {
@JvmField
Expand Down Expand Up @@ -144,6 +144,21 @@ class Coordonate : INBTTReady {

fun distanceTo(e: Entity): Double {
return Math.abs(e.posX - (x + 0.5)) + Math.abs(e.posY - (y + 0.5)) + Math.abs(e.posZ - (z + 0.5))
//return Math.sqrt(Math.pow((e.posX - (x+0.5)),2.0) + Math.pow((e.posY - (y+0.5)),2.0) + Math.pow((e.posZ - (z+0.5)),2.0))
}

fun directionOf(e: Entity): Vector3d { //returns a normalized vector (normalized means vector with only direction)

//val normalized = e.lookVec //help I don't know how to create a vector. This will work for now.
val normalized = Vector3d(0.0,0.0,0.0)
normalized.x = (e.posX - (x+0.5))
normalized.y = (e.posY - (y+0.5))
normalized.z = (e.posZ - (z+0.5))
val magnitude = Math.sqrt(Math.pow((normalized.x),2.0) + Math.pow((normalized.y),2.0) + Math.pow((normalized.z),2.0))
normalized.x = normalized.x/magnitude
normalized.y = normalized.y/magnitude
normalized.z = normalized.z/magnitude
return normalized
}

val meta: Int
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/ja13/eau/registry/ItemRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,29 @@ class ItemRegistry {

private fun registerArmor() {
var name: String
val copperMaterial = EnumHelper.addArmorMaterial("Copper", 10, intArrayOf(1, 3, 2, 1), 15)
copperMaterial.customCraftingMaterial = EAU.copperIngot.newItemStack().item
run {
name = I18N.TR_NAME(I18N.Type.ITEM, "Copper Helmet")
EAU.helmetCopper = genericArmorItem(ArmorMaterial.IRON, 2, ArmourType.Helmet, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_helmet").setCreativeTab(EAU.itemTab) as ItemArmor
EAU.helmetCopper = genericArmorItem(copperMaterial, 2, ArmourType.Helmet, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_helmet").setCreativeTab(EAU.itemTab) as ItemArmor
GameRegistry.registerItem(EAU.helmetCopper, "Eln.$name")
GameRegistry.registerCustomItemStack(name, ItemStack(EAU.helmetCopper))
}
run {
name = I18N.TR_NAME(I18N.Type.ITEM, "Copper Chestplate")
EAU.plateCopper = genericArmorItem(ArmorMaterial.IRON, 2, ArmourType.Chestplate, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_chestplate").setCreativeTab(EAU.itemTab) as ItemArmor
EAU.plateCopper = genericArmorItem(copperMaterial, 2, ArmourType.Chestplate, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_chestplate").setCreativeTab(EAU.itemTab) as ItemArmor
GameRegistry.registerItem(EAU.plateCopper, "Eln.$name")
GameRegistry.registerCustomItemStack(name, ItemStack(EAU.plateCopper))
}
run {
name = I18N.TR_NAME(I18N.Type.ITEM, "Copper Leggings")
EAU.legsCopper = genericArmorItem(ArmorMaterial.IRON, 2, ArmourType.Leggings, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_leggings").setCreativeTab(EAU.itemTab) as ItemArmor
EAU.legsCopper = genericArmorItem(copperMaterial, 2, ArmourType.Leggings, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_leggings").setCreativeTab(EAU.itemTab) as ItemArmor
GameRegistry.registerItem(EAU.legsCopper, "Eln.$name")
GameRegistry.registerCustomItemStack(name, ItemStack(EAU.legsCopper))
}
run {
name = I18N.TR_NAME(I18N.Type.ITEM, "Copper Boots")
EAU.bootsCopper = genericArmorItem(ArmorMaterial.IRON, 2, ArmourType.Boots, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_boots").setCreativeTab(EAU.itemTab) as ItemArmor
EAU.bootsCopper = genericArmorItem(copperMaterial, 2, ArmourType.Boots, "eau:textures/armor/copper_layer_1.png", "eau:textures/armor/copper_layer_2.png").setUnlocalizedName(name).setTextureName("eau:copper_boots").setCreativeTab(EAU.itemTab) as ItemArmor
GameRegistry.registerItem(EAU.bootsCopper, "Eln.$name")
GameRegistry.registerCustomItemStack(name, ItemStack(EAU.bootsCopper))
OmegaHaxors marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
43 changes: 38 additions & 5 deletions src/main/java/org/ja13/eau/sixnode/electriccable/ElectricCable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.util.DamageSource
import net.minecraftforge.client.IItemRenderer
import net.minecraft.entity.EntityLiving
import org.ja13.eau.misc.Coordonate
import org.ja13.eau.misc.Direction
import org.ja13.eau.misc.LRDU
Expand All @@ -14,6 +15,10 @@ import org.ja13.eau.misc.VoltageTier
import org.ja13.eau.sim.mna.misc.MnaConst
import org.lwjgl.opengl.GL11
import java.util.*
import net.minecraft.entity.monster.EntityCreeper
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.entity.monster.EntityEnderman


class ElectricCableDescriptor(name: String, render: org.ja13.eau.cable.CableRenderDescriptor, val material: String = "Copper"): org.ja13.eau.sixnode.genericcable.GenericCableDescriptor(name, ElectricCableElement::class.java, ElectricCableRender::class.java) {

Expand Down Expand Up @@ -199,12 +204,40 @@ class PlayerHarmer(val electricalLoad: org.ja13.eau.sim.ElectricalLoad, private
override fun process(time: Double) {
val harmLevel = Math.max(0.0, (electricalLoad.u - 50 - insulationVoltage) / 500.0)
val objects = location.world().getEntitiesWithinAABB(Entity::class.java, location.getAxisAlignedBB(4))
for(obj in objects) {
for (obj in objects) {
val ent = obj as Entity
val distance = location.distanceTo(ent)
val pain = (harmFunction(distance) * harmLevel).toFloat()
if (distance < 3 && pain > 0.05) {
ent.attackEntityFrom(DamageSource("Cable"), pain)
if ((ent is EntityLiving || ent is EntityPlayerMP) && ent.isEntityAlive) {
val distance = location.distanceTo(ent)
val pain = (harmFunction(distance) * harmLevel).toFloat()
val iframes = ent.hurtResistantTime
if (pain > 0.05 && ent.onGround) {
var touching = false
var arcing = false
if (distance <= 1) {
touching = true
}
if (distance <= 3 && !touching && iframes == 0) {
arcing = true
}
if (touching || arcing) {
ent.attackEntityFrom(DamageSource("Cable"), pain)
if (touching) {
ent.hurtResistantTime = 2 //remove almost all I-frames
ent.setVelocity(Math.min(location.directionOf(ent).x * pain, 1.0), Math.min(0.5 * pain, 3.0), Math.min((location.directionOf(ent).z * pain), 1.0)) //yeet
}
if (arcing) {
ent.hurtResistantTime = 15 //remove some I-frames
ent.setVelocity(0.0, Math.min(pain / 2.0, 0.65), 0.0) //make the entity jump
}
//apply special effects to certain mobs
if (ent is EntityEnderman) { ent.setFire(1) } //enderman will teleport
if (ent is EntityCreeper) { //creepers will explode (aw man!)
location.world().createExplosion(ent, ent.posX, ent.posY, ent.posZ, 3f, true)
ent.customNameTag = "Electrically-detonated Creeper"
ent.setDead()
}
}
}
}
}
}
Expand Down