Search in sources :

Example 1 with AdvancementProgress

use of net.minecraft.advancements.AdvancementProgress in project takumicraft by TNTModders.

the class TakumiUtils method getAdvancementUnlocked.

@SideOnly(Side.CLIENT)
public static boolean getAdvancementUnlocked(ResourceLocation location) {
    ClientAdvancementManager manager = Minecraft.getMinecraft().player.connection.getAdvancementManager();
    try {
        Field field = TakumiASMNameMap.getField(ClientAdvancementManager.class, "advancementToProgress");
        field.setAccessible(true);
        Map<Advancement, AdvancementProgress> advancementToProgress = (Map<Advancement, AdvancementProgress>) field.get(manager);
        if (advancementToProgress.containsKey(manager.getAdvancementList().getAdvancement(location))) {
            return advancementToProgress.get(manager.getAdvancementList().getAdvancement(location)).isDone();
        }
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : Field(java.lang.reflect.Field) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) ClientAdvancementManager(net.minecraft.client.multiplayer.ClientAdvancementManager) TakumiASMNameMap(com.tntmodders.asm.TakumiASMNameMap) Advancement(net.minecraft.advancements.Advancement) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with AdvancementProgress

use of net.minecraft.advancements.AdvancementProgress 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()));
    });
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ManaRecipes(com.teamwizardry.wizardry.crafting.mana.ManaRecipes) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) Random(java.util.Random) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PotionEffect(net.minecraft.potion.PotionEffect) BlockModFluid(com.teamwizardry.librarianlib.features.base.fluid.BlockModFluid) ModFluid(com.teamwizardry.librarianlib.features.base.fluid.ModFluid) MinecraftServer(net.minecraft.server.MinecraftServer) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Map(java.util.Map) FluidRecipeLoader(com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader) Nonnull(javax.annotation.Nonnull) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) Wizardry(com.teamwizardry.wizardry.Wizardry) ModPotions(com.teamwizardry.wizardry.init.ModPotions) Advancement(net.minecraft.advancements.Advancement) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) DamageSourceMana(com.teamwizardry.wizardry.common.core.DamageSourceMana) EntityUpdateEvent(com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent) FluidTracker(com.teamwizardry.wizardry.api.block.FluidTracker) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IExplodable(com.teamwizardry.wizardry.api.item.IExplodable) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) IExplodable(com.teamwizardry.wizardry.api.item.IExplodable) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) FluidRecipeLoader(com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader) Advancement(net.minecraft.advancements.Advancement) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with AdvancementProgress

use of net.minecraft.advancements.AdvancementProgress in project SpongeCommon by SpongePowered.

the class PlayerAdvancementsMixin method impl$updateProgressOnUnregister.

@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterion(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress impl$updateProgressOnUnregister(final AdvancementProgress advancementProgress, final String criterion) {
    if (((PlatformEntityBridge) this.player).bridge$isFakePlayer()) {
        return advancementProgress.getCriterion(criterion);
    }
    final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).advancement();
    final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
    final CriterionBridge criterionBridge = (CriterionBridge) advancementCriterion;
    // Only remove the trigger once the goal is reached
    if (criterionBridge.bridge$getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(criterionBridge.bridge$getScoreCriterion()).get().achieved()) {
        return null;
    }
    return advancementProgress.getCriterion(criterion);
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) PlatformEntityBridge(org.spongepowered.common.bridge.world.entity.PlatformEntityBridge) Advancement(net.minecraft.advancements.Advancement) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Nullable(javax.annotation.Nullable)

Example 4 with AdvancementProgress

use of net.minecraft.advancements.AdvancementProgress in project SpongeCommon by SpongePowered.

the class MixinPlayerAdvancements method onUnregisterListenersGetProgress.

@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterionProgress(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress onUnregisterListenersGetProgress(AdvancementProgress advancementProgress, String criterion) {
    final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).getAdvancement();
    final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
    final IMixinCriterion mixinCriterion = (IMixinCriterion) advancementCriterion;
    // Only remove the trigger once the goal is reached
    if (mixinCriterion.getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(mixinCriterion.getScoreCriterion()).get().achieved()) {
        return null;
    }
    return advancementProgress.getCriterionProgress(criterion);
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) IMixinAdvancementProgress(org.spongepowered.common.interfaces.advancement.IMixinAdvancementProgress) IMixinCriterion(org.spongepowered.common.interfaces.advancement.IMixinCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) Advancement(net.minecraft.advancements.Advancement) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Nullable(javax.annotation.Nullable)

Example 5 with AdvancementProgress

use of net.minecraft.advancements.AdvancementProgress in project ManaCraft by Yaossg.

the class Util method giveAdvancement.

public static void giveAdvancement(Entity player, String advance) {
    if (player.getServer() != null) {
        MinecraftServer server = player.getServer();
        if (player instanceof EntityPlayerMP) {
            EntityPlayerMP playerMP = (EntityPlayerMP) player;
            Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(advance));
            AdvancementProgress progress = playerMP.getAdvancements().getProgress(advancement);
            if (!progress.isDone()) {
                for (String s : progress.getRemaningCriteria()) {
                    playerMP.getAdvancements().grantCriterion(advancement, s);
                }
            }
        }
    }
}
Also used : AdvancementProgress(net.minecraft.advancements.AdvancementProgress) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Advancement(net.minecraft.advancements.Advancement) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

Advancement (net.minecraft.advancements.Advancement)5 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)5 Nullable (javax.annotation.Nullable)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockModFluid (com.teamwizardry.librarianlib.features.base.fluid.BlockModFluid)1 ModFluid (com.teamwizardry.librarianlib.features.base.fluid.ModFluid)1 EntityUpdateEvent (com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent)1 Wizardry (com.teamwizardry.wizardry.Wizardry)1 FluidTracker (com.teamwizardry.wizardry.api.block.FluidTracker)1 IExplodable (com.teamwizardry.wizardry.api.item.IExplodable)1 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)1 LibParticles (com.teamwizardry.wizardry.client.fx.LibParticles)1 DamageSourceMana (com.teamwizardry.wizardry.common.core.DamageSourceMana)1 FluidRecipeLoader (com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader)1 ManaRecipes (com.teamwizardry.wizardry.crafting.mana.ManaRecipes)1 ModPotions (com.teamwizardry.wizardry.init.ModPotions)1 TakumiASMNameMap (com.tntmodders.asm.TakumiASMNameMap)1 Field (java.lang.reflect.Field)1