Java Code Examples for net.minecraft.util.registry.Registry#register()

The following examples show how to use net.minecraft.util.registry.Registry#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForgeRegistry.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void register(V value) {
	Objects.requireNonNull(value, "value must not be null");
	Identifier identifier = value.getRegistryName();

	Optional<V> potentialOldValue = vanilla.getOrEmpty(identifier);

	potentialOldValue.ifPresent(
			oldValue -> {
				if (oldValue == value) {
					LOGGER.warn(REGISTRIES, "Registry {}: The object {} has been registered twice for the same name {}.", this.superType.getSimpleName(), value, identifier);

					return;
				} else {
					throw new IllegalArgumentException(String.format("The name %s has been registered twice, for %s and %s.", identifier, oldValue, value));
				}
			}
	);

	Identifier oldIdentifier = vanilla.getId(value);

	if (oldIdentifier != getDefaultKey()) {
		throw new IllegalArgumentException(String.format("The object %s{%x} has been registered twice, using the names %s and %s.", value, System.identityHashCode(value), oldIdentifier, identifier));
	}

	Registry.register(vanilla, identifier, value);
}
 
Example 2
Source File: GalacticraftRecipes.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static <T extends Recipe<?>> RecipeType<T> registerType(String id) {
    return Registry.register(Registry.RECIPE_TYPE, new Identifier(Constants.MOD_ID, id), new RecipeType<T>() {
        public String toString() {
            return id;
        }
    });
}
 
Example 3
Source File: GalacticraftEnergy.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public static void register() {
        Registry.register(UniversalComponents.ENERGY_TYPES, new Identifier(Constants.MOD_ID, Constants.Energy.GALACTICRAFT_JOULES), GALACTICRAFT_JOULES);
        Registry.register(UniversalComponents.ENERGY_TYPES, new Identifier(Constants.MOD_ID, Constants.Energy.GALACTICRAFT_OXYGEN), GALACTICRAFT_OXYGEN);

//        ItemComponentCallback.event(GalacticraftItems.BATTERY).register((stack, container) -> container.put(UniversalComponents.CAPACITOR_COMPONENT, new ItemCapacitorComponent(BatteryItem.getMaxEnergy(), GalacticraftEnergy.GALACTICRAFT_JOULES)));
//        ItemComponentCallback.event(GalacticraftItems.INFINITE_BATTERY).register((stack, container) -> {
//            ItemCapacitorComponent capacitorComponent = new ItemCapacitorComponent(Integer.MAX_VALUE, GalacticraftEnergy.GALACTICRAFT_JOULES);
//            capacitorComponent.copyFrom(GalacticraftEnergy.INFINITE_ENERGY_COMPONENT);
//            container.put(UniversalComponents.CAPACITOR_COMPONENT, capacitorComponent);
//        });
    }
 
Example 4
Source File: LibGuiTest.java    From LibGui with MIT License 5 votes vote down vote up
@Override
public void onInitialize() {
	Registry.register(Registry.ITEM, new Identifier(MODID, "client_gui"), new GuiItem());
	
	GUI_BLOCK = new GuiBlock();
	Registry.register(Registry.BLOCK, new Identifier(MODID, "gui"), GUI_BLOCK);
	GUI_BLOCK_ITEM = new BlockItem(GUI_BLOCK, new Item.Settings().group(ItemGroup.MISC));
	Registry.register(Registry.ITEM, new Identifier(MODID, "gui"), GUI_BLOCK_ITEM);
	GUI_BLOCKENTITY_TYPE = BlockEntityType.Builder.create(GuiBlockEntity::new, GUI_BLOCK).build(null);
	Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, "gui"), GUI_BLOCKENTITY_TYPE);
	
	GUI_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "gui"), (int syncId, PlayerInventory inventory) -> {
		return new TestDescription(GUI_SCREEN_HANDLER_TYPE, syncId, inventory, ScreenHandlerContext.EMPTY);
	});

	Optional<ModContainer> containerOpt = FabricLoader.getInstance().getModContainer("jankson");
	if (containerOpt.isPresent()) {
		ModContainer jankson = containerOpt.get();
		System.out.println("Jankson root path: "+jankson.getRootPath());
		try {
			Files.list(jankson.getRootPath()).forEach((path)->{
				path.getFileSystem().getFileStores().forEach((store)->{
					System.out.println("        Filestore: "+store.name());
				});
				System.out.println("    "+path.toAbsolutePath());
			});
		} catch (IOException e) {
			e.printStackTrace();
		}
		Path modJson = jankson.getPath("/fabric.mod.json");
		System.out.println("Jankson fabric.mod.json path: "+modJson);
		System.out.println(Files.exists(modJson) ? "Exists" : "Does Not Exist");
	} else {
		System.out.println("Container isn't present!");
	}
}
 
Example 5
Source File: HallowedFeatures.java    From the-hallow with MIT License 4 votes vote down vote up
public static <C extends FeatureConfig, F extends Feature<C>> F register(String name, F feature) {
	return Registry.register(Registry.FEATURE, TheHallow.id(name), feature);
}
 
