LOTS of alchemy changes...

This commit is contained in:
WayofTime 2014-08-25 07:58:39 -04:00
parent 64ccc50698
commit 2b749000b6
99 changed files with 7488 additions and 659 deletions

View file

@ -0,0 +1,378 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
public class TEAlchemicCalcinator extends TEReagentConduit implements IInventory
{
protected ItemStack[] inv;
protected ReagentContainer bufferTank = new ReagentContainer(Reagent.REAGENT_SIZE * 2);
protected int bufferTransferRate = 20;
private int lpPerTick = 10;
private int ticksPerReagent = 200;
public int progress;
public TEAlchemicCalcinator()
{
super(1, Reagent.REAGENT_SIZE * 4);
this.inv = new ItemStack[2];
this.tickRate = 20;
this.maxConnextions = 1;
this.progress = 0;
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
bufferTransferRate = tag.getInteger("bufferTransferRate");
progress = tag.getInteger("progress");
NBTTagCompound bufferTankTag = tag.getCompoundTag("bufferTank");
this.bufferTank = ReagentContainer.readFromNBT(bufferTankTag);
NBTTagList tagList = tag.getTagList("Inventory",Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound savedTag = (NBTTagCompound) tagList.getCompoundTagAt(i);
if(savedTag.getBoolean("Empty"))
{
inv[i] = null;
}else
{
inv[i] = ItemStack.loadItemStackFromNBT(savedTag);
}
}
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setInteger("bufferTransferRate", bufferTransferRate);
tag.setInteger("progress", progress);
NBTTagCompound bufferTankTag = new NBTTagCompound();
this.bufferTank.writeToNBT(bufferTankTag);
tag.setTag("bufferTank", bufferTankTag);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
NBTTagCompound savedTag = new NBTTagCompound();
if (inv[i] != null)
{
inv[i].writeToNBT(savedTag);
}else
{
savedTag.setBoolean("Empty", true);
}
itemList.appendTag(savedTag);
}
tag.setTag("Inventory", itemList);
}
@Override
public void updateEntity()
{
super.updateEntity();
if(!worldObj.isRemote)
{
moveBufferToMain();
tickProgress();
}
}
public void moveBufferToMain()
{
ReagentStack amountStack = this.bufferTank.drain(bufferTransferRate, false);
int drainAmount = this.fill(ForgeDirection.UNKNOWN, amountStack, false);
if(drainAmount > 0)
{
ReagentStack drainedStack = this.bufferTank.drain(drainAmount, true);
this.fill(ForgeDirection.UNKNOWN, drainedStack, true);
}
}
public void tickProgress()
{
ItemStack reagentItemStack = this.getStackInSlot(1);
if(reagentItemStack == null)
{
progress = 0;
return;
}
ReagentStack possibleReagent = ReagentRegistry.getReagentStackForItem(reagentItemStack);
if(possibleReagent == null || !this.canReagentFitBuffer(possibleReagent))
{
return;
}
ItemStack orbStack = this.getStackInSlot(0);
if(orbStack == null || !(orbStack.getItem() instanceof IBloodOrb))
{
return;
}
if(!SoulNetworkHandler.canSyphonFromOnlyNetwork(orbStack, lpPerTick))
{
SoulNetworkHandler.causeNauseaToPlayer(orbStack);
return;
}
SoulNetworkHandler.syphonFromNetwork(orbStack, lpPerTick);
progress++;
if (worldObj.getWorldTime() % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if(progress >= this.ticksPerReagent)
{
progress = 0;
this.bufferTank.fill(possibleReagent, true);
this.decrStackSize(1, 1);
}
}
public boolean canReagentFitBuffer(ReagentStack stack)
{
int amount = this.bufferTank.fill(stack, false);
return amount >= stack.amount;
}
@Override
public void readClientNBT(NBTTagCompound tag)
{
super.readClientNBT(tag);
NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
int size = tagList.tagCount();
this.tanks = new ReagentContainer[size];
for(int i=0; i<size; i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
this.tanks[i] = ReagentContainer.readFromNBT(savedTag);
}
NBTTagList invTagList = tag.getTagList("Inventory",Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < invTagList.tagCount(); i++)
{
NBTTagCompound savedTag = (NBTTagCompound) invTagList.getCompoundTagAt(i);
if(savedTag.getBoolean("Empty"))
{
inv[i] = null;
}else
{
inv[i] = ItemStack.loadItemStackFromNBT(savedTag);
}
}
}
@Override
public void writeClientNBT(NBTTagCompound tag)
{
super.writeClientNBT(tag);
NBTTagList tagList = new NBTTagList();
for(int i=0; i<this.tanks.length; i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
if(this.tanks[i] != null)
{
this.tanks[i].writeToNBT(savedTag);
}
tagList.appendTag(savedTag);
}
tag.setTag("reagentTanks", tagList);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
NBTTagCompound savedTag = new NBTTagCompound();
if (inv[i] != null)
{
inv[i].writeToNBT(savedTag);
}else
{
savedTag.setBoolean("Empty", true);
}
itemList.appendTag(savedTag);
}
tag.setTag("Inventory", itemList);
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeClientNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -999, nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readClientNBT(packet.func_148857_g());
}
@Override
public int getSizeInventory()
{
return inv.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inv[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit())
{
stack.stackSize = getInventoryStackLimit();
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public ItemStack decrStackSize(int slot, int amt)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize <= amt)
{
setInventorySlotContents(slot, null);
} else
{
stack = stack.splitStack(amt);
if (stack.stackSize == 0)
{
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
@Override
public String getInventoryName()
{
return "AlchemicCalcinator";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemStack)
{
return true;
}
@Override
public int fill(ForgeDirection from, ReagentStack resource, boolean doFill)
{
if(doFill && !worldObj.isRemote)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return super.fill(from, resource, doFill);
}
}

View file

@ -568,8 +568,21 @@ public class TEAltar extends TileEntity implements IInventory, IFluidTank, IFlui
{
this.lockdownDuration += 20;
}
}
}
}
}
if(AlchemicalWizardry.causeHungerWithRegen)
{
List<EntityPlayer> list = SpellHelper.getPlayersInRange(worldObj, xCoord+0.5, yCoord+0.5, zCoord+0.5, 15, 15);
for(EntityPlayer player : list)
{
PotionEffect regenEffect = player.getActivePotionEffect(Potion.regeneration);
if(regenEffect != null && regenEffect.getAmplifier() > 0)
{
player.addPotionEffect(new PotionEffect(Potion.hunger.id, 40, regenEffect.getAmplifier()*2 - 2));
}
}
}
}
if (worldObj.getWorldTime() % 100 == 0)

