BloodMagic/BM_src/WayofTime/alchemicalWizardry/common/rituals/RitualEffectCrushing.java
Fenn e3644f2d2b Massive rework of configs, items and blocks.
I redone where the items/blocsks are stored and how the configs are
handled to clean up it and give space. You can change the config line to
AWWayofTime if you want to keep the compatibility with old configs. Now
you reference the blocks from the ModBlocks and Items from the ModItems.
2014-01-17 21:05:38 +00:00

160 lines
6.3 KiB
Java

package WayofTime.alchemicalWizardry.common.rituals;
import WayofTime.alchemicalWizardry.common.LifeEssenceNetwork;
import WayofTime.alchemicalWizardry.common.ModBlocks;
import WayofTime.alchemicalWizardry.common.tileEntity.TEMasterStone;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.ArrayList;
public class RitualEffectCrushing extends RitualEffect {
@Override
public void performEffect(TEMasterStone ritualStone)
{
String owner = ritualStone.getOwner();
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;
World world = ritualStone.worldObj;
if (world.getWorldTime() % 40 != 0)
{
return;
}
int x = ritualStone.xCoord;
int y = ritualStone.yCoord;
int z = ritualStone.zCoord;
TileEntity tile = world.getBlockTileEntity(x, y + 1, z);
IInventory tileEntity;
if (tile instanceof IInventory)
{
tileEntity = (IInventory) tile;
} else
{
return;
}
if (tileEntity.getSizeInventory() <= 0)
{
return;
}
if (currentEssence < this.getCostPerRefresh())
{
EntityPlayer entityOwner = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(owner);
if (entityOwner == null)
{
return;
}
entityOwner.addPotionEffect(new PotionEffect(Potion.confusion.id, 80));
} else
{
//boolean flag = false;
for (int j = -3; j < 0; j++)
{
for (int i = -1; i <= 1; i++)
{
for (int k = -1; k <= 1; k++)
{
int blockID = world.getBlockId(x + i, y + j, z + k);
Block block = Block.blocksList[blockID];
int meta = world.getBlockMetadata(x + i, y + j, z + k);
if (block != null)
{
if ((block.equals(ModBlocks.ritualStone) || block.equals(ModBlocks.blockMasterStone)))
{
continue;
}
ArrayList<ItemStack> itemDropList = block.getBlockDropped(world, x + i, y + j, z + k, meta, 0);
if (itemDropList != null)
{
int invSize = tileEntity.getSizeInventory();
for (ItemStack item : itemDropList)
{
ItemStack copyStack = item.copyItemStack(item);
for (int n = 0; n < invSize; n++)
{
if (tileEntity.isItemValidForSlot(n, copyStack) && copyStack.stackSize != 0)
{
ItemStack itemStack = tileEntity.getStackInSlot(n);
if (itemStack == null)
{
tileEntity.setInventorySlotContents(n, copyStack);
copyStack.stackSize = 0;
} else
{
if (itemStack.getItem().equals(copyStack.getItem()))
{
int itemSize = itemStack.stackSize;
int copySize = copyStack.stackSize;
int maxSize = itemStack.getMaxStackSize();
if (copySize + itemSize < maxSize)
{
copyStack.stackSize = 0;
itemStack.stackSize = itemSize + copySize;
tileEntity.setInventorySlotContents(n, itemStack);
} else
{
copyStack.stackSize = itemSize + copySize - maxSize;
itemStack.stackSize = maxSize;
}
}
}
}
}
if (copyStack.stackSize > 0)
{
world.spawnEntityInWorld(new EntityItem(world, x + 0.4, y + 2, z + 0.5, copyStack));
//flag=true;
}
}
}
//if(flag)
world.setBlockToAir(x + i, y + j, z + k);
world.playSoundEffect(x + i, y + j, z + k, "mob.endermen.portal", 1.0F, 1.0F);
data.currentEssence = currentEssence - this.getCostPerRefresh();
data.markDirty();
return;
}
}
}
}
}
}
@Override
public int getCostPerRefresh()
{
return 7;
}
}