Example 6
Source File: GalacticraftBiomeSourceTypes.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public static void register() {
    Registry.register(Registry.BIOME_SOURCE, new Identifier(Constants.MOD_ID, "moon"), MoonBiomeSource.CODEC);
}
 
Example 7
Source File: HallowedBlockEntities.java    From the-hallow with MIT License 4 votes vote down vote up
private static <B extends BlockEntity> BlockEntityType<B> register(String name, Supplier<B> supplier, Block... supportedBlocks) {
	return Registry.register(Registry.BLOCK_ENTITY_TYPE, TheHallow.id(name), BlockEntityType.Builder.create(supplier, supportedBlocks).build(null));
}
 
Example 8
Source File: HallowedItems.java    From the-hallow with MIT License 4 votes vote down vote up
protected static <T extends Item> T register(String name, T item) {
	return Registry.register(Registry.ITEM, TheHallow.id(name), item);
}
 
Example 9
Source File: HallowedEnchantments.java    From the-hallow with MIT License 4 votes vote down vote up
protected static <T extends Enchantment> T register(String name, T enchantment) {
	return Registry.register(Registry.ENCHANTMENT, TheHallow.id(name), enchantment);
}
 
Example 10
Source File: HallowedSounds.java    From the-hallow with MIT License 4 votes vote down vote up
private static SoundEvent register(String name) {
	return Registry.register(Registry.SOUND_EVENT, TheHallow.id(name), new SoundEvent(TheHallow.id(name)));
}
 
Example 11
Source File: HallowedFeatures.java    From the-hallow with MIT License 4 votes vote down vote up
public static <C extends SurfaceConfig, F extends SurfaceBuilder<C>> F register(String name, F surfaceBuilder) {
	return Registry.register(Registry.SURFACE_BUILDER, TheHallow.id(name), surfaceBuilder);
}
 
Example 12
Source File: HallowedFluids.java    From the-hallow with MIT License 4 votes vote down vote up
static <T extends Fluid> T register(String name, T fluid) {
	T b = Registry.register(Registry.FLUID, TheHallow.id(name), fluid);
	return b;
}
 
Example 13
Source File: HallowedBiomes.java    From the-hallow with MIT License 4 votes vote down vote up
private static <T extends Biome> T register(String name, T biome) {
	return Registry.register(Registry.BIOME, TheHallow.id(name), biome);
}
 
Example 14
Source File: GalacticraftRecipes.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String id, S serializer) {
    return Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(Constants.MOD_ID, id), serializer);
}
 
Example 15
Source File: GalacticraftBlocks.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static Block registerMachine(Block block, String id) {
    Block registered = Registry.register(Registry.BLOCK, new Identifier(Constants.MOD_ID, id), block);
    Registry.register(Registry.ITEM, new Identifier(Constants.MOD_ID, id), new BlockItem(registered, new Item.Settings().group(MACHINES_GROUP)));
    return registered;
}
 
Example 16
Source File: GalacticraftBlocks.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static Block registerBlock(Block block, String id) {
    Block registered = registerBlockWithoutItem(block, id);
    Registry.register(Registry.ITEM, new Identifier(Constants.MOD_ID, id), new BlockItem(registered, new Item.Settings().group(BLOCKS_GROUP)));
    return registered;
}
 
Example 17
Source File: GalacticraftBlocks.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static Block registerBlockWithoutItem(Block block, String id) {
    return Registry.register(Registry.BLOCK, new Identifier(Constants.MOD_ID, id), block);
}
 
Example 18
Source File: GalacticraftParticles.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
public static void register() {
    Registry.register(Registry.PARTICLE_TYPE, new Identifier(Constants.MOD_ID, Constants.Particles.DRIPPING_CRUDE_OIL_PARTICLE), DRIPPING_FUEL_PARTICLE);
    Registry.register(Registry.PARTICLE_TYPE, new Identifier(Constants.MOD_ID, Constants.Particles.DRIPPING_FUEL_PARTICLE), DRIPPING_CRUDE_OIL_PARTICLE);
    Galacticraft.logger.info("Registered particles!");
}
 
Example 19
Source File: GalacticraftCelestialBodyTypes.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
private static CelestialBodyType register(CelestialBodyType type) {
    return Registry.register(AddonRegistry.CELESTIAL_BODIES, type.getId(), type);
}
 
Example 20
Source File: GalacticraftDimensions.java    From Galacticraft-Rewoven with MIT License 3 votes vote down vote up
public static void register() {
    Registry.register(Registry.CHUNK_GENERATOR, new Identifier(Constants.MOD_ID, "moon"), MoonChunkGenerator.CODEC);

    MOON = RegistryKey.of(Registry.DIMENSION, new Identifier(Constants.MOD_ID, "moon"));

    FabricDimensions.registerDefaultPlacer(MOON, GalacticraftDimensions::placeEntity);
}