Skip to content

Commit

Permalink
v0.0.1 - Player Vaults & Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyarin215 committed Nov 3, 2024
1 parent 70ded47 commit 1651f45
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 81 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.examplemod;
package com.doublepi.taus_economy;

import java.util.List;
import java.util.Set;
Expand All @@ -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<String> 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<List<? extends String>> 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<Item> items;

private static boolean validateItemName(final Object obj)
Expand All @@ -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();

}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<CreativeModeTab> 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<Block> 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<BlockItem> 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<Item> 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<CreativeModeTab, CreativeModeTab> 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.
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PlayerVaultBlock> CODEC = simpleCodec(PlayerVaultBlock::new);
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

public PlayerVaultBlock(Properties properties) {
super(properties);
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return CODEC;
}

@Override
protected RenderShape getRenderShape(BlockState pState) {
return RenderShape.MODEL;
}


@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}


}
61 changes: 61 additions & 0 deletions src/main/java/com/doublepi/taus_economy/registries/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -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<BlockEntityType<?>> BLOCK_ENTITIES =
DeferredRegister.create(BuiltInRegistries.BLOCK_ENTITY_TYPE, TausEconomy.MOD_ID);

//Player Vault
public static final DeferredBlock<Block> 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<BlockEntityType<PlayerVaultBlockEntity>> 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 <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block){
DeferredBlock<T> toReturn = BLOCKS.register(name,block);
registerBlockItem(name,toReturn);
return toReturn;
}
private static <T extends Block> void registerBlockItem(String name, DeferredBlock<T> 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);
}
}


31 changes: 31 additions & 0 deletions src/main/java/com/doublepi/taus_economy/registries/ModEvents.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/doublepi/taus_economy/registries/ModItems.java
Original file line number Diff line number Diff line change
@@ -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<Item> TOKEN = ITEMS.register("token",
()-> new Item(new Item.Properties()));


public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
}
}
Loading

0 comments on commit 1651f45

Please sign in to comment.