Testing the creation of hell

This commit is contained in:
WayofTime 2014-10-31 17:35:30 -04:00
parent 796e75b1f9
commit a2b006105e
2587 changed files with 0 additions and 129617 deletions

View file

@ -0,0 +1,376 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
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;
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;
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);
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,121 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainer;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
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;
}
public static ReagentContainerInfo[] getContainerInfoFromItem(ItemStack stack)
{
if (stack != null && stack.getItem() instanceof ItemBlock && ModBlocks.blockCrystalBelljar == ((ItemBlock) stack.getItem()).field_150939_a)
{
NBTTagCompound tag = stack.getTagCompound();
if (tag != null)
{
NBTTagList tagList = tag.getTagList("reagentTanks", Constants.NBT.TAG_COMPOUND);
int size = tagList.tagCount();
ReagentContainer[] tanks = new ReagentContainer[size];
ReagentContainerInfo[] infos = new ReagentContainerInfo[size];
for (int i = 0; i < size; i++)
{
NBTTagCompound savedTag = tagList.getCompoundTagAt(i);
tanks[i] = ReagentContainer.readFromNBT(savedTag);
if (tanks[i] != null)
{
infos[i] = tanks[i].getInfo();
}
}
return infos;
}
}
return new ReagentContainerInfo[0];
}
public void readTankNBTOnPlace(NBTTagCompound 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);
}
}
public void writeTankNBT(NBTTagCompound 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

@ -0,0 +1,32 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigm;
import net.minecraft.nbt.NBTTagCompound;
public class TEConduit extends TESpellBlock
{
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
}
//Logic for the actual block is under here
@Override
public void updateEntity()
{
}
@Override
protected void applySpellChange(SpellParadigm parad)
{
return;
}
}

View file