View file

@ -0,0 +1,92 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
public class TEBellJar extends TEReagentConduit
{
public TEBellJar()
{
super(1, 16000);
this.maxConnextions = 1;
this.affectedByRedstone = false;
}
public int getRSPowerOutput()
{
ReagentContainer thisTank = this.tanks[0];
if(thisTank != null)
{
ReagentStack stack = thisTank.getReagent();
if(stack != null)
{
return (15*stack.amount/thisTank.getCapacity());
}
}
return 0;
}
// @Override
// public void readClientNBT(NBTTagCompound tag)
// {
// super.readClientNBT(tag);
//
// NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
//
// int size = tagList.tagCount();
// this.tanks = new ReagentContainer[size];
//
// for(int i=0; i<size; i++)
// {
// NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
// this.tanks[i] = ReagentContainer.readFromNBT(savedTag);
// }
// }
//
// @Override
// public void writeClientNBT(NBTTagCompound tag)
// {
// super.writeClientNBT(tag);
//
// NBTTagList tagList = new NBTTagList();
//
// for(int i=0; i<this.tanks.length; i++)
// {
// NBTTagCompound savedTag = new NBTTagCompound();
// if(this.tanks[i] != null)
// {
// this.tanks[i].writeToNBT(savedTag);
// }
// tagList.appendTag(savedTag);
// }
//
// tag.setTag("reagentTanks", tagList);
// }
@Override
public void updateEntity()
{
super.updateEntity();
if(hasChanged == 1)
{
Block block = worldObj.getBlock(xCoord+1, yCoord, zCoord);
block.onNeighborBlockChange(worldObj, xCoord+1, yCoord, zCoord, block);
block = worldObj.getBlock(xCoord-1, yCoord, zCoord);
block.onNeighborBlockChange(worldObj, xCoord-1, yCoord, zCoord, block);
block = worldObj.getBlock(xCoord, yCoord+1, zCoord);
block.onNeighborBlockChange(worldObj, xCoord, yCoord+1, zCoord, block);
block = worldObj.getBlock(xCoord, yCoord-1, zCoord);
block.onNeighborBlockChange(worldObj, xCoord, yCoord-1, zCoord, block);
block = worldObj.getBlock(xCoord, yCoord, zCoord+1);
block.onNeighborBlockChange(worldObj, xCoord, yCoord, zCoord+1, block);
block = worldObj.getBlock(xCoord, yCoord, zCoord-1);
block.onNeighborBlockChange(worldObj, xCoord, yCoord, zCoord-1, block);
}
}
}

