Search in sources :

Example 6 with EquipmentSlot

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

the class PlayerScreenHandlerMixin method preventArmorInsertion.

@Inject(method = "Lnet/minecraft/screen/PlayerScreenHandler$1;canInsert(Lnet/minecraft/item/ItemStack;)Z", at = @At("HEAD"), cancellable = true)
private void preventArmorInsertion(ItemStack stack, CallbackInfoReturnable<Boolean> info) {
    PlayerEntity player = ((PlayerInventory) inventory).player;
    OriginComponent component = ModComponents.ORIGIN.get(player);
    EquipmentSlot slot = MobEntity.getPreferredEquipmentSlot(stack);
    if (component.getPowers(RestrictArmorPower.class).stream().anyMatch(rap -> !rap.canEquip(stack, slot))) {
        info.setReturnValue(false);
    }
    if (OriginComponent.getPowers(player, ElytraFlightPower.class).size() > 0) {
        if (stack.getItem() == Items.ELYTRA) {
            info.setReturnValue(false);
        }
    }
}
Also used : EquipmentSlot(net.minecraft.entity.EquipmentSlot) OriginComponent(io.github.apace100.origins.component.OriginComponent) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 7 with EquipmentSlot

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

the class DamageOverTimePower method getProtection.

private int getProtection() {
    if (protectingEnchantment == null) {
        return 0;
    } else {
        Map<EquipmentSlot, ItemStack> enchantedItems = protectingEnchantment.getEquipment(player);
        Iterable<ItemStack> iterable = enchantedItems.values();
        int i = 0;
        for (ItemStack itemStack : iterable) {
            i += EnchantmentHelper.getLevel(protectingEnchantment, itemStack);
        }
        return i * enchantedItems.size();
    }
}
Also used : EquipmentSlot(net.minecraft.entity.EquipmentSlot) ItemStack(net.minecraft.item.ItemStack)

Example 8 with EquipmentSlot

use of net.minecraft.entity.EquipmentSlot 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 9 with EquipmentSlot

use of net.minecraft.entity.EquipmentSlot in project BedrockIfy by juancarloscp52.

the class ArmorReplacer method tryChangeArmor.

public static void tryChangeArmor(PlayerEntity user, Hand hand) {
    ItemStack newArmor = user.getStackInHand(hand);
    EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(newArmor);
    ItemStack currentArmor = user.getEquippedStack(equipmentSlot);
    user.equipStack(equipmentSlot, newArmor.copy());
    currentArmor.setCooldown(5);
    user.setStackInHand(hand, currentArmor);
}
Also used : EquipmentSlot(net.minecraft.entity.EquipmentSlot) ItemStack(net.minecraft.item.ItemStack)

Example 10 with EquipmentSlot

use of net.minecraft.entity.EquipmentSlot in project ArmorStandEditor by Patbox.

the class EditorGuis method openInventoryEditor.

