- AuraCore: Finished Animation...

This commit is contained in:
HellFirePvP committed 2015-12-03 15:43:37 +01:00
1 parent 341db1019b
commit 57be489c85
23 files changed
+655 -345

No files matched your search

@@ -15,6 +15,7 @@ import makeo.gadomancy.client.renderers.block.BlockExtendedNodeJarRenderer;
import makeo.gadomancy.client.renderers.block.RenderBlockStoneMachine;
import makeo.gadomancy.client.renderers.block.RenderBlockTransparent;
import makeo.gadomancy.client.renderers.entity.RenderAdditionalGolemBase;
import makeo.gadomancy.client.renderers.entity.RenderEntityAuraCore;
import makeo.gadomancy.client.renderers.entity.RenderEntityItem;
import makeo.gadomancy.client.renderers.item.ItemCreativeNodeRenderer;
import makeo.gadomancy.client.renderers.item.ItemExNodeRenderer;
@@ -149,7 +150,7 @@ public class ClientProxy extends CommonProxy {
//Entities
RenderingRegistry.registerEntityRenderingHandler(EntityPermNoClipItem.class, new RenderSpecialItem());
RenderingRegistry.registerEntityRenderingHandler(EntityAuraCore.class, new RenderEntityItem());
RenderingRegistry.registerEntityRenderingHandler(EntityAuraCore.class, new RenderEntityAuraCore());
//Blocks
RegisteredBlocks.rendererTransparentBlock = registerBlockRenderer(new RenderBlockTransparent());
@@ -1,7 +1,7 @@
package makeo.gadomancy.client.effect;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.client.effect.fx.EntityFXFlow;
import makeo.gadomancy.client.effect.fx.FXFlow;
import makeo.gadomancy.client.effect.fx.Orbital;
import makeo.gadomancy.common.utils.Vector3;
import net.minecraft.client.renderer.Tessellator;
@@ -26,8 +26,10 @@ public class EffectHandler {
public static final EffectHandler instance = new EffectHandler();
public static List<Orbital> orbitals = new ArrayList<Orbital>();
public static List<FXFlow> fxFlows = new ArrayList<FXFlow>();
public static Lock orbitalsRWLock = new NonReentrantReentrantLock();
public static Lock flowRWLock = new NonReentrantReentrantLock();
public static EffectHandler getInstance() {
return instance;
@@ -37,18 +39,45 @@ public class EffectHandler {
public void onRender(RenderWorldLastEvent event) {
Tessellator tessellator = Tessellator.instance;
EntityFXFlow.FXFlowBase.sheduleRender(tessellator);
FXFlow.FXFlowBase.sheduleRender(tessellator);
Orbital.sheduleRenders(orbitals, event.partialTicks);
}
public EntityFXFlow effectFlow(World world, Vector3 origin, EntityFXFlow.EntityFlowProperties properties) {
EntityFXFlow flow = new EntityFXFlow(world);
flow.applyProperties(properties);
flow.setPosition(origin.getX(), origin.getY(), origin.getZ());
world.spawnEntityInWorld(flow);
public FXFlow effectFlow(World world, Vector3 origin, FXFlow.EntityFlowProperties properties) {
FXFlow flow = new FXFlow(world);
flow.applyProperties(properties).setPosition(origin);
registerFlow(flow);
return flow;
}
public void registerFlow(final FXFlow flow) {
new Thread(new Runnable() {
@Override
public void run() {
flowRWLock.lock();
try {
fxFlows.add(flow);
} finally {
flowRWLock.unlock();
}
}
}).start();
}
public void unregisterFlow(final FXFlow flow) {
new Thread(new Runnable() {
@Override
public void run() {
flowRWLock.lock();
try {
fxFlows.remove(flow);
} finally {
flowRWLock.unlock();
}
}
}).start();
}
public void registerOrbital(final Orbital orbital) {
new Thread(new Runnable() {
@Override
@@ -81,6 +110,7 @@ public class EffectHandler {
public void tick() {
Orbital.tickOrbitals(orbitals);
FXFlow.tickFlows(fxFlows);
}
public void clear() {
@@ -2,6 +2,7 @@ package makeo.gadomancy.client.effect.fx;
import makeo.gadomancy.common.utils.Vector3;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import java.awt.*;
import java.util.Random;
@@ -16,7 +17,7 @@ import java.util.Random;
*/
public abstract class EntityFXFlowPolicy {
public abstract void doSubParticles(EntityFXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ);
public abstract void doSubParticles(FXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ);
public enum Policies {
@@ -40,16 +41,16 @@ public abstract class EntityFXFlowPolicy {
static class DefaultPolicy extends EntityFXFlowPolicy {
@Override
public void doSubParticles(EntityFXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
public void doSubParticles(FXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
doParticles(fxFlow, policyCounter, posX, posY, posZ, fxFlow.getRand().nextInt(3) + 1);
}
public void doParticles(EntityFXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, int count) {
public void doParticles(FXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, int count) {
Random rand = fxFlow.getRand();
for (int i = 0; i < count; i++) {
Vector3 subOffset = genSubOffset(rand, fxFlow.getSurroundingDistance());
Color c = (fxFlow.getFadingColor() != null && rand.nextBoolean()) ? fxFlow.getFadingColor() : fxFlow.getColor();
EntityFXFlow.FXFlowBase flow = new EntityFXFlow.FXFlowBase(fxFlow.worldObj, posX + subOffset.getX(), posY + subOffset.getY(), posZ + subOffset.getZ(), c, rand.nextInt(1) + fxFlow.getSurroundingParticleSize(), 6, 240);
FXFlow.FXFlowBase flow = new FXFlow.FXFlowBase(Minecraft.getMinecraft().theWorld, posX + subOffset.getX(), posY + subOffset.getY(), posZ + subOffset.getZ(), c, rand.nextInt(1) + fxFlow.getSurroundingParticleSize(), 6, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow);
}
}
@@ -67,7 +68,7 @@ public abstract class EntityFXFlowPolicy {
public static final int TICKS_PER_FULL_TURN = 40;
@Override
public void doSubParticles(EntityFXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
public void doSubParticles(FXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
Vector3 rotationAxis = fxFlow.getMovementVector();
Vector3 perpendicular = rotationAxis.clone().perpendicular().normalize().multiply(fxFlow.getSurroundingDistance());
@@ -80,10 +81,11 @@ public abstract class EntityFXFlowPolicy {
perpendicular = perpendicular.rotate(currentRad, rotationAxis);
counterSide = counterSide.rotate(currentRad, rotationAxis);
World w = Minecraft.getMinecraft().theWorld;
Color c = (fxFlow.getFadingColor() != null) ? fxFlow.getFadingColor() : fxFlow.getColor();
EntityFXFlow.FXFlowBase flow = new EntityFXFlow.FXFlowBase(fxFlow.worldObj, posX + perpendicular.getX(), posY + perpendicular.getY(), posZ + perpendicular.getZ(), c, fxFlow.getSurroundingParticleSize(), 6, 240);
FXFlow.FXFlowBase flow = new FXFlow.FXFlowBase(w, posX + perpendicular.getX(), posY + perpendicular.getY(), posZ + perpendicular.getZ(), c, fxFlow.getSurroundingParticleSize(), 6, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow);
EntityFXFlow.FXFlowBase flow2 = new EntityFXFlow.FXFlowBase(fxFlow.worldObj, posX + counterSide.getX(), posY + counterSide.getY(), posZ + counterSide.getZ(), c, fxFlow.getSurroundingParticleSize(), 6, 240);
FXFlow.FXFlowBase flow2 = new FXFlow.FXFlowBase(w, posX + counterSide.getX(), posY + counterSide.getY(), posZ + counterSide.getZ(), c, fxFlow.getSurroundingParticleSize(), 6, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow2);
}
@@ -92,7 +94,7 @@ public abstract class EntityFXFlowPolicy {
static class CircularMixPolicy extends CircularPolicy {
@Override
public void doSubParticles(EntityFXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
public void doSubParticles(FXFlow fxFlow, int policyCounter, double posX, double posY, double posZ, double lastPosX, double lastPosY, double lastPosZ) {
super.doSubParticles(fxFlow, policyCounter, posX, posY, posZ, lastPosX, lastPosY, lastPosZ);
((DefaultPolicy) Policies.DEFAULT.getPolicy()).doParticles(fxFlow, policyCounter, posX, posY, posZ, fxFlow.getRand().nextInt(2));
@@ -1,5 +1,6 @@
package makeo.gadomancy.client.effect.fx;
import makeo.gadomancy.client.effect.EffectHandler;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.utils.MiscUtils;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
@@ -7,14 +8,13 @@ import makeo.gadomancy.common.utils.Vector3;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
* This class is part of the Gadomancy Mod
@@ -24,7 +24,7 @@ import java.util.*;
* <p/>
* Created by HellFirePvP @ 17.11.2015 18:45
*/
public class EntityFXFlow extends EntityThrowable {
public class FXFlow {
private Color color;
private Color fadingColor;
@@ -36,103 +36,111 @@ public class EntityFXFlow extends EntityThrowable {
private int livingTicks = -1;
private World origin;
private double motionBufferX, motionBufferY, motionBufferZ;
private double lastTickPosX, lastTickPosY, lastTickPosZ;
private double posX, posY, posZ;
private float motionMultiplier = 1;
private float mainParticleSize = 0.2F;
private float surroundingParticleSize = 0.1F;
private float surroundingDistance = 0.8F;
private double unmodMotionBufX, unmodMotionBufY, unmodMotionBufZ;
public long lastUpdateCall = System.currentTimeMillis();
public EntityFXFlow(World world) {
super(world);
setSize(0.0F, 0.0F); //Not visible
public FXFlow(World originWorld) {
this.origin = originWorld;
this.policy = EntityFXFlowPolicy.Policies.DEFAULT.getPolicy();
}
public EntityFXFlow applyTarget(Vector3 target) {
public FXFlow applyTarget(Vector3 target) {
this.target = target;
return this;
}
public EntityFXFlow setSurroundingDistance(float surroundingDistance) {
public FXFlow setSurroundingDistance(float surroundingDistance) {
this.surroundingDistance = (1 / surroundingDistance);
return this;
}
public EntityFXFlow setMainParticleSize(float newSize) {
public FXFlow setMainParticleSize(float newSize) {
this.mainParticleSize = newSize;
return this;
}
public EntityFXFlow setSurroundingParticleSize(float newSize) {
public FXFlow setSurroundingParticleSize(float newSize) {
this.surroundingParticleSize = newSize;
return this;
}
public EntityFXFlow setLivingTicks(int livingTicks) {
public FXFlow setLivingTicks(int livingTicks) {
this.livingTicks = livingTicks;
return this;
}
public EntityFXFlow setColor(Color newColor) {
public FXFlow setColor(Color newColor) {
this.fadingColor = this.color;
this.color = newColor;
return this;
}
public FXFlow setPosition(double x, double y, double z) {
this.posX = x;
this.posY = y;
this.posZ = z;
return this;
}
public FXFlow setPosition(Vector3 vec) {
return setPosition(vec.getX(), vec.getY(), vec.getZ());
}
public void setMotionMultiplier(float motionMultiplier) {
this.motionMultiplier = motionMultiplier;
}
public EntityFXFlow setMotion(double motionX, double motionY, double motionZ) {
public FXFlow setMotion(double motionX, double motionY, double motionZ) {
this.unmodMotionBufX = motionX;
this.unmodMotionBufY = motionY;
this.unmodMotionBufZ = motionZ;
motionX *= motionMultiplier;
motionY *= motionMultiplier;
motionZ *= motionMultiplier;
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
this.motionBufferX = motionX;
this.motionBufferY = motionY;
this.motionBufferZ = motionZ;
return this;
}
@Override
public void onUpdate() {
public void tick() {
livingTicks--;
if (livingTicks <= 0) {
EffectHandler.getInstance().unregisterFlow(this);
return;
}
this.calculateVelocity();
setVelocity(motionBufferX, motionBufferY, motionBufferZ);
this.lastTickPosX = this.posX;
this.lastTickPosY = this.posY;
this.lastTickPosZ = this.posZ;
this.posX += this.motionBufferX;
this.posY += this.motionBufferY;
this.posZ += this.motionBufferZ;
if(target == null) {
livingTicks--;
if (livingTicks <= 0) setDead();
} else {
if(target.distanceSquared(getPositionVector()) < 1) {
setDead();
}
}
super.onUpdate();
this.inGround = false;
if (!isDead && worldObj.isRemote) {
policyCounter += 1;
doParticles();
}
policyCounter += 1;
doParticles();
}
private void calculateVelocity() {
if(target == null) return;
if(livingTicks <= 0) return; //Never happens..
Vector3 pos = getPositionVector();
double motDirX = target.getX() - pos.getX();
double motDirY = target.getY() - pos.getY();
double motDirZ = target.getZ() - pos.getZ();
Vector3 mot = new Vector3(motDirX, motDirY, motDirZ).normalize().divide(4);
Vector3 mot = new Vector3(motDirX, motDirY, motDirZ).divide(livingTicks);
setMotion(mot.getX(), mot.getY(), mot.getZ());
}
@@ -149,23 +157,27 @@ public class EntityFXFlow extends EntityThrowable {
}
private void doParticles() {
FXFlowBase flow = new FXFlowBase(worldObj, posX, posY, posZ, color, mainParticleSize, 9, 240);
if(Minecraft.getMinecraft().theWorld == null) {
EffectHandler.getInstance().unregisterFlow(this);
return;
}
if(Minecraft.getMinecraft().theWorld.provider.dimensionId != origin.provider.dimensionId) {
EffectHandler.getInstance().unregisterFlow(this);
return;
}
FXFlowBase flow = new FXFlowBase(Minecraft.getMinecraft().theWorld, posX, posY, posZ, color, mainParticleSize, 9, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow); //Initial position.
double lastPosX = posX - (posX - lastTickPosX) / 2.0D;
double lastPosY = posY - (posY - lastTickPosY) / 2.0D;
double lastPosZ = posZ - (posZ - lastTickPosZ) / 2.0D;
FXFlowBase flow2 = new FXFlowBase(worldObj, lastPosX, lastPosY, lastPosZ, color, (float) (mainParticleSize * 0.8), 8, 240);
FXFlowBase flow2 = new FXFlowBase(Minecraft.getMinecraft().theWorld, lastPosX, lastPosY, lastPosZ, color, (float) (mainParticleSize * 0.8), 8, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow2); //Consistency to last position
if(policy != null)
policy.doSubParticles(this, policyCounter, posX, posY, posZ, lastPosX, lastPosY, lastPosZ);
}
@Override
public float getGravityVelocity() {
return 0.0F;
}
public Color getColor() {
return color;
}
@@ -190,10 +202,6 @@ public class EntityFXFlow extends EntityThrowable {
return motionMultiplier;
}
public Random getRand() {
return rand;
}
public boolean isMovementVectorNullLength() {
return new Vector3(motionBufferX, motionBufferY, motionBufferZ).lengthSquared() == 0;
}
@@ -203,15 +211,15 @@ public class EntityFXFlow extends EntityThrowable {
}
public Vector3 getMovementVector() {
Vector3 motion = new Vector3(motionBufferX, motionBufferY, motionBufferZ);
if(motion.lengthSquared() == 0) return new Vector3(unmodMotionBufX, unmodMotionBufY, unmodMotionBufZ);
return motion;
if(isMovementVectorNullLength()) return new Vector3(unmodMotionBufX, unmodMotionBufY, unmodMotionBufZ);
return new Vector3(motionBufferX, motionBufferY, motionBufferZ);
}
@Override
public void onImpact(MovingObjectPosition obj) {}
public Random getRand() {
return origin.rand;
}
public void applyProperties(EntityFlowProperties properties) {
public FXFlow applyProperties(EntityFlowProperties properties) {
if(properties != null) {
if(properties.hasTarget) {
applyTarget(properties.target);
@@ -243,6 +251,21 @@ public class EntityFXFlow extends EntityThrowable {
setPolicy(properties.policy);
}
}
return this;
}
public static void tickFlows(List<FXFlow> fxFlows) {
EffectHandler.flowRWLock.lock();
try {
for(FXFlow flow : fxFlows) {
if((System.currentTimeMillis() - flow.lastUpdateCall) > 1000L) {
EffectHandler.getInstance().unregisterFlow(flow);
}
flow.tick();
}
} finally {
EffectHandler.flowRWLock.unlock();
}
}
public static class EntityFlowProperties {
@@ -10,13 +10,14 @@ import net.minecraft.world.World;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
*
* Created by HellFirePvP @ 17.11.2015 18:41
*/
public final class Orbital {
@@ -25,6 +26,8 @@ public final class Orbital {
private final World world;
private int orbitalCounter = 0;
public boolean registered = false;
//INFO: Needs to be updated when its "owner" gets rendered.
public long lastRenderCall = System.currentTimeMillis();
private List<OrbitalRenderProperties> orbitals = new ArrayList<OrbitalRenderProperties>();
@@ -68,12 +71,57 @@ public final class Orbital {
orbitalNode.getRunnable().onRender(point, orbitalNode, partialTicks);
}
EntityFXFlow.FXFlowBase flow = new EntityFXFlow.FXFlowBase(world, point.getX(), point.getY(), point.getZ(),
FXFlow.FXFlowBase flow = new FXFlow.FXFlowBase(world, point.getX(), point.getY(), point.getZ(),
orbitalNode.getColor(), orbitalNode.getParticleSize(), orbitalNode.getMultiplier(), orbitalNode.getBrightness());
if(orbitalNode.getSubParticleColor() != null && world.rand.nextInt(3) == 0) {
Vector3 subOffset = genSubOffset(world.rand, 0.8F);
Color c = (world.rand.nextBoolean()) ? orbitalNode.getSubParticleColor() : orbitalNode.getColor();
FXFlow.FXFlowBase flow2 = new FXFlow.FXFlowBase(world,
point.getX() + subOffset.getX(), point.getY() + subOffset.getY(), point.getZ() + subOffset.getZ(),
c, 0.1F + (world.rand.nextBoolean() ? 0.0F : 0.1F), 6, 240);
Minecraft.getMinecraft().effectRenderer.addEffect(flow2);
}
Minecraft.getMinecraft().effectRenderer.addEffect(flow);
}
}
private Vector3 genSubOffset(Random rand, float surroundingDistance) {
float x = ((rand.nextFloat() / 4F) * surroundingDistance) * (rand.nextBoolean() ? 1 : -1);
float y = ((rand.nextFloat() / 4F) * surroundingDistance) * (rand.nextBoolean() ? 1 : -1);
float z = ((rand.nextFloat() / 4F) * surroundingDistance) * (rand.nextBoolean() ? 1 : -1);
return new Vector3(x, y, z);
}
public void reduceAllOffsets(float percent) {
for(OrbitalRenderProperties node : orbitals) {
node.reduceOffset(percent);
}
}
public Vector3[] getOrbitalStartPoints(OrbitalRenderProperties... properties) {
Vector3[] arr = new Vector3[properties.length];
for (int i = 0; i < properties.length; i++) {
OrbitalRenderProperties property = properties[i];
if(property == null) {
arr[i] = null;
continue;
}
Axis axis = property.getAxis();
int counterOffset = property.getOffsetTicks() % property.getTicksForFullCircle();
int currentDividedPolicyTick = (orbitalCounter + counterOffset) % property.getTicksForFullCircle();
float currentDegree = 360F * (((float) currentDividedPolicyTick) / ((float) property.getTicksForFullCircle()));
double currentRad = Math.toRadians(currentDegree);
arr[i] = axis.getAxis().clone().perpendicular().normalize().multiply(property.getOffset()).rotate(currentRad, axis.getAxis()).add(center);
}
return arr;
}
public static void sheduleRenders(List<Orbital> orbitals, float partialTicks) {
EffectHandler.orbitalsRWLock.lock();
try {
@@ -88,7 +136,14 @@ public final class Orbital {
public static void tickOrbitals(List<Orbital> orbitals) {
EffectHandler.orbitalsRWLock.lock();
try {
for(Orbital orbital : orbitals) orbital.orbitalCounter++;
for(Orbital orbital : orbitals) {
if((System.currentTimeMillis() - orbital.lastRenderCall) > 1000L) {
orbital.clearOrbitals();
EffectHandler.getInstance().unregisterOrbital(orbital);
} else {
orbital.orbitalCounter++;
}
}
} finally {
EffectHandler.orbitalsRWLock.unlock();
}
@@ -97,7 +152,7 @@ public final class Orbital {
public static class OrbitalRenderProperties {
private Axis axis;
private double offset;
private double originalOffset, offset;
private Color color = Color.WHITE;
private int ticksForFullCircle = 40;
private OrbitalRenderRunnable runnable = null;
@@ -106,8 +161,10 @@ public final class Orbital {
private float particleSize = 0.2F;
private int offsetTicks = 0;
private Color subParticleColor = null;
public OrbitalRenderProperties(Axis axis, double offsetLength) {
this.offset = offsetLength;
this.offset = this.originalOffset = offsetLength;
this.axis = axis;
}
@@ -146,6 +203,16 @@ public final class Orbital {
return this;
}
public OrbitalRenderProperties setSubParticleColor(Color subParticleColor) {
this.subParticleColor = subParticleColor;
return this;
}
//Percent from 0.0F to 1.0F
public void reduceOffset(float percent) {
this.offset = this.originalOffset * percent;
}
public float getParticleSize() {
return particleSize;
}
@@ -162,6 +229,10 @@ public final class Orbital {
return offset;
}
public Color getSubParticleColor() {
return subParticleColor;
}
public int getTicksForFullCircle() {
return ticksForFullCircle;
}
@@ -0,0 +1,30 @@
package makeo.gadomancy.client.renderers.entity;
import makeo.gadomancy.common.entities.EntityAuraCore;
import makeo.gadomancy.common.utils.MiscUtils;
import net.minecraft.entity.Entity;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
*
* Created by HellFirePvP @ 01.12.2015 13:55
*/
public class RenderEntityAuraCore extends RenderEntityItem {
@Override
public void doRender(Entity entity, double x, double y, double z, float parf1, float parf2) {
super.doRender(entity, x, y, z, parf1, parf2);
if(!(entity instanceof EntityAuraCore)) return;
EntityAuraCore ea = (EntityAuraCore) entity;
if(ea.auraOrbital != null) {
ea.auraOrbital.lastRenderCall = System.currentTimeMillis();
ea.auraOrbital.updateCenter(MiscUtils.getPositionVector(ea));
}
}
}
@@ -1,6 +1,5 @@
package makeo.gadomancy.client.renderers.entity;
import makeo.gadomancy.common.entities.EntityAuraCore;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderItem;
@@ -19,25 +18,22 @@ import net.minecraft.util.ResourceLocation;
*/
public class RenderEntityItem extends Render {
private RenderItem ri;
public RenderEntityItem() {
ri = new RenderItem();
ri.setRenderManager(RenderManager.instance);
}
private static RenderItem ri;
@Override
public void doRender(Entity entity, double x, double y, double z, float parf1, float parf2) {
if(!(entity instanceof EntityAuraCore)) return;
EntityItem ei = new EntityItem(entity.worldObj, x, y, z, ((EntityAuraCore) entity).getEntityItem());
ei.age = ((EntityAuraCore) entity).age;
ei.hoverStart = ((EntityAuraCore) entity).hoverStart;
ri.doRender(ei, x, y, z, parf1, parf2);
if(!(entity instanceof EntityItem)) return;
ri.doRender(entity, x, y, z, parf1, parf2);
}
@Override
protected ResourceLocation getEntityTexture(Entity p_110775_1_) {
return AbstractClientPlayer.locationStevePng;
}
static {
ri = new RenderItem();
ri.setRenderManager(RenderManager.instance);
}
}
@@ -69,13 +69,17 @@ public class RenderTileAuraPylon extends TileEntitySpecialRenderer {
GL11.glPopMatrix();
if(tile instanceof TileAuraPylonTop) {
if(((TileAuraPylonTop) tile).orbital == null && tile.getWorldObj() != null) {
((TileAuraPylonTop) tile).orbital = new Orbital(new Vector3(tile.xCoord + 0.5, tile.yCoord + 0.7, tile.zCoord + 0.5), tile.getWorldObj());
EffectHandler.getInstance().registerOrbital(((TileAuraPylonTop) tile).orbital);
TileAuraPylonTop ta = (TileAuraPylonTop) tile;
if(ta.orbital == null && tile.getWorldObj() != null) {
ta.orbital = new Orbital(new Vector3(tile.xCoord + 0.5, tile.yCoord + 0.7, tile.zCoord + 0.5), tile.getWorldObj());
}
if(((TileAuraPylonTop) tile).shouldRenderEffect()) {
Aspect a = ((TileAuraPylonTop) tile).getAspect();
if(ta.orbital != null && !ta.orbital.registered) {
EffectHandler.getInstance().registerOrbital(ta.orbital);
}
if(ta.shouldRenderEffect()) {
Aspect a = ta.getAspect();
if(a == null) a = Aspect.WEATHER;
Color c = new Color(a.getColor());
if(tile.getWorldObj().rand.nextInt(12) == 0) {
@@ -95,22 +99,24 @@ public class RenderTileAuraPylon extends TileEntitySpecialRenderer {
}
}
if(((TileAuraPylonTop) tile).shouldRenderEffect() && ((TileAuraPylonTop) tile).getAspect() != null) {
if(((TileAuraPylonTop) tile).orbital != null && ((TileAuraPylonTop) tile).orbital.orbitalsSize() == 0) {
Aspect a = ((TileAuraPylonTop) tile).getAspect();
if(ta.orbital != null) ta.orbital.lastRenderCall = System.currentTimeMillis();
if(ta.shouldRenderAuraEffect() && ta.getAspect() != null) {
if(ta.orbital != null && ta.orbital.orbitalsSize() == 0) {
Aspect a = ta.getAspect();
if(a != null) {
int col = a.getColor();
col |= (0x55 << 24);
Color c = new Color(col, true);
Random rand = tile.getWorldObj().rand;
addNewOrbitalPoint(((TileAuraPylonTop) tile).orbital, rand, c);
addNewOrbitalPoint(((TileAuraPylonTop) tile).orbital, rand, c);
addNewOrbitalPoint(((TileAuraPylonTop) tile).orbital, rand, c);
addNewOrbitalPoint(ta.orbital, rand, c);
addNewOrbitalPoint(ta.orbital, rand, c);
addNewOrbitalPoint(ta.orbital, rand, c);
}
}
} else {
if(((TileAuraPylonTop) tile).orbital != null && ((TileAuraPylonTop) tile).orbital.orbitalsSize() > 0) {
((TileAuraPylonTop) tile).orbital.clearOrbitals();
if(ta.orbital != null && ta.orbital.orbitalsSize() > 0) {
ta.orbital.clearOrbitals();
}
}
}
@@ -3,14 +3,11 @@ package makeo.gadomancy.common;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import makeo.gadomancy.client.ClientProxy;
import makeo.gadomancy.common.containers.ContainerArcanePackager;
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.entities.EntityAuraCore;
import makeo.gadomancy.common.entities.EntityPermNoClipItem;
import makeo.gadomancy.common.events.EventHandlerEntity;
import makeo.gadomancy.common.events.EventHandlerGolem;
import makeo.gadomancy.common.events.EventHandlerNetwork;
@@ -19,6 +16,7 @@ import makeo.gadomancy.common.familiar.FamiliarHandlerServer;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.registration.ModSubstitutions;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredEntities;
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
import makeo.gadomancy.common.registration.RegisteredIntegrations;
import makeo.gadomancy.common.registration.RegisteredItems;
@@ -28,7 +26,6 @@ import makeo.gadomancy.common.registration.RegisteredResearches;
import makeo.gadomancy.common.utils.Injector;
import makeo.gadomancy.common.utils.world.WorldProviderTCEldrich;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
@@ -86,17 +83,10 @@ public class CommonProxy implements IGuiHandler {
RegisteredPotions.init();
RegisteredEntities.init();
DimensionManager.registerProviderType(ModConfig.dimOuterId, WorldProviderTCEldrich.class, true);
DimensionManager.registerDimension(ModConfig.dimOuterId, ModConfig.dimOuterId);
registerEntity(EntityPermNoClipItem.class, "EntityPermItem", 32, 40, false);
registerEntity(EntityAuraCore.class, "EntityAuraCore", 32, 10, true);
}
private void registerEntity(Class<? extends Entity> entityClass, String name, int trackingRange, int updateFreq, boolean sendVelUpdates) {
int id = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(entityClass, name, id);
EntityRegistry.registerModEntity(entityClass, name, id, Gadomancy.instance, trackingRange, updateFreq, sendVelUpdates);
}
public void postInitalize() {
@@ -2,26 +2,17 @@ package makeo.gadomancy.common.aura;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketSyncAuraKnowledge;
import makeo.gadomancy.common.network.packets.PacketTCNotificationText;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.StatCollector;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.research.ResearchItem;
import thaumcraft.common.Thaumcraft;
import thaumcraft.common.lib.research.ResearchManager;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* This class is part of the Gadomancy Mod
@@ -33,28 +24,17 @@ import java.util.UUID;
*/
public class AuraResearchManager {
private static Map<UUID, List<String>> auraMap = new HashMap<UUID, List<String>>();
public static final String TC_AURA_RESEARCH_STR = "GADOMANCY.AURA.%s";
public static void tryUnlockAuraEffect(EntityPlayer player, Aspect aspect) {
UUID playerUUID = player.getUniqueID();
if(!AuraEffectHandler.registeredEffects.containsKey(aspect)) return;
if(!auraMap.containsKey(playerUUID)) {
auraMap.put(playerUUID, new ArrayList<String>());
}
if(auraMap.get(playerUUID).contains(aspect.getTag())) return;
auraMap.get(playerUUID).add(aspect.getTag());
String res = String.format(TC_AURA_RESEARCH_STR, aspect.getTag());
if(ResearchManager.isResearchComplete(player.getCommandSenderName(), res)) return;
Thaumcraft.proxy.getResearchManager().completeResearch(player, res);
PacketTCNotificationText text = new PacketTCNotificationText("gadomancy.aura.research.unlock", aspect.getTag());
PacketHandler.INSTANCE.sendTo(text, (EntityPlayerMP) player);
PacketSyncAuraKnowledge sync = new PacketSyncAuraKnowledge(auraMap.get(playerUUID));
PacketHandler.INSTANCE.sendTo(sync, (EntityPlayerMP) player);
}
//Side: CLIENT!!!
public static void recieveServerData(List<String> aspectTags) {
UUID ourPlayer = Minecraft.getMinecraft().thePlayer.getUniqueID();
auraMap.put(ourPlayer, aspectTags);
}
public static List<String> getLines(String aspectTag) {
@@ -73,62 +53,18 @@ public class AuraResearchManager {
}
public static List<String> getKnowledge(EntityPlayer player) {
return getKnowledge(player.getUniqueID());
}
public static List<String> getKnowledge(UUID playerUUID) {
return auraMap.get(playerUUID);
}
public static void loadDataFromFile(String playerName, UUID uniqueID, File auraData) {
if(!auraData.exists()) {
auraMap.put(uniqueID, new ArrayList<String>());
return;
}
NBTTagCompound compound;
try {
compound = CompressedStreamTools.read(auraData);
} catch (IOException e) {
Gadomancy.log.warn("Unable to load aura data for " + uniqueID + "/" + playerName);
auraMap.put(uniqueID, new ArrayList<String>());
return;
}
List<String> tags = new ArrayList<String>();
NBTTagList aspects = compound.getTagList("aspects", new NBTTagString().getId());
for (int i = 0; i < aspects.tagCount(); i++) {
String aspect = aspects.getStringTagAt(i);
if(Aspect.getAspect(aspect) != null) {
tags.add(aspect);
List<String> lines = new ArrayList<String>();
for(Aspect a : AuraEffectHandler.registeredEffects.keySet()) {
if(ResearchManager.isResearchComplete(player.getCommandSenderName(), String.format(TC_AURA_RESEARCH_STR, a.getTag()))) {
lines.add(a.getTag());
}
}
auraMap.put(uniqueID, tags);
return lines;
}
public static void saveDataToFile(String commandSenderName, UUID uniqueID, File auraData) {
if(!auraMap.containsKey(uniqueID)) return;
if(!auraData.exists()) {
try {
auraData.createNewFile();
} catch (IOException e) {
Gadomancy.log.error("Could not create aura data for " + uniqueID + "/" + commandSenderName);
return;
}
}
List<String> tags = auraMap.get(uniqueID);
NBTTagList list = new NBTTagList();
for(String s : tags) {
list.appendTag(new NBTTagString(s));
}
NBTTagCompound cmp = new NBTTagCompound();
cmp.setTag("aspects", list);
try {
CompressedStreamTools.write(cmp, auraData);
} catch (IOException e) {
Gadomancy.log.error("Could not write aura data for " + uniqueID + "/" + commandSenderName);
return;
public static void registerAuraResearches() {
for(Aspect a : AuraEffectHandler.registeredEffects.keySet()) {
new ResearchItem(String.format(TC_AURA_RESEARCH_STR, a.getTag()), Gadomancy.MODID).registerResearchItem();
}
}
}
@@ -2,6 +2,7 @@ package makeo.gadomancy.common.blocks.tiles;
import makeo.gadomancy.client.effect.EffectHandler;
import makeo.gadomancy.client.effect.fx.Orbital;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.ItemUtils;
import makeo.gadomancy.common.utils.Vector3;
import net.minecraft.block.Block;
@@ -28,6 +29,7 @@ public class TileAuraPylonTop extends SynchronizedTileEntity implements IAspectC
public Orbital orbital;
private boolean shouldRender = false;
private boolean shouldRenderAura = false;
@Override
public void updateEntity() {
@@ -37,10 +39,15 @@ public class TileAuraPylonTop extends SynchronizedTileEntity implements IAspectC
breakTile();
return;
}
if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) != RegisteredBlocks.blockAuraPylon || worldObj.getBlockMetadata(xCoord, yCoord - 1, zCoord) != 0) {
breakTile();
return;
}
TileAuraPylon pylon = (TileAuraPylon) te;
if(pylon.isPartOfMultiblock() && !pylon.isMasterTile()) breakTile();
} else {
shouldRender = !(te == null || !(te instanceof TileAuraPylon) || !((TileAuraPylon) te).isPartOfMultiblock());
shouldRender = te != null && te instanceof TileAuraPylon && ((TileAuraPylon) te).isPartOfMultiblock();
shouldRenderAura = te != null && te instanceof TileAuraPylon && ((TileAuraPylon) te).getEssentiaAmount() > 0;
}
}
@@ -71,11 +78,17 @@ public class TileAuraPylonTop extends SynchronizedTileEntity implements IAspectC
return shouldRender;
}
public boolean shouldRenderAuraEffect() {
return shouldRenderAura;
}
@Override
public void invalidate() {
super.invalidate();
if(orbital != null && orbital.registered) {
EffectHandler.getInstance().unregisterOrbital(orbital);
if(orbital != null) {
orbital.clearOrbitals();
if(orbital.registered)
EffectHandler.getInstance().unregisterOrbital(orbital);
}
}
@@ -22,7 +22,11 @@ public class ModConfig {
public static int entityNoClipItemDatawatcherFixedId = 20;
@Sync
public static int entityAuraCoreDatawatcherAspectId = 21;
public static int entityAuraCoreDatawatcherAspectsId = 21;
@Sync
public static int entityAuraCoreDatawatcherCoordId = 22;
@Sync
public static int entityAuraCoreDatawatcherTickId = 23;
@Sync
public static int golemDatawatcherId = 29;
@@ -53,7 +57,9 @@ public class ModConfig {
entityNoClipItemDatawatcherMasterId = config.getInt("itemNoClipDatawatcherMasterId", "entities", 19, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Master-Coordinates for EntityNoClipItem");
entityNoClipItemDatawatcherFixedId = config.getInt("itemNoClipDatawatcherFixId", "entities", 20, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Fixed-Coordinates for EntityNoClipItem");
entityAuraCoreDatawatcherAspectId = config.getInt("auraCoreDatawatcherAuraId", "entities", 21, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Auracore's current main aspect");
entityAuraCoreDatawatcherAspectsId = config.getInt("auraCoreDatawatcherAuraId", "entities", 21, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Auracore's current aspects");
entityAuraCoreDatawatcherCoordId = config.getInt("auraCoreDatawatcherCoordId", "entities", 22, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Auracore's starting crystal cluster coords");
entityAuraCoreDatawatcherTickId = config.getInt("auraCoreDatawatcherTickId", "entities", 23, 0, 31, "Do not edit unless you know what are you doing! - Datawatcher ID of the Auracore's interal effect tick to keep the core synced");
golemDatawatcherId = config.getInt("datawatcherId", "golem", 29, 0, 31, "Do not edit unless you know what are you doing!");
@@ -1,13 +1,22 @@
package makeo.gadomancy.common.entities;
import makeo.gadomancy.client.effect.EffectHandler;
import makeo.gadomancy.client.effect.fx.EntityFXFlowPolicy;
import makeo.gadomancy.client.effect.fx.FXFlow;
import makeo.gadomancy.client.effect.fx.Orbital;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.utils.MiscUtils;
import makeo.gadomancy.common.utils.Vector3;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.entities.EntitySpecialItem;
import java.awt.*;
/**
* This class is part of the Gadomancy Mod
@@ -19,29 +28,231 @@ import thaumcraft.common.entities.EntitySpecialItem;
*/
public class EntityAuraCore extends EntityItem {
private static final String SPLIT = ";";
private static final int PRE_GATHER_EFFECT_LENGTH = 50;
private static final int GATHER_EFFECT_LENGTH = 600; //20 + 430
private static final int GATHER_RANGE = 8;
private static final int CLUSTER_WEIGHT = 10; //Counts as 10 'blocks' 'scanned' with the given aspect.
public static final int CLUSTER_RANGE = 10; //Defines how close the clicked cluster has to be.
private int ticksExisted = 0;
private AspectList internalAuraList = new AspectList();
private Aspect dominatingAspect = null;
public AspectList internalAuraList = new AspectList();
public Orbital auraOrbital = null;
//Effect stuff ResidentSleeper
private Aspect[] effectAspects = new Aspect[6];
private Orbital.OrbitalRenderProperties[] effectProperties = new Orbital.OrbitalRenderProperties[6];
private FXFlow[] flows = new FXFlow[6];
private boolean orbitalFilled = false;
private String oldAspectDataSent = null;
public ChunkCoordinates activationLocation = null;
public EntityAuraCore(World world) {
super(world);
}
public EntityAuraCore(World world, double x, double y, double z, ItemStack stack, ChunkCoordinates startingCoords, Aspect[] aspects) {
super(world, x, y, z, stack);
this.activationLocation = startingCoords;
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherCoordId, startingCoords);
if(aspects.length == 1) {
this.internalAuraList.add(aspects[0], CLUSTER_WEIGHT * 6);
} else {
for(Aspect a : aspects) {
if(a == null) continue;
this.internalAuraList.add(a, CLUSTER_WEIGHT);
}
}
updateAndSendAspectData();
}
@Override
protected void entityInit() {
super.entityInit();
getDataWatcher().addObjectByDataType(ModConfig.entityAuraCoreDatawatcherAspectId, 4);
getDataWatcher().addObjectByDataType(ModConfig.entityAuraCoreDatawatcherTickId, 2);
getDataWatcher().addObjectByDataType(ModConfig.entityAuraCoreDatawatcherAspectsId, 4);
getDataWatcher().addObjectByDataType(ModConfig.entityAuraCoreDatawatcherCoordId, 6);
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherAspectId, "");
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherAspectsId, "");
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherCoordId, new ChunkCoordinates(0, -1, 0));
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherTickId, 0);
}
@Override
public void onUpdate() {
super.onUpdate();
if(auraOrbital == null && !MiscUtils.getPositionVector(this).equals(Vector3.ZERO)
&& worldObj.isRemote) {
auraOrbital = new Orbital(MiscUtils.getPositionVector(this), worldObj);
}
if(auraOrbital != null && worldObj.isRemote) {
if(!auraOrbital.registered) {
EffectHandler.getInstance().registerOrbital(auraOrbital);
}
auraOrbital.updateCenter(new Vector3(posX, posY, posZ));
if(ticksExisted > PRE_GATHER_EFFECT_LENGTH) {
int part = ticksExisted - PRE_GATHER_EFFECT_LENGTH;
float perc = ((float) GATHER_EFFECT_LENGTH - part) / ((float) GATHER_EFFECT_LENGTH);
auraOrbital.reduceAllOffsets(perc);
}
}
ticksExisted++;
if (this.age + 5 >= this.lifespan) {
this.age = 0;
}
if(!worldObj.isRemote) {
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherTickId, ticksExisted);
if(ticksExisted > GATHER_EFFECT_LENGTH) {
//TODO spawn EntityItem of type auraCore with dominating aspect + random aspect offset..
} else if(ticksExisted > PRE_GATHER_EFFECT_LENGTH) {
//TODO gather aura and call updateAndSendAspectData() once sth. was gathered.
}
} else {
ticksExisted = getDataWatcher().getWatchableObjectInt(ModConfig.entityAuraCoreDatawatcherTickId);
boolean changed = recieveAspectData();
for (int i = 0; i < effectProperties.length; i++) {
Orbital.OrbitalRenderProperties node = effectProperties[i];
if(node == null) {
if(effectAspects[i] == null) {
continue;
}
node = new Orbital.OrbitalRenderProperties(Orbital.Axis.persisentRandomAxis(), rand.nextDouble() + 2D);
node.setColor(new Color(effectAspects[i].getColor())).setTicksForFullCircle(60 + rand.nextInt(40));
node.setOffsetTicks(rand.nextInt(80));
Color c = getSubParticleColor(effectAspects[i]);
node.setSubParticleColor(c);
effectProperties[i] = node;
}
if(flows[i] == null && ticksExisted < PRE_GATHER_EFFECT_LENGTH) {
ChunkCoordinates origin = (ChunkCoordinates) getDataWatcher().getWatchedObject(ModConfig.entityAuraCoreDatawatcherCoordId).getObject();
Vector3 v = new Vector3(origin.posX + 0.5D, origin.posY + 0.5D, origin.posZ + 0.5D);
flows[i] = EffectHandler.getInstance().effectFlow(worldObj,
v, new FXFlow.EntityFlowProperties().setPolicy(EntityFXFlowPolicy.Policies.DEFAULT)
.setTarget(auraOrbital.getOrbitalStartPoints(node)[0])
.setColor(new Color(effectAspects[i].getColor())).setFading(getSubParticleColor(effectAspects[i])));
flows[i].setLivingTicks(PRE_GATHER_EFFECT_LENGTH - ticksExisted + 20);
}
if(flows[i] != null) flows[i].applyTarget(auraOrbital.getOrbitalStartPoints(node)[0]);
if(changed) {
if(effectProperties[i] != null) {
effectProperties[i].setColor(new Color(effectAspects[i].getColor()));
Color c = getSubParticleColor(effectAspects[i]);
node.setSubParticleColor(c);
}
if(flows[i] != null) {
flows[i].setColor(getSubParticleColor(effectAspects[i]));
flows[i].setColor(new Color(effectAspects[i].getColor()));
}
}
}
if(ticksExisted > PRE_GATHER_EFFECT_LENGTH) {
if(auraOrbital.orbitalsSize() == 0) {
for (int i = 0; i < 6; i++) {
Orbital.OrbitalRenderProperties node = effectProperties[i];
auraOrbital.addOrbitalPoint(node);
}
}
} else {
for (int i = 0; i < 6; i++) {
if(flows[i] != null) {
flows[i].lastUpdateCall = System.currentTimeMillis();
}
}
}
}
}
private Color getSubParticleColor(Aspect a) {
Color c = null;
if(a.equals(Aspect.AIR)) {
c = new Color(0xFEFFC9);
} else if(a.equals(Aspect.FIRE)) {
c = new Color(0xFFAA3C);
} else if(a.equals(Aspect.EARTH)) {
c = new Color(0x7EE35F);
} else if(a.equals(Aspect.WATER)) {
c = new Color(0x78CFCC);
} else if(a.equals(Aspect.ORDER)) {
c = new Color(0xFFFFFF);
} else if(a.equals(Aspect.ENTROPY)) {
c = new Color(0x000000);
}
return c;
}
//Client side only.
private boolean recieveAspectData() {
String rec = getDataWatcher().getWatchableObjectString(ModConfig.entityAuraCoreDatawatcherAspectsId);
if(oldAspectDataSent == null || !this.oldAspectDataSent.equals(rec)) {
oldAspectDataSent = rec;
} else {
return false;
}
if(rec.equals("")) return false;
String[] arr = rec.split(SPLIT);
if(arr.length != 6) throw new IllegalStateException("Server sent wrong Aura Data! '"
+ rec + "' Please report this error to the mod authors!");
for (int i = 0; i < arr.length; i++) {
String s = arr[i];
Aspect a = Aspect.getAspect(s);
effectAspects[i] = a;
}
return true;
}
private void updateAndSendAspectData() {
double avg = ((double) this.internalAuraList.visSize()) / ((double) this.internalAuraList.size());
Aspect[] sortedHtL = this.internalAuraList.getAspectsSortedAmount();
AspectList al = new AspectList();
for(Aspect a : sortedHtL) {
if(a == null) return;
int am = this.internalAuraList.getAmount(a);
if(am >= avg) {
al.add(a, am);
}
}
double perc = ((double) al.visSize()) / 6D;
Aspect[] arr = new Aspect[6];
sortedHtL = al.getAspectsSortedAmount();
int pt = 0;
for(Aspect a : sortedHtL) {
while(al.getAmount(a) - perc >= 0) {
arr[pt] = a;
pt++;
if(!al.reduce(a, (int) perc)) {
al.remove(a);
}
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
if(sb.length() > 0) {
sb.append(SPLIT);
}
sb.append(arr[i].getTag());
}
String toSend = sb.toString();
if(this.oldAspectDataSent == null || !this.oldAspectDataSent.equals(toSend)) {
this.oldAspectDataSent = toSend;
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherAspectsId, toSend);
}
}
@Override
@@ -56,8 +267,17 @@ public class EntityAuraCore extends EntityItem {
internalAuraList.add(Aspect.getAspect(cmp.getString("tag")), cmp.getInteger("amt"));
}
}
String tag = compound.getString("domAspect");
dominatingAspect = Aspect.getAspect(tag);
if(compound.hasKey("activationVecX") && compound.hasKey("activationVecY") && compound.hasKey("activationVecZ")) {
int x = compound.getInteger("activationVecX");
int y = compound.getInteger("activationVecY");
int z = compound.getInteger("activationVecZ");
activationLocation = new ChunkCoordinates(x, y, z);
}
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherCoordId,
this.activationLocation == null ? new ChunkCoordinates(0, -1, 0) : this.activationLocation);
getDataWatcher().updateObject(ModConfig.entityAuraCoreDatawatcherTickId, ticksExisted);
updateAndSendAspectData();
}
@Override
@@ -74,7 +294,10 @@ public class EntityAuraCore extends EntityItem {
list.appendTag(aspectCompound);
}
compound.setTag("auraList", list);
compound.setString("domAspect", dominatingAspect == null ? "" : dominatingAspect.getTag());
if(activationLocation != null) {
compound.setInteger("activationVecX", activationLocation.posX);
compound.setInteger("activationVecY", activationLocation.posY);
compound.setInteger("activationVecZ", activationLocation.posZ);
}
}
}
@@ -71,30 +71,6 @@ public class EventHandlerEntity {
}
}
@SubscribeEvent
public void onJoin(EntityJoinWorldEvent event) {
if(event.entity != null && event.entity instanceof EntityItem) {
ItemStack stack = ((EntityItem) event.entity).getEntityItem();
if(stack == null) return;
if(event.entity instanceof EntityAuraCore) return;
Item i = stack.getItem();
if(i instanceof ItemAuraCore) {
event.setCanceled(true);
if(event.world.isRemote) return;
EntityAuraCore e = new EntityAuraCore(event.world);
e.setEntityItemStack(((EntityItem) event.entity).getEntityItem());
e.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);
e.age = ((EntityItem) event.entity).age;
e.hoverStart = ((EntityItem) event.entity).hoverStart;
e.delayBeforeCanPickup = ((EntityItem) event.entity).delayBeforeCanPickup;
e.motionX = event.entity.motionX;
e.motionY = event.entity.motionY;
e.motionZ = event.entity.motionZ;
event.world.spawnEntityInWorld(e);
}
}
}
@SubscribeEvent
public void on(EntityItemPickupEvent event) {
if(!event.entityPlayer.worldObj.isRemote) {
@@ -125,16 +101,4 @@ public class EventHandlerEntity {
}
}
@SubscribeEvent
public void onLoad(PlayerEvent.LoadFromFile loadEvent) {
File auraData = loadEvent.getPlayerFile("auraDat");
AuraResearchManager.loadDataFromFile(loadEvent.entityPlayer.getCommandSenderName(), loadEvent.entityPlayer.getUniqueID(), auraData);
}
@SubscribeEvent
public void onSave(PlayerEvent.SaveToFile saveEvent) {
File auraData = saveEvent.getPlayerFile("auraDat");
AuraResearchManager.saveDataToFile(saveEvent.entityPlayer.getCommandSenderName(), saveEvent.entityPlayer.getUniqueID(), auraData);
}
}
@@ -3,10 +3,8 @@ package makeo.gadomancy.common.events;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.aura.AuraResearchManager;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketFamiliar;
import makeo.gadomancy.common.network.packets.PacketSyncAuraKnowledge;
import makeo.gadomancy.common.network.packets.PacketSyncConfigs;
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
import makeo.gadomancy.common.utils.GolemEnumHelper;
@@ -23,6 +21,8 @@ import net.minecraft.entity.player.EntityPlayerMP;
* Created by makeo @ 30.07.2015 18:26
*/
public class EventHandlerNetwork {
//TODO Restore old client configs on server leave again.
@SubscribeEvent
public void on(PlayerEvent.PlayerLoggedInEvent e) {
EntityPlayerMP p = (EntityPlayerMP) e.player;
@@ -31,7 +31,6 @@ public class EventHandlerNetwork {
Gadomancy.proxy.familiarHandler.checkPlayerEquipment(p);
PacketHandler.INSTANCE.sendTo(new PacketFamiliar.PacketFamiliarSyncCompletely(Gadomancy.proxy.familiarHandler.getCurrentActiveFamiliars()), p);
PacketHandler.INSTANCE.sendTo(new PacketSyncConfigs(), p);
PacketHandler.INSTANCE.sendTo(new PacketSyncAuraKnowledge(AuraResearchManager.getKnowledge(p)), p);
}
}
@@ -37,6 +37,5 @@ public class PacketHandler {
//Sync data
INSTANCE.registerMessage(PacketSyncConfigs.class, PacketSyncConfigs.class, id++, Side.CLIENT);
INSTANCE.registerMessage(PacketSyncAuraKnowledge.class, PacketSyncAuraKnowledge.class, id++, Side.CLIENT);
}
}
@@ -1,58 +0,0 @@
package makeo.gadomancy.common.network.packets;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import makeo.gadomancy.common.aura.AuraResearchManager;
import java.util.ArrayList;
import java.util.List;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by HellFirePvP @ 30.11.2015 00:00
*/
public class PacketSyncAuraKnowledge implements IMessage, IMessageHandler<PacketSyncAuraKnowledge, IMessage> {
private List<String> aspectTags = new ArrayList<String>();
public PacketSyncAuraKnowledge() {}
public PacketSyncAuraKnowledge(List<String> aspectTags) {
this.aspectTags = aspectTags;
}
@Override
public void fromBytes(ByteBuf buf) {
int it = buf.readInt();
for (int i = 0; i < it; i++) {
int length = buf.readInt();
byte[] strBytes = new byte[length];
buf.readBytes(strBytes, 0, length);
aspectTags.add(new String(strBytes));
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(aspectTags.size());
for(String tag : aspectTags) {
byte[] str = tag.getBytes();
buf.writeInt(str.length);
buf.writeBytes(str);
}
}
@Override
public IMessage onMessage(PacketSyncAuraKnowledge message, MessageContext ctx) {
AuraResearchManager.recieveServerData(message.aspectTags);
return null;
}
}
@@ -0,0 +1,31 @@
package makeo.gadomancy.common.registration;
import cpw.mods.fml.common.registry.EntityRegistry;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.entities.EntityAuraCore;
import makeo.gadomancy.common.entities.EntityPermNoClipItem;
import net.minecraft.entity.Entity;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by HellFirePvP @ 01.12.2015 13:59
*/
public class RegisteredEntities {
public static void init() {
registerEntity(EntityPermNoClipItem.class, "EntityPermItem", 32, 40, false);
registerEntity(EntityAuraCore.class, "EntityAuraCore", 32, 10, true);
}
private static void registerEntity(Class<? extends Entity> entityClass, String name, int trackingRange, int updateFreq, boolean sendVelUpdates) {
int id = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(entityClass, name, id);
EntityRegistry.registerModEntity(entityClass, name, id, Gadomancy.instance, trackingRange, updateFreq, sendVelUpdates);
}
}
@@ -40,6 +40,7 @@ public class RegisteredRecipes {
public static AspectList costsNodeManipulatorMultiblock = new AspectList().add(Aspect.FIRE, 100).add(Aspect.WATER, 100).add(Aspect.EARTH, 100).add(Aspect.AIR, 100).add(Aspect.ORDER, 100).add(Aspect.ENTROPY, 100);
public static AspectList costsEldritchPortalCreatorMultiblock = new AspectList().add(Aspect.FIRE, 150).add(Aspect.WATER, 150).add(Aspect.EARTH, 150).add(Aspect.AIR, 150).add(Aspect.ORDER, 150).add(Aspect.ENTROPY, 150);
public static AspectList costsAuraPylonMultiblock = new AspectList().add(Aspect.FIRE, 150).add(Aspect.WATER, 150).add(Aspect.EARTH, 150).add(Aspect.AIR, 150).add(Aspect.ORDER, 150).add(Aspect.ENTROPY, 150);
public static AspectList costsAuraCoreStart = new AspectList().add(Aspect.FIRE, 100).add(Aspect.WATER, 100).add(Aspect.EARTH, 100).add(Aspect.AIR, 100).add(Aspect.ORDER, 100).add(Aspect.ENTROPY, 100);
public static List multiblockNodeManipulator;
public static List multiblockEldritchPortalCreator;
@@ -1,6 +1,7 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.aura.AuraResearchManager;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.research.AlternatingResearchItem;
import makeo.gadomancy.common.research.PseudoResearchItem;
@@ -269,5 +270,8 @@ public class RegisteredResearches {
new AspectList().add(Aspect.WATER, 4).add(Aspect.MECHANISM, 8).add(Aspect.EARTH, 4).add(Aspect.ORDER, 8))
.setParents(researchJar.key, researchEssentiaMirror.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.REMOTEJAR.1"), new ResearchPage(RegisteredRecipes.recipeRemoteJar), new ResearchPage("gadomancy.research_page.REMOTEJAR.2")).registerResearchItem();
//Aura researches
AuraResearchManager.registerAuraResearches();
}
}
@@ -2,6 +2,7 @@ package makeo.gadomancy.common.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
@@ -57,7 +58,11 @@ public final class MiscUtils {
}
public static Vector3 getPositionVector(Entity e) {
return new Vector3(e.posX, e.posY, e.posZ);
Vector3 v = new Vector3(e.posX, e.posY, e.posZ);
if(e instanceof EntityItem) {
v.setY(v.getY() + 0.2F);
}
return v;
}
}
@@ -16,6 +16,8 @@ public class Vector3 {
private static final Random RAND = new Random();
public static final Vector3 ZERO = new Vector3(0, 0, 0);
protected double x;
protected double y;
protected double z;
@@ -1,11 +1,16 @@
package makeo.gadomancy.common.utils;
import cpw.mods.fml.common.network.NetworkRegistry;
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
import makeo.gadomancy.common.blocks.tiles.TileExtendedNodeJar;
import makeo.gadomancy.common.entities.EntityAuraCore;
import makeo.gadomancy.common.items.ItemAuraCore;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
import makeo.gadomancy.common.node.ExtendedNodeType;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredIntegrations;
import makeo.gadomancy.common.registration.RegisteredRecipes;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@@ -14,6 +19,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import thaumcraft.api.ThaumcraftApiHelper;
@@ -56,50 +62,80 @@ public class WandHandler {
tryAutomagyJarNodeCreation(i, entityPlayer, world, x, y, z);
}
} else if(target.equals(ConfigBlocks.blockCrystal)) {
List items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1).expand(4, 4, 4));
Iterator it = items.iterator();
EntityItem itemAuraCore = null;
while(itemAuraCore == null && it.hasNext()) {
Object item = it.next();
if(item != null && item instanceof EntityItem && !((EntityItem) item).isDead) {
EntityItem entityItem = (EntityItem) item;
if(entityItem.getEntityItem() != null && entityItem.getEntityItem().getItem() != null && entityItem.getEntityItem().getItem() instanceof ItemAuraCore) {
if(((ItemAuraCore) entityItem.getEntityItem().getItem()).isBlank(entityItem.getEntityItem())) itemAuraCore = entityItem;
}
//TODO 1 line down from here :3
//if (ResearchManager.isResearchComplete(entityPlayer.getCommandSenderName(), "INSERT_STH_HERE"))
tryAuraCoreCreation(i, entityPlayer, world, x, y, z);
}
}
private static void tryAuraCoreCreation(ItemStack i, EntityPlayer entityPlayer, World world, int x, int y, int z) {
if(world.isRemote) return;
List items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1)
.expand(EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE, EntityAuraCore.CLUSTER_RANGE));
Iterator it = items.iterator();
EntityItem itemAuraCore = null;
while(itemAuraCore == null && it.hasNext()) {
Object item = it.next();
if(item != null && item instanceof EntityItem && !((EntityItem) item).isDead) {
EntityItem entityItem = (EntityItem) item;
if(entityItem.getEntityItem() != null && entityItem.getEntityItem().getItem() != null
&& entityItem.getEntityItem().getItem() instanceof ItemAuraCore && !(item instanceof EntityAuraCore)) {
if(((ItemAuraCore) entityItem.getEntityItem().getItem()).isBlank(entityItem.getEntityItem())) itemAuraCore = entityItem;
}
}
}
if(itemAuraCore == null) return;
if(itemAuraCore == null) return;
int meta = world.getBlockMetadata(x, y, z);
if(meta <= 6) {
AspectList aspects = new AspectList();
switch (meta) {
case 0:
aspects.add(Aspect.AIR, 6);
break;
case 1:
aspects.add(Aspect.FIRE, 6);
break;
case 2:
aspects.add(Aspect.WATER, 6);
break;
case 3:
aspects.add(Aspect.EARTH, 6);
break;
case 4:
aspects.add(Aspect.ORDER, 6);
break;
case 5:
aspects.add(Aspect.ENTROPY, 6);
break;
case 6:
aspects.add(Aspect.AIR, 1).add(Aspect.EARTH, 1).add(Aspect.FIRE, 1).add(Aspect.WATER, 1).add(Aspect.ORDER, 1).add(Aspect.ENTROPY, 1);
break;
}
//TODO replace entityitem with entityAuraCore and attach starting aspects.
int meta = world.getBlockMetadata(x, y, z);
if(meta <= 6) {
Aspect[] aspects;
switch (meta) {
case 0:
aspects = new Aspect[]{Aspect.AIR};
break;
case 1:
aspects = new Aspect[]{Aspect.FIRE};
break;
case 2:
aspects = new Aspect[]{Aspect.WATER};
break;
case 3:
aspects = new Aspect[]{Aspect.EARTH};
break;
case 4:
aspects = new Aspect[]{Aspect.ORDER};
break;
case 5:
aspects = new Aspect[]{Aspect.ENTROPY};
break;
case 6:
aspects = new Aspect[]{Aspect.AIR, Aspect.FIRE, Aspect.EARTH, Aspect.WATER, Aspect.ORDER, Aspect.ENTROPY};
break;
default:
return;
}
if(!ThaumcraftApiHelper.consumeVisFromWandCrafting(i, entityPlayer, RegisteredRecipes.costsAuraCoreStart, true))
return;
PacketStartAnimation packet = new PacketStartAnimation(PacketStartAnimation.ID_BURST, x, y, z);
PacketHandler.INSTANCE.sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.dimensionId, x, y, z, 32.0D));
world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, 1.5F, false);
world.setBlockToAir(x, y, z);
EntityAuraCore ea =
new EntityAuraCore(itemAuraCore.worldObj, itemAuraCore.posX, itemAuraCore.posY, itemAuraCore.posZ,
itemAuraCore.getEntityItem(), new ChunkCoordinates(x, y, z), aspects);
ea.age = itemAuraCore.age;
ea.hoverStart = itemAuraCore.hoverStart;
ea.motionX = itemAuraCore.motionX;
ea.motionY = itemAuraCore.motionY;
ea.motionZ = itemAuraCore.motionZ;
itemAuraCore.worldObj.spawnEntityInWorld(ea);
itemAuraCore.setDead();
}
}