@ -0,0 +1,165 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.simple.HomSpell;
import WayofTime.alchemicalWizardry.common.spell.simple.HomSpellRegistry;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.world.World;
public class TEHomHeart extends TileEntity
{
public boolean canCastSpell(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
return true;
}
public int castSpell(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
HomSpell spell = getSpell();
if (spell != null)
{
switch (getModifiedParadigm())
{
case 0:
spell.onOffensiveRangedRightClick(par1ItemStack, par2World, par3EntityPlayer);
break;
case 1:
spell.onOffensiveMeleeRightClick(par1ItemStack, par2World, par3EntityPlayer);
break;
case 2:
spell.onDefensiveRightClick(par1ItemStack, par2World, par3EntityPlayer);
break;
case 3:
spell.onEnvironmentalRightClick(par1ItemStack, par2World, par3EntityPlayer);
break;
}
}
return 0;
}
public HomSpell getSpell()
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord - 1, yCoord, zCoord);
if (tileEntity instanceof TEAltar)
{
ItemStack itemStack = ((TEAltar) tileEntity).getStackInSlot(0);
if (itemStack != null)
{
HomSpell spell = HomSpellRegistry.getSpellForItemStack(itemStack);
if (spell != null)
{
return spell;
}
}
}
tileEntity = worldObj.getTileEntity(xCoord + 1, yCoord, zCoord);
if (tileEntity instanceof TEAltar)
{
ItemStack itemStack = ((TEAltar) tileEntity).getStackInSlot(0);
if (itemStack != null)
{
HomSpell spell = HomSpellRegistry.getSpellForItemStack(itemStack);
if (spell != null)
{
return spell;
}
}
}
tileEntity = worldObj.getTileEntity(xCoord, yCoord, zCoord - 1);
if (tileEntity instanceof TEAltar)
{
ItemStack itemStack = ((TEAltar) tileEntity).getStackInSlot(0);
if (itemStack != null)
{
HomSpell spell = HomSpellRegistry.getSpellForItemStack(itemStack);
if (spell != null)
{
return spell;
}
}
}
tileEntity = worldObj.getTileEntity(xCoord, yCoord, zCoord + 1);
if (tileEntity instanceof TEAltar)
{
ItemStack itemStack = ((TEAltar) tileEntity).getStackInSlot(0);
if (itemStack != null)
{
HomSpell spell = HomSpellRegistry.getSpellForItemStack(itemStack);
if (spell != null)
{
return spell;
}
}
}
return null;
}
public int getModifiedParadigm()
{
//TODO change so that it works with a Tile Entity for a custom head or whatnot
Block block = worldObj.getBlock(xCoord, yCoord + 1, zCoord);
if (block == Blocks.glowstone)
{
return 0;
} else if (block == Blocks.redstone_block)
{
return 1;
} else if (block == Blocks.anvil)
{
return 2;
} else if (block == Blocks.glass)
{
return 3;
}
TileEntity tileEntity = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
if (tileEntity instanceof TileEntitySkull)
{
int skullType = ((TileEntitySkull) tileEntity).func_145904_a();
switch (skullType)
{
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
case 4:
return 3;
}
}
return -1;
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import net.minecraft.tileentity.TileEntity;
public class TEImperfectRitualStone extends TileEntity
{
public TEImperfectRitualStone()
{
}
}

View file

@ -0,0 +1,627 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.api.alchemy.energy.*;
import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone;
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
import WayofTime.alchemicalWizardry.api.soulNetwork.LifeEssenceNetwork;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
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 java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class TEMasterStone extends TileEntity implements IMasterRitualStone
{
private String currentRitualString;
private boolean isActive;
private String owner;
private String varString1;
private int cooldown;
private int var1;
private int direction;
public boolean isRunning;
public int runningTime;
private NBTTagCompound customRitualTag;
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;
var1 = 0;
direction = 0;
varString1 = "";
currentRitualString = "";
isRunning = false;
runningTime = 0;
this.customRitualTag = new NBTTagCompound();
}
public void readClientNBT(NBTTagCompound tag)
{
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"));
}
customRitualTag = tag.getCompoundTag("customRitualTag");
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
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);
tag.setTag("customRitualTag", customRitualTag);
}
public void activateRitual(World world, int crystalLevel, EntityPlayer player)
{
if (world.isRemote)
{
return;
}
String testRitual = Rituals.checkValidRitual(world, xCoord, yCoord, zCoord);
if (testRitual.equals(""))
{
player.addChatMessage(new ChatComponentText("Nothing appears to have happened..."));
return;
}
boolean testLevel = Rituals.canCrystalActivate(testRitual, crystalLevel);
if (!testLevel)
{
player.addChatMessage(new ChatComponentText("Your crystal vibrates pathetically."));
return;
}
World worldSave = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) worldSave.loadItemData(LifeEssenceNetwork.class, owner);
if (data == null)
{
data = new LifeEssenceNetwork(owner);
worldSave.setItemData(owner, data);
}
int currentEssence = data.currentEssence;
if (currentEssence < Rituals.getCostForActivation(testRitual))
{
player.addChatMessage(new ChatComponentText("You feel a pull, but you are too weak to push any further."));
return;
}
if (!world.isRemote)
{
if (!Rituals.startRitual(this, testRitual, player))
{
player.addChatMessage(new ChatComponentText("The ritual appears to actively resist you!"));
return;
} else
{
data.currentEssence = currentEssence - Rituals.getCostForActivation(testRitual);
data.markDirty();
player.addChatMessage(new ChatComponentText("A rush of energy flows through the ritual!"));
for (int i = 0; i < 12; i++)
{
SpellHelper.sendIndexedParticleToAllAround(world, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
}
}
cooldown = Rituals.getInitialCooldown(testRitual);
var1 = 0;
currentRitualString = testRitual;
isActive = true;
isRunning = true;
direction = Rituals.getDirectionOfRitual(world, xCoord, yCoord, zCoord, testRitual);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public void setOwner(String owner)
{
this.owner = owner;
}
public void useOnRitualBroken()
{
Rituals.onRitualBroken(this, this.currentRitualString);
}
@Override
public void updateEntity()
{
if (isRunning && runningTime < 100)
{
runningTime++;
} else if (!isRunning && runningTime > 0)
{
runningTime--;
}
if (!isActive)
{
return;
}
int worldTime = (int) (worldObj.getWorldTime() % 24000);
if (worldObj.isRemote)
{
return;
}
if (worldTime % 100 == 0)
{
boolean testRunes = Rituals.checkDirectionOfRitualValid(worldObj, xCoord, yCoord, zCoord, currentRitualString, direction);
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
if (!testRunes)
{
Rituals.onRitualBroken(this, currentRitualString);
isActive = false;
currentRitualString = "";
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return;
}
}
if (worldObj.getBlockPowerInput(xCoord, yCoord, zCoord) > 0)
{
if (isRunning)
{
isRunning = false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
} else
{
if (!isRunning)
{
isRunning = true;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
performRitual(worldObj, xCoord, yCoord, zCoord, currentRitualString);
}
public void performRitual(World world, int x, int y, int z, String currentRitualString2)
{
Rituals.performEffect(this, currentRitualString2);
}
public String getOwner()
{
return owner;
}
public void setCooldown(int newCooldown)
{
this.cooldown = newCooldown;
}
public int getCooldown()
{
return this.cooldown;
}
public void setVar1(int newVar1)
{
this.var1 = newVar1;
}
public int getVar1()
{
return this.var1;
}
public void setActive(boolean active)
{
this.isActive = active;
this.isRunning = active;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public int getDirection()
{
return this.direction;
}
@Override
public World getWorld()
{
return this.getWorldObj();
}
@Override
public int getXCoord()
{
return xCoord;
}
@Override
public int getYCoord()
{
return yCoord;
}
@Override
public int getZCoord()
{
return zCoord;
}
public String getCurrentRitual()
{
return this.currentRitualString;
}
public void setCurrentRitual(String str)
{
this.currentRitualString = str;
}
@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()
{
double renderExtention = 1.0d;
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;
}
public boolean areTanksEmpty()
{
for (int i = 0; i < this.tanks.length; i++)
{
if (tanks[i] != null && tanks[i].getReagent() != null)
{
return false;
}
}
return true;
}
@Override
public NBTTagCompound getCustomRitualTag()
{
return this.customRitualTag;
}
@Override
public void setCustomRitualTag(NBTTagCompound tag)
{
this.customRitualTag = tag;
}
}

View file

@ -0,0 +1,108 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.block.IOrientable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TEOrientable extends TileEntity implements IOrientable
{
protected ForgeDirection inputFace;
protected ForgeDirection outputFace;
public TEOrientable()
{
this.inputFace = ForgeDirection.DOWN;
this.outputFace = ForgeDirection.UP;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.setInputDirection(ForgeDirection.getOrientation(par1NBTTagCompound.getInteger("inputFace")));
this.setOutputDirection(ForgeDirection.getOrientation(par1NBTTagCompound.getInteger("outputFace")));
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("inputFace", TEOrientable.getIntForForgeDirection(this.getInputDirection()));
par1NBTTagCompound.setInteger("outputFace", TEOrientable.getIntForForgeDirection(this.getOutputDirection()));
}
@Override
public ForgeDirection getInputDirection()
{
return this.inputFace;
}
@Override
public ForgeDirection getOutputDirection()
{
return this.outputFace;
}
@Override
public void setInputDirection(ForgeDirection direction)
{
this.inputFace = direction;
}
@Override
public void setOutputDirection(ForgeDirection direction)
{
this.outputFace = direction;
}
public static int getIntForForgeDirection(ForgeDirection direction)
{
switch (direction)
{
case DOWN:
return 0;
case UP:
return 1;
case NORTH:
return 2;
case SOUTH:
return 3;
case WEST:
return 4;
case EAST:
return 5;
default:
return 0;
}
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public boolean isSideRendered(ForgeDirection side)
{
if (side.equals(this.getInputDirection()) || side.equals(this.getOutputDirection()))
{
return true;
}
return false;
}
public String getResourceLocationForMeta(int meta)
{
return "";
}
}

View file

@ -0,0 +1,264 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
public class TEPedestal extends TileEntity implements IInventory
{
private ItemStack[] inv;
private int resultID;
private int resultDamage;
public static final int sizeInv = 1;
private boolean isActive;
public TEPedestal()
{
this.inv = new ItemStack[1];
resultID = 0;
resultDamage = 0;
isActive = false;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
resultID = par1NBTTagCompound.getInteger("resultID");
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
isActive = par1NBTTagCompound.getBoolean("isActive");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setInteger("resultID", resultID);
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
par1NBTTagCompound.setTag("Inventory", itemList);
par1NBTTagCompound.setBoolean("isActive", isActive);
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@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 void setInventorySlotContents(int slot, ItemStack itemStack)
{
inv[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName()
{
return "TEPedestal";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
//Logic for the actual block is under here
@Override
public void updateEntity()
{
super.updateEntity();
}
public void setActive()
{
isActive = false;
}
public boolean isActive()
{
return isActive;
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData)
{
if (intData == null)
{
return;
}
if (intData.length == 3)
{
for (int i = 0; i < 1; i++)
{
if (intData[i * 3 + 2] != 0)
{
ItemStack is = new ItemStack(Item.getItemById(intData[i * 3]), intData[i * 3 + 2], intData[i * 3 + 1]);
inv[i] = is;
} else
{
inv[i] = null;
}
}
}
}
public int[] buildIntDataList()
{
int[] sortList = new int[1 * 3];
int pos = 0;
for (ItemStack is : inv)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
if (slot == 0)
{
return true;
}
return false;
}
public void onItemDeletion()
{
worldObj.addWeatherEffect(new EntityLightningBolt(worldObj, xCoord, yCoord, zCoord));
for (int i = 0; i < 16; i++)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 2, xCoord, yCoord, zCoord);
}
}
}

View file

@ -0,0 +1,688 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistry;
import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistryComponent;
import WayofTime.alchemicalWizardry.common.IDemon;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.PlinthComponent;
import WayofTime.alchemicalWizardry.common.items.EnergyBattery;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.List;
public class TEPlinth extends TileEntity implements IInventory
{
private ItemStack[] inv;
private boolean isActive;
private boolean paradigm;
private ItemStack[] ring1Inv;
private ItemStack[] ring2Inv;
private ItemStack[] ring3Inv;
public static final int sizeInv = 1;
private int progressInterval;
private int progress;
public static List<PlinthComponent> pedestalPositions = new ArrayList();
public TEPlinth()
{
this.inv = new ItemStack[1];
this.ring1Inv = new ItemStack[6];
this.ring2Inv = new ItemStack[6];
this.ring3Inv = new ItemStack[6];
isActive = false;
progress = 0;
progressInterval = 50;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
NBTTagList ring1TagList = par1NBTTagCompound.getTagList("ring1Inv", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < ring1TagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) ring1TagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
ring1Inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
NBTTagList ring2TagList = par1NBTTagCompound.getTagList("ring2Inv", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < ring2TagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) ring2TagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
ring2Inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
NBTTagList ring3TagList = par1NBTTagCompound.getTagList("ring3Inv", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < ring3TagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) ring3TagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
ring3Inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
progress = par1NBTTagCompound.getInteger("progress");
progressInterval = par1NBTTagCompound.getInteger("progressInterval");
isActive = par1NBTTagCompound.getBoolean("isActive");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("Inventory", itemList);
NBTTagList ring1ItemList = new NBTTagList();
for (int i = 0; i < ring1Inv.length; i++)
{
ItemStack stack = ring1Inv[i];
if (ring1Inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
ring1Inv[i].writeToNBT(tag);
ring1ItemList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("ring1Inv", ring1ItemList);
NBTTagList ring2ItemList = new NBTTagList();
for (int i = 0; i < ring2Inv.length; i++)
{
ItemStack stack = ring2Inv[i];
if (ring2Inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
ring2Inv[i].writeToNBT(tag);
ring2ItemList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("ring2Inv", ring1ItemList);
NBTTagList ring3ItemList = new NBTTagList();
for (int i = 0; i < ring3Inv.length; i++)
{
ItemStack stack = ring3Inv[i];
if (ring3Inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
ring3Inv[i].writeToNBT(tag);
ring3ItemList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("ring3Inv", ring1ItemList);
par1NBTTagCompound.setInteger("progress", progress);
par1NBTTagCompound.setInteger("progressInterval", progressInterval);
par1NBTTagCompound.setBoolean("isActive", isActive);
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@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 void setInventorySlotContents(int slot, ItemStack itemStack)
{
inv[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName()
{
return "TEPlinth";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
//Logic for the actual block is under here
@Override
public void updateEntity()
{
super.updateEntity();
if (worldObj.isRemote)
{
return;
}
if (!isActive())
{
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof EnergyBattery)
{
int bloodOrbLevel = ((EnergyBattery) getStackInSlot(0).getItem()).getOrbLevel();
if (SummoningRegistry.isRecipeValid(bloodOrbLevel, composeItemsForRingAndParadigm(1, true), composeItemsForRingAndParadigm(2, true), composeItemsForRingAndParadigm(3, true)))
{
SummoningRegistryComponent src = SummoningRegistry.getRegistryComponent(bloodOrbLevel, composeItemsForRingAndParadigm(1, true), composeItemsForRingAndParadigm(2, true), composeItemsForRingAndParadigm(3, true));
isActive = true;
paradigm = true;
progress = 0;
ring1Inv = src.getRingRecipeForRing(1);
ring2Inv = src.getRingRecipeForRing(2);
ring3Inv = src.getRingRecipeForRing(3);
} else if (SummoningRegistry.isRecipeValid(bloodOrbLevel, composeItemsForRingAndParadigm(1, false), composeItemsForRingAndParadigm(2, false), composeItemsForRingAndParadigm(3, false)))
{
SummoningRegistryComponent src = SummoningRegistry.getRegistryComponent(bloodOrbLevel, composeItemsForRingAndParadigm(1, false), composeItemsForRingAndParadigm(2, false), composeItemsForRingAndParadigm(3, false));
isActive = true;
paradigm = false;
progress = 0;
ring1Inv = src.getRingRecipeForRing(1);
ring2Inv = src.getRingRecipeForRing(2);
ring3Inv = src.getRingRecipeForRing(3);
} else
{
isActive = false;
progress = 0;
}
}
} else
{
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof EnergyBattery)
{
if (progress % progressInterval == 0)
{
int ring = (progress / progressInterval) / 6 + 1;
int slot = (progress / progressInterval) % 6;
ItemStack itemStack;
switch (ring)
{
case 1:
itemStack = this.ring1Inv[slot];
break;
case 2:
itemStack = this.ring2Inv[slot];
break;
case 3:
itemStack = this.ring3Inv[slot];
break;
default:
itemStack = null;
}
if (itemStack == null)
{
progress += progressInterval;
} else
{
if (this.deleteItemStackInRing(ring, itemStack))
{
progress++;
}
}
} else
{
progress++;
}
if (progress >= progressInterval * 18)
{
int bloodOrbLevel = ((EnergyBattery) getStackInSlot(0).getItem()).getOrbLevel();
EntityLivingBase entity = SummoningRegistry.getEntity(worldObj, bloodOrbLevel, ring1Inv, ring2Inv, ring3Inv);
if (entity != null)
{
entity.setPosition(xCoord + 0.5, yCoord + 1, zCoord + 0.5);
worldObj.spawnEntityInWorld(entity);
if (entity instanceof IDemon)
{
((IDemon) entity).setSummonedConditions();
}
worldObj.createExplosion(entity, entity.posX, entity.posY, entity.posZ, 3, false);
deleteItemsInRing(1);
isActive = false;
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
}
}
public void deleteItemsInRing(int ring)
{
if (paradigm)
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.xOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
if (tileEntity instanceof TEPedestal)
{
((TEPedestal) tileEntity).setInventorySlotContents(0, null);
worldObj.markBlockForUpdate(xCoord + pc.xOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
i++;
}
}
}
} else
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.zOffset, yCoord + pc.yOffset, zCoord + pc.xOffset);
if (tileEntity instanceof TEPedestal)
{
((TEPedestal) tileEntity).setInventorySlotContents(0, null);
worldObj.markBlockForUpdate(xCoord + pc.zOffset, yCoord + pc.yOffset, zCoord + pc.xOffset);
i++;
}
}
}
}
}
public boolean deleteItemStackInRing(int ring, ItemStack itemStack)
{
if (itemStack == null)
{
return true;
}
if (paradigm)
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.xOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
if (tileEntity instanceof TEPedestal)
{
ItemStack possibleItem = ((TEPedestal) tileEntity).getStackInSlot(0);
if (possibleItem == null)
{
i++;
continue;
}
boolean test = false;
if (possibleItem.getItem() instanceof ItemBlock)
{
if (itemStack.getItem() instanceof ItemBlock)
{
test = true;
}
} else if (!(itemStack.getItem() instanceof ItemBlock))
{
test = true;
}
if (test)
{
if (itemStack.getItem() == possibleItem.getItem() && (itemStack.getItemDamage() == possibleItem.getItemDamage() || itemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE))
{
((TEPedestal) tileEntity).decrStackSize(0, 1);
if (((TEPedestal) tileEntity).getStackInSlot(0) != null && ((TEPedestal) tileEntity).getStackInSlot(0).stackSize == 0)
{
((TEPedestal) tileEntity).setInventorySlotContents(0, null);
}
((TEPedestal) tileEntity).onItemDeletion();
worldObj.markBlockForUpdate(xCoord + pc.xOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
return true;
}
}
i++;
}
}
}
} else
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.zOffset, yCoord + pc.yOffset, zCoord + pc.xOffset);
if (tileEntity instanceof TEPedestal)
{
ItemStack possibleItem = ((TEPedestal) tileEntity).getStackInSlot(0);
if (possibleItem == null)
{
i++;
continue;
}
boolean test = false;
if (possibleItem.getItem() instanceof ItemBlock)
{
if (itemStack.getItem() instanceof ItemBlock)
{
test = true;
}
} else if (!(itemStack.getItem() instanceof ItemBlock))
{
test = true;
}
if (test)
{
if (itemStack.getItem() == possibleItem.getItem() && (itemStack.getItemDamage() == possibleItem.getItemDamage() || itemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE))
{
((TEPedestal) tileEntity).decrStackSize(0, 1);
((TEPedestal) tileEntity).onItemDeletion();
worldObj.markBlockForUpdate(xCoord + pc.zOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
return true;
}
}
i++;
}
}
}
}
return false;
}
public ItemStack[] composeItemsForRingAndParadigm(int ring, boolean paradigm)
{
ItemStack[] composed = new ItemStack[6];
if (paradigm)
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.xOffset, yCoord + pc.yOffset, zCoord + pc.zOffset);
if (tileEntity instanceof TEPedestal)
{
composed[i] = ((TEPedestal) tileEntity).getStackInSlot(0);
i++;
}
}
}
} else
{
int i = 0;
for (PlinthComponent pc : pedestalPositions)
{
if (i < 6 && pc.getRing() == ring)
{
TileEntity tileEntity = worldObj.getTileEntity(xCoord + pc.zOffset, yCoord + pc.yOffset, zCoord + pc.xOffset);
if (tileEntity instanceof TEPedestal)
{
composed[i] = ((TEPedestal) tileEntity).getStackInSlot(0);
i++;
}
}
}
}
return composed;
}
public void setActive()
{
isActive = false;
}
public boolean isActive()
{
return isActive;
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData)
{
if (intData == null)
{
return;
}
if (intData.length == 3)
{
for (int i = 0; i < 1; i++)
{
if (intData[i * 3 + 2] != 0)
{
ItemStack is = new ItemStack(Item.getItemById(intData[i * 3]), intData[i * 3 + 2], intData[i * 3 + 1]);
inv[i] = is;
} else
{
inv[i] = null;
}
}
}
}
public int[] buildIntDataList()
{
int[] sortList = new int[1 * 3];
int pos = 0;
for (ItemStack is : inv)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
if (slot == 0)
{
return true;
}
return false;
}
public static void initialize()
{
pedestalPositions.add(new PlinthComponent(1, 0, -2, 1));
pedestalPositions.add(new PlinthComponent(2, 0, 0, 1));
pedestalPositions.add(new PlinthComponent(1, 0, +2, 1));
pedestalPositions.add(new PlinthComponent(-1, 0, -2, 1));
pedestalPositions.add(new PlinthComponent(-2, 0, 0, 1));
pedestalPositions.add(new PlinthComponent(-1, 0, +2, 1));
pedestalPositions.add(new PlinthComponent(3, 1, -5, 2));
pedestalPositions.add(new PlinthComponent(6, 1, 0, 2));
pedestalPositions.add(new PlinthComponent(3, 1, +5, 2));
pedestalPositions.add(new PlinthComponent(-3, 1, -5, 2));
pedestalPositions.add(new PlinthComponent(-6, 1, 0, 2));
pedestalPositions.add(new PlinthComponent(-3, 1, +5, 2));
pedestalPositions.add(new PlinthComponent(0, 2, -9, 3));
pedestalPositions.add(new PlinthComponent(7, 2, -4, 3));
pedestalPositions.add(new PlinthComponent(7, 2, +4, 3));
pedestalPositions.add(new PlinthComponent(0, 2, +9, 3));
pedestalPositions.add(new PlinthComponent(-7, 2, -4, 3));
pedestalPositions.add(new PlinthComponent(-7, 2, 4, 3));
}
}

View file

@ -0,0 +1,539 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.api.ColourAndCoords;
import WayofTime.alchemicalWizardry.api.alchemy.energy.*;
import WayofTime.alchemicalWizardry.common.Int3;
import WayofTime.alchemicalWizardry.common.entity.projectile.EntityParticleBeam;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
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.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
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 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;
}
this.sendPlayerStuffs();
}
}
@SideOnly(Side.CLIENT)
public void sendPlayerStuffs()
{
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();
if (reagent == null)
{
continue;
}
List<Int3> coords = entry.getValue();
for (Int3 coord : coords)
{
if (coord == null)
{
continue;
}
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);
}
}

