Skip to content

Commit

Permalink
Finish fabric part...
Browse files Browse the repository at this point in the history
  • Loading branch information
Killarexe committed Jan 31, 2024
1 parent 2a1bf2b commit 29679d7
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import org.slf4j.LoggerFactory;

import github.killarexe.copper_extension.CEMod;

import github.killarexe.copper_extension.fabric.registry.CERegistries;
import net.fabricmc.api.ModInitializer;

public class CEFabric implements ModInitializer {

public static final Logger LOGGER = LoggerFactory.getLogger(CEMod.MOD_ID);

@Override
public void onInitialize() {

CERegistries.register();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package github.killarexe.copper_extension.fabric.item;

import github.killarexe.copper_extension.fabric.registry.CEGameRules;
import github.killarexe.copper_extension.fabric.registry.CEItems;
import github.killarexe.copper_extension.item.RustableItem;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.GameRules.IntegerValue;
import net.minecraft.world.level.GameRules.Key;

public class FabricRustableItem extends RustableItem{

public FabricRustableItem(Item.Properties properties, ResourceLocation scrappedItemId, ResourceLocation waxedItemId, ResourceLocation rustItemId) {
super(properties, scrappedItemId, waxedItemId, rustItemId);
}

@Override
public Item getScrappedItem() {
return CEItems.getItem(getScrappedItemId());
}

@Override
public Item getWaxedItem() {
return CEItems.getItem(getWaxedItemId());
}

@Override
public Item getRustItem() {
return CEItems.getItem(getRustItemId());
}

@Override
public Key<IntegerValue> getOxidationChanceGameRule() {
return CEGameRules.COPPER_OXIDATION_CHANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package github.killarexe.copper_extension.fabric.item;

import github.killarexe.copper_extension.fabric.registry.CEItems;
import github.killarexe.copper_extension.item.ScrapableItem;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;

public class FabricScrapableItem extends ScrapableItem {

public FabricScrapableItem(Item.Properties properties, ResourceLocation scrappedItemId) {
super(properties, scrappedItemId);
}

@Override
public Item getScrappedItem() {
return CEItems.getItem(getScrappedItemId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package github.killarexe.copper_extension.fabric.item;

import github.killarexe.copper_extension.fabric.registry.CEItems;
import github.killarexe.copper_extension.item.WaxableItem;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;

public class FabricWaxableItem extends WaxableItem {

public FabricWaxableItem(Item.Properties properties, ResourceLocation scrappedItemId, ResourceLocation waxedItemId) {
super(properties, scrappedItemId, waxedItemId);
}

@Override
public Item getScrappedItem() {
return CEItems.getItem(getScrappedItemId());
}

@Override
public Item getWaxedItem() {
return CEItems.getItem(getWaxedItemId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package github.killarexe.copper_extension.fabric.registry;

import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.world.level.GameRules;

public class CEGameRules {
public static final GameRules.Key<GameRules.IntegerValue> COPPER_OXIDATION_CHANCE = GameRuleRegistry.register(
"copperOxidationChance", GameRules.Category.UPDATES, GameRuleFactory.createIntRule(1)
);

public static void register() {
//Just to load the class...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package github.killarexe.copper_extension.fabric.registry;

import java.util.HashMap;

import github.killarexe.copper_extension.CEMod;
import github.killarexe.copper_extension.fabric.item.*;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

public class CEItems {

private static final HashMap<String, Item> ITEMS = new HashMap<String, Item>();

public static final FabricScrapableItem WAXED_COPPER_INGOT = createItem("waxed_copper_ingot", new FabricScrapableItem(new FabricItemSettings(), new ResourceLocation("minecraft", "copper_ingot")));
public static final FabricScrapableItem WAXED_EXPOSED_COPPER_INGOT = createItem("waxed_exposed_copper_ingot", new FabricScrapableItem(new FabricItemSettings(), CEMod.id("exposed_copper_ingot")));
public static final FabricScrapableItem WAXED_WEATHERED_COPPER_INGOT = createItem("waxed_weathered_copper_ingot", new FabricScrapableItem(new FabricItemSettings(), CEMod.id("weathered_copper_ingot")));

public static final FabricRustableItem EXPOSED_COPPER_INGOT = createItem("exposed_copper_ingot", new FabricRustableItem(
new FabricItemSettings(),
new ResourceLocation("minecraft", "copper_ingot"),
CEMod.id("waxed_exposed_copper_ingot"),
CEMod.id("weathered_copper_ingot"))
);
public static final FabricRustableItem WEATHERED_COPPER_INGOT = createItem("weathered_copper_ingot", new FabricRustableItem(
new FabricItemSettings(),
CEMod.id("exposed_copper_ingot"),
CEMod.id("waxed_weathered_copper_ingot"),
CEMod.id("oxidized_copper_ingot")
));
public static final Item OXIDIZED_COPPER_INGOT = createItem("oxidized_copper_ingot", new FabricScrapableItem(new FabricItemSettings(), CEMod.id("weathered_copper_ingot")));

public static void register() {
ITEMS.forEach((id, item) -> {
Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(CEMod.MOD_ID, id), item);
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.INGREDIENTS).register((group) -> {
group.accept(item);
});
});
}

private static <T extends Item> T createItem(String id, T item) {
ITEMS.put(id, item);
return item;
}

public static Item getItem(ResourceLocation itemId) {
if(BuiltInRegistries.ITEM.containsKey(itemId)) {
return BuiltInRegistries.ITEM.get(itemId);
}
return Items.AIR;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package github.killarexe.copper_extension.fabric.registry;

import github.killarexe.copper_extension.fabric.CEFabric;

public class CERegistries {
public static void register() {
CEFabric.LOGGER.debug("Initializing Copper Extension Game Rules...");
CEGameRules.register();
CEFabric.LOGGER.debug("Initializing Copper Extension Items...");
CEItems.register();
CEFabric.LOGGER.debug("Copper Extension Items Initialized!");
}
}

0 comments on commit 29679d7

Please sign in to comment.