Search in sources :

Example 61 with ResourceLocation

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

the class Sounds method register.

private static SoundEvent register(String soundPath) {
    ResourceLocation resLoc = new ResourceLocation(Constants.MODID, soundPath);
    SoundEvent soundEvent = new SoundEvent(resLoc);
    ForgeRegistries.SOUND_EVENTS.register(soundEvent.setRegistryName(resLoc));
    if (registeredSounds.contains(soundPath)) {
        System.out.println("TCWARNING: duplicate sound registration for " + soundPath);
    }
    registeredSounds.add(soundPath);
    return soundEvent;
}
Also used : SoundEvent(net.minecraft.sounds.SoundEvent) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 62 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MC-Prefab by Brian-Wuest.

the class Structure method WaterReplacedWithCobbleStone.

/**
 * Determines if a water block was replaced with cobblestone because this structure was built in the nether or the
 * end.
 *
 * @param configuration The structure configuration.
 * @param block         The build block object.
 * @param world         The workd object.
 * @param originalPos   The original block position this structure was built on.
 * @param foundBlock    The actual block found at the current location.
 * @param blockState    The block state to set for the current block.
 * @param player        The player requesting this build.
 * @return Returns true if the water block was replaced by cobblestone, otherwise false.
 */
protected Boolean WaterReplacedWithCobbleStone(StructureConfiguration configuration, BuildBlock block, Level world, BlockPos originalPos, Block foundBlock, BlockState blockState, Player player) {
    // Replace water blocks and waterlogged blocks with cobblestone when this is not an ultra warm world type.
    // Also check a configuration value to determine if water blocks are allowed in non-over-world dimensions.
    boolean isOverWorld = Level.OVERWORLD.compareTo(world.dimension()) == 0;
    if (world.dimensionType().ultraWarm() || (!isOverWorld && Prefab.proxy.getServerConfiguration().allowWaterInNonOverworldDimensions)) {
        boolean foundWaterLikeBlock = (foundBlock instanceof LiquidBlock && blockState.getMaterial() == Material.WATER) || foundBlock instanceof SeagrassBlock;
        if (!foundWaterLikeBlock) {
            for (BuildProperty property : block.getProperties()) {
                if (property.getName().equalsIgnoreCase(BlockStateProperties.WATERLOGGED.getName()) && property.getValue().equalsIgnoreCase(BlockStateProperties.WATERLOGGED.getName(true))) {
                    // Found a waterlogged block. Replace with cobblestone.
                    foundWaterLikeBlock = true;
                    break;
                }
            }
        }
        if (foundWaterLikeBlock) {
            ResourceLocation cobbleIdentifier = Registry.BLOCK.getKey(Blocks.COBBLESTONE);
            block.setBlockDomain(cobbleIdentifier.getNamespace());
            block.setBlockName(cobbleIdentifier.getPath());
            block.setBlockState(Blocks.COBBLESTONE.defaultBlockState());
            BlockPos setBlockPos = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
            world.setBlock(setBlockPos, block.getBlockState(), BlockFlags.DEFAULT);
            return true;
        }
    }
    return false;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos)

Example 63 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MC-Prefab by Brian-Wuest.

the class BlockGlassStairs method skipRendering.

@Override
@OnlyIn(Dist.CLIENT)
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
    Tag<Block> tags = BlockTags.getAllTags().getTag(new ResourceLocation("forge", "glass"));
    Block adjacentBlock = adjacentBlockState.getBlock();
    return tags.contains(adjacentBlock) || adjacentBlock == this || (adjacentBlock == ModRegistry.GlassSlab.get() && adjacentBlockState.getValue(SlabBlock.TYPE) == SlabType.DOUBLE);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) SlabBlock(net.minecraft.world.level.block.SlabBlock) StairBlock(net.minecraft.world.level.block.StairBlock) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 64 with ResourceLocation

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

the class ForgeBlockTagsProvider method addColored.

private void addColored(Consumer<Block> consumer, Tag.Named<Block> group, String pattern) {
    String prefix = group.getName().getPath().toUpperCase(Locale.ENGLISH) + '_';
    for (DyeColor color : DyeColor.values()) {
        ResourceLocation key = new ResourceLocation("minecraft", pattern.replace("{color}", color.getName()));
        Tag.Named<Block> tag = getForgeTag(prefix + color.getName());
        Block block = ForgeRegistries.BLOCKS.getValue(key);
        if (block == null || block == Blocks.AIR)
            throw new IllegalStateException("Unknown vanilla block: " + key.toString());
        tag(tag).add(block);
        consumer.accept(block);
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) Tag(net.minecraft.tags.Tag) DyeColor(net.minecraft.world.item.DyeColor)

Example 65 with ResourceLocation

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

the class GlobalLootModifierProvider method run.

@Override
public void run(HashCache cache) throws IOException {
    start();
    Path forgePath = gen.getOutputFolder().resolve("data/forge/loot_modifiers/global_loot_modifiers.json");
    String modPath = "data/" + modid + "/loot_modifiers/";
    List<ResourceLocation> entries = new ArrayList<>();
    toSerialize.forEach(LamdbaExceptionUtils.rethrowBiConsumer((name, pair) -> {
        entries.add(new ResourceLocation(modid, name));
        Path modifierPath = gen.getOutputFolder().resolve(modPath + name + ".json");
        JsonObject json = pair.getB();
        json.addProperty("type", pair.getA().getRegistryName().toString());
        DataProvider.save(GSON, cache, json, modifierPath);
    }));
    JsonObject forgeJson = new JsonObject();
    forgeJson.addProperty("replace", this.replace);
    forgeJson.add("entries", GSON.toJsonTree(entries.stream().map(ResourceLocation::toString).collect(Collectors.toList())));
    DataProvider.save(GSON, cache, forgeJson, forgePath);
}
Also used : Path(java.nio.file.Path) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) IGlobalLootModifier(net.minecraftforge.common.loot.IGlobalLootModifier) HashCache(net.minecraft.data.HashCache) LamdbaExceptionUtils(cpw.mods.modlauncher.api.LamdbaExceptionUtils) Tuple(net.minecraft.util.Tuple) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) GlobalLootModifierSerializer(net.minecraftforge.common.loot.GlobalLootModifierSerializer) ArrayList(java.util.ArrayList) List(java.util.List) Gson(com.google.gson.Gson) Map(java.util.Map) DataGenerator(net.minecraft.data.DataGenerator) DataProvider(net.minecraft.data.DataProvider) Path(java.nio.file.Path) LootModifier(net.minecraftforge.common.loot.LootModifier) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

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