View file

@ -0,0 +1,156 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.ModBlocks;
import WayofTime.alchemicalWizardry.common.demonVillage.BuildingSchematic;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Random;
public class TESchematicSaver extends TileEntity
{
public Block targetBlock = ModBlocks.largeBloodStoneBrick;
public void rightClickBlock(EntityPlayer player, int side)
{
BuildingSchematic schematic = new BuildingSchematic();
int negX = this.getNegXLimit();
int negY = this.getNegYLimit();
int negZ = this.getNegZLimit();
int posX = this.getPosXLimit();
int posY = this.getPosYLimit();
int posZ = this.getPosZLimit();
for (int i = -negX + 1; i <= posX - 1; i++)
{
for (int j = -negY + 1; j <= posY - 1; j++)
{
for (int k = -negZ + 1; k <= posZ - 1; k++)
{
int meta = worldObj.getBlockMetadata(xCoord + i, yCoord + j, zCoord + k);
Block block = worldObj.getBlock(xCoord + i, yCoord + j, zCoord + k);
if (!block.isAir(worldObj, xCoord + i, yCoord + j, zCoord + k))
{
schematic.addBlockWithMeta(block, meta, i, j, k);
}
}
}
System.out.println("" + i);
}
System.out.println("I got here!");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(schematic);
System.out.println("Here, too!");
Writer writer;
try
{
writer = new FileWriter("config/BloodMagic/schematics/" + new Random().nextInt() + ".json");
writer.write(json);
writer.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
public int getPosYLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord, yCoord + i, zCoord)))
{
return i;
}
i++;
}
return 1;
}
public int getNegYLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord, yCoord - i, zCoord)))
{
return i;
}
i++;
}
return 1;
}
public int getPosXLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord + i, yCoord, zCoord)))
{
return i;
}
i++;
}
return 1;
}
public int getNegXLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord - i, yCoord, zCoord)))
{
return i;
}
i++;
}
return 1;
}
public int getPosZLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord, yCoord, zCoord + i)))
{
return i;
}
i++;
}
return 1;
}
public int getNegZLimit()
{
int i = 1;
while (i < 100)
{
if (targetBlock == (worldObj.getBlock(xCoord, yCoord, zCoord - i)))
{
return i;
}
i++;
}
return 1;
}
}

