use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.
the class ContainerAlchemyTable method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 8) {
if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true)) {
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
} else if (index > 8) {
if (itemstack1.getItem() instanceof IBloodOrb) {
if (// TODO: Add alchemy tools to list
!this.mergeItemStack(itemstack1, 7, 8, false)) {
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 0, 6, false)) {
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 9, 9 + 36, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0) {
slot.putStack(ItemStack.EMPTY);
} else {
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.
the class BloodAltar method startCycle.
public void startCycle() {
if (tileAltar.getWorld() != null)
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
checkTier();
if ((fluid == null || fluid.amount <= 0) && totalCharge <= 0)
return;
if (!isActive)
progress = 0;
ItemStack input = tileAltar.getStackInSlot(0);
if (!input.isEmpty()) {
// Do recipes
RecipeBloodAltar recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getBloodAltar(input);
if (recipe != null) {
if (recipe.getMinimumTier().ordinal() <= altarTier.ordinal()) {
this.isActive = true;
this.recipe = recipe;
this.liquidRequired = recipe.getSyphon();
this.consumptionRate = recipe.getConsumeRate();
this.drainRate = recipe.getDrainRate();
this.canBeFilled = false;
return;
}
} else if (input.getItem() instanceof IBloodOrb) {
this.isActive = true;
this.canBeFilled = true;
return;
}
}
isActive = false;
}
use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.
the class BloodAltar method updateAltar.
private void updateAltar() {
if (!isActive) {
if (cooldownAfterCrafting > 0)
cooldownAfterCrafting--;
return;
}
ItemStack input = tileAltar.getStackInSlot(0);
if (input.isEmpty())
return;
World world = tileAltar.getWorld();
BlockPos pos = tileAltar.getPos();
if (world.isRemote)
return;
if (!canBeFilled) {
boolean hasOperated = false;
int stackSize = input.getCount();
if (totalCharge > 0) {
int chargeDrained = Math.min(liquidRequired * stackSize - progress, totalCharge);
totalCharge -= chargeDrained;
progress += chargeDrained;
hasOperated = true;
}
if (fluid != null && fluid.amount >= 1) {
int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount);
if (liquidDrained > (liquidRequired * stackSize - progress))
liquidDrained = liquidRequired * stackSize - progress;
fluid.amount = fluid.amount - liquidDrained;
progress += liquidDrained;
hasOperated = true;
if (internalCounter % 4 == 0 && world instanceof WorldServer) {
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
}
} else if (!hasOperated && progress > 0) {
progress -= (int) (efficiencyMultiplier * drainRate);
if (internalCounter % 2 == 0 && world instanceof WorldServer) {
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.1, 0, 0.1, 0);
}
}
if (hasOperated) {
if (progress >= liquidRequired * stackSize) {
ItemStack result = ItemHandlerHelper.copyStackWithSize(recipe.getOutput(), stackSize);
BloodMagicCraftedEvent.Altar event = new BloodMagicCraftedEvent.Altar(recipe.getInput(), result);
MinecraftForge.EVENT_BUS.post(event);
tileAltar.setInventorySlotContents(0, event.getOutput());
progress = 0;
if (world instanceof WorldServer) {
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
}
this.cooldownAfterCrafting = 30;
this.isActive = false;
}
}
} else {
ItemStack contained = tileAltar.getStackInSlot(0);
if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable))
return;
BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained);
Binding binding = ((IBindable) contained.getItem()).getBinding(contained);
if (binding == null || orb == null)
return;
if (fluid != null && fluid.amount >= 1) {
int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount);
int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
fluid.amount = fluid.amount - drain;
if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) {
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.SPELL_WITCH, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.001);
}
}
}
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.
the class TileAlchemyTable method getContainedLp.
public int getContainedLp() {
ItemStack orbStack = getStackInSlot(orbSlot);
if (!orbStack.isEmpty()) {
if (orbStack.getItem() instanceof IBloodOrb) {
NBTTagCompound itemTag = orbStack.getTagCompound();
if (itemTag == null) {
return 0;
}
String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerUUID)) {
return 0;
}
SoulNetwork network = NetworkHelper.getSoulNetwork(ownerUUID);
return network.getCurrentEssence();
}
}
return 0;
}
use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.
the class GenericHandler method onInteract.
// Handles binding of IBindable's as well as setting a player's highest orb tier
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickItem event) {
if (event.getWorld().isRemote)
return;
EntityPlayer player = event.getEntityPlayer();
if (PlayerHelper.isFakePlayer(player))
return;
ItemStack held = event.getItemStack();
if (!held.isEmpty() && held.getItem() instanceof IBindable) {
// Make sure it's bindable
IBindable bindable = (IBindable) held.getItem();
Binding binding = bindable.getBinding(held);
if (binding == null) {
// If the binding is null, let's create one
if (bindable.onBind(player, held)) {
ItemBindEvent toPost = new ItemBindEvent(player, held);
if (// Allow cancellation of binding
MinecraftForge.EVENT_BUS.post(toPost))
return;
// Bind item to the player
BindableHelper.applyBinding(held, player);
}
// If the binding exists, we'll check if the player's name has changed since they last used it and update that if so.
} else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName())) {
binding.setOwnerName(player.getGameProfile().getName());
BindableHelper.applyBinding(held, binding);
}
}
if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) {
IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
SoulNetwork network = NetworkHelper.getSoulNetwork(player);
BloodOrb orb = bloodOrb.getOrb(held);
if (orb == null)
return;
if (orb.getTier() > network.getOrbTier())
network.setOrbTier(orb.getTier());
}
}
Aggregations