Work on the Dispersive upgrade, some fixes around for the sparks.

This commit is contained in:
Lizbeth Rika committed 2014-08-21 23:09:49 +01:00
1 parent 8e989a68b7
commit 89364fa445
2 files changed
+91 -19

No files matched your search

@@ -12,8 +12,12 @@
package vazkii.botania.common.entity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
@@ -22,6 +26,7 @@ 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.IManaItem;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.spark.ISparkAttachable;
import vazkii.botania.api.mana.spark.ISparkEntity;
@@ -29,11 +34,13 @@ 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;
import baubles.common.lib.PlayerHandler;
public class EntitySpark extends Entity implements ISparkEntity {
private static final int TRANSFER_RATE = 1000;
private static final String TAG_UPGRADE = "upgrade";
int removeTransferants = 2;
public EntitySpark(World world) {
super(world);
@@ -59,46 +66,104 @@ public class EntitySpark extends Entity implements ISparkEntity {
return;
}
Collection<ISparkEntity> transfers = getTransfers();
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);
Map<EntityPlayer, Map<ItemStack, Integer>> receivingPlayers = new HashMap();
ItemStack input = new ItemStack(ModItems.spark);
for(EntityPlayer player : players) {
List<ItemStack> stacks = new ArrayList();
stacks.addAll(Arrays.asList(player.inventory.mainInventory));
stacks.addAll(Arrays.asList(player.inventory.armorInventory));
stacks.addAll(Arrays.asList(PlayerHandler.getPlayerBaubles(player).stackList));
for(ItemStack stack : stacks) {
if(stack == null || !(stack.getItem() instanceof IManaItem))
continue;
IManaItem manaItem = (IManaItem) stack.getItem();
if(manaItem.canReceiveManaFromItem(stack, input)) {
Map receivingStacks;
boolean add = false;
if(!receivingPlayers.containsKey(player)) {
add = true;
receivingStacks = new HashMap();
} else receivingStacks = receivingPlayers.get(player);
int recv = Math.min(getAttachedTile().getCurrentMana(), Math.min(TRANSFER_RATE, manaItem.getMaxMana(stack) - manaItem.getMana(stack)));
if(recv > 0) {
receivingStacks.put(stack, recv);
if(add)
receivingPlayers.put(player, receivingStacks);
}
}
}
}
if(!receivingPlayers.isEmpty()) {
List<EntityPlayer> keys = new ArrayList(receivingPlayers.keySet());
Collections.shuffle(keys);
EntityPlayer player = keys.iterator().next();
Map<ItemStack, Integer> items = receivingPlayers.get(player);
ItemStack stack = items.keySet().iterator().next();
int cost = items.get(stack);
int manaToPut = Math.min(getAttachedTile().getCurrentMana(), cost);
((IManaItem) stack.getItem()).addMana(stack, manaToPut);
getAttachedTile().recieveMana(-manaToPut);
particlesTowards(player);
}
break;
}
case 2 : { // Dominant
for(ISparkEntity spark : sparks) {
if(spark == this)
continue;
int upgrade_ = spark.getUpgrade();
if(upgrade == 0 || upgrade == 3)
if(upgrade_ == 0)
spark.registerTransfer(this);
}
break;
}
case 3 : { // Recessive
for(ISparkEntity spark : sparks) {
if(spark == this)
continue;
int upgrade_ = spark.getUpgrade();
if(upgrade != 4)
registerTransfer(spark);
if(upgrade_ != 2 && upgrade_ != 4)
transfers.add(spark);
}
break;
}
}
}
Collection<ISparkEntity> sparks = getTransfers();
if(!sparks.isEmpty()) {
int manaTotal = Math.min(TRANSFER_RATE * sparks.size(), tile.getCurrentMana());
int manaForEach = manaTotal / sparks.size();
if(manaForEach > sparks.size())
for(ISparkEntity spark : sparks) {
if(!transfers.isEmpty()) {
int manaTotal = Math.min(TRANSFER_RATE * transfers.size(), tile.getCurrentMana());
int manaForEach = manaTotal / transfers.size();
if(manaForEach > transfers.size()) {
for(ISparkEntity spark : transfers) {
ISparkAttachable attached = spark.getAttachedTile();
attached.recieveMana(manaForEach);
particlesTowards((Entity) spark);
}
tile.recieveMana(-manaForEach);
tile.recieveMana(-manaTotal);
}
}
if(removeTransferants > 0)
removeTransferants--;
}
void particlesTowards(Entity e) {
@@ -110,12 +175,13 @@ public class EntitySpark extends Entity implements ISparkEntity {
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();
motion.multiply(0.04F);
float r = 0.5F + 0.4F * (float) Math.random();
float g = 0.5F + 0.4F * (float) Math.random();
float b = 0.5F + 0.4F * (float) Math.random();
float size = 0.125F + 0.125F * (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);
Botania.proxy.wispFX(worldObj, thisVec.x, thisVec.y, thisVec.z, r, g, b, size, (float) motion.x, (float) motion.y, (float) motion.z);
}
@Override
@@ -133,6 +199,9 @@ public class EntitySpark extends Entity implements ISparkEntity {
if(!worldObj.isRemote)
entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade + 1), 0F);
setUpgrade(0);
dataWatcher.updateObject(29, "");
removeTransferants = 2;
} else setDead();
return true;
} else if(stack.getItem() == ModItems.sparkUpgrade && upgrade == 0) {
@@ -163,7 +232,7 @@ public class EntitySpark extends Entity implements ISparkEntity {
int upgrade = getUpgrade();
entityDropItem(new ItemStack(ModItems.spark), 0F);
if(upgrade > 0)
entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade + 1), 0F);
entityDropItem(new ItemStack(ModItems.sparkUpgrade, 1, upgrade - 1), 0F);
}
}
@@ -196,7 +265,7 @@ public class EntitySpark extends Entity implements ISparkEntity {
Entity e = worldObj.getEntityByID(id);
if(e != null && e instanceof ISparkEntity) {
ISparkEntity spark = (ISparkEntity) e;
if(!spark.areIncomingTransfersDone() && spark.getAttachedTile() != null && !spark.getAttachedTile().isFull()) {
if(spark != this && !spark.areIncomingTransfersDone() && spark.getAttachedTile() != null && !spark.getAttachedTile().isFull() && spark.getUpgrade() != 4 && (getUpgrade() != 4 || !(spark.getAttachedTile() instanceof IManaPool))) {
entities.add((ISparkEntity) e);
added = true;
}
@@ -241,6 +310,9 @@ public class EntitySpark extends Entity implements ISparkEntity {
@Override
public boolean areIncomingTransfersDone() {
ISparkAttachable tile = getAttachedTile();
if(tile instanceof IManaPool)
return removeTransferants > 0;
return tile != null && tile.areIncomingTranfersDone();
}
@@ -141,7 +141,7 @@ public class ItemManaTablet extends ItemMod implements IManaItem, ICreativeManaP
@Override
public boolean canReceiveManaFromItem(ItemStack stack, ItemStack otherStack) {
return true;
return !isCreative(stack);
}
@Override