diff --git a/build.gradle b/build.gradle index c12e41c..0aa8079 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' } @@ -40,7 +40,7 @@ java { jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename {"${it}_${project.archivesBaseName}"} } } @@ -51,4 +51,4 @@ publishing { } } repositories {} -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index fad865b..c6ac597 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs = -Xmx1G org.gradle.parallel = true # Fabric Properties -minecraft_version = 1.20.2 -yarn_mappings = 1.20.2+build.4 -loader_version = 0.14.24 +minecraft_version = 1.20.4 +yarn_mappings = 1.20.4+build.3 +loader_version = 0.15.7 # Mod Properties -mod_version = 1.3.0 +mod_version = 1.4.0 maven_group = dev.jaxydog archives_base_name = cheese # Dependencies -fabric_version = 0.90.7+1.20.2 \ No newline at end of file +fabric_version = 0.96.3+1.20.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..12f5a0b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip -networkTimeout=10000 -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +distributionBase = GRADLE_USER_HOME +distributionPath = wrapper/dists +distributionUrl = https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout = 10000 +zipStoreBase = GRADLE_USER_HOME +zipStorePath = wrapper/dists diff --git a/src/main/java/dev/jaxydog/Cheese.java b/src/main/java/dev/jaxydog/Cheese.java index c32c0d5..78a01cd 100644 --- a/src/main/java/dev/jaxydog/Cheese.java +++ b/src/main/java/dev/jaxydog/Cheese.java @@ -14,24 +14,24 @@ public class Cheese implements ModInitializer { - public static final String MOD_ID = "cheese"; - public static final Logger LOGGER = LoggerFactory.getLogger(Cheese.MOD_ID); - public static final ItemGroup ITEM_GROUP = FabricItemGroup - .builder() - .icon(() -> CustomItems.CHEESE.getDefaultStack()) - .displayName(Text.translatable(Cheese.newId("default").toTranslationKey("itemGroup"))) - .build(); - - @Override - public void onInitialize() { - Registry.register(Registries.ITEM_GROUP, Cheese.newId("default"), Cheese.ITEM_GROUP); - - AutoRegisterImpl.runMain(); - - Cheese.LOGGER.info("Cheese has loaded :)"); - } - - public static final Identifier newId(String path) { - return Identifier.of(Cheese.MOD_ID, path); - } + public static final String MOD_ID = "cheese"; + public static final Logger LOGGER = LoggerFactory.getLogger(Cheese.MOD_ID); + public static final ItemGroup ITEM_GROUP = FabricItemGroup.builder() + .icon(CustomItems.CHEESE::getDefaultStack) + .displayName(Text.translatable(Cheese.newId("default").toTranslationKey("itemGroup"))) + .build(); + + @Override + public void onInitialize() { + Registry.register(Registries.ITEM_GROUP, Cheese.newId("default"), Cheese.ITEM_GROUP); + + AutoRegisterImpl.runMain(); + + Cheese.LOGGER.info("Cheese has loaded :)"); + } + + public static Identifier newId(String path) { + return Identifier.of(Cheese.MOD_ID, path); + } + } diff --git a/src/main/java/dev/jaxydog/CheeseClient.java b/src/main/java/dev/jaxydog/CheeseClient.java index 906dba5..4e40db5 100644 --- a/src/main/java/dev/jaxydog/CheeseClient.java +++ b/src/main/java/dev/jaxydog/CheeseClient.java @@ -5,8 +5,9 @@ public class CheeseClient implements ClientModInitializer { - @Override - public void onInitializeClient() { - AutoRegisterImpl.runClient(); - } + @Override + public void onInitializeClient() { + AutoRegisterImpl.runClient(); + } + } diff --git a/src/main/java/dev/jaxydog/content/block/CustomBlock.java b/src/main/java/dev/jaxydog/content/block/CustomBlock.java index e9e3565..a54f0ff 100644 --- a/src/main/java/dev/jaxydog/content/block/CustomBlock.java +++ b/src/main/java/dev/jaxydog/content/block/CustomBlock.java @@ -7,21 +7,22 @@ public class CustomBlock extends Block implements Registerable.Main { - private final String RAW_ID; + private final String RAW_ID; - public CustomBlock(String rawId, Settings settings) { - super(settings); - this.RAW_ID = rawId; - } + public CustomBlock(String rawId, Settings settings) { + super(settings); + this.RAW_ID = rawId; + } - @Override - public String getRawId() { - return this.RAW_ID; - } + @Override + public String getRawId() { + return this.RAW_ID; + } + + @Override + public void registerMain() { + Main.super.registerMain(); + Registry.register(Registries.BLOCK, this.getId(), this); + } - @Override - public void registerMain() { - Main.super.registerMain(); - Registry.register(Registries.BLOCK, this.getId(), this); - } } diff --git a/src/main/java/dev/jaxydog/content/block/CustomBlocks.java b/src/main/java/dev/jaxydog/content/block/CustomBlocks.java index 8710a61..777b4c5 100644 --- a/src/main/java/dev/jaxydog/content/block/CustomBlocks.java +++ b/src/main/java/dev/jaxydog/content/block/CustomBlocks.java @@ -9,12 +9,15 @@ @AutoRegister public class CustomBlocks { - public static final CustomBlock CHEESE_BLOCK = new CustomBlock( - "cheese_block", - Settings.copy(Blocks.SPONGE).mapColor(MapColor.PALE_YELLOW).hardness(1.0f).sounds(BlockSoundGroup.SLIME) - ); + public static final CustomBlock CHEESE_BLOCK = new CustomBlock( + "cheese_block", + Settings.copy(Blocks.SPONGE).mapColor(MapColor.PALE_YELLOW).hardness(1.0f).sounds(BlockSoundGroup.SLIME) + ); + + public static final TomatoesBlock TOMATOES = new TomatoesBlock(Settings.copy(Blocks.BEETROOTS) + .breakInstantly() + .noCollision() + .sounds(BlockSoundGroup.CROP) + .ticksRandomly()); - public static final TomatoesBlock TOMATOES = new TomatoesBlock( - Settings.copy(Blocks.BEETROOTS).breakInstantly().noCollision().sounds(BlockSoundGroup.CROP).ticksRandomly() - ); } diff --git a/src/main/java/dev/jaxydog/content/block/TomatoesBlock.java b/src/main/java/dev/jaxydog/content/block/TomatoesBlock.java index 4f96b42..3a2a04d 100644 --- a/src/main/java/dev/jaxydog/content/block/TomatoesBlock.java +++ b/src/main/java/dev/jaxydog/content/block/TomatoesBlock.java @@ -23,70 +23,71 @@ public class TomatoesBlock extends CropBlock implements Registerable.Client, Registerable.Main { - public static final int TOMATOES_MAX_AGE = 3; - public static final IntProperty AGE = Properties.AGE_3; - private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[] { - Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 2.0, 16.0), - Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 6.0, 16.0), - Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 9.0, 16.0), - Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 11.0, 16.0), - }; + public static final int TOMATOES_MAX_AGE = 3; + public static final IntProperty AGE = Properties.AGE_3; + private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[] { + Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 2.0, 16.0), + Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 6.0, 16.0), + Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 9.0, 16.0), + Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 11.0, 16.0), + }; - public TomatoesBlock(Settings settings) { - super(settings); - } + public TomatoesBlock(Settings settings) { + super(settings); + } - @Override - public IntProperty getAgeProperty() { - return TomatoesBlock.AGE; - } + @Override + public IntProperty getAgeProperty() { + return TomatoesBlock.AGE; + } - @Override - public int getMaxAge() { - return TomatoesBlock.TOMATOES_MAX_AGE; - } + @Override + public int getMaxAge() { + return TomatoesBlock.TOMATOES_MAX_AGE; + } - @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return TomatoesBlock.AGE_TO_SHAPE[this.getAge(state)]; - } + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return TomatoesBlock.AGE_TO_SHAPE[this.getAge(state)]; + } - @Override - public String getRawId() { - return "tomatoes"; - } + @Override + public String getRawId() { + return "tomatoes"; + } - @Override - protected ItemConvertible getSeedsItem() { - return CustomItems.TOMATO; - } + @Override + protected ItemConvertible getSeedsItem() { + return CustomItems.TOMATO; + } - @Override - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (random.nextInt(3) != 0) { - super.randomTick(state, world, pos, random); - } - } + @Override + public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + if (random.nextInt(3) != 0) { + super.randomTick(state, world, pos, random); + } + } - @Override - protected int getGrowthAmount(World world) { - return super.getGrowthAmount(world) / 3; - } + @Override + protected int getGrowthAmount(World world) { + return super.getGrowthAmount(world) / 3; + } - @Override - protected void appendProperties(Builder builder) { - builder.add(TomatoesBlock.AGE); - } + @Override + protected void appendProperties(Builder builder) { + builder.add(TomatoesBlock.AGE); + } - @Override - public void registerMain() { - Main.super.registerMain(); - Registry.register(Registries.BLOCK, this.getId(), this); - } + @Override + public void registerMain() { + Main.super.registerMain(); + Registry.register(Registries.BLOCK, this.getId(), this); + } + + @Override + public void registerClient() { + Client.super.registerClient(); + BlockRenderLayerMap.INSTANCE.putBlock(this, RenderLayer.getCutout()); + } - @Override - public void registerClient() { - Client.super.registerClient(); - BlockRenderLayerMap.INSTANCE.putBlock(this, RenderLayer.getCutout()); - } } diff --git a/src/main/java/dev/jaxydog/content/item/BottleItem.java b/src/main/java/dev/jaxydog/content/item/BottleItem.java index ca6c5c6..f995b72 100644 --- a/src/main/java/dev/jaxydog/content/item/BottleItem.java +++ b/src/main/java/dev/jaxydog/content/item/BottleItem.java @@ -10,21 +10,22 @@ public class BottleItem extends CustomItem { - public BottleItem(String rawId, Settings settings, LootModifier... lootModifiers) { - super(rawId, settings, lootModifiers); - } + public BottleItem(String rawId, Settings settings, LootModifier... lootModifiers) { + super(rawId, settings, lootModifiers); + } - @Override - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - if (user instanceof PlayerEntity && !((PlayerEntity) user).getAbilities().creativeMode) { - ((PlayerEntity) user).getInventory().insertStack(Items.GLASS_BOTTLE.getDefaultStack()); - } + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + if (user instanceof final PlayerEntity player && !player.isCreative()) { + player.giveItemStack(Items.GLASS_BOTTLE.getDefaultStack()); + } - return super.finishUsing(stack, world, user); - } + return super.finishUsing(stack, world, user); + } + + @Override + public UseAction getUseAction(ItemStack stack) { + return UseAction.DRINK; + } - @Override - public UseAction getUseAction(ItemStack stack) { - return UseAction.DRINK; - } } diff --git a/src/main/java/dev/jaxydog/content/item/BowlItem.java b/src/main/java/dev/jaxydog/content/item/BowlItem.java index 36115f6..c5c04f1 100644 --- a/src/main/java/dev/jaxydog/content/item/BowlItem.java +++ b/src/main/java/dev/jaxydog/content/item/BowlItem.java @@ -9,16 +9,17 @@ public class BowlItem extends CustomItem { - public BowlItem(String rawId, Settings settings, LootModifier... lootModifiers) { - super(rawId, settings, lootModifiers); - } + public BowlItem(String rawId, Settings settings, LootModifier... lootModifiers) { + super(rawId, settings, lootModifiers); + } - @Override - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { - if (user instanceof PlayerEntity && !((PlayerEntity) user).getAbilities().creativeMode) { - ((PlayerEntity) user).getInventory().insertStack(Items.BOWL.getDefaultStack()); - } + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { + if (user instanceof final PlayerEntity player && !player.isCreative()) { + player.giveItemStack(Items.BOWL.getDefaultStack()); + } + + return super.finishUsing(stack, world, user); + } - return super.finishUsing(stack, world, user); - } } diff --git a/src/main/java/dev/jaxydog/content/item/CustomAliasedBlockItem.java b/src/main/java/dev/jaxydog/content/item/CustomAliasedBlockItem.java index 6a752ca..3f6ccb7 100644 --- a/src/main/java/dev/jaxydog/content/item/CustomAliasedBlockItem.java +++ b/src/main/java/dev/jaxydog/content/item/CustomAliasedBlockItem.java @@ -3,8 +3,6 @@ import dev.jaxydog.Cheese; import dev.jaxydog.utility.LootModifier; import dev.jaxydog.utility.register.Registerable; -import java.util.LinkedList; -import java.util.List; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.block.Block; import net.minecraft.client.item.TooltipContext; @@ -17,43 +15,47 @@ import net.minecraft.util.Formatting; import net.minecraft.world.World; +import java.util.LinkedList; +import java.util.List; + public class CustomAliasedBlockItem extends AliasedBlockItem implements Registerable.Main { - private final String RAW_ID; - private final List LOOT_MODIFIERS = new LinkedList<>(); - - public CustomAliasedBlockItem(String rawId, Block block, Settings settings, LootModifier... lootModifiers) { - super(block, settings); - this.RAW_ID = rawId; - this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); - } - - @Override - public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { - var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; - var index = 0; - - while (I18n.hasTranslation(key + index)) { - tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); - index += 1; - } - - super.appendTooltip(stack, world, tooltip, context); - } - - @Override - public String getRawId() { - return this.RAW_ID; - } - - @Override - public void registerMain() { - Main.super.registerMain(); - Registry.register(Registries.ITEM, this.getId(), this); - ItemGroupEvents - .modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) - .register(e -> e.add(this)); - - this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); - } + private final String RAW_ID; + private final List LOOT_MODIFIERS = new LinkedList<>(); + + public CustomAliasedBlockItem(String rawId, Block block, Settings settings, LootModifier... lootModifiers) { + super(block, settings); + this.RAW_ID = rawId; + this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); + } + + @Override + public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { + var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; + var index = 0; + + while (I18n.hasTranslation(key + index)) { + tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); + index += 1; + } + + super.appendTooltip(stack, world, tooltip, context); + } + + @Override + public String getRawId() { + return this.RAW_ID; + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + @Override + public void registerMain() { + Main.super.registerMain(); + Registry.register(Registries.ITEM, this.getId(), this); + ItemGroupEvents.modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) + .register(e -> e.add(this)); + + this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); + } + } diff --git a/src/main/java/dev/jaxydog/content/item/CustomBlockItem.java b/src/main/java/dev/jaxydog/content/item/CustomBlockItem.java index 436dd92..6be2a8f 100644 --- a/src/main/java/dev/jaxydog/content/item/CustomBlockItem.java +++ b/src/main/java/dev/jaxydog/content/item/CustomBlockItem.java @@ -3,8 +3,6 @@ import dev.jaxydog.Cheese; import dev.jaxydog.utility.LootModifier; import dev.jaxydog.utility.register.Registerable; -import java.util.LinkedList; -import java.util.List; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.block.Block; import net.minecraft.client.item.TooltipContext; @@ -17,43 +15,47 @@ import net.minecraft.util.Formatting; import net.minecraft.world.World; +import java.util.LinkedList; +import java.util.List; + public class CustomBlockItem extends BlockItem implements Registerable.Main { - private final String RAW_ID; - private final List LOOT_MODIFIERS = new LinkedList<>(); - - public CustomBlockItem(String rawId, Block block, Settings settings, LootModifier... lootModifiers) { - super(block, settings); - this.RAW_ID = rawId; - this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); - } - - @Override - public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { - var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; - var index = 0; - - while (I18n.hasTranslation(key + index)) { - tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); - index += 1; - } - - super.appendTooltip(stack, world, tooltip, context); - } - - @Override - public String getRawId() { - return this.RAW_ID; - } - - @Override - public void registerMain() { - Main.super.registerMain(); - Registry.register(Registries.ITEM, this.getId(), this); - ItemGroupEvents - .modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) - .register(e -> e.add(this)); - - this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); - } + private final String RAW_ID; + private final List LOOT_MODIFIERS = new LinkedList<>(); + + public CustomBlockItem(String rawId, Block block, Settings settings, LootModifier... lootModifiers) { + super(block, settings); + this.RAW_ID = rawId; + this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); + } + + @Override + public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { + var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; + var index = 0; + + while (I18n.hasTranslation(key + index)) { + tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); + index += 1; + } + + super.appendTooltip(stack, world, tooltip, context); + } + + @Override + public String getRawId() { + return this.RAW_ID; + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + @Override + public void registerMain() { + Main.super.registerMain(); + Registry.register(Registries.ITEM, this.getId(), this); + ItemGroupEvents.modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) + .register(e -> e.add(this)); + + this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); + } + } diff --git a/src/main/java/dev/jaxydog/content/item/CustomItem.java b/src/main/java/dev/jaxydog/content/item/CustomItem.java index 7ba85f0..5167204 100644 --- a/src/main/java/dev/jaxydog/content/item/CustomItem.java +++ b/src/main/java/dev/jaxydog/content/item/CustomItem.java @@ -3,8 +3,6 @@ import dev.jaxydog.Cheese; import dev.jaxydog.utility.LootModifier; import dev.jaxydog.utility.register.Registerable; -import java.util.LinkedList; -import java.util.List; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; import net.minecraft.client.item.TooltipContext; import net.minecraft.client.resource.language.I18n; @@ -16,43 +14,47 @@ import net.minecraft.util.Formatting; import net.minecraft.world.World; +import java.util.LinkedList; +import java.util.List; + public class CustomItem extends Item implements Registerable.Main { - private final String RAW_ID; - private final List LOOT_MODIFIERS = new LinkedList<>(); - - public CustomItem(String rawId, Settings settings, LootModifier... lootModifiers) { - super(settings); - this.RAW_ID = rawId; - this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); - } - - @Override - public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { - var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; - var index = 0; - - while (I18n.hasTranslation(key + index)) { - tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); - index += 1; - } - - super.appendTooltip(stack, world, tooltip, context); - } - - @Override - public String getRawId() { - return this.RAW_ID; - } - - @Override - public void registerMain() { - Main.super.registerMain(); - Registry.register(Registries.ITEM, this.getId(), this); - ItemGroupEvents - .modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) - .register(e -> e.add(this)); - - this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); - } + private final String RAW_ID; + private final List LOOT_MODIFIERS = new LinkedList<>(); + + public CustomItem(String rawId, Settings settings, LootModifier... lootModifiers) { + super(settings); + this.RAW_ID = rawId; + this.LOOT_MODIFIERS.addAll(List.of(lootModifiers)); + } + + @Override + public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { + var key = stack.getItem().getTranslationKey(stack) + ".tooltip_"; + var index = 0; + + while (I18n.hasTranslation(key + index)) { + tooltip.add(Text.translatable((key + index).formatted(Formatting.GRAY))); + index += 1; + } + + super.appendTooltip(stack, world, tooltip, context); + } + + @Override + public String getRawId() { + return this.RAW_ID; + } + + @SuppressWarnings("OptionalGetWithoutIsPresent") + @Override + public void registerMain() { + Main.super.registerMain(); + Registry.register(Registries.ITEM, this.getId(), this); + ItemGroupEvents.modifyEntriesEvent(Registries.ITEM_GROUP.getKey(Cheese.ITEM_GROUP).get()) + .register(e -> e.add(this)); + + this.LOOT_MODIFIERS.forEach(LootModifier::registerMain); + } + } diff --git a/src/main/java/dev/jaxydog/content/item/CustomItems.java b/src/main/java/dev/jaxydog/content/item/CustomItems.java index 8ea7868..17dd1fa 100644 --- a/src/main/java/dev/jaxydog/content/item/CustomItems.java +++ b/src/main/java/dev/jaxydog/content/item/CustomItems.java @@ -11,111 +11,122 @@ import net.minecraft.loot.provider.number.UniformLootNumberProvider; import net.minecraft.util.Rarity; +@SuppressWarnings("unused") @AutoRegister public class CustomItems { - public static final BottleItem BEEF_GRAVY = new BottleItem("beef_gravy", - new Settings() - .food(new FoodComponent.Builder().hunger(1).saturationModifier(0.7f).build()) - .rarity(Rarity.COMMON)); - - public static final CustomItem CHEESE = new CustomItem("cheese", new Settings() - .food(new FoodComponent.Builder().hunger(1).saturationModifier(1.125f).snack().build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_AND_CRACKERS = new CustomItem("cheese_and_crackers", - new Settings().food( - new FoodComponent.Builder().hunger(2).saturationModifier(1.25f).snack().build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomBlockItem CHEESE_BLOCK = new CustomBlockItem("cheese_block", - CustomBlocks.CHEESE_BLOCK, new Settings().rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_CLOTH = - new CustomItem("cheese_cloth", new Settings().rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_CURDS = new CustomItem("cheese_curds", - new Settings().food( - new FoodComponent.Builder().hunger(2).saturationModifier(0.9f).snack().build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_FRIES = new CustomItem("cheese_fries", - new Settings() - .food(new FoodComponent.Builder().hunger(3).saturationModifier(0.85f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_PIZZA = new CustomItem("cheese_pizza", - new Settings() - .food(new FoodComponent.Builder().hunger(8).saturationModifier(0.825f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESE_STEAK = new CustomItem("cheese_steak", - new Settings().food( - new FoodComponent.Builder().hunger(15).meat().saturationModifier(0.75f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESY_BAKED_POTATO = new CustomItem("cheesy_baked_potato", - new Settings() - .food(new FoodComponent.Builder().hunger(6).saturationModifier(0.875f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CHEESY_DINO_NUGGET = new CustomItem("cheesy_dino_nugget", - new Settings().food( - new FoodComponent.Builder().hunger(4).meat().saturationModifier(0.75f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem CRACKERS = new CustomItem("crackers", - new Settings() - .food(new FoodComponent.Builder().hunger(3).saturationModifier(0.5f).build()) - .rarity(Rarity.COMMON)); - - public static final CustomItem DINO_NUGGET = new CustomItem("dino_nugget", - new Settings().food( - new FoodComponent.Builder().hunger(3).meat().saturationModifier(0.65f).build()) - .rarity(Rarity.COMMON)); - - public static final CustomItem DOUGH = - new CustomItem("dough", new Settings().rarity(Rarity.COMMON)); - - public static final CustomItem FRIES = new CustomItem("fries", - new Settings().food( - new FoodComponent.Builder().hunger(2).saturationModifier(0.65f).snack().build()) - .rarity(Rarity.COMMON)); - - public static final CustomItem GRILLED_CHEESE = new CustomItem("grilled_cheese", - new Settings() - .food(new FoodComponent.Builder().hunger(8).saturationModifier(0.625f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomItem MACARONI = new CustomItem("macaroni", - new Settings().food( - new FoodComponent.Builder().hunger(1).saturationModifier(0.5f).snack().build()) - .rarity(Rarity.COMMON)); - - public static final BowlItem MACARONI_AND_CHEESE = new BowlItem("macaroni_and_cheese", - new Settings() - .food(new FoodComponent.Builder().hunger(6).saturationModifier(1.25f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final BowlItem POUTINE = new BowlItem("poutine", - new Settings() - .food(new FoodComponent.Builder().hunger(8).saturationModifier(0.95f).build()) - .rarity(Rarity.UNCOMMON)); - - public static final CustomAliasedBlockItem TOMATO = new CustomAliasedBlockItem("tomato", - CustomBlocks.TOMATOES, - new Settings() - .food(new FoodComponent.Builder().hunger(2).saturationModifier(1.25f).build()) - .rarity(Rarity.COMMON), - new LootModifier(EntityType.ZOMBIE.getLootTableId(), () -> CustomItems.TOMATO, - BinomialLootNumberProvider.create(1, 0.01f)), - new LootModifier(LootTables.VILLAGE_PLAINS_CHEST, () -> CustomItems.TOMATO, - UniformLootNumberProvider.create(0, 16.0f)), - new LootModifier(LootTables.VILLAGE_SAVANNA_HOUSE_CHEST, () -> CustomItems.TOMATO, - UniformLootNumberProvider.create(0, 16.0f))); - - public static final BottleItem TOMATO_SAUCE = new BottleItem("tomato_sauce", - new Settings() - .food(new FoodComponent.Builder().hunger(4).saturationModifier(1.125f).build()) - .rarity(Rarity.COMMON)); + public static final BottleItem BEEF_GRAVY = new BottleItem("beef_gravy", + new Settings().food(new FoodComponent.Builder().hunger(1).saturationModifier(0.7f).build()) + .rarity(Rarity.COMMON) + ); + + public static final CustomItem CHEESE = new CustomItem("cheese", + new Settings().food(new FoodComponent.Builder().hunger(1).saturationModifier(1.125f).snack().build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_AND_CRACKERS = new CustomItem("cheese_and_crackers", + new Settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(1.25f).snack().build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomBlockItem CHEESE_BLOCK = new CustomBlockItem("cheese_block", + CustomBlocks.CHEESE_BLOCK, + new Settings().rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_CLOTH = new CustomItem("cheese_cloth", + new Settings().rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_CURDS = new CustomItem("cheese_curds", + new Settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(0.9f).snack().build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_FRIES = new CustomItem("cheese_fries", + new Settings().food(new FoodComponent.Builder().hunger(3).saturationModifier(0.85f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_PIZZA = new CustomItem("cheese_pizza", + new Settings().food(new FoodComponent.Builder().hunger(8).saturationModifier(0.825f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESE_STEAK = new CustomItem("cheese_steak", + new Settings().food(new FoodComponent.Builder().hunger(15).meat().saturationModifier(0.75f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESY_BAKED_POTATO = new CustomItem("cheesy_baked_potato", + new Settings().food(new FoodComponent.Builder().hunger(6).saturationModifier(0.875f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CHEESY_DINO_NUGGET = new CustomItem("cheesy_dino_nugget", + new Settings().food(new FoodComponent.Builder().hunger(4).meat().saturationModifier(0.75f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem CRACKERS = new CustomItem("crackers", + new Settings().food(new FoodComponent.Builder().hunger(3).saturationModifier(0.5f).build()) + .rarity(Rarity.COMMON) + ); + + public static final CustomItem DINO_NUGGET = new CustomItem("dino_nugget", + new Settings().food(new FoodComponent.Builder().hunger(3).meat().saturationModifier(0.65f).build()) + .rarity(Rarity.COMMON) + ); + + public static final CustomItem DOUGH = new CustomItem("dough", new Settings().rarity(Rarity.COMMON)); + + public static final CustomItem FRIES = new CustomItem("fries", + new Settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(0.65f).snack().build()) + .rarity(Rarity.COMMON) + ); + + public static final CustomItem GRILLED_CHEESE = new CustomItem("grilled_cheese", + new Settings().food(new FoodComponent.Builder().hunger(8).saturationModifier(0.625f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomItem MACARONI = new CustomItem("macaroni", + new Settings().food(new FoodComponent.Builder().hunger(1).saturationModifier(0.5f).snack().build()) + .rarity(Rarity.COMMON) + ); + + public static final BowlItem MACARONI_AND_CHEESE = new BowlItem("macaroni_and_cheese", + new Settings().food(new FoodComponent.Builder().hunger(6).saturationModifier(1.25f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final BowlItem POUTINE = new BowlItem("poutine", + new Settings().food(new FoodComponent.Builder().hunger(8).saturationModifier(0.95f).build()) + .rarity(Rarity.UNCOMMON) + ); + + public static final CustomAliasedBlockItem TOMATO = new CustomAliasedBlockItem("tomato", + CustomBlocks.TOMATOES, + new Settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(1.25f).build()) + .rarity(Rarity.COMMON), + new LootModifier(EntityType.ZOMBIE.getLootTableId(), + () -> CustomItems.TOMATO, + BinomialLootNumberProvider.create(1, 0.01f) + ), + new LootModifier(LootTables.VILLAGE_PLAINS_CHEST, + () -> CustomItems.TOMATO, + UniformLootNumberProvider.create(0, 16.0f) + ), + new LootModifier(LootTables.VILLAGE_SAVANNA_HOUSE_CHEST, + () -> CustomItems.TOMATO, + UniformLootNumberProvider.create(0, 16.0f) + ) + ); + + public static final BottleItem TOMATO_SAUCE = new BottleItem("tomato_sauce", + new Settings().food(new FoodComponent.Builder().hunger(4).saturationModifier(1.125f).build()) + .rarity(Rarity.COMMON) + ); + } diff --git a/src/main/java/dev/jaxydog/utility/LootModifier.java b/src/main/java/dev/jaxydog/utility/LootModifier.java index 0ac8160..e5c0cd1 100644 --- a/src/main/java/dev/jaxydog/utility/LootModifier.java +++ b/src/main/java/dev/jaxydog/utility/LootModifier.java @@ -1,9 +1,6 @@ package dev.jaxydog.utility; import dev.jaxydog.utility.register.Registerable; -import java.util.LinkedList; -import java.util.List; -import java.util.function.Supplier; import net.fabricmc.fabric.api.loot.v2.LootTableEvents; import net.minecraft.item.Item; import net.minecraft.loot.LootPool; @@ -11,36 +8,41 @@ import net.minecraft.loot.provider.number.LootNumberProvider; import net.minecraft.util.Identifier; +import java.util.LinkedList; +import java.util.List; +import java.util.function.Supplier; + public class LootModifier implements Registerable.Main { - private final Identifier TABLE_ID; - private final Supplier ITEM; - private final List PROVIDERS = new LinkedList<>(); + private final Identifier TABLE_ID; + private final Supplier ITEM; + private final List PROVIDERS = new LinkedList<>(); + + public LootModifier(Identifier tableId, Supplier item, LootNumberProvider... providers) { + this.TABLE_ID = tableId; + this.ITEM = item; + this.PROVIDERS.addAll(List.of(providers)); + } - public LootModifier(Identifier tableId, Supplier item, LootNumberProvider... providers) { - this.TABLE_ID = tableId; - this.ITEM = item; - this.PROVIDERS.addAll(List.of(providers)); - } + @Override + public String getRawId() { + throw new UnsupportedOperationException("The 'LootModifier' class does not have its own identifier"); + } - @Override - public String getRawId() { - throw new UnsupportedOperationException("The 'LootModifier' class does not have its own identifier"); - } + @Override + public void registerMain() { + Main.super.registerMain(); - @Override - public void registerMain() { - Main.super.registerMain(); + LootTableEvents.MODIFY.register((resource, loot, id, table, source) -> { + if (!id.equals(this.TABLE_ID) || !source.isBuiltin()) return; - LootTableEvents.MODIFY.register((resource, loot, id, table, source) -> { - if (!id.equals(this.TABLE_ID) || !source.isBuiltin()) return; + for (var provider : this.PROVIDERS) { + var entry = ItemEntry.builder(this.ITEM.get()); + var builder = LootPool.builder().rolls(provider).with(entry); - for (var provider : this.PROVIDERS) { - var entry = ItemEntry.builder(this.ITEM.get()); - var builder = LootPool.builder().rolls(provider).with(entry); + table.pool(builder.build()); + } + }); + } - table.pool(builder.build()); - } - }); - } } diff --git a/src/main/java/dev/jaxydog/utility/register/AutoRegister.java b/src/main/java/dev/jaxydog/utility/register/AutoRegister.java index f2813cd..803235f 100644 --- a/src/main/java/dev/jaxydog/utility/register/AutoRegister.java +++ b/src/main/java/dev/jaxydog/utility/register/AutoRegister.java @@ -8,9 +8,11 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface AutoRegister { - public boolean client() default true; - public boolean main() default true; + boolean client() default true; + + boolean main() default true; + + boolean server() default true; - public boolean server() default true; } diff --git a/src/main/java/dev/jaxydog/utility/register/AutoRegisterImpl.java b/src/main/java/dev/jaxydog/utility/register/AutoRegisterImpl.java index f8b0bce..3ebc687 100644 --- a/src/main/java/dev/jaxydog/utility/register/AutoRegisterImpl.java +++ b/src/main/java/dev/jaxydog/utility/register/AutoRegisterImpl.java @@ -3,111 +3,106 @@ import dev.jaxydog.Cheese; import dev.jaxydog.content.block.CustomBlocks; import dev.jaxydog.content.item.CustomItems; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + public final class AutoRegisterImpl { - public static final Class[] DEFINITIONS_CLASSES = new Class[] { CustomBlocks.class, CustomItems.class }; - - private AutoRegisterImpl() {} - - private static void run(RegisterEnv env, Class definitions) { - if (!definitions.isAnnotationPresent(AutoRegister.class)) return; - if (!env.shouldRegister(definitions.getAnnotation(AutoRegister.class))) return; - - for (var field : definitions.getFields()) { - if (field.isAnnotationPresent(SkipRegistration.class)) { - if (env.shouldSkip(field.getAnnotation(SkipRegistration.class))) continue; - } - - var modifiers = field.getModifiers(); - - if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) continue; - - try { - var value = field.get(null); - - if (!env.getInterface().isInstance(value)) continue; - - env.getMethod().invoke(value); - } catch (Exception e) { - Cheese.LOGGER.error(e.getLocalizedMessage()); - } - } - } - - private static void run(RegisterEnv env) { - for (var definitions : AutoRegisterImpl.DEFINITIONS_CLASSES) { - AutoRegisterImpl.run(env, definitions); - } - } - - @Environment(EnvType.CLIENT) - public static void runClient() { - AutoRegisterImpl.run(RegisterEnv.CLIENT); - } - - public static void runMain() { - AutoRegisterImpl.run(RegisterEnv.MAIN); - } - - @Environment(EnvType.SERVER) - public static void runServer() { - AutoRegisterImpl.run(RegisterEnv.SERVER); - } - - private static enum RegisterEnv { - CLIENT(Registerable.Client.class, "registerClient"), - MAIN(Registerable.Main.class, "registerMain"), - SERVER(Registerable.Server.class, "registerServer"); - - private final Class INTERFACE; - private final String METHOD_NAME; - - private RegisterEnv(Class iface, String methodName) { - this.INTERFACE = iface; - this.METHOD_NAME = methodName; - } - - public Class getInterface() { - return this.INTERFACE; - } - - public String getMethodName() { - return this.METHOD_NAME; - } - - public Method getMethod() throws NoSuchMethodException { - return this.getInterface().getMethod(this.getMethodName()); - } - - public boolean shouldRegister(AutoRegister annotation) { - switch (this) { - case CLIENT: - return annotation.client(); - case MAIN: - return annotation.main(); - case SERVER: - return annotation.server(); - } - - return false; - } - - public boolean shouldSkip(SkipRegistration annotation) { - switch (this) { - case CLIENT: - return annotation.client(); - case MAIN: - return annotation.main(); - case SERVER: - return annotation.server(); - } - - return false; - } - } + public static final Class[] DEFINITIONS_CLASSES = new Class[] { CustomBlocks.class, CustomItems.class }; + + private AutoRegisterImpl() {} + + private static void run(RegisterEnv env, Class definitions) { + if (!definitions.isAnnotationPresent(AutoRegister.class)) return; + if (!env.shouldRegister(definitions.getAnnotation(AutoRegister.class))) return; + + for (var field : definitions.getFields()) { + if (field.isAnnotationPresent(SkipRegistration.class)) { + if (env.shouldSkip(field.getAnnotation(SkipRegistration.class))) continue; + } + + var modifiers = field.getModifiers(); + + if (!(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers))) continue; + + try { + var value = field.get(null); + + if (!env.getInterface().isInstance(value)) continue; + + env.getMethod().invoke(value); + } catch (Exception e) { + Cheese.LOGGER.error(e.getLocalizedMessage()); + } + } + } + + private static void run(RegisterEnv env) { + for (var definitions : AutoRegisterImpl.DEFINITIONS_CLASSES) { + AutoRegisterImpl.run(env, definitions); + } + } + + @Environment(EnvType.CLIENT) + public static void runClient() { + AutoRegisterImpl.run(RegisterEnv.CLIENT); + } + + public static void runMain() { + AutoRegisterImpl.run(RegisterEnv.MAIN); + } + + @SuppressWarnings("unused") + @Environment(EnvType.SERVER) + public static void runServer() { + AutoRegisterImpl.run(RegisterEnv.SERVER); + } + + private enum RegisterEnv { + CLIENT(Registerable.Client.class, "registerClient"), + MAIN(Registerable.Main.class, "registerMain"), + SERVER(Registerable.Server.class, "registerServer"); + + private final Class INTERFACE; + private final String METHOD_NAME; + + RegisterEnv(Class iface, String methodName) { + this.INTERFACE = iface; + this.METHOD_NAME = methodName; + } + + public Class getInterface() { + return this.INTERFACE; + } + + public String getMethodName() { + return this.METHOD_NAME; + } + + public Method getMethod() throws NoSuchMethodException { + return this.getInterface().getMethod(this.getMethodName()); + } + + public boolean shouldRegister(AutoRegister annotation) { + return switch (this) { + case CLIENT -> annotation.client(); + case MAIN -> annotation.main(); + case SERVER -> annotation.server(); + }; + + } + + public boolean shouldSkip(SkipRegistration annotation) { + return switch (this) { + case CLIENT -> annotation.client(); + case MAIN -> annotation.main(); + case SERVER -> annotation.server(); + }; + + } + } + } diff --git a/src/main/java/dev/jaxydog/utility/register/Identifiable.java b/src/main/java/dev/jaxydog/utility/register/Identifiable.java index 9360498..26baeed 100644 --- a/src/main/java/dev/jaxydog/utility/register/Identifiable.java +++ b/src/main/java/dev/jaxydog/utility/register/Identifiable.java @@ -4,9 +4,11 @@ import net.minecraft.util.Identifier; public interface Identifiable { - public String getRawId(); - public default Identifier getId() { - return Cheese.newId(this.getRawId()); - } + String getRawId(); + + default Identifier getId() { + return Cheese.newId(this.getRawId()); + } + } diff --git a/src/main/java/dev/jaxydog/utility/register/Registerable.java b/src/main/java/dev/jaxydog/utility/register/Registerable.java index e155083..c3edcef 100644 --- a/src/main/java/dev/jaxydog/utility/register/Registerable.java +++ b/src/main/java/dev/jaxydog/utility/register/Registerable.java @@ -1,15 +1,24 @@ package dev.jaxydog.utility.register; public interface Registerable extends Identifiable { - public static interface Client extends Registerable { - public default void registerClient() {} - } - public static interface Main extends Registerable { - public default void registerMain() {} - } + interface Client extends Registerable { + + default void registerClient() {} + + } + + interface Main extends Registerable { + + default void registerMain() {} + + } + + interface Server extends Registerable { + + @SuppressWarnings("unused") + default void registerServer() {} + + } - public static interface Server extends Registerable { - public default void registerServer() {} - } } diff --git a/src/main/java/dev/jaxydog/utility/register/SkipRegistration.java b/src/main/java/dev/jaxydog/utility/register/SkipRegistration.java index 7cf9bc6..2023deb 100644 --- a/src/main/java/dev/jaxydog/utility/register/SkipRegistration.java +++ b/src/main/java/dev/jaxydog/utility/register/SkipRegistration.java @@ -1,9 +1,15 @@ package dev.jaxydog.utility.register; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) public @interface SkipRegistration { - public boolean client() default true; - public boolean main() default true; + boolean client() default true; + + boolean main() default true; + + boolean server() default true; - public boolean server() default true; } diff --git a/src/main/resources/cheese.mixins.json b/src/main/resources/cheese.mixins.json index 77a10ae..85fdbf7 100644 --- a/src/main/resources/cheese.mixins.json +++ b/src/main/resources/cheese.mixins.json @@ -2,7 +2,7 @@ "required": true, "package": "dev.jaxydog.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [], + "mixins": [ ], "injectors": { "defaultRequire": 1 } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f7a56e2..a1ad6a2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,27 +1,26 @@ { - "schemaVersion": 1, - "id": "cheese", - "version": "${version}", - "name": "Cheese", - "description": "Small mod to add cheese and cheese-adjacent items into Minecraft", - "authors": [ "Jaxydog" ], - "contact": { - "sources": "https://github.com/Jaxydog/Cheese", - "issues": "https://github.com/Jaxydog/Cheese/issues" - }, - "license": "MIT", - "icon": "assets/cheese/icon.png", - "environment": "*", - "entrypoints": { - "main": [ "dev.jaxydog.Cheese" ], - "client": [ "dev.jaxydog.CheeseClient" ] - }, - "mixins": [ "cheese.mixins.json" ], - "depends": { - "fabricloader": ">=0.14.24", - "minecraft": "~1.20.2", - "java": ">=17", - "fabric-api": "*" - }, - "suggests": { } + "schemaVersion": 1, + "id": "cheese", + "version": "${version}", + "name": "Cheese", + "description": "Small mod to add cheese and cheese-adjacent items into Minecraft", + "authors": [ "Jaxydog" ], + "contact": { + "sources": "https://github.com/Jaxydog/Cheese", + "issues": "https://github.com/Jaxydog/Cheese/issues" + }, + "license": "MIT", + "icon": "assets/cheese/icon.png", + "environment": "*", + "entrypoints": { + "main": [ "dev.jaxydog.Cheese" ], + "client": [ "dev.jaxydog.CheeseClient" ] + }, + "mixins": [ "cheese.mixins.json" ], + "depends": { + "fabricloader": ">=0.15.7", + "minecraft": "~1.20.4", + "java": ">=17", + "fabric-api": "*" + } }