diff --git a/gradle.properties b/gradle.properties index 215002e..7b6f045 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ minecraft_version=1.21.1 # The Minecraft version range can use any release version of Minecraft as bounds. # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # as they do not follow standard versioning conventions. -minecraft_version_range=[1.21.1, 1.22) +minecraft_version_range=[1.21, 1.21.1] # The Neo version must agree with the Minecraft version to get a valid artifact neo_version=21.1.73 # The Neo version range can use any version of Neo as bounds @@ -28,18 +28,18 @@ loader_version_range=[4,) # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. -mod_id=examplemod +mod_id=taus_economy # The human-readable display name for the mod. -mod_name=Example Mod +mod_name=Tau's Economy # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. -mod_license=All Rights Reserved +mod_license=MIT # The mod version. See https://semver.org/ -mod_version=1.0.0 +mod_version=0.0.1 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html -mod_group_id=com.example.examplemod +mod_group_id=com.doublepi.taus_economy # The authors of the mod. This is a simple text string that is used for display purposes in the mod list. -mod_authors=YourNameHere, OtherNameHere +mod_authors=Tau # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. mod_description=Example mod description.\nNewline characters can be used and will be replaced properly. diff --git a/src/main/java/com/example/examplemod/Config.java b/src/main/java/com/doublepi/taus_economy/Config.java similarity index 51% rename from src/main/java/com/example/examplemod/Config.java rename to src/main/java/com/doublepi/taus_economy/Config.java index d70d1eb..673e6c0 100644 --- a/src/main/java/com/example/examplemod/Config.java +++ b/src/main/java/com/doublepi/taus_economy/Config.java @@ -1,4 +1,4 @@ -package com.example.examplemod; +package com.doublepi.taus_economy; import java.util.List; import java.util.Set; @@ -14,33 +14,34 @@ // An example config class. This is not required, but it's a good idea to have one to keep your config organized. // Demonstrates how to use Neo's config APIs -@EventBusSubscriber(modid = ExampleMod.MODID, bus = EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = TausEconomy.MOD_ID, bus = EventBusSubscriber.Bus.MOD) public class Config { private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder(); - private static final ModConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER - .comment("Whether to log the dirt block on common setup") - .define("logDirtBlock", true); + private static final ModConfigSpec.IntValue TOKENS_PER_TASK = BUILDER + .comment("The number of tokens given to the player after completing a task:") + .defineInRange("tokens_per_task",1,0,64); - private static final ModConfigSpec.IntValue MAGIC_NUMBER = BUILDER - .comment("A magic number") - .defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE); + private static final ModConfigSpec.IntValue TOKENS_PER_GOAL = BUILDER + .comment("The number of tokens given to the player after completing a goal:") + .defineInRange("tokens_per_goal",3,0,64); + + private static final ModConfigSpec.IntValue TOKENS_PER_CHALLENGE = BUILDER + .comment("The number of tokens given to the player after completing a challenge:") + .defineInRange("tokens_per_challenge",5,0,64); public static final ModConfigSpec.ConfigValue MAGIC_NUMBER_INTRODUCTION = BUILDER .comment("What you want the introduction message to be for the magic number") .define("magicNumberIntroduction", "The magic number is... "); - // a list of strings that are treated as resource locations for items - private static final ModConfigSpec.ConfigValue> ITEM_STRINGS = BUILDER - .comment("A list of items to log on common setup.") - .defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), Config::validateItemName); static final ModConfigSpec SPEC = BUILDER.build(); public static boolean logDirtBlock; - public static int magicNumber; - public static String magicNumberIntroduction; + public static int token_per_task; + public static int token_per_goal; + public static int token_per_challenge; public static Set items; private static boolean validateItemName(final Object obj) @@ -51,13 +52,9 @@ private static boolean validateItemName(final Object obj) @SubscribeEvent static void onLoad(final ModConfigEvent event) { - logDirtBlock = LOG_DIRT_BLOCK.get(); - magicNumber = MAGIC_NUMBER.get(); - magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get(); - - // convert the list of strings into a set of items - items = ITEM_STRINGS.get().stream() - .map(itemName -> BuiltInRegistries.ITEM.get(ResourceLocation.parse(itemName))) - .collect(Collectors.toSet()); + token_per_task = TOKENS_PER_TASK.get(); + token_per_goal = TOKENS_PER_GOAL.get(); + token_per_challenge = TOKENS_PER_CHALLENGE.get(); + } } diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/doublepi/taus_economy/TausEconomy.java similarity index 52% rename from src/main/java/com/example/examplemod/ExampleMod.java rename to src/main/java/com/doublepi/taus_economy/TausEconomy.java index 835a48d..b1c4727 100644 --- a/src/main/java/com/example/examplemod/ExampleMod.java +++ b/src/main/java/com/doublepi/taus_economy/TausEconomy.java @@ -1,5 +1,9 @@ -package com.example.examplemod; +package com.doublepi.taus_economy; +import com.doublepi.taus_economy.registries.ModBlocks; +import com.doublepi.taus_economy.registries.ModEvents; +import com.doublepi.taus_economy.registries.ModItems; +import com.doublepi.taus_economy.registries.ModTabs; import org.slf4j.Logger; import com.mojang.logging.LogUtils; @@ -35,52 +39,24 @@ import net.neoforged.neoforge.registries.DeferredRegister; // The value here should match an entry in the META-INF/neoforge.mods.toml file -@Mod(ExampleMod.MODID) -public class ExampleMod +@Mod(TausEconomy.MOD_ID) +public class TausEconomy { // Define mod id in a common place for everything to reference - public static final String MODID = "examplemod"; + public static final String MOD_ID = "taus_economy"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); - // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace - public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID); - // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace - public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID); - // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace - public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); - - // Creates a new Block with the id "examplemod:example_block", combining the namespace and path - public static final DeferredBlock EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE)); - // Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path - public static final DeferredItem EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK); - - // Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2 - public static final DeferredItem EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder() - .alwaysEdible().nutrition(1).saturationModifier(2f).build())); - - // Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab - public static final DeferredHolder EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder() - .title(Component.translatable("itemGroup.examplemod")) //The language key for the title of your CreativeModeTab - .withTabsBefore(CreativeModeTabs.COMBAT) - .icon(() -> EXAMPLE_ITEM.get().getDefaultInstance()) - .displayItems((parameters, output) -> { - output.accept(EXAMPLE_ITEM.get()); // Add the example item to the tab. For your own tabs, this method is preferred over the event - }).build()); // The constructor for the mod class is the first code that is run when your mod is loaded. // FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically. - public ExampleMod(IEventBus modEventBus, ModContainer modContainer) + public TausEconomy(IEventBus modEventBus, ModContainer modContainer) { // Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); - // Register the Deferred Register to the mod event bus so blocks get registered - BLOCKS.register(modEventBus); - // Register the Deferred Register to the mod event bus so items get registered - ITEMS.register(modEventBus); - // Register the Deferred Register to the mod event bus so tabs get registered - CREATIVE_MODE_TABS.register(modEventBus); - + ModItems.register(modEventBus); + ModBlocks.register(modEventBus); + ModEvents.register(); // Register ourselves for server and other game events we are interested in. // Note that this is necessary if and only if we want *this* class (ExampleMod) to respond directly to events. // Do not add this line if there are no @SubscribeEvent-annotated functions in this class, like onServerStarting() below. @@ -95,22 +71,13 @@ public ExampleMod(IEventBus modEventBus, ModContainer modContainer) private void commonSetup(final FMLCommonSetupEvent event) { - // Some common setup code - LOGGER.info("HELLO FROM COMMON SETUP"); - - if (Config.logDirtBlock) - LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); - - LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber); - Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString())); } // Add the example block item to the building blocks tab private void addCreative(BuildCreativeModeTabContentsEvent event) { - if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) - event.accept(EXAMPLE_BLOCK_ITEM); + ModTabs.addToExistingTabs(event); } // You can use SubscribeEvent and let the Event Bus discover methods to call @@ -122,7 +89,7 @@ public void onServerStarting(ServerStartingEvent event) } // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent - @EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) + @EventBusSubscriber(modid = MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { @SubscribeEvent diff --git a/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlock.java b/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlock.java new file mode 100644 index 0000000..ab8fc42 --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlock.java @@ -0,0 +1,59 @@ +package com.doublepi.taus_economy.blocks; + +import com.mojang.serialization.MapCodec; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import org.jetbrains.annotations.Nullable; + +public class PlayerVaultBlock extends BaseEntityBlock { + public static final MapCodec CODEC = simpleCodec(PlayerVaultBlock::new); + public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; + + public PlayerVaultBlock(Properties properties) { + super(properties); + } + + @Override + protected MapCodec codec() { + return CODEC; + } + + @Override + protected RenderShape getRenderShape(BlockState pState) { + return RenderShape.MODEL; + } + + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(FACING); + } + + @Override + public BlockState rotate(BlockState state, LevelAccessor level, BlockPos pos, Rotation direction) { + return state.setValue(FACING, direction.rotate(state.getValue(FACING))); + } + + @Override + protected BlockState mirror(BlockState state, Mirror mirror) { + return state.rotate(mirror.getRotation(state.getValue(FACING))); + } + + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + return this.defaultBlockState() + .setValue(FACING, context.getHorizontalDirection().getOpposite()); + } + + @Override + public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { + return new PlayerVaultBlockEntity(blockPos,blockState); + } +} diff --git a/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlockEntity.java b/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlockEntity.java new file mode 100644 index 0000000..10e6206 --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/blocks/PlayerVaultBlockEntity.java @@ -0,0 +1,14 @@ +package com.doublepi.taus_economy.blocks; + +import com.doublepi.taus_economy.registries.ModBlocks; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; + +public class PlayerVaultBlockEntity extends BlockEntity { + public PlayerVaultBlockEntity(BlockPos pos, BlockState blockState) { + super(ModBlocks.PLAYER_VAULT_BE.get(), pos, blockState); + } + + +} diff --git a/src/main/java/com/doublepi/taus_economy/registries/ModBlocks.java b/src/main/java/com/doublepi/taus_economy/registries/ModBlocks.java new file mode 100644 index 0000000..0a5be70 --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/registries/ModBlocks.java @@ -0,0 +1,61 @@ +package com.doublepi.taus_economy.registries; + +import com.doublepi.taus_economy.TausEconomy; +import com.doublepi.taus_economy.blocks.PlayerVaultBlock; +import com.doublepi.taus_economy.blocks.PlayerVaultBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.VaultBlock; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; +import net.minecraft.world.level.material.MapColor; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredBlock; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.function.Supplier; + +public class ModBlocks { + + //Deferred Register + public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(TausEconomy.MOD_ID); + public static final DeferredRegister> BLOCK_ENTITIES = + DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, TausEconomy.MOD_ID); + + //Player Vault + public static final DeferredBlock PLAYER_VAULT = registerBlock("player_vault", + ()-> new PlayerVaultBlock(BlockBehaviour.Properties.of() + .mapColor(MapColor.STONE).instrument(NoteBlockInstrument.BASEDRUM) + .noOcclusion().sound(SoundType.VAULT).strength(50).lightLevel((blockState)->7) + .isViewBlocking(ModBlocks::never))); + + public static final Supplier> PLAYER_VAULT_BE = + BLOCK_ENTITIES.register("player_vault_be", () -> BlockEntityType.Builder.of( + PlayerVaultBlockEntity::new, ModBlocks.PLAYER_VAULT.get()).build(null)); + + private static boolean never(BlockState state, BlockGetter blockGetter, BlockPos pos) { + return false; + } + private static DeferredBlock registerBlock(String name, Supplier block){ + DeferredBlock toReturn = BLOCKS.register(name,block); + registerBlockItem(name,toReturn); + return toReturn; + } + private static void registerBlockItem(String name, DeferredBlock block){ + ModItems.ITEMS.register(name, ()-> new BlockItem(block.get(), new Item.Properties())); + } + public static void register(IEventBus eventBus){ + BLOCKS.register(eventBus); + BLOCK_ENTITIES.register(eventBus); + } +} + + diff --git a/src/main/java/com/doublepi/taus_economy/registries/ModEvents.java b/src/main/java/com/doublepi/taus_economy/registries/ModEvents.java new file mode 100644 index 0000000..81d6caf --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/registries/ModEvents.java @@ -0,0 +1,31 @@ +package com.doublepi.taus_economy.registries; + +import com.doublepi.taus_economy.Config; +import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.AdvancementType; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.entity.player.AdvancementEvent; + +public class ModEvents { + + public static void register(){ + NeoForge.EVENT_BUS.addListener(ModEvents::giveToken); + } + + private static void giveToken(AdvancementEvent.AdvancementEarnEvent event){ + Advancement advancement = event.getAdvancement().value(); + Player player = event.getEntity(); + AdvancementType type = advancement.display().get().getType(); + + if(type == AdvancementType.TASK) + player.addItem(new ItemStack(ModItems.TOKEN.get(), Config.token_per_task)); + if(type == AdvancementType.GOAL) + player.addItem(new ItemStack(ModItems.TOKEN.get(),Config.token_per_goal)); + if(type == AdvancementType.CHALLENGE) + player.addItem(new ItemStack(ModItems.TOKEN.get(),Config.token_per_challenge)); + } +} diff --git a/src/main/java/com/doublepi/taus_economy/registries/ModItems.java b/src/main/java/com/doublepi/taus_economy/registries/ModItems.java new file mode 100644 index 0000000..6d83416 --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/registries/ModItems.java @@ -0,0 +1,20 @@ +package com.doublepi.taus_economy.registries; + +import com.doublepi.taus_economy.TausEconomy; +import net.minecraft.world.item.Item; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; + +public class ModItems { + + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(TausEconomy.MOD_ID); + + public static final DeferredItem TOKEN = ITEMS.register("token", + ()-> new Item(new Item.Properties())); + + + public static void register(IEventBus eventBus) { + ITEMS.register(eventBus); + } +} diff --git a/src/main/java/com/doublepi/taus_economy/registries/ModTabs.java b/src/main/java/com/doublepi/taus_economy/registries/ModTabs.java new file mode 100644 index 0000000..7105d75 --- /dev/null +++ b/src/main/java/com/doublepi/taus_economy/registries/ModTabs.java @@ -0,0 +1,15 @@ +package com.doublepi.taus_economy.registries; + +import net.minecraft.world.item.CreativeModeTabs; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; + +public class ModTabs { + + + public static void addToExistingTabs(BuildCreativeModeTabContentsEvent event){ + if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) + event.accept(ModBlocks.PLAYER_VAULT); + if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) + event.accept(ModItems.TOKEN); + } +} diff --git a/src/main/resources/assets/examplemod/lang/en_us.json b/src/main/resources/assets/examplemod/lang/en_us.json deleted file mode 100644 index 3b34651..0000000 --- a/src/main/resources/assets/examplemod/lang/en_us.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "itemGroup.examplemod": "Example Mod Tab", - "block.examplemod.example_block": "Example Block", - "item.examplemod.example_item": "Example Item" -} diff --git a/src/main/resources/assets/taus_economy/blockstates/player_vault.json b/src/main/resources/assets/taus_economy/blockstates/player_vault.json new file mode 100644 index 0000000..1355aca --- /dev/null +++ b/src/main/resources/assets/taus_economy/blockstates/player_vault.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=east": { + "model": "minecraft:block/vault_active", + "y": 90 + }, + "facing=north": { + "model": "minecraft:block/vault_active" + }, + "facing=south": { + "model": "minecraft:block/vault_active", + "y": 180 + }, + "facing=west": { + "model": "minecraft:block/vault_active", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/taus_economy/lang/en_us.json b/src/main/resources/assets/taus_economy/lang/en_us.json new file mode 100644 index 0000000..4b7245f --- /dev/null +++ b/src/main/resources/assets/taus_economy/lang/en_us.json @@ -0,0 +1,4 @@ +{ + "item.taus_economy.token": "Advancement Token", + "block.taus_economy.player_vault": "Player Vault" +} diff --git a/src/main/resources/assets/taus_economy/models/item/player_vault.json b/src/main/resources/assets/taus_economy/models/item/player_vault.json new file mode 100644 index 0000000..848fa30 --- /dev/null +++ b/src/main/resources/assets/taus_economy/models/item/player_vault.json @@ -0,0 +1,3 @@ +{ + "parent": "minecraft:block/vault" +} \ No newline at end of file diff --git a/src/main/resources/assets/taus_economy/models/item/token.json b/src/main/resources/assets/taus_economy/models/item/token.json new file mode 100644 index 0000000..6d5037e --- /dev/null +++ b/src/main/resources/assets/taus_economy/models/item/token.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "taus_economy:item/token" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/taus_economy/textures/item/token.png b/src/main/resources/assets/taus_economy/textures/item/token.png new file mode 100644 index 0000000..b50f5a2 Binary files /dev/null and b/src/main/resources/assets/taus_economy/textures/item/token.png differ