Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jake/lightning port #267

Open
wants to merge 11 commits into
base: FD/OldPackets
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
55 changes: 52 additions & 3 deletions src/main/java/com/crowsofwar/avatar/AvatarMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.crowsofwar.avatar.blocks.AvatarBlocks;
import com.crowsofwar.avatar.client.gui.AvatarGuiHandler;
import com.crowsofwar.avatar.client.particle.AvatarParticles;
import com.crowsofwar.avatar.client.render.lightning.main.ModEventHandler;
import com.crowsofwar.avatar.client.render.lightning.main.PacketDispatcher;
import com.crowsofwar.avatar.common.triggers.AvatarTriggers;
import com.crowsofwar.avatar.config.*;
import com.crowsofwar.avatar.entity.*;
Expand Down Expand Up @@ -66,9 +68,14 @@
import com.crowsofwar.avatar.util.windhelper.WindHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.RangedAttribute;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand All @@ -81,11 +88,16 @@
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Logger;
import org.joml.Matrix4f;
import org.joml.Vector4f;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Random;

import static com.crowsofwar.avatar.config.ConfigMobs.MOBS_CONFIG;
import static com.crowsofwar.avatar.config.ConfigStats.STATS_CONFIG;
Expand All @@ -112,6 +124,17 @@ public class AvatarMod {
private int nextMessageID = 1;
private int nextEntityID = 1;

// From Drillgon's MainRegistry
public static Logger logger;
public static int generalOverride = 0;
public static int polaroidID = 1;
public static final int schrabFromUraniumChance = 100;
public static int x;
public static int y;
public static int z;
public static long time;
Random rand = new Random();


private static void registerAbilities() {
/* Air */
Expand Down Expand Up @@ -349,7 +372,25 @@ public void preInit(FMLPreInitializationEvent e) {
}
}**/


// From Drillgon's MainRegistry
if(generalOverride > 0 && generalOverride < 19) {
polaroidID = generalOverride;
} else {
polaroidID = rand.nextInt(18) + 1;
while(polaroidID == 4 || polaroidID == 9)
polaroidID = rand.nextInt(18) + 1;
}
if(SharedMonsterAttributes.MAX_HEALTH.clampValue(Integer.MAX_VALUE) <= 2000)
try{
@SuppressWarnings("deprecation")
Field f = ReflectionHelper.findField(RangedAttribute.class, "maximumValue", "field_111118_b");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
f.set(SharedMonsterAttributes.MAX_HEALTH, Integer.MAX_VALUE);
} catch(Exception ignored){}
proxy.checkGLCaps();
reloadConfig();
}

@EventHandler
Expand Down Expand Up @@ -422,10 +463,19 @@ public void init(FMLInitializationEvent e) {

proxy.init();
proxy.registerParticles();
PacketDispatcher.registerPackets();
MinecraftForge.EVENT_BUS.register(new ModEventHandler());

AvatarTriggers.init();

}

public static void reloadConfig() {
// Configuration config = new Configuration(new File(proxy.getDataDir().getPath() + "/config/hbm/hbm.cfg"));
// config.load();
// config.save();
}

