Search in sources :

Example 1 with Unique

use of org.spongepowered.asm.mixin.Unique in project nbt-crafting by Siphalor.

the class MixinIngredient method loadIngredientEntryCondition.

@Unique
private static IngredientEntryCondition loadIngredientEntryCondition(JsonObject jsonObject) {
    if (jsonObject.has("data")) {
        if (JsonHelper.hasString(jsonObject, "data")) {
            try {
                CompoundTag compoundTag = new StringNbtReader(new StringReader(jsonObject.get("data").getAsString())).parseCompoundTag();
                IngredientEntryCondition condition = new IngredientEntryCondition();
                if (compoundTag.contains("require") || compoundTag.contains("deny")) {
                    if (compoundTag.contains("require"))
                        condition.requiredElements = compoundTag.getCompound("require");
                    if (compoundTag.contains("deny"))
                        condition.deniedElements = compoundTag.getCompound("deny");
                } else {
                    condition.requiredElements = compoundTag;
                }
                return condition;
            } catch (CommandSyntaxException e) {
                e.printStackTrace();
            }
        } else if (jsonObject.get("data").isJsonObject()) {
            return IngredientEntryCondition.fromJson((JsonObject) JsonPreprocessor.process(jsonObject.get("data").getAsJsonObject()));
        }
    }
    return new IngredientEntryCondition();
}
Also used : StringNbtReader(net.minecraft.nbt.StringNbtReader) StringReader(com.mojang.brigadier.StringReader) CompoundTag(net.minecraft.nbt.CompoundTag) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Unique(org.spongepowered.asm.mixin.Unique)

Example 2 with Unique

use of org.spongepowered.asm.mixin.Unique in project nbt-crafting by Siphalor.

the class MixinIngredient method ofAdvancedEntries.

