use of com.bewitchment.api.registry.Ritual in project Bewitchment by Um-Mitternacht.
the class BlockGlyph method livingDeath.
@SubscribeEvent
public void livingDeath(LivingDeathEvent event) {
EntityLivingBase living = event.getEntityLiving();
if (!living.world.isRemote) {
BlockPos pos = living.getPosition();
EntityPlayer player = living.world.getClosestPlayer(living.posX, living.posY, living.posZ, 10, false);
if (player != null) {
for (BlockPos pos0 : BlockPos.getAllInBoxMutable(pos.add(-2, -2, -2), pos.add(2, 2, 2))) {
if (living.world.getTileEntity(pos0) instanceof TileEntityGlyph) {
TileEntityGlyph tile = (TileEntityGlyph) living.world.getTileEntity(pos0);
Ritual ritual = GameRegistry.findRegistry(Ritual.class).getValuesCollection().stream().filter(r -> r.matches(living.world, pos0, tile.getInventories()[0])).findFirst().orElse(null);
if (ritual != null && ritual.sacrificePredicate != null && ritual.sacrificePredicate.test(living))
tile.startRitual(player, ritual);
}
}
}
}
}
use of com.bewitchment.api.registry.Ritual in project Bewitchment by Um-Mitternacht.
the class TileEntityGlyph method activate.
@Override
public boolean activate(World world, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing face) {
if (!world.isRemote) {
if (player.isSneaking()) {
int last = getLastNonEmptySlot(inventory);
if (last > -1) {
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inventory.extractItem(last, inventory.getStackInSlot(last).getCount(), false));
stopRitual(false);
}
} else {
ItemStack stack = player.getHeldItem(hand);
if (ritual == null) {
if (!stack.isEmpty()) {
int slot = getFirstEmptySlot(inventory);
if (slot < 10 && slot > -1)
inventory.insertItem(slot, stack.splitStack(1), false);
} else {
Ritual rit = GameRegistry.findRegistry(Ritual.class).getValuesCollection().stream().filter(r -> r.matches(world, pos, inventory)).findFirst().orElse(null);
if (rit != null) {
if (rit.isValid(world, pos, player, inventory))
startRitual(player, rit);
else
player.sendStatusMessage(new TextComponentTranslation(rit.getPreconditionMessage()), true);
} else
player.sendStatusMessage(new TextComponentTranslation("ritual.null"), true);
}
} else {
if (stack.getItem() == ModObjects.waystone && stack.hasTagCompound() && stack.getTagCompound().hasKey("location")) {
if (ritual.canBePerformedRemotely) {
effectivePos = BlockPos.fromLong(stack.getTagCompound().getLong("location"));
effectiveDim = stack.getTagCompound().getInteger("dimension");
stack.damageItem(1, player);
syncToClient();
}
} else
stopRitual(false);
}
}
}
return true;
}
Aggregations