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());
}
}
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);
}
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;
}
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);
}
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();
}
}
Aggregations