use of com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent in project Wizardry by TeamWizardry.
the class BlockFluidMana method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
Entity entityIn = event.getEntity();
BlockPos pos = entityIn.getPosition();
World world = entityIn.world;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
// Fizz all entities in the pool
if (world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> true, entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));
// Nullify gravity of player
if (!world.isRemote)
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> {
((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
if (RandUtil.nextInt(50) == 0)
entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
});
// Subtract player food
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityPlayer, entity -> {
if (!world.isRemote) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
if (advancement == null)
return;
AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
for (String s : progress.getRemaningCriteria()) {
((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
}
}
if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
});
// Explode explodable items
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IExplodable, entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
}
run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> {
List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
});
}
Aggregations