View file

@ -0,0 +1,252 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
public class TESocket extends TileEntity implements IInventory
{
private ItemStack[] inv;
private int resultID;
private int resultDamage;
public static final int sizeInv = 1;
private boolean isActive;
public TESocket()
{
this.inv = new ItemStack[1];
resultID = 0;
resultDamage = 0;
isActive = false;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
resultID = par1NBTTagCompound.getInteger("resultID");
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
isActive = par1NBTTagCompound.getBoolean("isActive");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setInteger("resultID", resultID);
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
par1NBTTagCompound.setTag("Inventory", itemList);
par1NBTTagCompound.setBoolean("isActive", isActive);
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@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 void setInventorySlotContents(int slot, ItemStack itemStack)
{
inv[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName()
{
return "TESocket";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
//Logic for the actual block is under here
@Override
public void updateEntity()
{
super.updateEntity();
}
public void setActive()
{
isActive = false;
}
public boolean isActive()
{
return isActive;
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData)
{
if (intData == null)
{
return;
}
if (intData.length == 3)
{
for (int i = 0; i < 1; i++)
{
if (intData[i * 3 + 2] != 0)
{
ItemStack is = new ItemStack(Item.getItemById(intData[i * 3]), intData[i * 3 + 2], intData[i * 3 + 1]);
inv[i] = is;
} else
{
inv[i] = null;
}
}
}
}
public int[] buildIntDataList()
{
int[] sortList = new int[1 * 3];
int pos = 0;
for (ItemStack is : inv)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
if (slot == 0)
{
return true;
}
return false;
}
}

View file

@ -0,0 +1,80 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.ModBlocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TESpectralBlock extends TileEntity
{
private int ticksRemaining;
public TESpectralBlock()
{
ticksRemaining = 0;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
ticksRemaining = par1NBTTagCompound.getInteger("ticksRemaining");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("ticksRemaining", ticksRemaining);
}
@Override
public void updateEntity()
{
super.updateEntity();
if (worldObj.isRemote)
{
return;
}
this.ticksRemaining--;
if (this.ticksRemaining <= 0)
{
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
public static boolean createSpectralBlockAtLocation(World world, int x, int y, int z, int duration)
{
if (!world.isAirBlock(x, y, z))
{
return false;
}
world.setBlock(x, y, z, ModBlocks.spectralBlock);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TESpectralBlock)
{
((TESpectralBlock) tile).setDuration(duration);
return true;
}
return false;
}
public void setDuration(int dur)
{
this.ticksRemaining = dur;
}
public void resetDuration(int dur)
{
if (this.ticksRemaining < dur)
{
this.ticksRemaining = dur;
}
}
}

View file

@ -0,0 +1,149 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.IFluidBlock;
public class TESpectralContainer extends TileEntity
{
private ItemStack[] inv;
private int ticksRemaining;
public TESpectralContainer()
{
this.inv = new ItemStack[1];
ticksRemaining = 0;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
ticksRemaining = par1NBTTagCompound.getInteger("ticksRemaining");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("Inventory", itemList);
par1NBTTagCompound.setInteger("ticksRemaining", ticksRemaining);
}
@Override
public void updateEntity()
{
super.updateEntity();
this.ticksRemaining--;
if (this.ticksRemaining <= 0)
{
this.returnContainedBlock();
}
}
public static boolean createSpectralBlockAtLocation(World world, int x, int y, int z, int duration)
{
Block block = world.getBlock(x, y, z);
if (block == null)
{
return false;
}
if (world.getTileEntity(x, y, z) == null || block instanceof IFluidBlock)
{
int meta = world.getBlockMetadata(x, y, z);
ItemStack item = new ItemStack(block, 1, meta);
world.setBlock(x, y, z, ModBlocks.blockSpectralContainer);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TESpectralContainer)
{
((TESpectralContainer) tile).setContainedItem(item);
((TESpectralContainer) tile).setDuration(duration);
return true;
}
}
return false;
}
public void setDuration(int dur)
{
this.ticksRemaining = dur;
}
public void resetDuration(int dur)
{
if (this.ticksRemaining < dur)
{
this.ticksRemaining = dur;
}
}
public void setContainedItem(ItemStack item)
{
this.inv[0] = item;
}
public void returnContainedBlock()
{
ItemStack item = this.inv[0];
if (item != null)
{
if (item.getItem() instanceof ItemBlock)
{
Block block = ((ItemBlock) item.getItem()).field_150939_a;
int meta = item.getItemDamage();
if (block != null)
{
this.worldObj.setBlock(xCoord, yCoord, zCoord, block, meta, 6);
}
}
} else
{
this.worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
}

View file

@ -0,0 +1,48 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigm;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class TESpellBlock extends TEOrientable
{
public void modifySpellParadigm(SpellParadigm parad)
{
this.applySpellChange(parad);
TileEntity tile = this.getTileAtOutput();
if (tile instanceof TESpellBlock)
{
TESpellBlock outputBlock = (TESpellBlock) tile;
outputBlock.modifySpellParadigm(parad);
}
}
protected abstract void applySpellChange(SpellParadigm parad);
public TESpellBlock getTileAtOutput()
{
ForgeDirection output = this.getOutputDirection();
int xOffset = output.offsetX;
int yOffset = output.offsetY;
int zOffset = output.offsetZ;
TileEntity tile = worldObj.getTileEntity(xCoord + xOffset, yCoord + yOffset, zCoord + zOffset);
if (tile instanceof TESpellBlock && ((TESpellBlock) tile).canInputRecieveOutput(output))
{
return (TESpellBlock) tile;
}
return null;
}
public boolean canInputRecieve()
{
return true;
}
public boolean canInputRecieveOutput(ForgeDirection output)
{
return this.canInputRecieve() && this.getInputDirection().getOpposite() == output;
}
}

View file

@ -0,0 +1,47 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigm;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.*;
public class TESpellEffectBlock extends TESpellBlock
{
@Override
protected void applySpellChange(SpellParadigm parad)
{
parad.addBufferedEffect(this.getSpellEffect());
}
public SpellEffect getSpellEffect()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
return new SpellEffectFire();
case 1:
return new SpellEffectIce();
case 2:
return new SpellEffectWind();
case 3:
return new SpellEffectEarth();
}
return new SpellEffectFire();
}
@Override
public String getResourceLocationForMeta(int meta)
{
switch (meta)
{
case 0:
return "alchemicalwizardry:textures/models/SpellEffectFire.png";
case 1:
return "alchemicalwizardry:textures/models/SpellEffectIce.png";
case 2:
return "alchemicalwizardry:textures/models/SpellEffectWind.png";
case 3:
return "alchemicalwizardry:textures/models/SpellEffectEarth.png";
}
return "";
}
}

View file

@ -0,0 +1,163 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigm;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancementCost;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancementPotency;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancementPower;
public class TESpellEnhancementBlock extends TESpellBlock
{
@Override
protected void applySpellChange(SpellParadigm parad)
{
int i = -1;
switch (this.enhancementType())
{
case 0:
i = parad.getBufferedEffectPower();
break;
case 1:
i = parad.getBufferedEffectCost();
break;
case 2:
i = parad.getBufferedEffectPotency();
break;
}
if (i != -1 && i < this.getLimit())
{
parad.applyEnhancement(getSpellEnhancement());
} else if (i < this.getLimit())
{
this.doBadStuff();
}
}
public SpellEnhancement getSpellEnhancement()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
case 1:
case 2:
case 3:
case 4:
return new SpellEnhancementPower();
case 5:
case 6:
case 7:
case 8:
case 9:
return new SpellEnhancementCost();
case 10:
case 11:
case 12:
case 13:
case 14:
return new SpellEnhancementPotency();
}
return new SpellEnhancementCost();
}
public int getLimit()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
return 1;
case 1:
return 2;
case 2:
return 3;
case 3:
return 4;
case 4:
return 5;
case 5:
return 1;
case 6:
return 2;
case 7:
return 3;
case 8:
return 4;
case 9:
return 5;
case 10:
return 1;
case 11:
return 2;
case 12:
return 3;
case 13:
return 4;
case 14:
return 5;
}
return 0;
}
public int enhancementType() //0 is power, 1 is cost, 2 is potency
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
case 1:
case 2:
case 3:
case 4:
return 0;
case 5:
case 6:
case 7:
case 8:
case 9:
return 1;
case 10:
case 11:
case 12:
case 13:
case 14:
return 2;
}
return 1;
}
public void doBadStuff()
{
}
@Override
public String getResourceLocationForMeta(int meta)
{
switch (meta)
{
case 0:
return "alchemicalwizardry:textures/models/SpellEnhancementPower1.png";
case 1:
return "alchemicalwizardry:textures/models/SpellEnhancementPower2.png";
case 2:
return "alchemicalwizardry:textures/models/SpellEnhancementPower3.png";
case 5:
return "alchemicalwizardry:textures/models/SpellEnhancementCost1.png";
case 6:
return "alchemicalwizardry:textures/models/SpellEnhancementCost2.png";
case 7:
return "alchemicalwizardry:textures/models/SpellEnhancementCost3.png";
case 10:
return "alchemicalwizardry:textures/models/SpellEnhancementPotency1.png";
case 11:
return "alchemicalwizardry:textures/models/SpellEnhancementPotency2.png";
case 12:
return "alchemicalwizardry:textures/models/SpellEnhancementPotency3.png";
}
return "alchemicalwizardry:textures/models/SpellEnhancementPower1.png";
}
}

