Skip to content

Commit

Permalink
feat: Add Flag of Ireland and started base flag code
Browse files Browse the repository at this point in the history
  • Loading branch information
GaeaKat committed Aug 18, 2024
1 parent 3e75787 commit 7eed6df
Show file tree
Hide file tree
Showing 25 changed files with 479 additions and 141 deletions.
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ group = mod_group_id

repositories {
mavenLocal()
maven {
name = 'GeckoLib'
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
content {
includeGroup("software.bernie.geckolib")
}
}
maven { // JEI
url "https://maven.blamejared.com"
}
maven { // TOP
url "https://maven.k-4u.nl"
}
}

base {
Expand Down Expand Up @@ -122,7 +135,12 @@ dependencies {
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"
implementation "software.bernie.geckolib:geckolib-neoforge-${minecraft_version}:${geckolib_version}"
compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}"
compileOnly "mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}"
runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"

implementation "mcjty.theoneprobe:theoneprobe:${top_version}"
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ mod_group_id=irish.eimi.bratacha
mod_authors=Eimi-Codes, GaeaKat
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=A mod to add flags to Minecraft

# Dependencies
geckolib_version=4.5.6
jei_version=19.8.2.99
top_version=1.21_neo-12.0.3-5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.21 2024-08-18T01:17:53.362797 Languages: en_us for mod: bratacha
d92039e67986396c9d9fbee3ca06a6d89a33d74e assets/bratacha/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.21 2024-08-18T01:14:13.725058 Item Models: bratacha
cf8093f06e45e999b05e55f9ba4ebb156029e5c0 assets/bratacha/models/item/flag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.21 2024-08-18T01:21:47.558581 Languages: ga_ie for mod: bratacha
b2db30ced2ae2bc64e1dbcf041da6c2104d3a439 assets/bratacha/lang/ga_ie.json
3 changes: 3 additions & 0 deletions src/generated/resources/assets/bratacha/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"block.bratacha.flag": "Flag of Ireland"
}
3 changes: 3 additions & 0 deletions src/generated/resources/assets/bratacha/lang/ga_ie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"block.bratacha.flag": "Bratach na hÉireann"
}
6 changes: 6 additions & 0 deletions src/generated/resources/assets/bratacha/models/item/flag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "bratacha:item/flag"
}
}
83 changes: 5 additions & 78 deletions src/main/java/irish/eimi/bratacha/BratachaMod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package irish.eimi.bratacha;

import irish.eimi.bratacha.common.datagen.DataGeneration;
import irish.eimi.bratacha.common.init.Registration;
import org.slf4j.Logger;

import com.mojang.logging.LogUtils;
Expand Down Expand Up @@ -42,95 +44,20 @@ public class BratachaMod
public static final String MODID = "bratacha";
// 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 BratachaMod(IEventBus modEventBus, ModContainer modContainer)
{
// Register the commonSetup method for modloading
Registration.init(modEventBus);
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);

// 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.
NeoForge.EVENT_BUS.register(this);

// Register the item to a creative tab
modEventBus.addListener(this::addCreative);

// Register our mod's ModConfigSpec so that FML can create and load the config file for us
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
modEventBus.addListener(Registration::addCreative);
modEventBus.addListener(DataGeneration::generate);
}

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);
}

// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event)
{
// Do something when the server starts
LOGGER.info("HELLO from server starting");
}

// 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)
public static class ClientModEvents
{
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event)
{
// Some client setup code
LOGGER.info("HELLO FROM CLIENT SETUP");
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
}
}
}
63 changes: 0 additions & 63 deletions src/main/java/irish/eimi/bratacha/Config.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/irish/eimi/bratacha/client/BratachaModClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package irish.eimi.bratacha.client;

import irish.eimi.bratacha.BratachaMod;
import irish.eimi.bratacha.client.init.RegistrationClient;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;

@Mod(value = BratachaMod.MODID, dist = Dist.CLIENT)
public class BratachaModClient {

public BratachaModClient(IEventBus modBus) {
modBus.addListener(RegistrationClient::registerRenders);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package irish.eimi.bratacha.client.init;

import irish.eimi.bratacha.client.renderer.block.FlagBlockEntityRenderer;
import irish.eimi.bratacha.common.entities.blocks.FlagBlockEntity;
import irish.eimi.bratacha.common.init.Registration;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;

public class RegistrationClient {

public static void registerRenders(final EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(Registration.FLAG_BLOCK_ENTITY.get(),
FlagBlockEntityRenderer::new);
}
}
23 changes: 23 additions & 0 deletions src/main/java/irish/eimi/bratacha/client/models/FlagModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package irish.eimi.bratacha.client.models;

import irish.eimi.bratacha.BratachaMod;
import irish.eimi.bratacha.common.entities.blocks.FlagBlockEntity;
import net.minecraft.resources.ResourceLocation;
import software.bernie.geckolib.model.GeoModel;

public class FlagModel extends GeoModel<FlagBlockEntity> {
@Override
public ResourceLocation getModelResource(FlagBlockEntity animatable) {
return ResourceLocation.fromNamespaceAndPath(BratachaMod.MODID,"geo/block/flag.geo.json");
}

@Override
public ResourceLocation getTextureResource(FlagBlockEntity animatable) {
return ResourceLocation.fromNamespaceAndPath(BratachaMod.MODID,"textures/block/flag.png");
}

@Override
public ResourceLocation getAnimationResource(FlagBlockEntity animatable) {
return ResourceLocation.fromNamespaceAndPath(BratachaMod.MODID,"animations/block/flag.animation.json");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package irish.eimi.bratacha.client.renderer.block;

import irish.eimi.bratacha.client.models.FlagModel;
import irish.eimi.bratacha.common.entities.blocks.FlagBlockEntity;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer;

public class FlagBlockEntityRenderer extends GeoBlockRenderer<FlagBlockEntity> {
public FlagBlockEntityRenderer(BlockEntityRendererProvider.Context context) {
super(new FlagModel());
}
}
71 changes: 71 additions & 0 deletions src/main/java/irish/eimi/bratacha/common/blocks/FlagBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package irish.eimi.bratacha.common.blocks;

import com.mojang.serialization.MapCodec;
import irish.eimi.bratacha.common.entities.blocks.FlagBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class FlagBlock extends DirectionalBlock implements EntityBlock {
public static final MapCodec<FlagBlock> CODEC = simpleCodec(FlagBlock::new);
public FlagBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.SOUTH));
}

@Override
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new FlagBlockEntity(blockPos,blockState);
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed blockstate.
*/
@Override
protected BlockState rotate(BlockState state, Rotation rot) {
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
}

/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed blockstate.
*/
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}
@Override
protected RenderShape getRenderShape(BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}


@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return super.getShape(state, level, pos, context);
}

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

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getNearestLookingDirection().getOpposite().getOpposite());
}
}
Loading

0 comments on commit 7eed6df

Please sign in to comment.