@EventHandler
public void postInit(FMLPostInitializationEvent e) {
AvatarAnalytics.INSTANCE.init();
Expand All @@ -438,10 +488,9 @@ public void postInit(FMLPostInitializationEvent e) {
mat.rotate(90, 1, 0, 0);
Vector4f v = new Vector4f(2, 1, 1, 1).mul(mat);
}

//Allows for BendingContext shenanigans
Abilities.all().forEach(Ability::postInit);

proxy.postInit(e);
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crowsofwar.avatar.bending.bending.lightning;

import com.crowsofwar.avatar.client.particle.AvatarParticles;
import com.crowsofwar.avatar.client.render.lightning.main.*;
import com.crowsofwar.avatar.util.data.AbilityData;
import com.crowsofwar.avatar.util.data.BendingData;
import com.crowsofwar.avatar.util.data.TickHandler;
Expand All @@ -9,14 +10,21 @@
import com.crowsofwar.avatar.client.particle.NetworkParticleSpawner;
import com.crowsofwar.avatar.client.particle.ParticleSpawner;
import com.crowsofwar.gorecore.util.Vector;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;

import javax.annotation.Nullable;
import java.util.UUID;
Expand Down Expand Up @@ -60,53 +68,149 @@ public boolean tick(BendingContext ctx) {

int duration = data.getTickHandlerDuration(this);

float movementMultiplier = 0.6f - 0.7f * MathHelper.sqrt(duration / 40f);
applyMovementModifier(entity, MathHelper.clamp(movementMultiplier, 0.1f, 1));
double inverseRadius = (40F - duration) / 10;

if (duration % 3 == 0) {
for (int i = 0; i < 8; i++) {
Vector lookpos = Vector.toRectangular(Math.toRadians(entity.rotationYaw +
i * 45), 0).times(inverseRadius).withY(entity.getEyeHeight() / 2);
particleSpawner.spawnParticles(world, AvatarParticles.getParticleElectricity(), 1, 2, lookpos.x() + entity.posX,
lookpos.y() + entity.getEntityBoundingBox().minY, lookpos.z() + entity.posZ, 2, 1.2, 2, true);
}
}

if (duration >= 40) {

AbilityData abilityData = getLightningData(ctx);
if (abilityData == null) {
return true;
}

double speed = abilityData.getLevel() >= 1 ? 30 : 40;
float damage = abilityData.getLevel() >= 2 ? 8 : 6;
float size = 1;
float[] turbulenceValues = { 0.6f, 1.2f };

if (abilityData.isMasterPath(AbilityData.AbilityTreePath.FIRST)) {
damage = 12;
size = 0.75f;
turbulenceValues = new float[] { 0.6f, 1.2f, 0.8f };
EntityPlayer player = (EntityPlayer) entity;

if(!player.world.isRemote) {
NBTTagCompound perDat = player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
int lightning = perDat.getInteger("lightningCharge");
if(lightning > 0){
lightning ++;
if(lightning == 60){
RayTraceResult r = Library.rayTraceIncludeEntities(player, 100, 1);
if(r != null && r.typeOfHit != RayTraceResult.Type.MISS){
NBTTagCompound tag = new NBTTagCompound();
tag.setString("type", "lightning");
tag.setString("mode", "beam");
tag.setDouble("hitX", r.hitVec.x);
tag.setDouble("hitY", r.hitVec.y);
tag.setDouble("hitZ", r.hitVec.z);
Vec3d normal = new Vec3d(r.sideHit.getXOffset(), r.sideHit.getYOffset(), r.sideHit.getZOffset());
tag.setDouble("normX", normal.x);
tag.setDouble("normY", normal.y);
tag.setDouble("normZ", normal.z);
if(r.typeOfHit == RayTraceResult.Type.ENTITY){
r.entityHit.attackEntityFrom(ModDamageSource.electricity, 20);
if(r.entityHit instanceof EntityLiving && ((EntityLiving)r.entityHit).getHealth() <= 0){
r.entityHit.setDead();
PacketDispatcher.wrapper.sendToAllTracking(new PacketSpecialDeath(r.entityHit, 2, (float)player.getLookVec().x, (float)player.getLookVec().y, (float)player.getLookVec().z), new NetworkRegistry.TargetPoint(player.world.provider.getDimension(), r.entityHit.posX, r.entityHit.posY, r.entityHit.posZ, 0));
}
tag.setInteger("hitType", 1);
} else if(r.typeOfHit == RayTraceResult.Type.BLOCK){
tag.setInteger("hitType", 0);
}
Vec3d direction = player.getLookVec().scale(0.75);
switch(r.sideHit.getAxis()){
case X:
direction = new Vec3d(-direction.x, direction.y, direction.z);
break;
case Y:
direction = new Vec3d(direction.x, -direction.y, direction.z);
break;
case Z:
direction = new Vec3d(direction.x, direction.y, -direction.z);
break;
}
NBTTagCompound tag2 = new NBTTagCompound();
tag2.setString("type", "spark");
tag2.setString("mode", "coneBurst");
tag2.setDouble("posX", r.hitVec.x);
tag2.setDouble("posY", r.hitVec.y);
tag2.setDouble("posZ", r.hitVec.z);
tag2.setDouble("dirX", direction.x);
tag2.setDouble("dirY", direction.y);
tag2.setDouble("dirZ", direction.z);
tag2.setFloat("r", 0.4F);
tag2.setFloat("g", 0.8F);
tag2.setFloat("b", 0.9F);
tag2.setFloat("a", 2F);
tag2.setInteger("lifetime", 5);
tag2.setInteger("randLifetime", 20);
tag2.setFloat("width", 0.04F);
tag2.setFloat("length", 0.7F);
tag2.setFloat("randLength", 1.5F);
tag2.setFloat("gravity", 0.1F);
tag2.setFloat("angle", 80F);
tag2.setInteger("count", 60+player.world.rand.nextInt(20));
tag2.setFloat("randomVelocity", 0.4F);
PacketDispatcher.wrapper.sendToAllTracking(new AuxParticlePacketNT(tag2, r.hitVec.x, r.hitVec.y, r.hitVec.z), new NetworkRegistry.TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 0));
Vec3d ssgChainPos = new Vec3d(-0.18, -0.1, 0.35);
ssgChainPos = ssgChainPos.rotatePitch((float) Math.toRadians(-player.rotationPitch));
ssgChainPos = ssgChainPos.rotateYaw((float) Math.toRadians(-player.rotationYaw));
ssgChainPos = ssgChainPos.add(player.posX, player.posY + player.getEyeHeight(), player.posZ);
PacketDispatcher.wrapper.sendToAllTracking(new AuxParticlePacketNT(tag, ssgChainPos.x, ssgChainPos.y, ssgChainPos.z), new NetworkRegistry.TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 0));
} else {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("type", "lightning");
tag.setString("mode", "beam");
Vec3d hit = player.getPositionEyes(1).add(player.getLookVec().scale(100));
tag.setDouble("hitX", hit.x);
tag.setDouble("hitY", hit.y);
tag.setDouble("hitZ", hit.z);
tag.setInteger("hitType", -1);

Vec3d ssgChainPos = new Vec3d(-0.18, -0.1, 0.35);
ssgChainPos = ssgChainPos.rotatePitch((float) Math.toRadians(-player.rotationPitch));
ssgChainPos = ssgChainPos.rotateYaw((float) Math.toRadians(-player.rotationYaw));
ssgChainPos = ssgChainPos.add(player.posX, player.posY + player.getEyeHeight(), player.posZ);

PacketDispatcher.wrapper.sendToAllTracking(new AuxParticlePacketNT(tag, ssgChainPos.x, ssgChainPos.y, ssgChainPos.z), new NetworkRegistry.TargetPoint(player.world.provider.getDimension(), player.posX, player.posY, player.posZ, 0));
}
}
if(lightning == 84){
lightning = 0;
}
}
if (abilityData.isMasterPath(AbilityData.AbilityTreePath.SECOND)) {
size = 1.5f;
}

speed += powerRating / 15;
damage *= ctx.getBender().getDamageMult(Lightningbending.ID);

fireLightning(world, entity, damage, speed, size, turbulenceValues);

entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(MOVEMENT_MODIFIER_ID);

world.playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1, 2);

perDat.setInteger("lightningCharge", lightning);
return true;

}

// float movementMultiplier = 0.6f - 0.7f * MathHelper.sqrt(duration / 40f);
// applyMovementModifier(entity, MathHelper.clamp(movementMultiplier, 0.1f, 1));
// double inverseRadius = (40F - duration) / 10;

// if (duration % 3 == 0) {
// for (int i = 0; i < 8; i++) {
// Vector lookpos = Vector.toRectangular(Math.toRadians(entity.rotationYaw +
// i * 45), 0).times(inverseRadius).withY(entity.getEyeHeight() / 2);
// particleSpawner.spawnParticles(world, AvatarParticles.getParticleElectricity(), 1, 2, lookpos.x() + entity.posX,
// lookpos.y() + entity.getEntityBoundingBox().minY, lookpos.z() + entity.posZ, 2, 1.2, 2, true);
// }
// }

// if (duration >= 40) {
//
// AbilityData abilityData = getLightningData(ctx);
// if (abilityData == null) {
// return true;
// }
//
// double speed = abilityData.getLevel() >= 1 ? 30 : 40;
// float damage = abilityData.getLevel() >= 2 ? 8 : 6;
// float size = 1;
// float[] turbulenceValues = { 0.6f, 1.2f };
//
// if (abilityData.isMasterPath(AbilityData.AbilityTreePath.FIRST)) {
// damage = 12;
// size = 0.75f;
// turbulenceValues = new float[] { 0.6f, 1.2f, 0.8f };
// }
// if (abilityData.isMasterPath(AbilityData.AbilityTreePath.SECOND)) {
// size = 1.5f;
// }
//
// speed += powerRating / 15;
// damage *= ctx.getBender().getDamageMult(Lightningbending.ID);
//
// fireLightning(world, entity, damage, speed, size, turbulenceValues);
//
// entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(MOVEMENT_MODIFIER_ID);
//
// world.playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1, 2);
//
// return true;
//
// }

return false;

}
Expand Down
Loading
Loading