View file

@ -0,0 +1,46 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.*;
public class TESpellModifierBlock extends TESpellBlock
{
@Override
protected void applySpellChange(SpellParadigm parad)
{
parad.modifyBufferedEffect(this.getSpellModifier());
}
public SpellModifier getSpellModifier()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
return new SpellModifierDefault();
case 1:
return new SpellModifierOffensive();
case 2:
return new SpellModifierDefensive();
case 3:
return new SpellModifierEnvironmental();
}
return new SpellModifierDefault();
}
@Override
public String getResourceLocationForMeta(int meta)
{
switch (meta)
{
case 0:
return "alchemicalwizardry:textures/models/SpellModifierDefault.png";
case 1:
return "alchemicalwizardry:textures/models/SpellModifierOffensive.png";
case 2:
return "alchemicalwizardry:textures/models/SpellModifierDefensive.png";
case 3:
return "alchemicalwizardry:textures/models/SpellModifierEnvironmental.png";
}
return "alchemicalwizardry:textures/models/SpellModifierDefault.png";
}
}

View file

@ -0,0 +1,75 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.spell.complex.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TESpellParadigmBlock extends TESpellBlock
{
public SpellParadigm getSpellParadigm()
{
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
switch (meta)
{
case 0:
return new SpellParadigmProjectile();
case 1:
return new SpellParadigmSelf();
case 2:
return new SpellParadigmMelee();
case 3:
return new SpellParadigmTool();
}
return new SpellParadigmSelf();
}
@Override
protected void applySpellChange(SpellParadigm parad)
{
return;
}
public boolean canInputRecieve()
{
return false;
}
public void castSpell(World world, EntityPlayer entity, ItemStack spellCasterStack)
{
SpellParadigm parad = this.getSpellParadigm();
this.modifySpellParadigm(parad);
parad.applyAllSpellEffects();
parad.castSpell(world, entity, spellCasterStack);
}
@Override
public String getResourceLocationForMeta(int meta)
{
switch (meta)
{
case 0:
return "alchemicalwizardry:textures/models/SpellParadigmProjectile.png";
case 1:
return "alchemicalwizardry:textures/models/SpellParadigmSelf.png";
case 2:
return "alchemicalwizardry:textures/models/SpellParadigmMelee.png";
case 3:
return "alchemicalwizardry:textures/models/SpellParadigmTool.png";
}
return "alchemicalwizardry:textures/models/SpellParadigmProjectile.png";
}
@Override
public void setInputDirection(ForgeDirection direction)
{
}
@Override
public ForgeDirection getInputDirection()
{
return ForgeDirection.UNKNOWN;
}
}

View file