public static void openInventoryEditor(ServerPlayerEntity player, LivingEntity entity) {
    SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X2, player, false);
    ArmorStandInventory inventory = new ArmorStandInventory(entity);
    gui.setTitle(new TranslatableText("armorstandeditor.gui.inventory_title"));
    for (int x = 0; x < inventory.size(); x++) {
        gui.setSlotRedirect(x, new Slot(inventory, x, 0, 0));
        if (entity instanceof ArmorStandEntity) {
            ArmorStandEntity ae = (ArmorStandEntity) entity;
            ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) ae;
            boolean isUnlocked = isSlotUnlocked(ae, ArmorStandInventory.getEquipmentSlot(x));
            gui.setSlot(x + 9, new GuiElementBuilder(isUnlocked ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText(isUnlocked ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                EquipmentSlot slot = ArmorStandInventory.getEquipmentSlot(index - 9);
                int disabledSlots = asea.getDisabledSlots();
                boolean isUnlockedTmp = isSlotUnlocked(ae, slot);
                if (isUnlockedTmp) {
                    disabledSlots |= 1 << slot.getArmorStandSlotId();
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 8;
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 16;
                } else {
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId());
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 8);
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 16);
                }
                asea.setDisabledSlots(disabledSlots);
                boolean isUnlocked2 = isSlotUnlocked(ae, slot);
                ItemStack stack = new ItemStack(isUnlocked2 ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE);
                stack.setCustomName(new TranslatableText(isUnlocked2 ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false)));
                ((GuiElement) gui.getSlot(index)).setItemStack(stack);
            }));
        } else {
            gui.setSlot(x + 9, new GuiElementBuilder(Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText("armorstandeditor.gui.cantlockslots").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.RED))));
        }
    }
    GuiElement empty = new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")).build();
    gui.setSlot(6, empty);
    gui.setSlot(7, empty);
    gui.setSlot(8, empty);
    gui.setSlot(15, empty);
    gui.setSlot(16, empty);
    gui.setSlot(17, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("armorstandeditor.gui.close").setStyle(Style.EMPTY.withItalic(false))).setCallback(((index, type, action) -> {
        gui.close();
    })));
    gui.open();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) ConfigManager(eu.pb4.armorstandeditor.config.ConfigManager) Item(net.minecraft.item.Item) StringTag(net.minecraft.nbt.StringTag) Permissions(me.lucko.fabric.api.permissions.v0.Permissions) TranslatableText(net.minecraft.text.TranslatableText) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) Slot(net.minecraft.screen.slot.Slot) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Style(net.minecraft.text.Style) GuiElementInterface(eu.pb4.sgui.api.elements.GuiElementInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnvilInputGui(eu.pb4.sgui.api.gui.AnvilInputGui) ItemFrameEntityAccessor(eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor) Enchantments(net.minecraft.enchantment.Enchantments) EquipmentSlot(net.minecraft.entity.EquipmentSlot) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ClickType(eu.pb4.sgui.api.ClickType) ScreenHandlerType(net.minecraft.screen.ScreenHandlerType) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) Collection(java.util.Collection) ItemFrameInventory(eu.pb4.armorstandeditor.helpers.ItemFrameInventory) GuiElement(eu.pb4.sgui.api.elements.GuiElement) Items(net.minecraft.item.Items) ArmorStandData(eu.pb4.armorstandeditor.helpers.ArmorStandData) Collectors(java.util.stream.Collectors) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) Text(net.minecraft.text.Text) SlotActionType(net.minecraft.screen.slot.SlotActionType) ListTag(net.minecraft.nbt.ListTag) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) EquipmentSlot(net.minecraft.entity.EquipmentSlot) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) Slot(net.minecraft.screen.slot.Slot) EquipmentSlot(net.minecraft.entity.EquipmentSlot) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) ItemStack(net.minecraft.item.ItemStack) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) GuiElement(eu.pb4.sgui.api.elements.GuiElement) LiteralText(net.minecraft.text.LiteralText)

Aggregations

EquipmentSlot (net.minecraft.entity.EquipmentSlot)16 ItemStack (net.minecraft.item.ItemStack)11 LivingEntity (net.minecraft.entity.LivingEntity)4 EntityAttribute (net.minecraft.entity.attribute.EntityAttribute)3 EntityAttributeModifier (net.minecraft.entity.attribute.EntityAttributeModifier)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 OriginComponent (io.github.apace100.origins.component.OriginComponent)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Item (net.minecraft.item.Item)2 ListTag (net.minecraft.nbt.ListTag)2 Slot (net.minecraft.screen.slot.Slot)2 Identifier (net.minecraft.util.Identifier)2 JsonParseException (com.google.gson.JsonParseException)1 Pair (com.mojang.datafixers.util.Pair)1 CommandManager (com.tangykiwi.kiwiclient.command.CommandManager)1 ModuleManager (com.tangykiwi.kiwiclient.modules.ModuleManager)1 EChestMemory (com.tangykiwi.kiwiclient.util.tooltip.EChestMemory)1 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)1