use of WayofTime.bloodmagic.soul.IDiscreteDemonWill in project BloodMagic by WayofTime.
the class TileDemonCrucible method update.
@Override
public void update() {
if (getWorld().isRemote) {
return;
}
internalCounter++;
if (getWorld().isBlockPowered(getPos())) {
// TODO: Fill the contained gem if it is there.
ItemStack stack = this.getStackInSlot(0);
if (stack.getItem() instanceof IDemonWillGem) {
IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
for (EnumDemonWillType type : EnumDemonWillType.values()) {
if (willMap.containsKey(type)) {
double current = willMap.get(type);
double fillAmount = Math.min(gemDrainRate, current);
if (fillAmount > 0) {
fillAmount = gemItem.fillWill(type, stack, fillAmount, true);
if (willMap.get(type) - fillAmount <= 0) {
willMap.remove(type);
} else {
willMap.put(type, willMap.get(type) - fillAmount);
}
}
}
}
}
} else {
ItemStack stack = this.getStackInSlot(0);
if (!stack.isEmpty()) {
if (stack.getItem() instanceof IDemonWillGem) {
IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
for (EnumDemonWillType type : EnumDemonWillType.values()) {
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate);
double filled = WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, drainAmount, maxWill, false);
filled = gemItem.drainWill(type, stack, filled, false);
if (filled > 0) {
filled = gemItem.drainWill(type, stack, filled, true);
WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
}
}
} else if (// TODO: Limit the speed of this process
stack.getItem() instanceof IDiscreteDemonWill) {
IDiscreteDemonWill willItem = (IDiscreteDemonWill) stack.getItem();
EnumDemonWillType type = willItem.getType(stack);
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double needed = maxWill - currentAmount;
double discreteAmount = willItem.getDiscretization(stack);
if (needed >= discreteAmount) {
double filled = willItem.drainWill(stack, discreteAmount);
if (filled > 0) {
WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
if (stack.getCount() <= 0) {
this.setInventorySlotContents(0, ItemStack.EMPTY);
}
}
}
}
}
}
}
use of WayofTime.bloodmagic.soul.IDiscreteDemonWill in project BloodMagic by WayofTime.
the class ItemRitualReader method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
EnumRitualReaderState state = this.getState(stack);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IMasterRitualStone) {
IMasterRitualStone master = (IMasterRitualStone) tile;
this.setMasterBlockPos(stack, pos);
this.setBlockPos(stack, BlockPos.ORIGIN);
switch(state) {
case INFORMATION:
master.provideInformationOfRitualToPlayer(player);
break;
case SET_AREA:
String range = this.getCurrentBlockRange(stack);
if (player.isSneaking()) {
String newRange = master.getNextBlockRange(range);
range = newRange;
this.setCurrentBlockRange(stack, newRange);
}
master.provideInformationOfRangeToPlayer(player, range);
break;
case SET_WILL_TYPES:
List<EnumDemonWillType> typeList = new ArrayList<>();
NonNullList<ItemStack> inv = player.inventory.mainInventory;
for (int i = 0; i < 9; i++) {
ItemStack testStack = inv.get(i);
if (testStack.isEmpty()) {
continue;
}
if (testStack.getItem() instanceof IDiscreteDemonWill) {
EnumDemonWillType type = ((IDiscreteDemonWill) testStack.getItem()).getType(testStack);
if (!typeList.contains(type)) {
typeList.add(type);
}
}
}
master.setActiveWillConfig(player, typeList);
master.provideInformationOfWillConfigToPlayer(player, typeList);
break;
}
return EnumActionResult.FAIL;
} else {
if (state == EnumRitualReaderState.SET_AREA) {
BlockPos masterPos = this.getMasterBlockPos(stack);
if (!masterPos.equals(BlockPos.ORIGIN)) {
BlockPos containedPos = getBlockPos(stack);
if (containedPos.equals(BlockPos.ORIGIN)) {
this.setBlockPos(stack, pos.subtract(masterPos));
player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.firstBlock"), true);
// TODO: Notify player.
} else {
tile = world.getTileEntity(masterPos);
if (tile instanceof IMasterRitualStone) {
IMasterRitualStone master = (IMasterRitualStone) tile;
master.setBlockRangeByBounds(player, this.getCurrentBlockRange(stack), containedPos, pos.subtract(masterPos));
}
this.setBlockPos(stack, BlockPos.ORIGIN);
}
}
}
}
}
return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
use of WayofTime.bloodmagic.soul.IDiscreteDemonWill in project BloodMagic by WayofTime.
the class BlockDemonCrucible method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack heldItem = player.getHeldItem(hand);
TileDemonCrucible crucible = (TileDemonCrucible) world.getTileEntity(pos);
if (crucible == null || player.isSneaking())
return false;
if (!heldItem.isEmpty()) {
if (!(heldItem.getItem() instanceof IDiscreteDemonWill) && !(heldItem.getItem() instanceof IDemonWillGem)) {
return true;
}
}
Utils.insertItemToTile(crucible, player);
world.notifyBlockUpdate(pos, state, state, 3);
return true;
}
Aggregations