@ -0,0 +1,367 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.block.BlockTeleposer;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import WayofTime.alchemicalWizardry.common.items.TelepositionFocus;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import java.util.Iterator;
import java.util.List;
public class TETeleposer extends TileEntity implements IInventory
{
private ItemStack[] inv;
private int resultID;
private int resultDamage;
private int previousInput;
public static final int sizeInv = 1;
private boolean isActive;
public TETeleposer()
{
this.inv = new ItemStack[1];
resultID = 0;
resultDamage = 0;
isActive = false;
previousInput = 0;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
NBTTagList tagList = par1NBTTagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
int slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
resultID = par1NBTTagCompound.getInteger("resultID");
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
isActive = par1NBTTagCompound.getBoolean("isActive");
previousInput = par1NBTTagCompound.getInteger("previousInput");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (inv[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
par1NBTTagCompound.setInteger("resultID", resultID);
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
par1NBTTagCompound.setTag("Inventory", itemList);
par1NBTTagCompound.setBoolean("isActive", isActive);
par1NBTTagCompound.setInteger("previousInput", previousInput);
}
@Override
public int getSizeInventory()
{
return 1;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inv[slot];
}
@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 void setInventorySlotContents(int slot, ItemStack itemStack)
{
inv[slot] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
{
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName()
{
return "TETeleposer";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityPlayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
//Logic for the actual block is under here
@Override
public void updateEntity()
{
super.updateEntity();
EntityPlayer d;
if (worldObj.isRemote)
{
return;
}
int currentInput = worldObj.getBlockPowerInput(xCoord, yCoord, zCoord);
if (previousInput == 0 && currentInput != 0)
{
ItemStack focus = this.getStackInSlot(0);
if (focus != null && focus.getItem() instanceof TelepositionFocus)
{
TelepositionFocus focusItem = (TelepositionFocus) (focus.getItem());
int xf = focusItem.xCoord(focus);
int yf = focusItem.yCoord(focus);
int zf = focusItem.zCoord(focus);
World worldF = focusItem.getWorld(focus);
int damage = (int) (0.5f * Math.sqrt((xCoord - xf) * (xCoord - xf) + (yCoord - yf + 1) * (yCoord - yf + 1) + (zCoord - zf) * (zCoord - zf)));
int focusLevel = ((TelepositionFocus) focusItem).getFocusLevel();
int transportCount = 0;
int entityCount = 0;
if (worldF != null && worldF.getTileEntity(xf, yf, zf) instanceof TETeleposer && !worldF.getTileEntity(xf, yf, zf).equals(this))
{
//Prime the teleportation
int d0 = focusLevel - 1;
AxisAlignedBB axisalignedbb1 = AxisAlignedBB.getBoundingBox((double) this.xCoord, (double) this.yCoord + d0 + 1, (double) this.zCoord, (double) (this.xCoord + 1), (double) (this.yCoord + 2 + d0), (double) (this.zCoord + 1)).expand(d0, d0, d0);
axisalignedbb1.maxY = Math.min((double) this.worldObj.getHeight(), this.yCoord + 2 + d0 + d0);
List list1 = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb1);
Iterator iterator1 = list1.iterator();
EntityLivingBase entityplayer1;
while (iterator1.hasNext())
{
entityplayer1 = (EntityLivingBase) iterator1.next();
entityCount++;
}
AxisAlignedBB axisalignedbb2 = AxisAlignedBB.getBoundingBox(xf, yf + d0 + 1, zf, xf + 1, yf + 2 + d0, zf).expand(d0, d0, d0);
List list2 = worldF.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb2);
Iterator iterator2 = list2.iterator();
EntityLivingBase entityplayer2;
while (iterator2.hasNext())
{
entityplayer2 = (EntityLivingBase) iterator2.next();
entityCount++;
}
if (EnergyItems.canSyphonInContainer(focus, damage * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) + damage * entityCount))
{
for (int k = 0; k <= (focusLevel * 2 - 2); k++)
for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++)
{
for (int j = -(focusLevel - 1); j <= (focusLevel - 1); j++)
{
{
if (BlockTeleposer.swapBlocks(worldObj, worldF, xCoord + i, yCoord + 1 + k, zCoord + j, xf + i, yf + 1 + k, zf + j))
{
transportCount++;
}
}
}
}
if (!worldF.equals(worldObj))
{
entityCount = 0;
}
EnergyItems.syphonWhileInContainer(focus, damage * transportCount + damage * entityCount);
//Teleport
if (worldF.equals(worldObj))
{
iterator1 = list1.iterator();
iterator2 = list2.iterator();
while (iterator1.hasNext())
{
entityplayer1 = (EntityLivingBase) iterator1.next();
entityplayer1.worldObj = worldF;
entityplayer1.setPositionAndUpdate(entityplayer1.posX - this.xCoord + xf, entityplayer1.posY - this.yCoord + yf, entityplayer1.posZ - this.zCoord + zf);
}
while (iterator2.hasNext())
{
entityplayer2 = (EntityLivingBase) iterator2.next();
entityplayer2.worldObj = worldF;
entityplayer2.setPositionAndUpdate(entityplayer2.posX + this.xCoord - xf, entityplayer2.posY + this.yCoord - yf, entityplayer2.posZ + this.zCoord - zf);
}
}
}
}
}
}
previousInput = currentInput;
}
public void setActive()
{
isActive = false;
}
public boolean isActive()
{
return isActive;
}
@Override
public Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData)
{
if (intData == null)
{
return;
}
if (intData.length == 3)
{
for (int i = 0; i < 1; i++)
{
if (intData[i * 3 + 2] != 0)
{
ItemStack is = new ItemStack(Item.getItemById(intData[i * 3]), intData[i * 3 + 2], intData[i * 3 + 1]);
inv[i] = is;
} else
{
inv[i] = null;
}
}
}
}
public int[] buildIntDataList()
{
int[] sortList = new int[1 * 3];
int pos = 0;
for (ItemStack is : inv)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
if (slot == 0)
{
return true;
}
return false;
}
}

View file

