Search in sources :

Example 1 with Instance

use of mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance in project Railcraft by Railcraft.

the class MultiBlockFormedTrigger method deserializeInstance.

@Override
public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) {
    Class<? extends TileEntity> type;
    if (json.has("type")) {
        String id = JsonUtils.getString(json, "type");
        type = TileEntity.REGISTRY.getObject(new ResourceLocation(id));
    } else {
        type = null;
    }
    NBTPredicate nbt = JsonTools.whenPresent(json, "nbt", NBTPredicate::deserialize, NBTPredicate.ANY);
    return new Instance(type, nbt);
}
Also used : ICriterionInstance(net.minecraft.advancements.ICriterionInstance) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) ResourceLocation(net.minecraft.util.ResourceLocation) NBTPredicate(net.minecraft.advancements.critereon.NBTPredicate)

Example 2 with Instance

use of mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance in project Railcraft by Railcraft.

the class MultiBlockFormedTrigger method onMultiBlockForm.

@SubscribeEvent
public void onMultiBlockForm(MultiBlockEvent.Form event) {
    TileRailcraft tile = event.getMaster();
    GameProfile owner = tile.getOwner();
    MinecraftServer server = requireNonNull(Game.getServer());
    EntityPlayerMP player = server.getPlayerList().getPlayerByUUID(owner.getId());
    if (player == null) {
        // Offline
        return;
    }
    PlayerAdvancements advancements = player.getAdvancements();
    Collection<Listener<Instance>> done = manager.get(advancements).stream().filter(listener -> listener.getCriterionInstance().matches(tile)).collect(Collectors.toList());
    for (Listener<Instance> listener : done) {
        listener.grantCriterion(advancements);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) GameProfile(com.mojang.authlib.GameProfile) Conditions(mods.railcraft.common.util.misc.Conditions) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RailcraftConstantsAPI(mods.railcraft.api.core.RailcraftConstantsAPI) MinecraftServer(net.minecraft.server.MinecraftServer) MultiBlockEvent(mods.railcraft.common.events.MultiBlockEvent) Objects.requireNonNull(java.util.Objects.requireNonNull) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Collection(java.util.Collection) Game(mods.railcraft.common.util.misc.Game) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) JsonTools(mods.railcraft.common.util.json.JsonTools) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) JsonUtils(net.minecraft.util.JsonUtils) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) NBTPredicate(net.minecraft.advancements.critereon.NBTPredicate) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) GameProfile(com.mojang.authlib.GameProfile) ICriterionInstance(net.minecraft.advancements.ICriterionInstance) Instance(mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileRailcraft(mods.railcraft.common.blocks.TileRailcraft) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Instance (mods.railcraft.common.advancements.criterion.MultiBlockFormedTrigger.Instance)2 ICriterionInstance (net.minecraft.advancements.ICriterionInstance)2 NBTPredicate (net.minecraft.advancements.critereon.NBTPredicate)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)1 JsonObject (com.google.gson.JsonObject)1 GameProfile (com.mojang.authlib.GameProfile)1 Collection (java.util.Collection)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors (java.util.stream.Collectors)1 RailcraftConstantsAPI (mods.railcraft.api.core.RailcraftConstantsAPI)1 TileRailcraft (mods.railcraft.common.blocks.TileRailcraft)1 MultiBlockEvent (mods.railcraft.common.events.MultiBlockEvent)1 JsonTools (mods.railcraft.common.util.json.JsonTools)1 Conditions (mods.railcraft.common.util.misc.Conditions)1 Game (mods.railcraft.common.util.misc.Game)1 PlayerAdvancements (net.minecraft.advancements.PlayerAdvancements)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 MinecraftServer (net.minecraft.server.MinecraftServer)1