@Unique
private static Ingredient ofAdvancedEntries(Stream<? extends IngredientEntry> entries) {
    if (entries == null)
        NbtCrafting.logError("Internal error: can't construct ingredient from null entry stream!");
    try {
        Ingredient ingredient;
        // noinspection ConstantConditions
        ingredient = (Ingredient) ((ICloneable) (Object) Ingredient.EMPTY).clone();
        ((IIngredient) (Object) ingredient).nbtCrafting$setAdvancedEntries(entries);
        return ingredient;
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    return Ingredient.EMPTY;
}
Also used : ICloneable(de.siphalor.nbtcrafting.util.duck.ICloneable) Ingredient(net.minecraft.recipe.Ingredient) Unique(org.spongepowered.asm.mixin.Unique)

Example 3 with Unique

use of org.spongepowered.asm.mixin.Unique in project nbt-crafting by Siphalor.

the class MixinIngredient method advancedEntryFromJson.

@Unique
private static IngredientEntry advancedEntryFromJson(JsonObject jsonObject) {
    if (jsonObject.has("item") && jsonObject.has("tag")) {
        throw new JsonParseException("An ingredient entry is either a tag or an item or a potion, not both");
    }
    if (jsonObject.has("item")) {
        final Identifier identifier = new Identifier(JsonHelper.getString(jsonObject, "item"));
        try {
            final Item item = Registry.ITEM.getOrEmpty(identifier).orElseThrow(() -> {
                throw new JsonSyntaxException("Unknown item '" + identifier.toString() + "'");
            });
            IngredientStackEntry entry = new IngredientStackEntry(Registry.ITEM.getRawId(item), loadIngredientEntryCondition(jsonObject));
            if (jsonObject.has("remainder")) {
                entry.setRecipeRemainder(ShapedRecipe.getItemStack(JsonHelper.getObject(jsonObject, "remainder")));
            }
            return entry;
        } catch (Throwable e) {
            e.printStackTrace();
            return null;
        }
    }
    if (jsonObject.has("potion")) {
        final Identifier identifier = new Identifier(JsonHelper.getString(jsonObject, "potion"));
        try {
            Registry.POTION.getOrEmpty(identifier).orElseThrow(() -> {
                throw new JsonSyntaxException("Unknown potion '" + identifier.toString() + "'");
            });
            IngredientEntryCondition condition = loadIngredientEntryCondition(jsonObject);
            if (condition.requiredElements == NbtUtil.EMPTY_COMPOUND)
                condition.requiredElements = new CompoundTag();
            condition.requiredElements.putString("Potion", identifier.toString());
            IngredientStackEntry entry = new IngredientStackEntry(Registry.ITEM.getRawId(Items.POTION), condition);
            if (jsonObject.has("remainder")) {
                entry.setRecipeRemainder(ShapedRecipe.getItemStack(JsonHelper.getObject(jsonObject, "remainder")));
            }
            return entry;
        } catch (Throwable e) {
            e.printStackTrace();
            return null;
        }
    }
    if (!jsonObject.has("tag")) {
        throw new JsonParseException("An ingredient entry needs either a tag or an item");
    }
    final Identifier identifier2 = new Identifier(JsonHelper.getString(jsonObject, "tag"));
    final Tag<Item> tag = ItemTags.getContainer().get(identifier2);
    if (tag == null) {
        throw new JsonSyntaxException("Unknown item tag '" + identifier2 + "'");
    }
    IngredientMultiStackEntry entry = new IngredientMultiStackEntry(tag.values().stream().map(Registry.ITEM::getRawId).collect(Collectors.toList()), loadIngredientEntryCondition(jsonObject));
    entry.setTag(identifier2.toString());
    if (jsonObject.has("remainder")) {
        entry.setRecipeRemainder(ShapedRecipe.getItemStack(JsonHelper.getObject(jsonObject, "remainder")));
    }
    return entry;
}
Also used : Item(net.minecraft.item.Item) Identifier(net.minecraft.util.Identifier) CompoundTag(net.minecraft.nbt.CompoundTag) Unique(org.spongepowered.asm.mixin.Unique)

Example 4 with Unique

use of org.spongepowered.asm.mixin.Unique in project Botania by VazkiiMods.

the class FabricMixinEnderMan method checkForVincs.

@Unique
private void checkForVincs(Args args) {
    double x = args.get(0);
    double y = args.get(1);
    double z = args.get(2);
    Vec3 vincPos = SubTileVinculotus.onEndermanTeleport((EnderMan) (Object) this, x, y, z);
    if (vincPos != null) {
        args.set(0, vincPos.x());
        args.set(1, vincPos.y());
        args.set(2, vincPos.z());
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) Unique(org.spongepowered.asm.mixin.Unique)

Example 5 with Unique

use of org.spongepowered.asm.mixin.Unique in project beebuddy by queenofthebees.

the class BeeEntityMixin method beebuddy$initTamedGoals.

@Unique
private void beebuddy$initTamedGoals() {
    BeeEntity us = (BeeEntity) (Object) this;
    this.goalSelector.add(0, new BeeSitGoal(us));
    this.goalSelector.add(1, StingGoalInvoker.beebuddy$make(us, us, 1.399999976158142D, true));
    this.goalSelector.add(2, new FollowParentGoal(us, 1.25D));
    this.goalSelector.add(3, new FollowFriendGoal(us));
    this.goalSelector.add(4, new AnimalMateGoal(us, 1.0D));
    if (pollinateGoal == null) {
        // we can be called before initGoals's body
        pollinateGoal = PollinateGoalInvoker.beebuddy$make(us);
    }
    this.goalSelector.add(5, pollinateGoal);
    if (moveToFlowerGoal == null) {
        moveToFlowerGoal = MoveToFlowerGoalInvoker.beebuddy$make(us);
    }
    this.goalSelector.add(6, moveToFlowerGoal);
    this.goalSelector.add(7, new SitOnHeadGoal(us));
    this.goalSelector.add(7, BeeWanderAroundGoalInvoker.beebuddy$make(us));
    this.goalSelector.add(8, new LookAtEntityGoal(us, PlayerEntity.class, 4.0F));
    this.goalSelector.add(8, new SwimGoal(us));
    BeeEntityMixin mix = this;
    this.targetSelector.add(1, (new RevengeGoal(this) {

        @Override
        public boolean canStart() {
            if (!super.canStart()) {
                return false;
            }
            if (us.getAttacker() != null) {
                UUID u = us.getAttacker().getUuid();
                return !u.equals(mix.beebuddy$getFriend());
            } else {
                return true;
            }
        }

        @Override
        public boolean shouldContinue() {
            return us.hasAngerTime() && super.shouldContinue();
        }
    }).setGroupRevenge(new Class[0]));
}
Also used : RevengeGoal(net.minecraft.entity.ai.goal.RevengeGoal) FollowParentGoal(net.minecraft.entity.ai.goal.FollowParentGoal) FollowFriendGoal(nomble.beebuddy.entity.ai.goal.FollowFriendGoal) LookAtEntityGoal(net.minecraft.entity.ai.goal.LookAtEntityGoal) SitOnHeadGoal(nomble.beebuddy.entity.ai.goal.SitOnHeadGoal) SwimGoal(net.minecraft.entity.ai.goal.SwimGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) AnimalMateGoal(net.minecraft.entity.ai.goal.AnimalMateGoal) BeeSitGoal(nomble.beebuddy.entity.ai.goal.BeeSitGoal) BeeEntity(net.minecraft.entity.passive.BeeEntity) UUID(java.util.UUID) Unique(org.spongepowered.asm.mixin.Unique)

Aggregations

Unique (org.spongepowered.asm.mixin.Unique)28 CompoundTag (net.minecraft.nbt.CompoundTag)5 File (java.io.File)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 Long2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap)2 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)2 FileWriter (java.io.FileWriter)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ParentTask (me.shedaniel.betterloadingscreen.api.step.ParentTask)2 PacketByteBuf (net.minecraft.network.PacketByteBuf)2 ChunkHolder (net.minecraft.server.level.ChunkHolder)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 Identifier (net.minecraft.util.Identifier)2 ChunkPos (net.minecraft.world.level.ChunkPos)2 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)2 ChunkHolderInterface (carpet.fakes.ChunkHolderInterface)1 ChunkTicketManagerInterface (carpet.fakes.ChunkTicketManagerInterface)1 ServerLightingProviderInterface (carpet.fakes.ServerLightingProviderInterface)1