@ -0,0 +1,881 @@
package WayofTime.alchemicalWizardry.common.tileEntity;
import WayofTime.alchemicalWizardry.ModItems;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemicalPotionCreationHandler;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipe;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import WayofTime.alchemicalWizardry.common.IBindingAgent;
import WayofTime.alchemicalWizardry.common.ICatalyst;
import WayofTime.alchemicalWizardry.common.IFillingAgent;
import WayofTime.alchemicalWizardry.common.NewPacketHandler;
import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry;
import WayofTime.alchemicalWizardry.common.alchemy.ICombinationalCatalyst;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import WayofTime.alchemicalWizardry.common.items.potion.AlchemyFlask;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.oredict.OreDictionary;
public class TEWritingTable extends TileEntity implements IInventory
{
private ItemStack[] inv;
private int progress;
private int progressNeeded = 100;
private int amountUsed;
private int accelerationTime;
public static final int sizeInv = 7;
public TEWritingTable()
{
inv = new ItemStack[7];
}
@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();
}
}
@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 void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
NBTTagList tagList = tagCompound.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
byte slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length)
{
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
progress = tagCompound.getInteger("progress");
amountUsed = tagCompound.getInteger("amountUsed");
accelerationTime = tagCompound.getInteger("accelerationTime");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++)
{
ItemStack stack = inv[i];
if (stack != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
stack.writeToNBT(tag);
itemList.appendTag(tag);
}
}
tagCompound.setTag("Inventory", itemList);
tagCompound.setInteger("progress", progress);
tagCompound.setInteger("amountUsed", amountUsed);
tagCompound.setInteger("accelerationTime", accelerationTime);
}
@Override
public String getInventoryName()
{
return "aw.TEWritingTable";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return false;
}
@Override
public net.minecraft.network.Packet getDescriptionPacket()
{
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData)
{
if (intData == null)
{
return;
}
if (intData.length == 3 * 7)
{
for (int i = 0; i < 7; i++)
{
if (intData[i * 3 + 2] != 0)
{
ItemStack is = new ItemStack(Item.getItemById(intData[i * 3]), intData[i * 3 + 2], intData[i * 3 + 1]);
inv[i] = is;
} else
{
inv[i] = null;
}
}
}
}
public int[] buildIntDataList()
{
int[] sortList = new int[7 * 3];
int pos = 0;
for (ItemStack is : inv)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
public ItemStack getResultingItemStack()
{
ItemStack[] composedRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
composedRecipe[i] = inv[i + 1];
}
return AlchemyRecipeRegistry.getResult(composedRecipe, inv[0]);
}
public boolean isRecipeValid()
{
return (getResultingItemStack() != null);
}
public int getAmountNeeded(ItemStack bloodOrb)
{
ItemStack[] composedRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
composedRecipe[i] = inv[i + 1];
}
return AlchemyRecipeRegistry.getAmountNeeded(composedRecipe, bloodOrb);
}
public boolean containsPotionFlask()
{
if (getPotionFlaskPosition() != -1)
{
return true;
} else
{
return false;
}
}
public int getPotionFlaskPosition()
{
for (int i = 1; i <= 5; i++)
{
if (inv[i] != null && !(inv[i].getItem() instanceof ItemBlock) && inv[i].getItem() == ModItems.alchemyFlask)
{
return i;
}
}
return -1;
}
public boolean containsCombinationCatalyst()
{
if (getCombinationCatalystPosition() != -1)
{
return true;
} else
{
return false;
}
}
public int getCombinationCatalystPosition()
{
for (int i = 1; i <= 5; i++)
{
if (inv[i] != null && inv[i].getItem() instanceof ICombinationalCatalyst)
{
return i;
}
}
return -1;
}
public boolean containsRegisteredPotionIngredient()
{
if (getRegisteredPotionIngredientPosition() != -1)
{
return true;
} else
{
return false;
}
}
public int getRegisteredPotionIngredientPosition()
{
ItemStack[] composedRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
composedRecipe[i] = inv[i + 1];
}
int location = AlchemicalPotionCreationHandler.getRegisteredPotionIngredientPosition(composedRecipe);
if (location != -1)
{
return location + 1;
}
return -1;
}
public boolean containsCatalyst()
{
if (getCatalystPosition() != -1)
{
return true;
}
return false;
}
public int getCatalystPosition()
{
for (int i = 0; i < 5; i++)
{
if (inv[i + 1] != null && inv[i + 1].getItem() instanceof ICatalyst)
{
return i + 1;
}
}
return -1;
}
public boolean containsBindingAgent()
{
if (getBindingAgentPosition() != -1)
{
return true;
}
return false;
}
public int getBindingAgentPosition()
{
for (int i = 0; i < 5; i++)
{
if (inv[i + 1] != null && inv[i + 1].getItem() instanceof IBindingAgent)
{
return i + 1;
}
}
return -1;
}
public boolean containsFillingAgent()
{
if (getFillingAgentPosition() != -1)
{
return true;
}
return false;
}
public int getFillingAgentPosition()
{
for (int i = 0; i < 5; i++)
{
if (inv[i + 1] != null && inv[i + 1].getItem() instanceof IFillingAgent)
{
return i + 1;
}
}
return -1;
}
public boolean containsBlankSlate()
{
if (getBlankSlatePosition() != -1)
{
return true;
}
return false;
}
public int getBlankSlatePosition()
{
for (int i = 0; i < 5; i++)
{
if (inv[i + 1] != null && inv[i + 1].getItem() == ModItems.blankSlate)
{
return i + 1;
}
}
return -1;
}
@Override
public void updateEntity()
{
long worldTime = worldObj.getWorldTime();
if (worldObj.isRemote)
{
return;
}
if (accelerationTime > 0)
{
accelerationTime--;
}
if (containsPotionFlask() && containsRegisteredPotionIngredient())
{
if (containsCatalyst())
{
if (getStackInSlot(6) == null)
{
progress++;
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (progress >= progressNeeded)
{
ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
ItemStack ingredientStack = inv[this.getRegisteredPotionIngredientPosition()];
ItemStack catalystStack = inv[this.getCatalystPosition()];
if (flaskStack == null || ingredientStack == null || catalystStack == null)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
int potionID = AlchemicalPotionCreationHandler.getPotionIDForStack(ingredientStack);
int catalystLevel = ((ICatalyst) catalystStack.getItem()).getCatalystLevel();
boolean isConcentration = ((ICatalyst) catalystStack.getItem()).isConcentration();
if (potionID == -1 || catalystLevel < 0)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
if (isConcentration)
{
((AlchemyFlask) flaskStack.getItem()).setConcentrationOfPotion(flaskStack, potionID, catalystLevel);
} else
{
((AlchemyFlask) flaskStack.getItem()).setDurationFactorOfPotion(flaskStack, potionID, catalystLevel);
}
this.setInventorySlotContents(6, flaskStack);
this.decrStackSize(this.getPotionFlaskPosition(), 1);
this.decrStackSize(this.getCatalystPosition(), 1);
this.decrStackSize(this.getRegisteredPotionIngredientPosition(), 1);
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
} else if (containsBindingAgent())
{
if (getStackInSlot(6) == null)
{
progress++;
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (progress >= progressNeeded)
{
ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
ItemStack ingredientStack = inv[this.getRegisteredPotionIngredientPosition()];
ItemStack agentStack = inv[this.getBindingAgentPosition()];
if (flaskStack == null || ingredientStack == null || agentStack == null)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
int potionEffectNumber = ((AlchemyFlask) flaskStack.getItem()).getNumberOfPotionEffects(flaskStack);
int potionID = AlchemicalPotionCreationHandler.getPotionIDForStack(ingredientStack);
int tickDuration = AlchemicalPotionCreationHandler.getPotionTickDurationForStack(ingredientStack);
float successChance = ((IBindingAgent) agentStack.getItem()).getSuccessRateForPotionNumber(potionEffectNumber);
if (potionID == -1)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
((AlchemyFlask) flaskStack.getItem()).addPotionEffect(flaskStack, potionID, tickDuration);
if (successChance > worldObj.rand.nextFloat())
{
this.setInventorySlotContents(6, flaskStack);
} else
{
worldObj.createExplosion(null, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 2, false);
}
this.decrStackSize(this.getPotionFlaskPosition(), 1);
this.decrStackSize(this.getBindingAgentPosition(), 1);
this.decrStackSize(this.getRegisteredPotionIngredientPosition(), 1);
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
} else if (this.containsBlankSlate() && this.containsPotionFlask())
{
if (getStackInSlot(6) == null)
{
progress++;
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (progress >= progressNeeded)
{
ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
ItemStack blankSlate = inv[this.getBlankSlatePosition()];
if (flaskStack == null || blankSlate == null)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
((AlchemyFlask) flaskStack.getItem()).setIsPotionThrowable(true, flaskStack);
this.setInventorySlotContents(6, flaskStack);
this.decrStackSize(this.getPotionFlaskPosition(), 1);
this.decrStackSize(this.getBlankSlatePosition(), 1);
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
} else if (this.containsFillingAgent() && this.containsPotionFlask())
{
if (getStackInSlot(6) == null)
{
progress++;
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (progress >= progressNeeded)
{
ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
ItemStack fillingAgent = inv[this.getFillingAgentPosition()];
if (flaskStack == null || fillingAgent == null)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
int potionEffects = ((AlchemyFlask) flaskStack.getItem()).getNumberOfPotionEffects(flaskStack);
int potionFillAmount = ((IFillingAgent) fillingAgent.getItem()).getFilledAmountForPotionNumber(potionEffects);
flaskStack.setItemDamage(Math.max(0, flaskStack.getItemDamage() - potionFillAmount));
this.setInventorySlotContents(6, flaskStack);
this.decrStackSize(this.getPotionFlaskPosition(), 1);
this.decrStackSize(this.getFillingAgentPosition(), 1);
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
} else if (this.containsPotionFlask() && this.containsCombinationCatalyst())
{
//TODO
if (getStackInSlot(6) == null && CombinedPotionRegistry.hasCombinablePotionEffect(inv[this.getPotionFlaskPosition()]))
{
progress++;
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (progress >= progressNeeded)
{
ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
ItemStack combinationCatalyst = inv[this.getCombinationCatalystPosition()];
if (flaskStack == null || combinationCatalyst == null)
{
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
}
ItemStack newFlask = CombinedPotionRegistry.applyPotionEffect(flaskStack);
if (newFlask != null)
{
this.setInventorySlotContents(6, newFlask);
this.decrStackSize(this.getPotionFlaskPosition(), 1);
this.decrStackSize(this.getCombinationCatalystPosition(), 1);
progress = 0;
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
} else
{
if (!isRecipeValid())
{
progress = 0;
return;
}
if (progress <= 0)
{
progress = 0;
amountUsed = this.getAmountNeeded(getStackInSlot(0));
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
int acceleration = this.getSpeedIncrease();
if (getStackInSlot(6) == null)
{
if (!EnergyItems.syphonWhileInContainer(getStackInSlot(0), amountUsed * acceleration))
{
return;
}
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
progress += acceleration;
if (progress >= progressNeeded)
{
progress = 0;
this.setInventorySlotContents(6, getResultingItemStack());
ItemStack[] composedRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
composedRecipe[i] = inv[i + 1];
}
this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
} else if (getStackInSlot(6).getItem() == getResultingItemStack().getItem() && getResultingItemStack().stackSize <= (getStackInSlot(6).getMaxStackSize() - getStackInSlot(6).stackSize))
{
if (worldTime % 4 == 0)
{
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
if (!EnergyItems.syphonWhileInContainer(getStackInSlot(0), amountUsed * acceleration))
{
return;
}
progress += acceleration;
if (progress >= progressNeeded)
{
progress = 0;
ItemStack result = getResultingItemStack().copy();
result.stackSize += getStackInSlot(6).stackSize;
this.setInventorySlotContents(6, result);
ItemStack[] composedRecipe = new ItemStack[5];
for (int i = 0; i < 5; i++)
{
composedRecipe[i] = inv[i + 1];
}
this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
}
public void decrementSlots(ItemStack[] recipe) //TODO Fix this. This doesn't work.
{
boolean[] decrementedList = new boolean[]{false, false, false, false, false};
for (int i = 0; i < (Math.min(recipe.length, 5)); i++)
{
ItemStack decStack = recipe[i];
if (decStack == null)
{
continue;
}
for (int j = 0; j < 5; j++)
{
ItemStack testStack = this.getStackInSlot(j + 1);
if (testStack != null && (testStack.isItemEqual(decStack) || (testStack.getItem() == decStack.getItem() && decStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) && !(decrementedList[j]))
{
if (testStack.getItem().hasContainerItem(testStack))
{
this.inv[j + 1] = testStack.getItem().getContainerItem(testStack);
} else
{
this.decrStackSize(j + 1, 1);
}
decrementedList[j] = true;
break;
}
}
}
}
public ItemStack[] getRecipeForItems(ItemStack[] recipe, ItemStack bloodOrb)
{
if (bloodOrb == null)
{
return null;
}
if (!(bloodOrb.getItem() instanceof IBloodOrb))
{
return null;
}
int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel();
for (AlchemyRecipe ar : AlchemyRecipeRegistry.recipes)
{
if (ar.doesRecipeMatch(recipe, bloodOrbLevel))
{
return ar.getRecipe();
}
}
return null;
}
public int getSpeedIncrease()
{
return accelerationTime > 0 ? 5 : 1;
}
public boolean isWorking()
{
return this.progress > 0;
}
public void setAccelerationTime(int accelerationTime)
{
this.accelerationTime = accelerationTime;
}
}

View file

@ -0,0 +1,91 @@
package WayofTime.alchemicalWizardry.common.tileEntity.container;
import WayofTime.alchemicalWizardry.common.tileEntity.TEAltar;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerAltar extends Container
{
protected TEAltar tileEntity;
public ContainerAltar(InventoryPlayer inventoryPlayer, TEAltar te)
{
tileEntity = te;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
addSlotToContainer(new Slot(tileEntity, j + i * 3, 62 + j * 18, 17 + i * 18));
}
}
bindPlayerInventory(inventoryPlayer);
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return tileEntity.isUseableByPlayer(entityplayer);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot < 9)
{
if (!this.mergeItemStack(stackInSlot, 0, 35, true))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, 9, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
} else
{
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}

View file

@ -0,0 +1,92 @@
package WayofTime.alchemicalWizardry.common.tileEntity.container;
import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerTeleposer extends Container
{
protected TETeleposer tileEntity;
public ContainerTeleposer(InventoryPlayer inventoryPlayer, TETeleposer te)
{
tileEntity = te;
addSlotToContainer(new Slot(tileEntity, 0, 80, 67));
bindPlayerInventory(inventoryPlayer);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return tileEntity.isUseableByPlayer(player);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 198));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot == 7)
{
if (!this.mergeItemStack(stackInSlot, 7, 35, true))
{
return null;
}
slotObject.onSlotChange(stackInSlot, stack);
}
if (slot < 1)
{
if (!this.mergeItemStack(stackInSlot, 7, 35, true))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, 0, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
} else
{
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}

View file

@ -0,0 +1,94 @@
package WayofTime.alchemicalWizardry.common.tileEntity.container;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerWritingTable extends Container
{
protected TEWritingTable tileEntity;
public ContainerWritingTable(InventoryPlayer inventoryPlayer, TEWritingTable te)
{
tileEntity = te;
addSlotToContainer(new Slot(tileEntity, 0, 152, 110));
addSlotToContainer(new Slot(tileEntity, 1, 80, 18));
addSlotToContainer(new Slot(tileEntity, 2, 33, 52));
addSlotToContainer(new Slot(tileEntity, 3, 51, 110));
addSlotToContainer(new Slot(tileEntity, 4, 109, 110));
addSlotToContainer(new Slot(tileEntity, 5, 127, 52));
addSlotToContainer(new Slot(tileEntity, 6, 80, 67));
bindPlayerInventory(inventoryPlayer);
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return tileEntity.isUseableByPlayer(player);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 198));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot <= 6)
{
if (!this.mergeItemStack(stackInSlot, 7, 43, true))
{
return null;
}
} else if (stack.getItem() instanceof IBloodOrb)
{
if (!this.mergeItemStack(stackInSlot, 0, 1, false))
{
return null;
}
} else if (!this.mergeItemStack(stackInSlot, 1, 6, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
} else
{
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}

View file

@ -0,0 +1,73 @@
package WayofTime.alchemicalWizardry.common.tileEntity.gui;
import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer;
import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable;
import WayofTime.alchemicalWizardry.common.tileEntity.container.ContainerTeleposer;
import WayofTime.alchemicalWizardry.common.tileEntity.container.ContainerWritingTable;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class GuiHandler implements IGuiHandler
{
//returns an instance of the Container you made earlier
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity;
switch (id)
{
case 0:
tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TEWritingTable)
{
return new ContainerWritingTable(player.inventory, (TEWritingTable) tileEntity);
}
case 1:
tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TETeleposer)
{
return new ContainerTeleposer(player.inventory, (TETeleposer) tileEntity);
}
}
return null;
}
//returns an instance of the Gui you made earlier
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tileEntity;
switch (id)
{
case 0:
tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TEWritingTable)
{
return new GuiWritingTable(player.inventory, (TEWritingTable) tileEntity);
}
break;
case 1:
tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TETeleposer)
{
return new GuiTeleposer(player.inventory, (TETeleposer) tileEntity);
}
break;
}
return null;
}
}

View file

@ -0,0 +1,42 @@
package WayofTime.alchemicalWizardry.common.tileEntity.gui;
import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer;
import WayofTime.alchemicalWizardry.common.tileEntity.container.ContainerTeleposer;
import net.minecraft.client.gui.inventory.GuiBrewingStand;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
public class GuiTeleposer extends GuiContainer
{
public GuiTeleposer(InventoryPlayer inventoryPlayer, TETeleposer tileEntity)
{
super(new ContainerTeleposer(inventoryPlayer, tileEntity));
xSize = 176;
ySize = 222;
}
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
//the parameters for drawString are: string, x, y, color
fontRendererObj.drawString("Teleposer", 8, 6, 4210752);
//draws "Inventory" or your regional equivalent
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, 130, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
//draw your Gui here, only thing you need to change is the path
ResourceLocation test = new ResourceLocation("alchemicalwizardry", "gui/Teleposer.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(test);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
GuiBrewingStand d;
}
}

View file

@ -0,0 +1,43 @@
package WayofTime.alchemicalWizardry.common.tileEntity.gui;
import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable;
import WayofTime.alchemicalWizardry.common.tileEntity.container.ContainerWritingTable;
import net.minecraft.client.gui.inventory.GuiBrewingStand;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
public class GuiWritingTable extends GuiContainer
{
public GuiWritingTable(InventoryPlayer inventoryPlayer, TEWritingTable tileEntity)
{
super(new ContainerWritingTable(inventoryPlayer, tileEntity));
xSize = 176;
ySize = 222;
}
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
//draw text and stuff here
//the parameters for drawString are: string, x, y, color
fontRendererObj.drawString("Alchemic Chemistry Set", 8, 6, 4210752);
//draws "Inventory" or your regional equivalent
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, 130, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
//draw your Gui here, only thing you need to change is the path
ResourceLocation test = new ResourceLocation("alchemicalwizardry", "gui/WritingTable.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(test);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
GuiBrewingStand d;
}
}