Search in sources :

Example 66 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ForgeMod method registerFluids.

// done in an event instead of deferred to only enable if a mod requests it
public void registerFluids(RegistryEvent.Register<Fluid> event) {
    if (enableMilkFluid) {
        // set up attributes
        FluidAttributes.Builder attributesBuilder = FluidAttributes.builder(new ResourceLocation("forge", "block/milk_still"), new ResourceLocation("forge", "block/milk_flowing")).density(1024).viscosity(1024);
        ForgeFlowingFluid.Properties properties = new ForgeFlowingFluid.Properties(MILK, FLOWING_MILK, attributesBuilder).bucket(() -> Items.MILK_BUCKET);
        // register fluids
        event.getRegistry().register(new ForgeFlowingFluid.Source(properties).setRegistryName(MILK.getId()));
        event.getRegistry().register(new ForgeFlowingFluid.Flowing(properties).setRegistryName(FLOWING_MILK.getId()));
    }
}
Also used : FluidAttributes(net.minecraftforge.fluids.FluidAttributes) ResourceLocation(net.minecraft.resources.ResourceLocation) ForgeFlowingFluid(net.minecraftforge.fluids.ForgeFlowingFluid) LevelStorageSource(net.minecraft.world.level.storage.LevelStorageSource)

Example 67 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ForgeMod method missingSoundMapping.

public void missingSoundMapping(RegistryEvent.MissingMappings<SoundEvent> event) {
    // Removed in 1.15, see https://minecraft.gamepedia.com/Parrot#History
    List<String> removedSounds = Arrays.asList("entity.parrot.imitate.panda", "entity.parrot.imitate.zombie_pigman", "entity.parrot.imitate.enderman", "entity.parrot.imitate.polar_bear", "entity.parrot.imitate.wolf");
    for (RegistryEvent.MissingMappings.Mapping<SoundEvent> mapping : event.getAllMappings()) {
        ResourceLocation regName = mapping.key;
        if (regName != null && regName.getNamespace().equals("minecraft")) {
            String path = regName.getPath();
            if (removedSounds.stream().anyMatch(s -> s.equals(path))) {
                LOGGER.info("Ignoring removed minecraft sound {}", regName);
                mapping.ignore();
            }
        }
    }
}
Also used : SoundEvent(net.minecraft.sounds.SoundEvent) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 68 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ForgeMod method registerLootData.

// ModBus
@SubscribeEvent
// automatically called by Forge
@SuppressWarnings("unused")
public void registerLootData(RegistryEvent.Register<GlobalLootModifierSerializer<?>> event) {
    // Ignore the event itself: this is done only not to statically initialize our custom LootConditionType
    Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), LootTableIdCondition.LOOT_TABLE_ID);
    Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), CanToolPerformAction.LOOT_CONDITION_TYPE);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 69 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class CraftingHelper method getIngredient.

public static Ingredient getIngredient(JsonElement json) {
    if (json == null || json.isJsonNull())
        throw new JsonSyntaxException("Json cannot be null");
    if (json.isJsonArray()) {
        List<Ingredient> ingredients = Lists.newArrayList();
        List<Ingredient> vanilla = Lists.newArrayList();
        json.getAsJsonArray().forEach((ele) -> {
            Ingredient ing = CraftingHelper.getIngredient(ele);
            if (// Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
            ing.getClass() == Ingredient.class)
                vanilla.add(ing);
            else
                ingredients.add(ing);
        });
        if (!vanilla.isEmpty())
            ingredients.add(Ingredient.merge(vanilla));
        if (ingredients.size() == 0)
            throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
        if (ingredients.size() == 1)
            return ingredients.get(0);
        return new CompoundIngredient(ingredients);
    }
    if (!json.isJsonObject())
        throw new JsonSyntaxException("Expcted ingredient to be a object or array of objects");
    JsonObject obj = (JsonObject) json;
    String type = GsonHelper.getAsString(obj, "type", "minecraft:item");
    if (type.isEmpty())
        throw new JsonSyntaxException("Ingredient type can not be an empty string");
    IIngredientSerializer<?> serializer = ingredients.get(new ResourceLocation(type));
    if (serializer == null)
        throw new JsonSyntaxException("Unknown ingredient type: " + type);
    return serializer.parse(obj);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.world.item.crafting.Ingredient) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject)

Example 70 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelProvider method getBuilder.

public T getBuilder(String path) {
    Preconditions.checkNotNull(path, "Path must not be null");
    ResourceLocation outputLoc = extendWithFolder(path.contains(":") ? new ResourceLocation(path) : new ResourceLocation(modid, path));
    this.existingFileHelper.trackGenerated(outputLoc, MODEL);
    return generatedModels.computeIfAbsent(outputLoc, factory);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)130 Map (java.util.Map)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 CompoundTag (net.minecraft.nbt.CompoundTag)11 List (java.util.List)10 BlockPos (net.minecraft.core.BlockPos)9 Collectors (java.util.stream.Collectors)7 Block (net.minecraft.world.level.block.Block)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 JsonElement (com.google.gson.JsonElement)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 Registry (net.minecraft.core.Registry)5 ServerLevel (net.minecraft.server.level.ServerLevel)5 InputStream (java.io.InputStream)4