More work on Sparks and their upgrades.

This commit is contained in:
Lizbeth Rika committed 2014-08-21 21:31:45 +01:00
1 parent cf6a6c96c0
commit 8e989a68b7
7 files changed
+165 -65

No files matched your search

@@ -24,6 +24,10 @@ public interface ISparkEntity {
public void registerTransfer(ISparkEntity entity);
public int getUpgrade();
public void setUpgrade(int upgrade);
public boolean areIncomingTransfersDone();
}
@@ -13,17 +13,22 @@ package vazkii.botania.api.mana.spark;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
public final class SparkHelper {
public static final int SPARK_SCAN_RANGE = 16;
public static final int SPARK_SCAN_RANGE = 12;
public static List<ISparkEntity> getSparksAround(World world, double x, double y, double z) {
return SparkHelper.getEntitiesAround(ISparkEntity.class, world, x, y, z);
}
public static <T> List<T> getEntitiesAround(Class<? extends T> clazz, World world, double x, double y, double z) {
int r = SPARK_SCAN_RANGE;
List<ISparkEntity> sparks = world.getEntitiesWithinAABB(ISparkEntity.class, AxisAlignedBB.getBoundingBox(x - r, y - r, z - r, x + r, y + r, z + r));
return sparks;
List<T> entities = world.getEntitiesWithinAABB(clazz, AxisAlignedBB.getBoundingBox(x - r, y - r, z - r, x + r, y + r, z + r));
return entities;
}
}
@@ -21,7 +21,7 @@ import net.minecraft.world.World;
public interface IWandable {
/**
* Called when the item is used by a wand. Note that the player parameter can be null
* Called when the block is used by a wand. Note that the player parameter can be null
* if this function is called from a dispenser.
*/
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, int x, int y, int z, int side);
@@ -15,8 +15,11 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import vazkii.botania.api.mana.spark.ISparkEntity;
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;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.client.renderer.texture.TextureMap;
@@ -31,52 +34,63 @@ public class RenderSpark extends RenderEntity {
@Override
public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) {
EntitySpark spark = (EntitySpark) par1Entity;
IIcon iicon = ItemSpark.worldIcon;
if(iicon != null) {
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);
int time = ClientTickHandler.ticksInGame;
GL11.glColor4f(1F, 1F, 1F, 0.7F + (0.3F * (float) (Math.sin((double) time / 5.0) + 0.5) * 2));
GL11.glScalef(0.75F, 0.75F, 0.75F);
this.bindEntityTexture(par1Entity);
Tessellator tessellator = Tessellator.instance;
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);
this.func_77026_a(tessellator, iicon);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
int time = ClientTickHandler.ticksInGame;
GL11.glColor4f(1F, 1F, 1F, 0.7F + (0.3F * (float) (Math.sin((double) time / 5.0) + 0.5) * 2));
GL11.glScalef(0.75F, 0.75F, 0.75F);
this.bindEntityTexture(par1Entity);
Tessellator tessellator = Tessellator.instance;
float r = 180.0F - this.renderManager.playerViewY;
GL11.glRotatef(r, 0.0F, 1.0F, 0.0F);
this.func_77026_a(tessellator, iicon);
int upgrade = spark.getUpgrade() - 1;
if(upgrade >= 0 && upgrade < ItemSparkUpgrade.worldIcons.length) {
GL11.glTranslatef(-0.02F, 0.24F, 0.005F);
GL11.glScalef(0.15F, 0.15F, 0.15F);
this.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();
}
@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;
GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
p_77026_1_.startDrawingQuads();
p_77026_1_.setNormal(0.0F, 1.0F, 0.0F);
p_77026_1_.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);
p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);
p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);
p_77026_1_.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);
p_77026_1_.draw();
}
@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((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);
p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);
p_77026_1_.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);
p_77026_1_.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);
p_77026_1_.draw();
}
}
@@ -16,13 +16,16 @@ import java.util.Collection;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.spark.ISparkAttachable;
import vazkii.botania.api.mana.spark.ISparkEntity;
import vazkii.botania.api.mana.spark.SparkHelper;
import vazkii.botania.common.Botania;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.item.ModItems;
@@ -30,13 +33,15 @@ import vazkii.botania.common.item.ModItems;
public class EntitySpark extends Entity implements ISparkEntity {
private static final int TRANSFER_RATE = 1000;
private static final String TAG_UPGRADE = "upgrade";
public EntitySpark(World world) {
super(world);
}
@Override
protected void entityInit() {
setSize(0.5F, 0.5F);
dataWatcher.addObject(28, 0);
dataWatcher.addObject(29, "");
@@ -47,49 +52,118 @@ public class EntitySpark extends Entity implements ISparkEntity {
@Override
public void onUpdate() {
super.onUpdate();
ISparkAttachable tile = getAttachedTile();
if(tile == null) {
setDead();
return;
}
if(getUpgrade() != 0) {
int upgrade = getUpgrade();
if(upgrade != 0) {
List<ISparkEntity> sparks = SparkHelper.getSparksAround(worldObj, posX, posY, posZ);
switch(upgrade) {
case 1 : { // Dispersive
List<EntityPlayer> players = SparkHelper.getEntitiesAround(EntityPlayer.class, worldObj, posX, posY, posZ);
break;
}
case 2 : { // Dominant
for(ISparkEntity spark : sparks) {
int upgrade_ = spark.getUpgrade();
if(upgrade == 0 || upgrade == 3)
spark.registerTransfer(this);
}
break;
}
case 3 : { // Recessive
for(ISparkEntity spark : sparks) {
int upgrade_ = spark.getUpgrade();
if(upgrade != 4)
registerTransfer(spark);
}
break;
}
}
}
Collection<ISparkEntity> sparks = getTransfers();
if(!sparks.isEmpty()) {
int manaTotal = Math.min(TRANSFER_RATE * sparks.size(), tile.getCurrentMana());
int manaForEach = manaTotal / sparks.size();
for(ISparkEntity spark : sparks) {
ISparkAttachable attached = spark.getAttachedTile();
tile.recieveMana(-manaForEach);
attached.recieveMana(manaForEach);
Vector3 thisVec = Vector3.fromEntityCenter(this).add(0, 1, 0);
Vector3 receiverVec = Vector3.fromEntityCenter((Entity) spark).add(0, 1, 0);
Vector3 motion = receiverVec.copy().sub(thisVec);
motion.multiply(0.04125F);
Botania.proxy.wispFX(worldObj, posX, posY, posZ, 0F, 0F, 1F, 0.25F, (float) motion.x, (float) motion.y, (float) motion.z);
if(manaForEach > sparks.size())
for(ISparkEntity spark : sparks) {
ISparkAttachable attached = spark.getAttachedTile();
attached.recieveMana(manaForEach);
particlesTowards((Entity) spark);
}
tile.recieveMana(-manaForEach);
}
}
void particlesTowards(Entity e) {
Vector3 thisVec = Vector3.fromEntityCenter(this).add(0, 0, 0);
Vector3 receiverVec = Vector3.fromEntityCenter(e).add(0, 0, 0);
double rc = 0.45;
thisVec.add((Math.random() - 0.5) * rc, (Math.random() - 0.5) * rc, (Math.random() - 0.5) * rc);
receiverVec.add((Math.random() - 0.5) * rc, (Math.random() - 0.5) * rc, (Math.random() - 0.5) * rc);
Vector3 motion = receiverVec.copy().sub(thisVec);
motion.multiply(0.04125F);
float r = 0.3F + 0.6F * (float) Math.random();
float g = 0.3F + 0.6F * (float) Math.random();
float b = 0.3F + 0.6F * (float) Math.random();
Botania.proxy.wispFX(worldObj, thisVec.x, thisVec.y, thisVec.z, r, g, b, 0.25F, (float) motion.x, (float) motion.y, (float) motion.z);
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean interactFirst(EntityPlayer player) {
ItemStack stack = player.getCurrentEquippedItem();
if(stack != null) {
int upgrade = getUpgrade();
if(stack.getItem() == ModItems.twigWand) {
if(upgrade > 0) {
if(!worldObj.isRemote)
entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade + 1), 0F);
setUpgrade(0);
} else setDead();
return true;
} else if(stack.getItem() == ModItems.sparkUpgrade && upgrade == 0) {
int newUpgrade = stack.getItemDamage() + 1;
setUpgrade(newUpgrade);
stack.stackSize--;
return true;
}
}
return false;
}
@Override
protected void readEntityFromNBT(NBTTagCompound cmp) {
setUpgrade(cmp.getInteger(TAG_UPGRADE));
}
@Override
protected void writeEntityToNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_UPGRADE, getUpgrade());
}
@Override
public void setDead() {
super.setDead();
if(!worldObj.isRemote) {
int upgrade = getUpgrade();
entityDropItem(new ItemStack(ModItems.spark), 0F);
// Upgrade Drop here
if(upgrade > 0)
entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade + 1), 0F);
}
}
@@ -116,7 +190,7 @@ public class EntitySpark extends Entity implements ISparkEntity {
for(String s : tokens) {
if(s.isEmpty())
continue;
int id = Integer.parseInt(s);
boolean added = false;
Entity e = worldObj.getEntityByID(id);
@@ -149,15 +223,17 @@ public class EntitySpark extends Entity implements ISparkEntity {
public void registerTransfer(ISparkEntity entity) {
if(worldObj.isRemote || getTransfers().contains(entity))
return;
String transfers = dataWatcher.getWatchableObjectString(29);
dataWatcher.updateObject(29, transfers + (transfers.isEmpty() ? "" : ";") + ((Entity) entity).getEntityId());
}
@Override
public int getUpgrade() {
return dataWatcher.getWatchableObjectInt(28);
}
@Override
public void setUpgrade(int upgrade) {
dataWatcher.updateObject(28, upgrade);
}
@@ -61,7 +61,7 @@ public class ItemSpark extends ItemMod {
@Override
public IIcon getIconFromDamage(int p_77617_1_) {
return worldIcon;
return invIcon;
}
}
@@ -19,6 +19,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
@@ -173,7 +174,7 @@ public class ItemTwigWand extends Item16Colors implements ICoordBoundItem {
return false;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
int ticks = getTicksSinceSpreaderUse(par1ItemStack);