Skip to content

Commit

Permalink
Fully fledged test item + more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Dec 22, 2024
1 parent 2e23a85 commit f1c1497
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 36 deletions.
2 changes: 1 addition & 1 deletion legacy-fabric-item-api-v1/1.7.10/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minVersionIncluded=1.3
minVersionIncluded=1.7
maxVersionIncluded=1.7.10
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.registry.v2.RegistryIds;
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry;

@Mixin(Item.class)
public class ItemMixin {
Expand All @@ -39,6 +38,6 @@ public class ItemMixin {

@Inject(method = "setup", at = @At("RETURN"))
private static void registerRegistry(CallbackInfo ci) {
RegistryHelper.addRegistry(RegistryIds.ITEMS, (FabricRegistry<?>) REGISTRY);
RegistryHelper.addRegistry(RegistryIds.ITEMS, REGISTRY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import net.legacyfabric.fabric.impl.registry.RegistryEventHelper;

/**
* An event for when a registry has been remapped.
* An event for when a registry has been remapped, but hasn't been updated yet.
*
* @param <T> the type of entries within the registry
*/
@FunctionalInterface
public interface RegistryRemapCallback<T> {
/**
* Called when the registry has been remapped.
* Called when the registry has been remapped but hasn't been updated yet.
* @param changedIdsMap A map containing changed ids in the registry following the remapping process.
* Key is the original id and Value is the affected entry data see {@link FabricRegistryEntry}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.registry;

import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.resource.ItemModelRegistry;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
this.registerItems();
}

private void registerItems() {
Item testItem = new Item().setItemGroup(ItemGroup.FOOD);
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.registry;

import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.resource.ItemModelRegistry;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
this.registerItems();
}

private void registerItems() {
Item testItem = new Item().setItemGroup(ItemGroup.FOOD);
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.registry;

import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
this.registerItems();
}

private void registerItems() {
Item testItem = new Item()
.setItemGroup(ItemGroup.FOOD)
.getFromId(new Identifier("legacy-fabric-api", "test_item").toString());
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.registry;

import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.resource.ItemModelRegistry;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
this.registerItems();
}

private void registerItems() {
Item testItem = new Item().setItemGroup(ItemGroup.FOOD);
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.test.registry;

import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.resource.ItemModelRegistry;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
this.registerItems();
}

private void registerItems() {
Item testItem = new Item().setItemGroup(ItemGroup.FOOD);
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,27 @@

package net.legacyfabric.fabric.test.registry;

import java.util.concurrent.ThreadLocalRandom;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.itemgroup.ItemGroup;

import net.fabricmc.api.ModInitializer;

import net.legacyfabric.fabric.api.registry.v1.RegistryHelper;
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper;
import net.legacyfabric.fabric.api.resource.ItemModelRegistry;
import net.legacyfabric.fabric.api.util.Identifier;

public class RegistryTest implements ModInitializer {
@Override
public void onInitialize() {
Block concBlock = new Block(Material.STONE, MaterialColor.BLACK).setItemGroup(ItemGroup.FOOD);
Block concBlock2 = new Block(Material.STONE, MaterialColor.BLUE).setItemGroup(ItemGroup.FOOD);
Block[] blocks = ThreadLocalRandom.current().nextBoolean() ? new Block[] {concBlock, concBlock2} : new Block[] {concBlock2, concBlock};

for (Block block : blocks) {
int color = 1644825;

if (block == concBlock2) {
color = 3361970;
}

Identifier identifier = new Identifier("legacy-fabric-api", "conc_block_" + color);

RegistryHelper.registerBlock(block, identifier);
RegistryHelper.registerItem(new BlockItem(block), identifier);
}
this.registerItems();
}

private void registerItems() {
Item testItem = new Item().setItemGroup(ItemGroup.FOOD);
RegistryHelper.registerItem(testItem, new Identifier("legacy-fabric-api", "test_item"));
RegistryHelper.register(
Item.REGISTRY,
new Identifier("legacy-fabric-api", "test_item"), testItem
);
ItemModelRegistry.registerItemModel(testItem, new Identifier("legacy-fabric-api:test_item"));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"api.keybinding.testTranslationKey": "Test Keybinding",
"legacyfabric.api.youreTesting": "You're Testing Fabric API!"
"legacyfabric.api.youreTesting": "You're Testing Fabric API!",
"item.legacy-fabric-api.test_item.name": "Test Item"
}

0 comments on commit f1c1497

Please sign in to comment.