View file

@ -1,13 +1,27 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone;
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
import WayofTime.alchemicalWizardry.api.soulNetwork.LifeEssenceNetwork;
@ -25,9 +39,15 @@ public class TEMasterStone extends TileEntity implements IMasterRitualStone
private int direction;
public boolean isRunning;
public int runningTime;
protected ReagentContainer[] tanks;
protected Map<Reagent, Integer> attunedTankMap;
public TEMasterStone()
{
tanks = new ReagentContainer[]{new ReagentContainer(1000),new ReagentContainer(1000),new ReagentContainer(1000)};
this.attunedTankMap = new HashMap();
isActive = false;
owner = "";
cooldown = 0;
@ -39,32 +59,117 @@ public class TEMasterStone extends TileEntity implements IMasterRitualStone
runningTime = 0;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
public void readClientNBT(NBTTagCompound tag)
{
super.readFromNBT(par1NBTTagCompound);
isActive = par1NBTTagCompound.getBoolean("isActive");
owner = par1NBTTagCompound.getString("owner");
cooldown = par1NBTTagCompound.getInteger("cooldown");
var1 = par1NBTTagCompound.getInteger("var1");
direction = par1NBTTagCompound.getInteger("direction");
currentRitualString = par1NBTTagCompound.getString("currentRitualString");
isRunning = par1NBTTagCompound.getBoolean("isRunning");
runningTime = par1NBTTagCompound.getInteger("runningTime");
currentRitualString = tag.getString("currentRitualString");
isRunning = tag.getBoolean("isRunning");
runningTime = tag.getInteger("runningTime");
NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
int size = tagList.tagCount();
this.tanks = new ReagentContainer[size];
for(int i=0; i<size; i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
this.tanks[i] = ReagentContainer.readFromNBT(savedTag);
}
}
public void writeClientNBT(NBTTagCompound tag)
{
tag.setString("currentRitualString", currentRitualString);
tag.setBoolean("isRunning", isRunning);
tag.setInteger("runningTime",runningTime);
NBTTagList tagList = new NBTTagList();
for(int i=0; i<this.tanks.length; i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
if(this.tanks[i] != null)
{
this.tanks[i].writeToNBT(savedTag);
}
tagList.appendTag(savedTag);
}
tag.setTag("reagentTanks", tagList);
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
isActive = tag.getBoolean("isActive");
owner = tag.getString("owner");
cooldown = tag.getInteger("cooldown");
var1 = tag.getInteger("var1");
direction = tag.getInteger("direction");
currentRitualString = tag.getString("currentRitualString");
isRunning = tag.getBoolean("isRunning");
runningTime = tag.getInteger("runningTime");
NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
int size = tagList.tagCount();
this.tanks = new ReagentContainer[size];
for(int i=0; i<size; i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
this.tanks[i] = ReagentContainer.readFromNBT(savedTag);
}
NBTTagList attunedTagList = tag.getTagList("attunedTankMap", Constants.NBT.TAG_COMPOUND);
for(int i=0; i<attunedTagList.tagCount(); i++)
{
NBTTagCompound savedTag = attunedTagList.getCompoundTagAt(i);
Reagent reagent = ReagentRegistry.getReagentForKey(savedTag.getString("reagent"));
this.attunedTankMap.put(reagent, savedTag.getInteger("amount"));
}
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setBoolean("isActive", isActive);
par1NBTTagCompound.setString("owner", owner);
par1NBTTagCompound.setInteger("cooldown", cooldown);
par1NBTTagCompound.setInteger("var1", var1);
par1NBTTagCompound.setInteger("direction", direction);
par1NBTTagCompound.setString("currentRitualString", currentRitualString);
par1NBTTagCompound.setBoolean("isRunning", isRunning);
par1NBTTagCompound.setInteger("runningTime",runningTime);
super.writeToNBT(tag);
tag.setBoolean("isActive", isActive);
tag.setString("owner", owner);
tag.setInteger("cooldown", cooldown);
tag.setInteger("var1", var1);
tag.setInteger("direction", direction);
tag.setString("currentRitualString", currentRitualString);
tag.setBoolean("isRunning", isRunning);
tag.setInteger("runningTime",runningTime);
NBTTagList tagList = new NBTTagList();
for(int i=0; i<this.tanks.length; i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
if(this.tanks[i] != null)
{
this.tanks[i].writeToNBT(savedTag);
}
tagList.appendTag(savedTag);
}
tag.setTag("reagentTanks", tagList);
NBTTagList attunedTagList = new NBTTagList();
for(Entry<Reagent, Integer> entry : this.attunedTankMap.entrySet())
{
NBTTagCompound savedTag = new NBTTagCompound();
savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey()));
savedTag.setInteger("amount", entry.getValue());
attunedTagList.appendTag(savedTag);
}
tag.setTag("attunedTankMap", attunedTagList);
}
public void activateRitual(World world, int crystalLevel, EntityPlayer player)
@ -269,11 +374,26 @@ public class TEMasterStone extends TileEntity implements IMasterRitualStone
this.currentRitualString = str;
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
// @Override
// public Packet getDescriptionPacket()
// {
// return NewPacketHandler.getPacket(this);
// }
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeClientNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -999, nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readClientNBT(packet.func_148857_g());
}
public AxisAlignedBB getRenderBoundingBox()
{
@ -281,4 +401,191 @@ public class TEMasterStone extends TileEntity implements IMasterRitualStone
AxisAlignedBB bb = AxisAlignedBB. getBoundingBox(xCoord-renderExtention, yCoord-renderExtention, zCoord-renderExtention, xCoord+1+renderExtention, yCoord+1+renderExtention, zCoord+1+renderExtention);
return bb;
}
/* ISegmentedReagentHandler */
@Override
public int fill(ForgeDirection from, ReagentStack resource, boolean doFill)
{
if(doFill)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
int totalFill = 0;
boolean useTankLimit = !this.attunedTankMap.isEmpty();
if(resource != null)
{
int totalTanksFillable = useTankLimit ? this.getTanksTunedToReagent(resource.reagent) : this.tanks.length;
int tanksFilled = 0;
int maxFill = resource.amount;
for(int i=this.tanks.length-1; i>=0; i--)
{
ReagentStack remainingStack = resource.copy();
remainingStack.amount = maxFill - totalFill;
boolean doesReagentMatch = tanks[i].getReagent() == null ? false : tanks[i].getReagent().isReagentEqual(remainingStack);
if(doesReagentMatch)
{
totalFill += tanks[i].fill(remainingStack, doFill);
tanksFilled++;
}else
{
continue;
}
if(totalFill >= maxFill || tanksFilled >= totalTanksFillable)
{
return totalFill;
}
}
if(tanksFilled >= totalTanksFillable)
{
return totalFill;
}
for(int i=this.tanks.length-1; i>=0; i--)
{
ReagentStack remainingStack = resource.copy();
remainingStack.amount = maxFill - totalFill;
boolean isTankEmpty = tanks[i].getReagent() == null;
if(isTankEmpty)
{
totalFill += tanks[i].fill(remainingStack, doFill);
tanksFilled++;
}else
{
continue;
}
if(totalFill >= maxFill || tanksFilled >= totalTanksFillable)
{
return totalFill;
}
}
}
return totalFill;
}
@Override
public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain)
{
if(resource == null)
{
return null;
}
if(doDrain)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
int maxDrain = resource.amount;
Reagent reagent = resource.reagent;
int drained = 0;
for(int i=0; i<tanks.length; i++)
{
if(drained >= maxDrain)
{
break;
}
if (resource.isReagentEqual(tanks[i].getReagent()))
{
ReagentStack drainStack = tanks[i].drain(maxDrain-drained, doDrain);
if(drainStack != null)
{
drained += drainStack.amount;
}
}
}
return new ReagentStack(reagent, drained);
}
/* Only returns the amount from the first available tank */
@Override
public ReagentStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
for(int i=0; i<tanks.length; i++)
{
ReagentStack stack = tanks[i].drain(maxDrain, doDrain);
if(stack != null)
{
if(doDrain)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return stack;
}
}
return null;
}
@Override
public boolean canFill(ForgeDirection from, Reagent reagent)
{
return true;
}
@Override
public boolean canDrain(ForgeDirection from, Reagent reagent)
{
return true;
}
@Override
public ReagentContainerInfo[] getContainerInfo(ForgeDirection from)
{
ReagentContainerInfo[] info = new ReagentContainerInfo[this.getNumberOfTanks()];
for(int i=0; i<this.getNumberOfTanks(); i++)
{
info[i] = tanks[i].getInfo();
}
return info;
}
@Override
public int getNumberOfTanks()
{
return tanks.length;
}
@Override
public int getTanksTunedToReagent(Reagent reagent)
{
if(this.attunedTankMap.containsKey(reagent) && this.attunedTankMap.get(reagent) != null)
{
return this.attunedTankMap.get(reagent);
}
return 0;
}
@Override
public void setTanksTunedToReagent(Reagent reagent, int total)
{
if(total == 0 && this.attunedTankMap.containsKey(reagent))
{
this.attunedTankMap.remove(reagent);
return;
}
this.attunedTankMap.put(reagent, new Integer(total));
}
@Override
public Map<Reagent, Integer> getAttunedTankMap()
{
return this.attunedTankMap;
}
}

