diff --git a/src/main/java/vazkii/botania/api/corporea/ICorporeaSpark.java b/src/main/java/vazkii/botania/api/corporea/ICorporeaSpark.java new file mode 100644 index 000000000..1f697be19 --- /dev/null +++ b/src/main/java/vazkii/botania/api/corporea/ICorporeaSpark.java @@ -0,0 +1,75 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 13, 2015, 10:53:05 PM (GMT)] + */ +package vazkii.botania.api.corporea; + +import java.util.List; + +import net.minecraft.inventory.IInventory; + +/** + * An interface for a Corporea Spark. Includes functions for handling + * connections. + */ +public interface ICorporeaSpark { + + /** + * Called to register the connections for the spark network passed in. Parameters include the master spark, + * which is the one that initiated the chain call, the referrer which passed the call to this instance + * and the List of sparks connected. Normal behavior should be to find any sparks around that are not + * already present in the list of connections and add them to it, passing the function call to them. + *

+ * The connections List and the master Spark should be kept in this instance as pointers for use in + * getConnections() and getMaster() and passed in to any subsequent registerConnections calls on sparks + * found nearby. This is only called whenever a new spark is added or removed from and to the network, + * at that point the connection list in the master spark would be cleared out, also clearing out the one + * in this instance, as it should be a pointer. + */ + public void registerConnections(ICorporeaSpark master, ICorporeaSpark referrer, List connections); + + /** + * Gets the inventory this spark is bound to, generally the one right below it. + */ + public IInventory getInventory(); + + /** + * Gets the list of sparks this spark is connected to, see registerConnections(). This list + * should also include itself. This list must be checked against on a regular basis to verify + * that the spark is still in the network, if that's not the case, the pointer should be + * eliminated. + */ + public List getConnections(); + + /** + * Gets the list of sparks that this spark added to the list of connections during registerConnections(), this + * is mainly used to create a non messy chain of particles to display the network when a spark is right + * clicked with a wand. + */ + public List getRelatives(); + + /** + * Gets the master spark in this network, see registerConnections(). The value this returns + * should be null and the pointer should be eliminated if the spark is no longer present + * in the network. + */ + public ICorporeaSpark getMaster(); + + /** + * Gets if this spark is considered a master spark. + */ + public boolean isMaster(); + + /** + * Gets the network that this spark is on, or the color it's displaying. Sparks may only connect to others + * of the same network, and on changing network should trigger a re-cache of the previous network. + */ + public int getNetwork(); + +} diff --git a/src/main/java/vazkii/botania/api/package-info.java b/src/main/java/vazkii/botania/api/package-info.java index c58b509ac..988f70c08 100644 --- a/src/main/java/vazkii/botania/api/package-info.java +++ b/src/main/java/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "31", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "32", provides = "BotaniaAPI") package vazkii.botania.api; import cpw.mods.fml.common.API; diff --git a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java index 9f0891002..440fde5b4 100644 --- a/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/src/main/java/vazkii/botania/client/core/proxy/ClientProxy.java @@ -59,6 +59,7 @@ import vazkii.botania.client.render.block.RenderSpawnerClaw; import vazkii.botania.client.render.block.RenderSpecialFlower; import vazkii.botania.client.render.block.RenderSpreader; import vazkii.botania.client.render.block.RenderTinyPotato; +import vazkii.botania.client.render.entity.RenderCorporeaSpark; import vazkii.botania.client.render.entity.RenderDoppleganger; import vazkii.botania.client.render.entity.RenderPixie; import vazkii.botania.client.render.entity.RenderSpark; @@ -103,6 +104,7 @@ import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.core.proxy.CommonProxy; import vazkii.botania.common.core.version.VersionChecker; +import vazkii.botania.common.entity.EntityCorporeaSpark; import vazkii.botania.common.entity.EntityDoppleganger; import vazkii.botania.common.entity.EntityPixie; import vazkii.botania.common.entity.EntitySpark; @@ -207,6 +209,7 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerEntityRenderingHandler(EntityDoppleganger.class, new RenderDoppleganger()); RenderingRegistry.registerEntityRenderingHandler(EntitySpark.class, new RenderSpark()); RenderingRegistry.registerEntityRenderingHandler(EntityThornChakram.class, new RenderSnowball(ModItems.thornChakram)); + RenderingRegistry.registerEntityRenderingHandler(EntityCorporeaSpark.class, new RenderCorporeaSpark()); ShaderHelper.initShaders(); } diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java b/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java new file mode 100644 index 000000000..a9e9f1b8e --- /dev/null +++ b/src/main/java/vazkii/botania/client/render/entity/RenderCorporeaSpark.java @@ -0,0 +1,24 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 14, 2015, 1:04:34 AM (GMT)] + */ +package vazkii.botania.client.render.entity; + +import net.minecraft.util.IIcon; +import vazkii.botania.common.entity.EntityCorporeaSpark; +import vazkii.botania.common.item.ItemCorporeaSpark; + +public class RenderCorporeaSpark extends RenderSparkBase { + + @Override + public IIcon getBaseIcon(EntityCorporeaSpark entity) { + return entity.isMaster() ? ItemCorporeaSpark.worldIconMaster : ItemCorporeaSpark.worldIcon; + } + +} diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java b/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java index 914088c50..91c3e9f50 100644 --- a/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java +++ b/src/main/java/vazkii/botania/client/render/entity/RenderSpark.java @@ -6,90 +6,23 @@ * Botania is Open Source and distributed under the * Botania License: http://botaniamod.net/license.php * - * File Created @ [Aug 21, 2014, 5:53:22 PM (GMT)] + * File Created @ [Feb 14, 2015, 1:03:11 AM (GMT)] */ package vazkii.botania.client.render.entity; -import java.util.Random; - -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.entity.RenderEntity; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.entity.Entity; import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; -import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.common.entity.EntitySpark; -import vazkii.botania.common.item.ItemSpark; import vazkii.botania.common.item.ItemSparkUpgrade; -public class RenderSpark extends RenderEntity { +public class RenderSpark extends RenderSparkBase { @Override - public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) { - EntitySpark spark = (EntitySpark) par1Entity; - IIcon iicon = ItemSpark.worldIcon; - - GL11.glPushMatrix(); - GL11.glTranslatef((float)par2, (float)par4, (float)par6); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glAlphaFunc(GL11.GL_GREATER, 0.05F); - - double time = ClientTickHandler.ticksInGame + par9; - time += new Random(par1Entity.getEntityId()).nextInt(); - GL11.glColor4f(1F, 1F, 1F, 0.7F + 0.3F * (float) (Math.sin(time / 5.0) + 0.5) * 2); - - float scale = 0.75F + 0.1F * (float) Math.sin(time / 10); - GL11.glScalef(scale, scale, scale); - bindEntityTexture(par1Entity); - Tessellator tessellator = Tessellator.instance; - - float r = 180.0F - renderManager.playerViewY; - GL11.glRotatef(r, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-renderManager.playerViewX, 1F, 0F, 0F); - func_77026_a(tessellator, iicon); - int upgrade = spark.getUpgrade() - 1; - if(upgrade >= 0 && upgrade < ItemSparkUpgrade.worldIcons.length) { - GL11.glTranslatef(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F); - GL11.glScalef(0.2F, 0.2F, 0.2F); - func_77026_a(tessellator, ItemSparkUpgrade.worldIcons[upgrade]); - } - GL11.glRotatef(-r, 0.0F, 1.0F, 0.0F); - - GL11.glDisable(GL11.GL_BLEND); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - GL11.glPopMatrix(); + public IIcon getSpinningIcon(EntitySpark entity) { + int upgrade = entity.getUpgrade() - 1; + return upgrade >= 0 && upgrade < ItemSparkUpgrade.worldIcons.length ? ItemSparkUpgrade.worldIcons[upgrade] : null; } - - @Override - protected ResourceLocation getEntityTexture(Entity p_110775_1_) { - return TextureMap.locationItemsTexture; - } - - private void func_77026_a(Tessellator p_77026_1_, IIcon p_77026_2_) { - float f = p_77026_2_.getMinU(); - float f1 = p_77026_2_.getMaxU(); - float f2 = p_77026_2_.getMinV(); - float f3 = p_77026_2_.getMaxV(); - float f4 = 1.0F; - float f5 = 0.5F; - float f6 = 0.25F; - - p_77026_1_.startDrawingQuads(); - p_77026_1_.setNormal(0.0F, 1.0F, 0.0F); - p_77026_1_.setBrightness(240); - p_77026_1_.addVertexWithUV(0.0F - f5, 0.0F - f6, 0.0D, f, f3); - p_77026_1_.addVertexWithUV(f4 - f5, 0.0F - f6, 0.0D, f1, f3); - p_77026_1_.addVertexWithUV(f4 - f5, f4 - f6, 0.0D, f1, f2); - p_77026_1_.addVertexWithUV(0.0F - f5, f4 - f6, 0.0D, f, f2); - p_77026_1_.draw(); - - } - + } diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java b/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java new file mode 100644 index 000000000..0030e215b --- /dev/null +++ b/src/main/java/vazkii/botania/client/render/entity/RenderSparkBase.java @@ -0,0 +1,104 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Aug 21, 2014, 5:53:22 PM (GMT)] + */ +package vazkii.botania.client.render.entity; + +import java.util.Random; + +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderEntity; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.Entity; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import vazkii.botania.client.core.handler.ClientTickHandler; +import vazkii.botania.common.item.ItemSpark; +import vazkii.botania.common.item.ItemSparkUpgrade; + +public class RenderSparkBase extends RenderEntity { + + @Override + public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) { + T tEntity = (T) par1Entity; + IIcon iicon = getBaseIcon(tEntity); + + GL11.glPushMatrix(); + GL11.glTranslatef((float)par2, (float)par4, (float)par6); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glAlphaFunc(GL11.GL_GREATER, 0.05F); + + double time = ClientTickHandler.ticksInGame + par9; + time += new Random(par1Entity.getEntityId()).nextInt(); + GL11.glColor4f(1F, 1F, 1F, 0.7F + 0.3F * (float) (Math.sin(time / 5.0) + 0.5) * 2); + + float scale = 0.75F + 0.1F * (float) Math.sin(time / 10); + GL11.glScalef(scale, scale, scale); + bindEntityTexture(par1Entity); + Tessellator tessellator = Tessellator.instance; + + float r = 180.0F - renderManager.playerViewY; + GL11.glRotatef(r, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-renderManager.playerViewX, 1F, 0F, 0F); + func_77026_a(tessellator, iicon); + + IIcon spinningIcon = getSpinningIcon(tEntity); + if(spinningIcon != null) { + GL11.glTranslatef(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F); + GL11.glScalef(0.2F, 0.2F, 0.2F); + func_77026_a(tessellator, spinningIcon); + } + + GL11.glRotatef(-r, 0.0F, 1.0F, 0.0F); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + } + + public IIcon getBaseIcon(T entity) { + return ItemSpark.worldIcon; + } + + public IIcon getSpinningIcon(T entity) { + return null; + } + + @Override + protected ResourceLocation getEntityTexture(Entity p_110775_1_) { + return TextureMap.locationItemsTexture; + } + + private void func_77026_a(Tessellator p_77026_1_, IIcon p_77026_2_) { + float f = p_77026_2_.getMinU(); + float f1 = p_77026_2_.getMaxU(); + float f2 = p_77026_2_.getMinV(); + float f3 = p_77026_2_.getMaxV(); + float f4 = 1.0F; + float f5 = 0.5F; + float f6 = 0.25F; + + p_77026_1_.startDrawingQuads(); + p_77026_1_.setNormal(0.0F, 1.0F, 0.0F); + p_77026_1_.setBrightness(240); + p_77026_1_.addVertexWithUV(0.0F - f5, 0.0F - f6, 0.0D, f, f3); + p_77026_1_.addVertexWithUV(f4 - f5, 0.0F - f6, 0.0D, f1, f3); + p_77026_1_.addVertexWithUV(f4 - f5, f4 - f6, 0.0D, f1, f2); + p_77026_1_.addVertexWithUV(0.0F - f5, f4 - f6, 0.0D, f, f2); + p_77026_1_.draw(); + + } + +} diff --git a/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java b/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java index aacad8d0e..933102794 100644 --- a/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/src/main/java/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -289,6 +289,8 @@ public final class BotaniaCreativeTab extends CreativeTabs { addItem(ModItems.manaGun); addItem(ModItems.clip); addItem(ModItems.lens); + + addItem(ModItems.corporeaSpark); } private void addItem(Item item) { diff --git a/src/main/java/vazkii/botania/common/entity/EntityCorporeaSpark.java b/src/main/java/vazkii/botania/common/entity/EntityCorporeaSpark.java new file mode 100644 index 000000000..367c44bda --- /dev/null +++ b/src/main/java/vazkii/botania/common/entity/EntityCorporeaSpark.java @@ -0,0 +1,226 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 13, 2015, 10:52:40 PM (GMT)] + */ +package vazkii.botania.common.entity; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import vazkii.botania.api.corporea.ICorporeaSpark; +import vazkii.botania.common.core.helper.InventoryHelper; +import vazkii.botania.common.item.ModItems; + +public class EntityCorporeaSpark extends Entity implements ICorporeaSpark { + + private static final int SCAN_RANGE = 8; + + private static final String TAG_MASTER = "master"; + private static final String TAG_NETWORK = "network"; + + ICorporeaSpark master; + List connections = new ArrayList(); + List relatives = new ArrayList(); + boolean firstUpdate = true; + boolean didStartupParticles = false; + + public EntityCorporeaSpark(World world) { + super(world); + isImmuneToFire = true; + } + + @Override + protected void entityInit() { + setSize(0.5F, 0.5F); + dataWatcher.addObject(28, 0); + dataWatcher.addObject(29, 0); + + dataWatcher.setObjectWatched(28); + dataWatcher.setObjectWatched(29); + } + + @Override + public boolean canBeCollidedWith() { + return true; + } + + @Override + public void onUpdate() { + super.onUpdate(); + IInventory inv = getInventory(); + if(inv == null) { + if(!worldObj.isRemote) + setDead(); + return; + } + + if(isMaster()) + master = this; + + if(firstUpdate) { + if(isMaster()) + restartNetwork(); + else { + List sparks = getNearbySparks(); + if(sparks.size() > 0) { + for(ICorporeaSpark spark : sparks) { + ICorporeaSpark master = spark.getMaster(); + if(master != null) { + this.master = master; + restartNetwork(); + break; + } + } + } + } + + firstUpdate = false; + } + + if(!didStartupParticles) { + displayRelatives(new ArrayList(), master); + didStartupParticles = true; + } + } + + @Override + public void setDead() { + super.setDead(); + if(!worldObj.isRemote) + entityDropItem(new ItemStack(ModItems.corporeaSpark, 1, isMaster() ? 1 : 0), 0F); + connections.remove(this); + restartNetwork(); + } + + @Override + public void registerConnections(ICorporeaSpark master, ICorporeaSpark referrer, List connections) { + List sparks = getNearbySparks(); + relatives.clear(); + for(ICorporeaSpark spark : sparks) { + if(spark == null || connections.contains(spark) || spark.getNetwork() != getNetwork() || spark.isMaster()) + continue; + + connections.add(spark); + relatives.add(spark); + spark.registerConnections(master, this, connections); + } + + this.master = master; + this.connections = connections; + } + + List getNearbySparks() { + return worldObj.getEntitiesWithinAABB(ICorporeaSpark.class, AxisAlignedBB.getBoundingBox(posX - SCAN_RANGE, posY - SCAN_RANGE, posZ - SCAN_RANGE, posX + SCAN_RANGE, posY + SCAN_RANGE, posZ + SCAN_RANGE)); + } + + public void restartNetwork() { + if(master != null) + master.registerConnections(master, this, new ArrayList()); + } + + void displayRelatives(ArrayList checked, ICorporeaSpark spark) { + if(spark == null) + return; + + List sparks = spark.getRelatives(); + if(sparks.isEmpty()) + EntitySpark.particleBeam((Entity) spark, (Entity) spark.getMaster()); + else for(ICorporeaSpark endSpark : sparks) { + if(!checked.contains(endSpark)) { + EntitySpark.particleBeam((Entity) spark, (Entity) endSpark); + checked.add(endSpark); + displayRelatives(checked, endSpark); + } + } + } + + @Override + public IInventory getInventory() { + int x = MathHelper.floor_double(posX); + int y = MathHelper.floor_double(posY - 1); + int z = MathHelper.floor_double(posZ); + return InventoryHelper.getInventory(worldObj, x, y, z); + } + + @Override + public List getConnections() { + return connections; + } + + @Override + public List getRelatives() { + return relatives; + } + + @Override + public ICorporeaSpark getMaster() { + return master; + } + + public void setMaster(boolean master) { + dataWatcher.updateObject(28, master ? 1 : 0); + } + + @Override + public boolean isMaster() { + return dataWatcher.getWatchableObjectInt(28) == 1; + } + + public void setNetwork(int network) { + dataWatcher.updateObject(29, network); + } + + @Override + public int getNetwork() { + return dataWatcher.getWatchableObjectInt(29); + } + + @Override + public boolean interactFirst(EntityPlayer player) { + ItemStack stack = player.getCurrentEquippedItem(); + if(stack != null) { + if(stack.getItem() == ModItems.twigWand) { + if(player.isSneaking()) { + setDead(); + if(player.worldObj.isRemote) + player.swingItem(); + return true; + } else { + didStartupParticles = false; + return true; + } + } // TODO Dyeing + } + + return false; + } + + @Override + protected void readEntityFromNBT(NBTTagCompound cmp) { + setMaster(cmp.getBoolean(TAG_MASTER)); + setNetwork(cmp.getInteger(TAG_NETWORK)); + } + + @Override + protected void writeEntityToNBT(NBTTagCompound cmp) { + cmp.setBoolean(TAG_MASTER, isMaster()); + cmp.setInteger(TAG_NETWORK, getNetwork()); + } + +} diff --git a/src/main/java/vazkii/botania/common/entity/EntitySpark.java b/src/main/java/vazkii/botania/common/entity/EntitySpark.java index a3b956d32..a930a3ef0 100644 --- a/src/main/java/vazkii/botania/common/entity/EntitySpark.java +++ b/src/main/java/vazkii/botania/common/entity/EntitySpark.java @@ -71,30 +71,8 @@ public class EntitySpark extends Entity implements ISparkEntity { List allSparks = SparkHelper.getSparksAround(worldObj, posX, posY, posZ); if(worldObj.isRemote && !didStartupParticles) { - for(ISparkEntity spark : allSparks) { - Entity e = (Entity) spark; - Vector3 orig = new Vector3(e.posX , e.posY + 0.25, e.posZ); - Vector3 end = new Vector3(posX, posY + 0.25, posZ); - Vector3 diff = end.copy().sub(orig); - Vector3 movement = diff.copy().normalize().multiply(0.05); - int iters = (int) (diff.mag() / movement.mag()); - float huePer = 1F / iters; - float hueSum = (float) Math.random(); - - Vector3 currentPos = orig.copy(); - for(int i = 0; i < iters; i++) { - float hue = i * huePer + hueSum; - Color color = Color.getHSBColor(hue, 1F, 1F); - float r = Math.min(1F, color.getRed() / 255F + 0.4F); - float g = Math.min(1F, color.getGreen() / 255F + 0.4F); - float b = Math.min(1F, color.getBlue() / 255F + 0.4F); - - Botania.proxy.setSparkleFXNoClip(true); - Botania.proxy.sparkleFX(worldObj, currentPos.x, currentPos.y, currentPos.z, r, g, b, 0.6F, 12); - Botania.proxy.setSparkleFXNoClip(false); - currentPos.add(movement); - } - } + for(ISparkEntity spark : allSparks) + particleBeam(this, (Entity) spark); didStartupParticles = true; } @@ -229,6 +207,33 @@ public class EntitySpark extends Entity implements ISparkEntity { Botania.proxy.wispFX(worldObj, thisVec.x, thisVec.y, thisVec.z, r, g, b, size, (float) motion.x, (float) motion.y, (float) motion.z); } + + public static void particleBeam(Entity e1, Entity e2) { + if(e1 == null || e2 == null) + return; + + Vector3 orig = new Vector3(e1.posX , e1.posY + 0.25, e1.posZ); + Vector3 end = new Vector3(e2.posX, e2.posY + 0.25, e2.posZ); + Vector3 diff = end.copy().sub(orig); + Vector3 movement = diff.copy().normalize().multiply(0.05); + int iters = (int) (diff.mag() / movement.mag()); + float huePer = 1F / iters; + float hueSum = (float) Math.random(); + + Vector3 currentPos = orig.copy(); + for(int i = 0; i < iters; i++) { + float hue = i * huePer + hueSum; + Color color = Color.getHSBColor(hue, 1F, 1F); + float r = Math.min(1F, color.getRed() / 255F + 0.4F); + float g = Math.min(1F, color.getGreen() / 255F + 0.4F); + float b = Math.min(1F, color.getBlue() / 255F + 0.4F); + + Botania.proxy.setSparkleFXNoClip(true); + Botania.proxy.sparkleFX(e1.worldObj, currentPos.x, currentPos.y, currentPos.z, r, g, b, 0.6F, 12); + Botania.proxy.setSparkleFXNoClip(false); + currentPos.add(movement); + } + } @Override public boolean canBeCollidedWith() { diff --git a/src/main/java/vazkii/botania/common/entity/ModEntities.java b/src/main/java/vazkii/botania/common/entity/ModEntities.java index d5b492f8a..d029d83e8 100644 --- a/src/main/java/vazkii/botania/common/entity/ModEntities.java +++ b/src/main/java/vazkii/botania/common/entity/ModEntities.java @@ -30,6 +30,7 @@ public final class ModEntities { EntityRegistry.registerModEntity(EntityThrownItem.class, LibEntityNames.THROWN_ITEM, id++, Botania.instance, 64, 20, true); EntityRegistry.registerModEntity(EntityMagicMissile.class, LibEntityNames.MAGIC_MISSILE, id++, Botania.instance, 64, 10, true); EntityRegistry.registerModEntity(EntityThornChakram.class, LibEntityNames.THORN_CHAKRAM, id++, Botania.instance, 64, 10, true); + EntityRegistry.registerModEntity(EntityCorporeaSpark.class, LibEntityNames.CORPOREA_SPARK, id++, Botania.instance, 64, 10, false); } } diff --git a/src/main/java/vazkii/botania/common/item/ItemCorporeaSpark.java b/src/main/java/vazkii/botania/common/item/ItemCorporeaSpark.java new file mode 100644 index 000000000..d8ae2dbd8 --- /dev/null +++ b/src/main/java/vazkii/botania/common/item/ItemCorporeaSpark.java @@ -0,0 +1,79 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 13, 2015, 10:25:32 PM (GMT)] + */ +package vazkii.botania.common.item; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import vazkii.botania.client.core.helper.IconHelper; +import vazkii.botania.common.entity.EntityCorporeaSpark; +import vazkii.botania.common.lib.LibItemNames; + +public class ItemCorporeaSpark extends ItemMod { + + public static IIcon invIcon, worldIcon, invIconMaster, worldIconMaster; + + public ItemCorporeaSpark() { + setUnlocalizedName(LibItemNames.CORPOREA_SPARK); + setHasSubtypes(true); + } + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for(int i = 0; i < 2; i++) + list.add(new ItemStack(item, 1, i)); + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xv, float yv, float zv) { + TileEntity tile = world.getTileEntity(x, y, z); + if(tile instanceof IInventory) { // TODO Check for spark in position already + stack.stackSize--; + if(!world.isRemote) { + EntityCorporeaSpark spark = new EntityCorporeaSpark(world); + if(stack.getItemDamage() == 1) + spark.setMaster(true); + spark.setPosition(x + 0.5, y + 1.5, z + 0.5); + world.spawnEntityInWorld(spark); + world.markBlockForUpdate(x, y, z); + } + return true; + } + return false; + } + + @Override + public void registerIcons(IIconRegister par1IconRegister) { + invIcon = IconHelper.forItem(par1IconRegister, this, 0); + worldIcon = IconHelper.forItem(par1IconRegister, this, 1); + invIconMaster = IconHelper.forItem(par1IconRegister, this, 2); + worldIconMaster = IconHelper.forItem(par1IconRegister, this, 3); + } + + @Override + public String getUnlocalizedName(ItemStack par1ItemStack) { + return super.getUnlocalizedName(par1ItemStack) + par1ItemStack.getItemDamage(); + } + + @Override + public IIcon getIconFromDamage(int meta) { + return meta == 0 ? invIcon : invIconMaster; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/ModItems.java b/src/main/java/vazkii/botania/common/item/ModItems.java index e81251952..d9c0f082e 100644 --- a/src/main/java/vazkii/botania/common/item/ModItems.java +++ b/src/main/java/vazkii/botania/common/item/ModItems.java @@ -201,6 +201,7 @@ public final class ModItems { public static Item overgrowthSeed; public static Item craftPattern; public static Item ancientWill; + public static Item corporeaSpark; public static void init() { lexicon = new ItemLexicon(); @@ -310,6 +311,7 @@ public final class ModItems { overgrowthSeed = new ItemOvergrowthSeed(); craftPattern = new ItemCraftPattern(); ancientWill = new ItemAncientWill(); + corporeaSpark = new ItemCorporeaSpark(); OreDictionary.registerOre(LibOreDict.LEXICON, lexicon); for(int i = 0; i < 16; i++) { diff --git a/src/main/java/vazkii/botania/common/lib/LibEntityNames.java b/src/main/java/vazkii/botania/common/lib/LibEntityNames.java index 1eb28e062..22c40695e 100644 --- a/src/main/java/vazkii/botania/common/lib/LibEntityNames.java +++ b/src/main/java/vazkii/botania/common/lib/LibEntityNames.java @@ -25,5 +25,6 @@ public final class LibEntityNames { public static final String THROWN_ITEM = LibResources.PREFIX_MOD + "thrownItem"; public static final String MAGIC_MISSILE = LibResources.PREFIX_MOD + "magicMissile"; public static final String THORN_CHAKRAM = LibResources.PREFIX_MOD + "thornChakram"; + public static final String CORPOREA_SPARK = LibResources.PREFIX_MOD + "corporeaSpark"; } diff --git a/src/main/java/vazkii/botania/common/lib/LibItemNames.java b/src/main/java/vazkii/botania/common/lib/LibItemNames.java index 743cf4774..45d5c3955 100644 --- a/src/main/java/vazkii/botania/common/lib/LibItemNames.java +++ b/src/main/java/vazkii/botania/common/lib/LibItemNames.java @@ -120,6 +120,7 @@ public final class LibItemNames { public static final String OVERGROWTH_SEED = "overgrowthSeed"; public static final String CRAFT_PATTERN = "craftPattern"; public static final String ANCIENT_WILL = "ancientWill"; + public static final String CORPOREA_SPARK = "corporeaSpark"; public static final String[] LENS_NAMES = new String[] { "lensNormal", diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index a954d7099..28537857c 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -296,6 +296,7 @@ entity.Botania.botania:spark.name=Spark entity.Botania.botania:thrownItem.name=Thrown Item entity.Botania.botania:magicMissile.name=Magic Missile entity.Botania.botania:thornChakram.name=Thorn Chakram +entity.Botania.botania:corporeaSpark.name=Corporea Spark # ACHIEVEMENT NAMES + DESC achievement.botania:flowerPickup=Sky of Beginning @@ -1012,6 +1013,8 @@ item.botania:ancientWill2.name=Will of Guthan item.botania:ancientWill3.name=Will of Torag item.botania:ancientWill4.name=Will of Verac item.botania:ancientWill5.name=Will of Karil +item.botania:corporeaSpark0.name=Corporea Spark +item.botania:corporeaSpark1.name=Master Corporea Spark # BREW NAMES botania.brew.fallback=Fallback diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark0.png b/src/main/resources/assets/botania/textures/items/corporeaSpark0.png new file mode 100644 index 000000000..512d55712 Binary files /dev/null and b/src/main/resources/assets/botania/textures/items/corporeaSpark0.png differ diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark0.png.mcmeta b/src/main/resources/assets/botania/textures/items/corporeaSpark0.png.mcmeta new file mode 100644 index 000000000..ffd1e527a --- /dev/null +++ b/src/main/resources/assets/botania/textures/items/corporeaSpark0.png.mcmeta @@ -0,0 +1,20 @@ +{ + "animation": { + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 6, + 5, + 4, + 3, + 2, + 1, + 0 + ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark1.png b/src/main/resources/assets/botania/textures/items/corporeaSpark1.png new file mode 100644 index 000000000..dd355be2d Binary files /dev/null and b/src/main/resources/assets/botania/textures/items/corporeaSpark1.png differ diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark1.png.mcmeta b/src/main/resources/assets/botania/textures/items/corporeaSpark1.png.mcmeta new file mode 100644 index 000000000..a706817a6 --- /dev/null +++ b/src/main/resources/assets/botania/textures/items/corporeaSpark1.png.mcmeta @@ -0,0 +1,23 @@ +{ + "animation": { + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 6, + 5, + 4, + 3, + 2, + 1, + 0 + ] + }, + "texture": { + "blur": true + } +} \ No newline at end of file diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark2.png b/src/main/resources/assets/botania/textures/items/corporeaSpark2.png new file mode 100644 index 000000000..004ffcc46 Binary files /dev/null and b/src/main/resources/assets/botania/textures/items/corporeaSpark2.png differ diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark2.png.mcmeta b/src/main/resources/assets/botania/textures/items/corporeaSpark2.png.mcmeta new file mode 100644 index 000000000..ffd1e527a --- /dev/null +++ b/src/main/resources/assets/botania/textures/items/corporeaSpark2.png.mcmeta @@ -0,0 +1,20 @@ +{ + "animation": { + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 6, + 5, + 4, + 3, + 2, + 1, + 0 + ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark3.png b/src/main/resources/assets/botania/textures/items/corporeaSpark3.png new file mode 100644 index 000000000..4814a6c35 Binary files /dev/null and b/src/main/resources/assets/botania/textures/items/corporeaSpark3.png differ diff --git a/src/main/resources/assets/botania/textures/items/corporeaSpark3.png.mcmeta b/src/main/resources/assets/botania/textures/items/corporeaSpark3.png.mcmeta new file mode 100644 index 000000000..a706817a6 --- /dev/null +++ b/src/main/resources/assets/botania/textures/items/corporeaSpark3.png.mcmeta @@ -0,0 +1,23 @@ +{ + "animation": { + "frames": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 6, + 5, + 4, + 3, + 2, + 1, + 0 + ] + }, + "texture": { + "blur": true + } +} \ No newline at end of file