First steps on corporea stuff. Sparks attach and index the network.

This commit is contained in:
Lizbeth Rika committed 2015-02-14 01:58:11 +00:00
1 parent 01ea000244
commit 9c3d58f0a5
23 files changed
+643 -98

No files matched your search

@@ -0,0 +1,75 @@
/**
* This class was created by <Vazkii>. 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.
* <br><br>
* 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<ICorporeaSpark> 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<ICorporeaSpark> 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<ICorporeaSpark> 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();
}
@@ -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;
@@ -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();
}
@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. 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<EntityCorporeaSpark> {
@Override
public IIcon getBaseIcon(EntityCorporeaSpark entity) {
return entity.isMaster() ? ItemCorporeaSpark.worldIconMaster : ItemCorporeaSpark.worldIcon;
}
}
@@ -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<EntitySpark> {
@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();
}
}
@@ -0,0 +1,104 @@
/**
* This class was created by <Vazkii>. 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<T extends Entity> 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();
}
}
@@ -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) {
@@ -0,0 +1,226 @@
/**
* This class was created by <Vazkii>. 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<ICorporeaSpark> connections = new ArrayList();
List<ICorporeaSpark> 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<ICorporeaSpark> 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<ICorporeaSpark> connections) {
List<ICorporeaSpark> 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<ICorporeaSpark> 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<ICorporeaSpark> checked, ICorporeaSpark spark) {
if(spark == null)
return;
List<ICorporeaSpark> 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<ICorporeaSpark> getConnections() {
return connections;
}
@Override
public List<ICorporeaSpark> 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());
}
}
@@ -71,30 +71,8 @@ public class EntitySpark extends Entity implements ISparkEntity {
List<ISparkEntity> 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() {
@@ -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);
}
}
@@ -0,0 +1,79 @@
/**
* This class was created by <Vazkii>. 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;
}
}
@@ -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++) {
@@ -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";
}
@@ -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",