View file

@ -1,8 +1,530 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import net.minecraft.tileentity.TileEntity;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class TEReagentConduit extends TileEntity
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import WayofTime.alchemicalWizardry.api.ColourAndCoords;
import WayofTime.alchemicalWizardry.api.alchemy.energy.IAlchemyGoggles;
import WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import WayofTime.alchemicalWizardry.api.alchemy.energy.TileSegmentedReagentHandler;
import WayofTime.alchemicalWizardry.common.Int3;
import WayofTime.alchemicalWizardry.common.entity.projectile.EntityParticleBeam;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
public class TEReagentConduit extends TileSegmentedReagentHandler
{
public List<ColourAndCoords> destinationList; //These are offsets
public Map<Reagent, List<Int3>> reagentTargetList;
public Map<Reagent, Integer> reagentTankDesignationList;
public int tickRate = 20; //Rate that the reagents are sent
}
int hasChanged = 0;
public boolean affectedByRedstone = true;
public int maxConnextions = 5;
public int renderCount = 0;
public TEReagentConduit()
{
this(2, 2000);
}
public TEReagentConduit(int numberOfTanks, int size)
{
super(numberOfTanks, size);
destinationList = new LinkedList();
reagentTargetList = new HashMap();
reagentTankDesignationList = new HashMap();
}
public Int3 getColour()
{
int[] redMap = new int[this.tanks.length];
int[] greenMap = new int[this.tanks.length];
int[] blueMap = new int[this.tanks.length];
for(int i=0; i<this.tanks.length; i++)
{
ReagentContainer container = this.tanks[i];
if(container != null && container.getReagent() != null)
{
Reagent reagent = container.getReagent().reagent;
redMap[i] = reagent.getColourRed();
greenMap[i] = reagent.getColourGreen();
blueMap[i] = reagent.getColourBlue();
}
}
int red = 0;
int green = 0;
int blue = 0;
for(int i=0; i<this.tanks.length; i++)
{
red += redMap[i];
green += greenMap[i];
blue += blueMap[i];
}
red /= this.tanks.length;
green /= this.tanks.length;
blue /= this.tanks.length;
return new Int3(red, green, blue);
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setInteger("hasChanged", hasChanged);
NBTTagList tagList = new NBTTagList();
for(int i=0; i<destinationList.size(); i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
tagList.appendTag(destinationList.get(i).writeToNBT(savedTag));
}
tag.setTag("destinationList", tagList);
NBTTagList reagentTagList = new NBTTagList(); //TODO
for(Entry<Reagent, List<Int3>> entry : reagentTargetList.entrySet())
{
NBTTagCompound savedTag = new NBTTagCompound();
savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey()));
NBTTagList coordinateTagList = new NBTTagList();
for(Int3 coord : entry.getValue())
{
NBTTagCompound coordinateTag = new NBTTagCompound();
coord.writeToNBT(coordinateTag);
coordinateTagList.appendTag(coordinateTag);
}
savedTag.setTag("coordinateList", coordinateTagList);
reagentTagList.appendTag(savedTag);
}
tag.setTag("reagentTargetList", reagentTagList);
NBTTagList tankDesignationList = new NBTTagList();
for(Entry<Reagent, Integer> entry : this.reagentTankDesignationList.entrySet())
{
NBTTagCompound savedTag = new NBTTagCompound();
savedTag.setString("reagent", ReagentRegistry.getKeyForReagent(entry.getKey()));
savedTag.setInteger("integer", entry.getValue());
tankDesignationList.appendTag(savedTag);
}
tag.setTag("tankDesignationList", tankDesignationList);
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
hasChanged = tag.getInteger("hasChanged");
NBTTagList tagList = tag.getTagList("destinationList", Constants.NBT.TAG_COMPOUND);
destinationList = new LinkedList();
for(int i=0; i<tagList.tagCount(); i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
destinationList.add(ColourAndCoords.readFromNBT(savedTag));
}
reagentTargetList = new HashMap();
NBTTagList reagentTagList = tag.getTagList("reagentTargetList", Constants.NBT.TAG_COMPOUND);
for(int i=0; i<reagentTagList.tagCount(); i++)
{
NBTTagCompound savedTag = reagentTagList.getCompoundTagAt(i);
Reagent reagent = ReagentRegistry.getReagentForKey(savedTag.getString("reagent"));
List<Int3> coordList = new LinkedList();
NBTTagList coordinateList = savedTag.getTagList("coordinateList", Constants.NBT.TAG_COMPOUND);
for(int j=0; j<coordinateList.tagCount(); j++)
{
coordList.add(Int3.readFromNBT(coordinateList.getCompoundTagAt(j)));
}
reagentTargetList.put(reagent, coordList);
}
reagentTankDesignationList = new HashMap();
NBTTagList tankDesignationList = tag.getTagList("tankDesignationList", Constants.NBT.TAG_COMPOUND);
for(int i=0; i<tankDesignationList.tagCount(); i++)
{
NBTTagCompound savedTag = tankDesignationList.getCompoundTagAt(i);
this.reagentTankDesignationList.put(ReagentRegistry.getReagentForKey(savedTag.getString("reagent")), new Integer(savedTag.getInteger("integer")));
}
}
public void readClientNBT(NBTTagCompound tag)
{
NBTTagList tagList = tag.getTagList("destinationList", Constants.NBT.TAG_COMPOUND);
destinationList = new LinkedList();
for(int i=0; i<tagList.tagCount(); i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
destinationList.add(ColourAndCoords.readFromNBT(savedTag));
}
NBTTagList reagentTagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
int size = reagentTagList.tagCount();
this.tanks = new ReagentContainer[size];
for(int i=0; i<size; i++)
{
NBTTagCompound savedTag = reagentTagList.getCompoundTagAt(i);
this.tanks[i] = ReagentContainer.readFromNBT(savedTag);
}
}
public void writeClientNBT(NBTTagCompound tag)
{
NBTTagList tagList = new NBTTagList();
for(int i=0; i<destinationList.size(); i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
tagList.appendTag(destinationList.get(i).writeToNBT(savedTag));
}
tag.setTag("destinationList", tagList);
NBTTagList reagentTagList = new NBTTagList();
for(int i=0; i<this.tanks.length; i++)
{
NBTTagCompound savedTag = new NBTTagCompound();
if(this.tanks[i] != null)
{
this.tanks[i].writeToNBT(savedTag);
}
reagentTagList.appendTag(savedTag);
}
tag.setTag("reagentTanks", reagentTagList);
}
@Override
public void updateEntity()
{
if(!worldObj.isRemote)
{
if(hasChanged > 1)
{
hasChanged = 1;
}else if(hasChanged == 1)
{
hasChanged = 0;
}
if(worldObj.getWorldTime() % 100 == 99)
{
this.updateColourList();
}
if(affectedByRedstone && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
return;
}
int totalTransfered = 0;
for(Entry<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet())
{
for(Int3 coord : entry.getValue())
{
if(totalTransfered >= this.tickRate)
{
break;
}
ReagentStack maxDrainAmount = this.drain(ForgeDirection.UNKNOWN, new ReagentStack(entry.getKey(), this.tickRate - totalTransfered), false);
if(maxDrainAmount == null)
{
continue;
}
int amountLeft = maxDrainAmount.amount;
if(amountLeft <= 0)
{
continue;
}
int x = xCoord + coord.xCoord;
int y = yCoord + coord.yCoord;
int z = zCoord + coord.zCoord;
TileEntity tile = worldObj.getTileEntity(x, y, z);
if(tile instanceof IReagentHandler)
{
int amount = Math.min(((IReagentHandler) tile).fill(ForgeDirection.UNKNOWN, maxDrainAmount, false), amountLeft);
if(amount > 0)
{
amountLeft -= amount;
totalTransfered += amount;
ReagentStack stack = this.drain(ForgeDirection.UNKNOWN, new ReagentStack(entry.getKey(), amount), true);
((IReagentHandler) tile).fill(ForgeDirection.UNKNOWN, stack, true);
}
}
}
}
}else
{
if(affectedByRedstone && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
return;
}
renderCount++;
if(worldObj.getWorldTime() % 100 != 0)
{
return;
}
Minecraft mc = Minecraft.getMinecraft();
EntityPlayer player = mc.thePlayer;
World world = mc.theWorld;
if(SpellHelper.canPlayerSeeAlchemy(player))
{
for(ColourAndCoords colourSet : this.destinationList)
{
if(!(worldObj.getTileEntity(xCoord + colourSet.xCoord, yCoord + colourSet.yCoord, zCoord + colourSet.zCoord) instanceof IReagentHandler))
{
continue;
}
EntityParticleBeam beam = new EntityParticleBeam(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
double velocity = Math.sqrt(Math.pow(colourSet.xCoord, 2) + Math.pow(colourSet.yCoord, 2) + Math.pow(colourSet.zCoord, 2));
double wantedVel = 0.3d;
beam.setVelocity(wantedVel*colourSet.xCoord/velocity, wantedVel*colourSet.yCoord/velocity, wantedVel*colourSet.zCoord/velocity);
beam.setColour(colourSet.colourRed / 255f, colourSet.colourGreen/255f, colourSet.colourBlue/255f);
beam.setDestination(xCoord + colourSet.xCoord, yCoord + colourSet.yCoord, zCoord + colourSet.zCoord);
worldObj.spawnEntityInWorld(beam);
}
}
}
}
public void updateColourList()
{
if(worldObj.isRemote)
{
return;
}
List<ColourAndCoords> newList = this.compileListForReagentTargets(this.reagentTargetList);
if(newList != null && !newList.equals(destinationList))
{
this.destinationList = newList;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
public List<ColourAndCoords> compileListForReagentTargets(Map<Reagent, List<Int3>> map)
{
List<ColourAndCoords> list = new LinkedList();
for(Entry<Reagent, List<Int3>> entry : map.entrySet())
{
if(entry.getValue() != null)
{
Reagent reagent = entry.getKey();
List<Int3> coords = entry.getValue();
for(Int3 coord : coords)
{
list.add(new ColourAndCoords(reagent.getColourRed(), reagent.getColourGreen(), reagent.getColourBlue(), reagent.getColourIntensity(), coord.xCoord, coord.yCoord, coord.zCoord));
}
}
}
return list;
}
public boolean addDestinationViaOffset(int red, int green, int blue, int intensity, int xOffset, int yOffset, int zOffset)
{
if(xOffset == 0 && yOffset == 0 && zOffset == 0)
{
return false;
}
this.destinationList.add(new ColourAndCoords(red, green, blue, intensity, xOffset, yOffset, zOffset));
return true;
}
public boolean addDestinationViaActual(int red, int green, int blue, int intensity, int x, int y, int z)
{
return this.addDestinationViaOffset(red, green, blue, intensity, x - this.xCoord, y - this.yCoord, z - this.zCoord);
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeClientNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 90210, nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readClientNBT(packet.func_148857_g());
}
public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset)
{
int totalConnections = 0;
for(Entry<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet())
{
if(entry.getValue() != null)
{
totalConnections += entry.getValue().size();
}
}
if(totalConnections >= this.maxConnextions)
{
//Send message that it cannot be done? Maybe add a Player instance
return false;
}
if(xOffset == 0 && yOffset == 0 && zOffset == 0)
{
return false;
}
Int3 newCoord = new Int3(xOffset, yOffset, zOffset);
if(this.reagentTargetList.containsKey(reagent))
{
List<Int3> coordList = this.reagentTargetList.get(reagent);
if(coordList == null)
{
List<Int3> newCoordList = new LinkedList();
newCoordList.add(newCoord);
this.reagentTargetList.put(reagent, newCoordList);
}else
{
coordList.add(newCoord);
}
return true;
}else
{
List<Int3> newCoordList = new LinkedList();
newCoordList.add(newCoord);
this.reagentTargetList.put(reagent, newCoordList);
return true;
}
}
public boolean addReagentDestinationViaActual(Reagent reagent, int x, int y, int z)
{
return (this.addReagentDestinationViaOffset(reagent, x-xCoord, y-yCoord, z-zCoord));
}
public boolean removeReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset)
{
if(this.reagentTargetList.containsKey(reagent))
{
List<Int3> coords = this.reagentTargetList.get(reagent);
if(coords != null)
{
Int3 reference = new Int3(xOffset, yOffset, zOffset);
return coords.remove(reference);
}
}
return false;
}
public boolean removeReagentDestinationViaActual(Reagent reagent, int x, int y, int z)
{
return this.removeReagentDestinationViaOffset(reagent, x-xCoord, y-yCoord, z-zCoord);
}
@Override
public int fill(ForgeDirection from, ReagentStack resource, boolean doFill)
{
if(doFill && !worldObj.isRemote)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
hasChanged = 2;
}
return super.fill(from, resource, doFill);
}
@Override
public ReagentStack drain(ForgeDirection from, ReagentStack resource, boolean doDrain)
{
if(doDrain && !worldObj.isRemote)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
hasChanged = 2;
}
return super.drain(from, resource, doDrain);
}
}