Search in sources :

Example 81 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project Totemic by TeamTotemic.

the class TotemicBlockStateProvider method registerStatesAndModels.

@Override
protected void registerStatesAndModels() {
    for (TotemBaseBlock block : ModBlocks.getTotemBases().values()) {
        ResourceLocation blockName = block.getRegistryName();
        ModelFile blockModel = models().getExistingFile(new ResourceLocation(blockName.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + blockName.getPath()));
        // Block state
        horizontalBlock(block, blockModel);
        // Item model
        itemModels().withExistingParent(block.getRegistryName().toString(), blockModel.getLocation());
    }
}
Also used : ModelFile(net.minecraftforge.client.model.generators.ModelFile) ResourceLocation(net.minecraft.resources.ResourceLocation) TotemBaseBlock(pokefenn.totemic.block.totem.TotemBaseBlock)

Example 82 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class MobSpawnerData method getNextEntity.

// @formatter:on
private static WeightedSerializableObject<EntityArchetype> getNextEntity(final BaseSpawnerAccessor logic) {
    final int weight = ((WeighedRandom_WeighedRandomItemAccessor) logic.accessor$nextSpawnData()).accessor$weight();
    final String resourceLocation = logic.accessor$nextSpawnData().getTag().getString(Constants.Entity.ENTITY_TYPE_ID);
    final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
    final CompoundTag data = logic.accessor$nextSpawnData().getTag();
    final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(data)).build();
    return new WeightedSerializableObject<>(archetype, weight);
}
Also used : EntityArchetype(org.spongepowered.api.entity.EntityArchetype) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) ResourceLocation(net.minecraft.resources.ResourceLocation) CompoundTag(net.minecraft.nbt.CompoundTag) WeightedSerializableObject(org.spongepowered.api.util.weighted.WeightedSerializableObject)

Example 83 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class MobSpawnerData method getEntities.

private static WeightedTable<EntityArchetype> getEntities(final BaseSpawner logic) {
    final WeightedTable<EntityArchetype> possibleEntities = new WeightedTable<>();
    for (final SpawnData weightedEntity : ((BaseSpawnerAccessor) logic).accessor$spawnPotentials()) {
        final CompoundTag nbt = weightedEntity.getTag();
        final String resourceLocation = nbt.getString(Constants.Entity.ENTITY_TYPE_ID);
        final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
        final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(nbt)).build();
        possibleEntities.add(new WeightedSerializableObject<>(archetype, ((WeighedRandom_WeighedRandomItemAccessor) weightedEntity).accessor$weight()));
    }
    return possibleEntities;
}
Also used : WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) ResourceLocation(net.minecraft.resources.ResourceLocation) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) SpawnData(net.minecraft.world.level.SpawnData) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 84 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class SpongeCookingRecipeSerializer method fromJson.

@Override
public R fromJson(final ResourceLocation recipeId, final JsonObject json) {
    final String group = GsonHelper.getAsString(json, Constants.Recipe.GROUP, "");
    final JsonElement jsonelement = GsonHelper.isArrayNode(json, Constants.Recipe.COOKING_INGREDIENT) ? GsonHelper.getAsJsonArray(json, Constants.Recipe.COOKING_INGREDIENT) : GsonHelper.getAsJsonObject(json, Constants.Recipe.COOKING_INGREDIENT);
    final Ingredient ingredient = IngredientUtil.spongeDeserialize(jsonelement);
    final String result = GsonHelper.getAsString(json, Constants.Recipe.RESULT);
    final ResourceLocation resourcelocation = new ResourceLocation(result);
    final ItemStack itemstack = new ItemStack(Registry.ITEM.getOptional(resourcelocation).orElseThrow(() -> new IllegalStateException("Item: " + result + " does not exist")));
    final ItemStack spongeStack = IngredientResultUtil.deserializeItemStack(json.getAsJsonObject(Constants.Recipe.SPONGE_RESULT));
    final Function<Container, ItemStack> resultFunction = IngredientResultUtil.deserializeResultFunction(json);
    final float exp = GsonHelper.getAsFloat(json, Constants.Recipe.COOKING_EXP, 0.0F);
    final int cookTime = GsonHelper.getAsInt(json, Constants.Recipe.COOKING_TIME, this.defaultCookingTime);
    return this.create(recipeId, group, ingredient, spongeStack == null ? itemstack : spongeStack, exp, cookTime, resultFunction);
}
Also used : Container(net.minecraft.world.Container) Ingredient(net.minecraft.world.item.crafting.Ingredient) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) ItemStack(net.minecraft.world.item.ItemStack)

Example 85 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class PacketUtil method createPlayPayload.

public static net.minecraft.network.protocol.Packet<?> createPlayPayload(final ResourceKey channel, final ChannelBuf payload, final EngineConnectionSide<?> side) {
    if (side == EngineConnectionSide.CLIENT) {
        final ServerboundCustomPayloadPacketAccessor packet = (ServerboundCustomPayloadPacketAccessor) new ServerboundCustomPayloadPacket();
        packet.accessor$identifier((ResourceLocation) (Object) channel);
        packet.accessor$data((FriendlyByteBuf) payload);
        return (net.minecraft.network.protocol.Packet<?>) packet;
    } else if (side == EngineConnectionSide.SERVER) {
        final ClientboundCustomPayloadPacketAccessor packet = (ClientboundCustomPayloadPacketAccessor) new ClientboundCustomPayloadPacket();
        packet.accessor$identifier((ResourceLocation) (Object) channel);
        packet.accessor$data((FriendlyByteBuf) payload);
        return (net.minecraft.network.protocol.Packet<?>) packet;
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ServerboundCustomQueryPacket(net.minecraft.network.protocol.login.ServerboundCustomQueryPacket) ClientboundCustomPayloadPacket(net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket) ServerboundCustomPayloadPacket(net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket) Packet(org.spongepowered.api.network.channel.packet.Packet) ClientboundCustomQueryPacket(net.minecraft.network.protocol.login.ClientboundCustomQueryPacket) ServerboundCustomPayloadPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundCustomPayloadPacketAccessor) ClientboundCustomPayloadPacket(net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket) ServerboundCustomPayloadPacket(net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket) ClientboundCustomPayloadPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ClientboundCustomPayloadPacketAccessor) 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