Search in sources :

Example 26 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project origins-fabric by apace100.

the class EntityConditions method register.

@SuppressWarnings("unchecked")
public static void register() {
    register(new ConditionFactory<>(Origins.identifier("constant"), new SerializableData().add("value", SerializableDataType.BOOLEAN), (data, entity) -> data.getBoolean("value")));
    register(new ConditionFactory<>(Origins.identifier("and"), new SerializableData().add("conditions", SerializableDataType.ENTITY_CONDITIONS), (data, entity) -> ((List<ConditionFactory<LivingEntity>.Instance>) data.get("conditions")).stream().allMatch(condition -> condition.test(entity))));
    register(new ConditionFactory<>(Origins.identifier("or"), new SerializableData().add("conditions", SerializableDataType.ENTITY_CONDITIONS), (data, entity) -> ((List<ConditionFactory<LivingEntity>.Instance>) data.get("conditions")).stream().anyMatch(condition -> condition.test(entity))));
    register(new ConditionFactory<>(Origins.identifier("block_collision"), new SerializableData().add("offset_x", SerializableDataType.FLOAT).add("offset_y", SerializableDataType.FLOAT).add("offset_z", SerializableDataType.FLOAT), (data, entity) -> entity.world.getBlockCollisions(entity, entity.getBoundingBox().offset(data.getFloat("offset_x") * entity.getBoundingBox().getXLength(), data.getFloat("offset_y") * entity.getBoundingBox().getYLength(), data.getFloat("offset_z") * entity.getBoundingBox().getZLength())).findAny().isPresent()));
    register(new ConditionFactory<>(Origins.identifier("brightness"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.FLOAT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.getBrightnessAtEyes(), data.getFloat("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("daytime"), new SerializableData(), (data, entity) -> entity.world.getTimeOfDay() % 24000L < 13000L));
    register(new ConditionFactory<>(Origins.identifier("time_of_day"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.world.getTimeOfDay() % 24000L, data.getInt("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("fall_flying"), new SerializableData(), (data, entity) -> entity.isFallFlying()));
    register(new ConditionFactory<>(Origins.identifier("exposed_to_sun"), new SerializableData(), (data, entity) -> {
        if (entity.world.isDay() && !((EntityAccessor) entity).callIsBeingRainedOn()) {
            float f = entity.getBrightnessAtEyes();
            BlockPos blockPos = entity.getVehicle() instanceof BoatEntity ? (new BlockPos(entity.getX(), (double) Math.round(entity.getY()), entity.getZ())).up() : new BlockPos(entity.getX(), (double) Math.round(entity.getY()), entity.getZ());
            return f > 0.5F && entity.world.isSkyVisible(blockPos);
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("in_rain"), new SerializableData(), (data, entity) -> ((EntityAccessor) entity).callIsBeingRainedOn()));
    register(new ConditionFactory<>(Origins.identifier("invisible"), new SerializableData(), (data, entity) -> entity.isInvisible()));
    register(new ConditionFactory<>(Origins.identifier("on_fire"), new SerializableData(), (data, entity) -> entity.isOnFire()));
    register(new ConditionFactory<>(Origins.identifier("exposed_to_sky"), new SerializableData(), (data, entity) -> {
        BlockPos blockPos = entity.getVehicle() instanceof BoatEntity ? (new BlockPos(entity.getX(), (double) Math.round(entity.getY()), entity.getZ())).up() : new BlockPos(entity.getX(), (double) Math.round(entity.getY()), entity.getZ());
        return entity.world.isSkyVisible(blockPos);
    }));
    register(new ConditionFactory<>(Origins.identifier("sneaking"), new SerializableData(), (data, entity) -> entity.isSneaking()));
    register(new ConditionFactory<>(Origins.identifier("sprinting"), new SerializableData(), (data, entity) -> entity.isSprinting()));
    register(new ConditionFactory<>(Origins.identifier("power_active"), new SerializableData().add("power", SerializableDataType.POWER_TYPE), (data, entity) -> ((PowerTypeReference<?>) data.get("power")).isActive(entity)));
    register(new ConditionFactory<>(Origins.identifier("status_effect"), new SerializableData().add("effect", SerializableDataType.STATUS_EFFECT).add("min_amplifier", SerializableDataType.INT, 0).add("max_amplifier", SerializableDataType.INT, Integer.MAX_VALUE).add("min_duration", SerializableDataType.INT, 0).add("max_duration", SerializableDataType.INT, Integer.MAX_VALUE), (data, entity) -> {
        StatusEffect effect = (StatusEffect) data.get("effect");
        if (effect == null) {
            return false;
        }
        if (entity.hasStatusEffect(effect)) {
            StatusEffectInstance instance = entity.getStatusEffect(effect);
            return instance.getDuration() <= data.getInt("max_duration") && instance.getDuration() >= data.getInt("min_duration") && instance.getAmplifier() <= data.getInt("max_amplifier") && instance.getAmplifier() >= data.getInt("min_amplifier");
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("submerged_in"), new SerializableData().add("fluid", SerializableDataType.FLUID_TAG), (data, entity) -> entity.isSubmergedIn((Tag<Fluid>) data.get("fluid"))));
    register(new ConditionFactory<>(Origins.identifier("fluid_height"), new SerializableData().add("fluid", SerializableDataType.FLUID_TAG).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.DOUBLE), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.getFluidHeight((Tag<Fluid>) data.get("fluid")), data.getDouble("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("origin"), new SerializableData().add("origin", SerializableDataType.IDENTIFIER).add("layer", SerializableDataType.IDENTIFIER, null), (data, entity) -> {
        OriginComponent component = ModComponents.ORIGIN.get(entity);
        Identifier originId = data.getId("origin");
        if (data.isPresent("layer")) {
            Identifier layerId = data.getId("layer");
            OriginLayer layer = OriginLayers.getLayer(layerId);
            if (layer == null) {
                return false;
            } else {
                Origin origin = component.getOrigin(layer);
                if (origin != null) {
                    return origin.getIdentifier().equals(originId);
                }
                return false;
            }
        } else {
            return component.getOrigins().values().stream().anyMatch(o -> o.getIdentifier().equals(originId));
        }
    }));
    register(new ConditionFactory<>(Origins.identifier("power"), new SerializableData().add("power", SerializableDataType.IDENTIFIER), (data, entity) -> {
        try {
            PowerType<?> powerType = PowerTypeRegistry.get(data.getId("power"));
            return ModComponents.ORIGIN.get(entity).hasPower(powerType);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }));
    register(new ConditionFactory<>(Origins.identifier("food_level"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        if (entity instanceof PlayerEntity) {
            return ((Comparison) data.get("comparison")).compare(((PlayerEntity) entity).getHungerManager().getFoodLevel(), data.getInt("compare_to"));
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("saturation_level"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.FLOAT), (data, entity) -> {
        if (entity instanceof PlayerEntity) {
            return ((Comparison) data.get("comparison")).compare(((PlayerEntity) entity).getHungerManager().getSaturationLevel(), data.getFloat("compare_to"));
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("on_block"), new SerializableData().add("block_condition", SerializableDataType.BLOCK_CONDITION, null), (data, entity) -> entity.isOnGround() && (!data.isPresent("block_condition") || ((ConditionFactory<CachedBlockPosition>.Instance) data.get("block_condition")).test(new CachedBlockPosition(entity.world, entity.getBlockPos().down(), true)))));
    register(new ConditionFactory<>(Origins.identifier("equipped_item"), new SerializableData().add("equipment_slot", SerializableDataType.EQUIPMENT_SLOT).add("item_condition", SerializableDataType.ITEM_CONDITION), (data, entity) -> ((ConditionFactory<ItemStack>.Instance) data.get("item_condition")).test(entity.getEquippedStack((EquipmentSlot) data.get("equipment_slot")))));
    register(new ConditionFactory<>(Origins.identifier("attribute"), new SerializableData().add("attribute", SerializableDataType.ATTRIBUTE).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.DOUBLE), (data, entity) -> {
        double attrValue = 0F;
        EntityAttributeInstance attributeInstance = entity.getAttributeInstance((EntityAttribute) data.get("attribute"));
        if (attributeInstance != null) {
            attrValue = attributeInstance.getValue();
        }
        return ((Comparison) data.get("comparison")).compare(attrValue, data.getDouble("compare_to"));
    }));
    register(new ConditionFactory<>(Origins.identifier("swimming"), new SerializableData(), (data, entity) -> entity.isSwimming()));
    register(new ConditionFactory<>(Origins.identifier("resource"), new SerializableData().add("resource", SerializableDataType.POWER_TYPE).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        int resourceValue = 0;
        OriginComponent component = ModComponents.ORIGIN.get(entity);
        Power p = component.getPower((PowerType<?>) data.get("resource"));
        if (p instanceof VariableIntPower) {
            resourceValue = ((VariableIntPower) p).getValue();
        } else if (p instanceof CooldownPower) {
            resourceValue = ((CooldownPower) p).getRemainingTicks();
        }
        return ((Comparison) data.get("comparison")).compare(resourceValue, data.getInt("compare_to"));
    }));
    register(new ConditionFactory<>(Origins.identifier("air"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.getAir(), data.getInt("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("in_block"), new SerializableData().add("block_condition", SerializableDataType.BLOCK_CONDITION), (data, entity) -> ((ConditionFactory<CachedBlockPosition>.Instance) data.get("block_condition")).test(new CachedBlockPosition(entity.world, entity.getBlockPos(), true))));
    register(new ConditionFactory<>(Origins.identifier("block_in_radius"), new SerializableData().add("block_condition", SerializableDataType.BLOCK_CONDITION).add("radius", SerializableDataType.INT).add("shape", SerializableDataType.enumValue(Shape.class), Shape.CUBE).add("compare_to", SerializableDataType.INT, 1).add("comparison", SerializableDataType.COMPARISON, Comparison.GREATER_THAN_OR_EQUAL), (data, entity) -> {
        Predicate<CachedBlockPosition> blockCondition = ((ConditionFactory<CachedBlockPosition>.Instance) data.get("block_condition"));
        int stopAt = -1;
        Comparison comparison = ((Comparison) data.get("comparison"));
        int compareTo = data.getInt("compare_to");
        switch(comparison) {
            case EQUAL:
            case LESS_THAN_OR_EQUAL:
            case GREATER_THAN:
                stopAt = compareTo + 1;
                break;
            case LESS_THAN:
            case GREATER_THAN_OR_EQUAL:
                stopAt = compareTo;
                break;
        }
        int count = 0;
        for (BlockPos pos : Shape.getPositions(entity.getBlockPos(), (Shape) data.get("shape"), data.getInt("radius"))) {
            if (blockCondition.test(new CachedBlockPosition(entity.world, pos, true))) {
                count++;
                if (count == stopAt) {
                    break;
                }
            }
        }
        return comparison.compare(count, compareTo);
    }));
    register(new ConditionFactory<>(Origins.identifier("dimension"), new SerializableData().add("dimension", SerializableDataType.IDENTIFIER), (data, entity) -> entity.world.getRegistryKey() == RegistryKey.of(Registry.DIMENSION, data.getId("dimension"))));
    register(new ConditionFactory<>(Origins.identifier("xp_levels"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        if (entity instanceof PlayerEntity) {
            return ((Comparison) data.get("comparison")).compare(((PlayerEntity) entity).experienceLevel, data.getInt("compare_to"));
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("xp_points"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        if (entity instanceof PlayerEntity) {
            return ((Comparison) data.get("comparison")).compare(((PlayerEntity) entity).totalExperience, data.getInt("compare_to"));
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("health"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.FLOAT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.getHealth(), data.getFloat("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("relative_health"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.FLOAT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.getHealth() / entity.getMaxHealth(), data.getFloat("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("biome"), new SerializableData().add("biome", SerializableDataType.IDENTIFIER, null).add("biomes", SerializableDataType.IDENTIFIERS, null).add("condition", SerializableDataType.BIOME_CONDITION, null), (data, entity) -> {
        Biome biome = entity.world.getBiome(entity.getBlockPos());
        ConditionFactory<Biome>.Instance condition = (ConditionFactory<Biome>.Instance) data.get("condition");
        if (data.isPresent("biome") || data.isPresent("biomes")) {
            Identifier biomeId = entity.world.getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
            if (data.isPresent("biome") && biomeId.equals(data.getId("biome"))) {
                return condition == null || condition.test(biome);
            }
            if (data.isPresent("biomes") && ((List<Identifier>) data.get("biomes")).contains(biomeId)) {
                return condition == null || condition.test(biome);
            }
            return false;
        }
        return condition == null || condition.test(biome);
    }));
    register(new ConditionFactory<>(Origins.identifier("entity_type"), new SerializableData().add("entity_type", SerializableDataType.ENTITY_TYPE), (data, entity) -> entity.getType() == data.get("entity_type")));
    register(new ConditionFactory<>(Origins.identifier("scoreboard"), new SerializableData().add("objective", SerializableDataType.STRING).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        if (entity instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) entity;
            Scoreboard scoreboard = player.getScoreboard();
            ScoreboardObjective objective = scoreboard.getObjective(data.getString("objective"));
            String playerName = player.getName().asString();
            if (scoreboard.playerHasObjective(playerName, objective)) {
                int value = scoreboard.getPlayerScore(playerName, objective).getScore();
                return ((Comparison) data.get("comparison")).compare(value, data.getInt("compare_to"));
            }
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("command"), new SerializableData().add("command", SerializableDataType.STRING).add("permission_level", SerializableDataType.INT, 4).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT), (data, entity) -> {
        MinecraftServer server = entity.world.getServer();
        if (server != null) {
            ServerCommandSource source = new ServerCommandSource(CommandOutput.DUMMY, entity.getPos(), entity.getRotationClient(), entity.world instanceof ServerWorld ? (ServerWorld) entity.world : null, data.getInt("permission_level"), entity.getName().getString(), entity.getDisplayName(), server, entity);
            int output = server.getCommandManager().execute(source, data.getString("command"));
            return ((Comparison) data.get("comparison")).compare(output, data.getInt("compare_to"));
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("predicate"), new SerializableData().add("predicate", SerializableDataType.IDENTIFIER), (data, entity) -> {
        MinecraftServer server = entity.world.getServer();
        if (server != null) {
            LootCondition lootCondition = server.getPredicateManager().get((Identifier) data.get("predicate"));
            if (lootCondition != null) {
                LootContext.Builder lootBuilder = (new LootContext.Builder((ServerWorld) entity.world)).parameter(LootContextParameters.ORIGIN, entity.getPos()).optionalParameter(LootContextParameters.THIS_ENTITY, entity);
                return lootCondition.test(lootBuilder.build(LootContextTypes.COMMAND));
            }
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("fall_distance"), new SerializableData().add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.FLOAT), (data, entity) -> ((Comparison) data.get("comparison")).compare(entity.fallDistance, data.getFloat("compare_to"))));
    register(new ConditionFactory<>(Origins.identifier("collided_horizontally"), new SerializableData(), (data, entity) -> entity.horizontalCollision));
    register(new ConditionFactory<>(Origins.identifier("in_block_anywhere"), new SerializableData().add("block_condition", SerializableDataType.BLOCK_CONDITION).add("comparison", SerializableDataType.COMPARISON, Comparison.GREATER_THAN_OR_EQUAL).add("compare_to", SerializableDataType.INT, 1), (data, entity) -> {
        Predicate<CachedBlockPosition> blockCondition = ((ConditionFactory<CachedBlockPosition>.Instance) data.get("block_condition"));
        int stopAt = -1;
        Comparison comparison = ((Comparison) data.get("comparison"));
        int compareTo = data.getInt("compare_to");
        switch(comparison) {
            case EQUAL:
            case LESS_THAN_OR_EQUAL:
            case GREATER_THAN:
                stopAt = compareTo + 1;
                break;
            case LESS_THAN:
            case GREATER_THAN_OR_EQUAL:
                stopAt = compareTo;
                break;
        }
        int count = 0;
        Box box = entity.getBoundingBox();
        BlockPos blockPos = new BlockPos(box.minX + 0.001D, box.minY + 0.001D, box.minZ + 0.001D);
        BlockPos blockPos2 = new BlockPos(box.maxX - 0.001D, box.maxY - 0.001D, box.maxZ - 0.001D);
        BlockPos.Mutable mutable = new BlockPos.Mutable();
        for (int i = blockPos.getX(); i <= blockPos2.getX() && count < stopAt; ++i) {
            for (int j = blockPos.getY(); j <= blockPos2.getY() && count < stopAt; ++j) {
                for (int k = blockPos.getZ(); k <= blockPos2.getZ() && count < stopAt; ++k) {
                    mutable.set(i, j, k);
                    if (blockCondition.test(new CachedBlockPosition(entity.world, mutable, false))) {
                        count++;
                    }
                }
            }
        }
        return comparison.compare(count, compareTo);
    }));
    register(new ConditionFactory<>(Origins.identifier("entity_group"), new SerializableData().add("group", SerializableDataType.ENTITY_GROUP), (data, entity) -> entity.getGroup() == (EntityGroup) data.get("group")));
    register(new ConditionFactory<>(Origins.identifier("in_tag"), new SerializableData().add("tag", SerializableDataType.ENTITY_TAG), (data, entity) -> ((Tag<EntityType<?>>) data.get("tag")).contains(entity.getType())));
    register(new ConditionFactory<>(Origins.identifier("climbing"), new SerializableData(), (data, entity) -> entity.isClimbing()));
    register(new ConditionFactory<>(Origins.identifier("tamed"), new SerializableData(), (data, entity) -> {
        if (entity instanceof TameableEntity) {
            return ((TameableEntity) entity).isTamed();
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("using_item"), new SerializableData().add("item_condition", SerializableDataType.ITEM_CONDITION, null), (data, entity) -> {
        if (entity.isUsingItem()) {
            ConditionFactory<ItemStack>.Instance condition = (ConditionFactory<ItemStack>.Instance) data.get("item_condition");
            if (condition != null) {
                Hand activeHand = entity.getActiveHand();
                ItemStack handStack = entity.getStackInHand(activeHand);
                return condition.test(handStack);
            } else {
                return true;
            }
        }
        return false;
    }));
    register(new ConditionFactory<>(Origins.identifier("moving"), new SerializableData(), (data, entity) -> ((MovingEntity) entity).isMoving()));
    register(new ConditionFactory<>(Origins.identifier("enchantment"), new SerializableData().add("enchantment", SerializableDataType.ENCHANTMENT).add("comparison", SerializableDataType.COMPARISON).add("compare_to", SerializableDataType.INT).add("calculation", SerializableDataType.STRING, "sum"), (data, entity) -> {
        int value = 0;
        Enchantment enchantment = (Enchantment) data.get("enchantment");
        String calculation = data.getString("calculation");
        switch(calculation) {
            case "sum":
                for (ItemStack stack : enchantment.getEquipment(entity).values()) {
                    value += EnchantmentHelper.getLevel(enchantment, stack);
                }
                break;
            case "max":
                value = EnchantmentHelper.getEquipmentLevel(enchantment, entity);
                break;
            default:
                Origins.LOGGER.error("Error in \"enchantment\" entity condition, undefined calculation type: \"" + calculation + "\".");
                break;
        }
        return ((Comparison) data.get("comparison")).compare(value, data.getInt("compare_to"));
    }));
}
Also used : EntityType(net.minecraft.entity.EntityType) io.github.apace100.origins.power(io.github.apace100.origins.power) Origins(io.github.apace100.origins.Origins) LootContext(net.minecraft.loot.context.LootContext) CommandOutput(net.minecraft.server.command.CommandOutput) MinecraftServer(net.minecraft.server.MinecraftServer) Shape(io.github.apace100.origins.util.Shape) EquipmentSlot(net.minecraft.entity.EquipmentSlot) LootCondition(net.minecraft.loot.condition.LootCondition) OriginLayers(io.github.apace100.origins.origin.OriginLayers) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Predicate(java.util.function.Predicate) EntityAccessor(io.github.apace100.origins.mixin.EntityAccessor) EntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) StatusEffect(net.minecraft.entity.effect.StatusEffect) List(java.util.List) ModRegistries(io.github.apace100.origins.registry.ModRegistries) SerializableData(io.github.apace100.origins.util.SerializableData) Identifier(net.minecraft.util.Identifier) TameableEntity(net.minecraft.entity.passive.TameableEntity) CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) Scoreboard(net.minecraft.scoreboard.Scoreboard) Enchantment(net.minecraft.enchantment.Enchantment) ScoreboardObjective(net.minecraft.scoreboard.ScoreboardObjective) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Comparison(io.github.apace100.origins.util.Comparison) ServerWorld(net.minecraft.server.world.ServerWorld) SerializableDataType(io.github.apace100.origins.util.SerializableDataType) BoatEntity(net.minecraft.entity.vehicle.BoatEntity) LootContextParameters(net.minecraft.loot.context.LootContextParameters) EntityGroup(net.minecraft.entity.EntityGroup) ItemStack(net.minecraft.item.ItemStack) MovingEntity(io.github.apace100.origins.access.MovingEntity) RegistryKey(net.minecraft.util.registry.RegistryKey) Origin(io.github.apace100.origins.origin.Origin) Hand(net.minecraft.util.Hand) EntityAttribute(net.minecraft.entity.attribute.EntityAttribute) OriginComponent(io.github.apace100.origins.component.OriginComponent) LootContextTypes(net.minecraft.loot.context.LootContextTypes) Tag(net.minecraft.tag.Tag) Box(net.minecraft.util.math.Box) OriginLayer(io.github.apace100.origins.origin.OriginLayer) BlockPos(net.minecraft.util.math.BlockPos) Registry(net.minecraft.util.registry.Registry) Fluid(net.minecraft.fluid.Fluid) ModComponents(io.github.apace100.origins.registry.ModComponents) Biome(net.minecraft.world.biome.Biome) EntityAccessor(io.github.apace100.origins.mixin.EntityAccessor) Origin(io.github.apace100.origins.origin.Origin) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Predicate(java.util.function.Predicate) Identifier(net.minecraft.util.Identifier) MovingEntity(io.github.apace100.origins.access.MovingEntity) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) EntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance) BoatEntity(net.minecraft.entity.vehicle.BoatEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) Fluid(net.minecraft.fluid.Fluid) Box(net.minecraft.util.math.Box) Hand(net.minecraft.util.Hand) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) StatusEffect(net.minecraft.entity.effect.StatusEffect) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) SerializableData(io.github.apace100.origins.util.SerializableData) Shape(io.github.apace100.origins.util.Shape) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) EntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance) EquipmentSlot(net.minecraft.entity.EquipmentSlot) LootCondition(net.minecraft.loot.condition.LootCondition) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.server.world.ServerWorld) Biome(net.minecraft.world.biome.Biome) Comparison(io.github.apace100.origins.util.Comparison) Scoreboard(net.minecraft.scoreboard.Scoreboard) OriginLayer(io.github.apace100.origins.origin.OriginLayer) OriginComponent(io.github.apace100.origins.component.OriginComponent) CachedBlockPosition(net.minecraft.block.pattern.CachedBlockPosition) EntityAttribute(net.minecraft.entity.attribute.EntityAttribute) ScoreboardObjective(net.minecraft.scoreboard.ScoreboardObjective) MinecraftServer(net.minecraft.server.MinecraftServer) Tag(net.minecraft.tag.Tag)

Example 27 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project BedrockIfy by juancarloscp52.

the class InGameHudMixin method renderStatusEffectOverlay.

/**
 * Render the status effect overlay with the screen border distance applied.
 */
@Inject(method = "renderStatusEffectOverlay", at = @At("HEAD"), cancellable = true)
public void renderStatusEffectOverlay(MatrixStack matrixStack, CallbackInfo info) {
    Collection<StatusEffectInstance> collection = Objects.requireNonNull(this.client.player).getStatusEffects();
    if (!collection.isEmpty()) {
        RenderSystem.enableBlend();
        int beneficialEffects = 0;
        int harmfulEffects = 0;
        StatusEffectSpriteManager statusEffectSpriteManager = this.client.getStatusEffectSpriteManager();
        List<Runnable> list = Lists.newArrayListWithExpectedSize(collection.size());
        this.client.getTextureManager().bindTexture(HandledScreen.BACKGROUND_TEXTURE);
        for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(collection)) {
            StatusEffect statusEffect = statusEffectInstance.getEffectType();
            if (statusEffectInstance.shouldShowIcon()) {
                int x = this.scaledWidth - screenBorder;
                int y = 1 + screenBorder;
                if (this.client.isDemo()) {
                    y += 15;
                }
                if (statusEffect.isBeneficial()) {
                    ++beneficialEffects;
                    x -= 25 * beneficialEffects;
                } else {
                    ++harmfulEffects;
                    x -= 25 * harmfulEffects;
                    y += 26;
                }
                RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
                float spriteAlpha = 1.0F;
                if (statusEffectInstance.isAmbient()) {
                    this.drawTexture(matrixStack, x, y, 165, 166, 24, 24);
                } else {
                    this.drawTexture(matrixStack, x, y, 141, 166, 24, 24);
                    if (statusEffectInstance.getDuration() <= 200) {
                        int m = 10 - statusEffectInstance.getDuration() / 20;
                        spriteAlpha = MathHelper.clamp((float) statusEffectInstance.getDuration() / 10.0F / 5.0F * 0.5F, 0.0F, 0.5F) + MathHelper.cos((float) statusEffectInstance.getDuration() * 3.1415927F / 5.0F) * MathHelper.clamp((float) m / 10.0F * 0.25F, 0.0F, 0.25F);
                    }
                }
                Sprite sprite = statusEffectSpriteManager.getSprite(statusEffect);
                int finalX = x + 3;
                int finalY = y + 3;
                float finalAlpha = spriteAlpha;
                list.add(() -> {
                    this.client.getTextureManager().bindTexture(sprite.getAtlas().getId());
                    RenderSystem.color4f(1.0F, 1.0F, 1.0F, finalAlpha);
                    drawSprite(matrixStack, finalX, finalY, this.getZOffset(), 18, 18, sprite);
                });
            }
        }
        list.forEach(Runnable::run);
    }
    info.cancel();
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Sprite(net.minecraft.client.texture.Sprite) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) StatusEffectSpriteManager(net.minecraft.client.texture.StatusEffectSpriteManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project meteor-client by MeteorDevelopment.

the class StatusEffectAmplifierMapSetting method load.

@Override
public Object2IntMap<StatusEffect> load(NbtCompound tag) {
    get().clear();
    NbtCompound valueTag = tag.getCompound("value");
    for (String key : valueTag.getKeys()) {
        StatusEffect statusEffect = Registry.STATUS_EFFECT.get(new Identifier(key));
        if (statusEffect != null)
            get().put(statusEffect, valueTag.getInt(key));
    }
    return get();
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound)

Example 29 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project meteor-client by MeteorDevelopment.

the class StatusEffectAmplifierMapSetting method save.

@Override
public NbtCompound save(NbtCompound tag) {
    NbtCompound valueTag = new NbtCompound();
    for (StatusEffect statusEffect : get().keySet()) {
        Identifier id = Registry.STATUS_EFFECT.getId(statusEffect);
        if (id != null)
            valueTag.putInt(id.toString(), get().getInt(statusEffect));
    }
    tag.put("value", valueTag);
    return tag;
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound)

Example 30 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project meteor-client by MeteorDevelopment.

the class StatusEffectAmplifierMapSettingScreen method initTable.

private void initTable() {
    List<StatusEffect> statusEffects = new ArrayList<>(setting.get().keySet());
    statusEffects.sort(Comparator.comparing(Names::get));
    for (StatusEffect statusEffect : statusEffects) {
        String name = Names.get(statusEffect);
        if (!StringUtils.containsIgnoreCase(name, filterText))
            continue;
        table.add(theme.label(name)).expandCellX();
        WIntEdit level = theme.intEdit(setting.get().getInt(statusEffect), 0, Integer.MAX_VALUE, true);
        level.action = () -> {
            setting.get().put(statusEffect, level.get());
            setting.onChanged();
        };
        table.add(level).minWidth(50);
        table.row();
    }
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) WIntEdit(meteordevelopment.meteorclient.gui.widgets.input.WIntEdit) ArrayList(java.util.ArrayList)

Aggregations

StatusEffect (net.minecraft.entity.effect.StatusEffect)44 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)24 Identifier (net.minecraft.util.Identifier)10 ItemStack (net.minecraft.item.ItemStack)9 ArrayList (java.util.ArrayList)6 List (java.util.List)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 NbtCompound (net.minecraft.nbt.NbtCompound)4 NbtList (net.minecraft.nbt.NbtList)4 ServerWorld (net.minecraft.server.world.ServerWorld)4 Origins (io.github.apace100.origins.Origins)3 ModRegistries (io.github.apace100.origins.registry.ModRegistries)3 Sprite (net.minecraft.client.texture.Sprite)3 StatusEffectSpriteManager (net.minecraft.client.texture.StatusEffectSpriteManager)3 LivingEntity (net.minecraft.entity.LivingEntity)3 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)3 SoundCategory (net.minecraft.sound.SoundCategory)3 BlockPos (net.minecraft.util.math.BlockPos)3 Registry (net.minecraft.util.registry.Registry)3 ImmutableMap (com.google.common.collect.ImmutableMap)2