0% found this document useful (0 votes)
3 views11 pages

Mod Ding

This document provides a detailed guide on creating a Minecraft mod using Forge for Java Edition that introduces a 'Mystic Apple' item with a speed boost effect and modifies zombie behavior to break wooden doors on Normal difficulty. It includes steps for setting up the modding environment, creating the mod structure, and handling game difficulty changes over time, accounting for player sleep. The guide emphasizes building, testing, and distributing the mod while providing necessary code snippets and explanations for each component.

Uploaded by

James
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Mod Ding

This document provides a detailed guide on creating a Minecraft mod using Forge for Java Edition that introduces a 'Mystic Apple' item with a speed boost effect and modifies zombie behavior to break wooden doors on Normal difficulty. It includes steps for setting up the modding environment, creating the mod structure, and handling game difficulty changes over time, accounting for player sleep. The guide emphasizes building, testing, and distributing the mod while providing necessary code snippets and explanations for each component.

Uploaded by

James
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Creating a Minecraft mod with a simple concept can be an exciting project!

For simplicity, we’ll focus


on making a basic mod using Minecraft Forge for Minecraft Java Edition, which is a popular modding
platform.
Concept: Let's create a simple mod that introduces a new item called a "Mystic Apple" which, when
eaten, gives the player a temporary speed boost.

Steps to Create the Mod


1. Set Up Your Modding Environment
1. Install JDK: You need the Java Development Kit (JDK). Download and install the latest
version from the Oracle JDK website or use OpenJDK.
2. Set Up Forge:
• Download the MDK (Mod Developer Kit) from the Forge website.
• Extract the MDK to a folder of your choice.
3. Set Up Your IDE: Use an IDE like IntelliJ IDEA or Eclipse.
4. Open the Project:
• Open your IDE and import the build.gradle file from the extracted MDK folder as a
Gradle project.
• Run the genEclipseRuns or genIntellijRuns task in Gradle to generate run
configurations.

2. Create the Mod Structure


1. Main Class: Create a main class for your mod.
java
Copy code
// com.example.mysticapple.MysticAppleMod.java
package com.example.mysticapple;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(MysticAppleMod.MODID)
public class MysticAppleMod {
public static final String MODID = "mysticapple";
private static final Logger LOGGER = LogManager.getLogger();

public MysticAppleMod() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
bus.addListener(this::setup);
bus.addListener(this::doClientStuff);
}
private void setup(final FMLCommonSetupEvent event) {
LOGGER.info("HELLO FROM PREINIT");
}

private void doClientStuff(final FMLClientSetupEvent event) {


LOGGER.info("HELLO FROM CLIENT SETUP");
}
}

2. Register the Item: Create a class to register your new item.


java
Copy code
// com.example.mysticapple.ModItems.java
package com.example.mysticapple;

import net.minecraft.item.Item;
import net.minecraft.item.Food;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Item.Properties;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ObjectHolder;

@Mod.EventBusSubscriber(modid = MysticAppleMod.MODID, bus =


Mod.EventBusSubscriber.Bus.MOD)
public class ModItems {
@ObjectHolder(MysticAppleMod.MODID + ":mystic_apple")
public static final Item MYSTIC_APPLE = null;

@SubscribeEvent
public static void registerItems(final RegistryEvent.Register<Item> event) {
event.getRegistry().register(new Item(new Properties()
.group(ItemGroup.FOOD)
.food(new Food.Builder().hunger(4).saturation(1.2f).effect(() -> new
EffectInstance(Effects.SPEED, 600, 1), 1.0f).build()))
.setRegistryName("mystic_apple"));
}
}

3. Add the Item Texture and Model:


• Create a folder structure:
src/main/resources/assets/mysticapple/textures/item.
• Place your item texture (e.g., mystic_apple.png) in this folder.
json
Copy code
// src/main/resources/assets/mysticapple/models/item/mystic_apple.json
{
"parent": "item/generated",
"textures": {
"layer0": "mysticapple:item/mystic_apple"
}
}
4. Add the Language Localization:
• Create a localization file:
src/main/resources/assets/mysticapple/lang/en_us.json.
json
Copy code
{
"item.mysticapple.mystic_apple": "Mystic Apple"
}

5. Add Mod Metadata:


• Modify the mods.toml file in src/main/resources/META-INF/.
toml
Copy code
modLoader="javafml"
loaderVersion="[36,)"
license="MIT"
[[mods]]
modId="mysticapple"
version="1.0"
displayName="Mystic Apple Mod"
description='Adds a mystic apple with special powers.'

3. Build and Test the Mod


1. Build the Mod:
• Use Gradle to build your mod: run gradlew build from your project's root
directory.
2. Test the Mod:
• Copy the generated .jar file from build/libs to your Minecraft mods folder.
• Launch Minecraft with the Forge profile and test the mod in-game.

4. Distribution
• Ensure you comply with licensing for distribution.
• You can share your .jar file or upload it to a modding site like CurseForge.

Tools and Resources


• Forge Documentation: Forge Documentation
• Minecraft Item API: Minecraft Item Documentation
This simple mod introduces a new item with special effects, a great starting point for more complex
projects! Feel free to expand it by adding more features, like custom recipes or effects.
4o
can you give the code for a minecraft 1.16.5 forge mod that lets zombies break wooden doors on
normal difficulty, and also starts the game in peaceful then after 1 minecraft day sets the game to easy,
and then after another 5 minecraft days sets the game to normal
ChatGPT
Certainly! Let's create a Minecraft 1.16.5 Forge mod that modifies zombie behavior to break wooden
doors on Normal difficulty and changes the game difficulty over time.

Overview
1. Zombies Break Wooden Doors:
• On Normal difficulty, zombies will break wooden doors.
2. Difficulty Timer:
• Start the game in Peaceful.
• After 1 Minecraft day (20 minutes), set the difficulty to Easy.
• After another 5 Minecraft days (100 minutes), set the difficulty to Normal.

Step-by-Step Implementation
1. Setup the Modding Environment
Follow the instructions to set up Minecraft Forge and your modding environment from the previous
answer. You should already have the JDK, Forge MDK, and an IDE.

2. Create the Mod Structure


1. Main Class: Create the main class for your mod.
java
Copy code
// com.example.zombiemod.ZombieMod.java
package com.example.zombiemod;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(ZombieMod.MODID)
public class ZombieMod {
public static final String MODID = "zombiemod";

public ZombieMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new DifficultyChanger());
}
private void setup(final FMLCommonSetupEvent event) {
}

private void doClientStuff(final FMLClientSetupEvent event) {


}

@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {

event.getServer().getWorldData().setDifficulty(net.minecraft.world.Difficulty.PEACE
FUL);
}
}

2. Zombie Behavior: Modify zombie behavior to break wooden doors on Normal difficulty.
java
Copy code
// com.example.zombiemod.ZombieDoorBreaking.java
package com.example.zombiemod;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.world.Difficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ZombieMod.MODID, bus =


Mod.EventBusSubscriber.Bus.FORGE)
public class ZombieDoorBreaking {

@SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof ZombieEntity) {
ZombieEntity zombie = (ZombieEntity) event.getEntity();
World world = event.getWorld();

if (world.getDifficulty() == Difficulty.NORMAL) {
zombie.goalSelector.addGoal(1, new
net.minecraft.entity.ai.goal.BreakDoorGoal(zombie,
net.minecraft.block.Blocks.OAK_DOOR));
}
}
}
}

3. Difficulty Changer: Create a class to handle difficulty changes based on in-game time.
java
Copy code
// com.example.zombiemod.DifficultyChanger.java
package com.example.zombiemod;

import net.minecraft.world.Difficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class DifficultyChanger {


private long ticks = 0;
private boolean easySet = false;
private boolean normalSet = false;

@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
return;
}

World world = event.world;


ticks++;

// After 1 day (20 minutes)


if (ticks >= 24000 && !easySet) {
world.getServer().getWorldData().setDifficulty(Difficulty.EASY);
easySet = true;
}

// After another 5 days (total 6 days)


if (ticks >= 144000 && !normalSet) {
world.getServer().getWorldData().setDifficulty(Difficulty.NORMAL);
normalSet = true;
}
}
}

4. Add Mod Metadata: Modify mods.toml file to include your mod's information.
toml
Copy code
modLoader="javafml"
loaderVersion="[36,)"
license="MIT"
[[mods]]
modId="zombiemod"
version="1.0"
displayName="Zombie Mod"
description='Zombies break wooden doors on normal difficulty and game difficulty
changes over time.'

3. Build and Test the Mod


1. Build: Use Gradle to build your mod: run gradlew build from your project's root directory.

2. Test: Copy the generated .jar file from build/libs to your Minecraft mods folder and test
it in-game.

Summary of Classes
• ZombieMod.java: Main class for the mod.
• ZombieDoorBreaking.java: Handles zombie door-breaking behavior.
• DifficultyChanger.java: Changes game difficulty based on the in-game time.
Additional Notes
• Ensure your mod is placed in the src/main/java directory following the package structure.
• Textures and additional resources are not needed for this specific mod.
• Testing in a development environment can be done by running the runClient task in your
IDE.

Resources
• Forge Documentation: Forge Docs
• Minecraft Block API: Minecraft Block Documentation
Feel free to enhance or modify the mod further based on your needs!
4o
does this take into account sleeping through nights
ChatGPT
The initial implementation does not account for players sleeping through the night, which affects the
in-game time progression. We need to adjust the DifficultyChanger to correctly handle time
progression when players sleep.

Modified DifficultyChanger.java
We'll adjust the DifficultyChanger to check the actual in-game time instead of relying solely on
tick counting. We'll also reset the tick counter when players sleep through the night to ensure accurate
timing.
Here's the updated code:
java
Copy code
// com.example.zombiemod.DifficultyChanger.java
package com.example.zombiemod;

import net.minecraft.world.Difficulty;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.world.SleepFinishedTimeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ZombieMod.MODID, bus =


Mod.EventBusSubscriber.Bus.FORGE)
public class DifficultyChanger {
private static final long DAY_TICKS = 24000;
private static final long EASY_TICKS = DAY_TICKS; // 1 day
private static final long NORMAL_TICKS = DAY_TICKS * 6; // 6 days

@SubscribeEvent
public static void onWorldTick(TickEvent.WorldTickEvent event) {
if (event.phase == TickEvent.Phase.START || !(event.world instanceof
ServerWorld)) {
return;
}

ServerWorld world = (ServerWorld) event.world;


long time = world.getDayTime(); // Get the in-game time

if (time >= EASY_TICKS && time < NORMAL_TICKS) {


world.getServer().getWorldData().setDifficulty(Difficulty.EASY);
} else if (time >= NORMAL_TICKS) {
world.getServer().getWorldData().setDifficulty(Difficulty.NORMAL);
}
}

@SubscribeEvent
public static void onSleepFinished(SleepFinishedTimeEvent event) {
long time = event.getNewTime();
long day = time / DAY_TICKS;
long easyDay = EASY_TICKS / DAY_TICKS;
long normalDay = NORMAL_TICKS / DAY_TICKS;

if (day >= easyDay && day < normalDay) {

event.getWorld().getServer().getWorldData().setDifficulty(Difficulty.EASY);
} else if (day >= normalDay) {

event.getWorld().getServer().getWorldData().setDifficulty(Difficulty.NORMAL);
}
}
}

Explanation
1. Tick Counting: We use world.getDayTime() to get the current in-game time in ticks.
This method accounts for time changes due to sleeping.
2. Difficulty Change Timing:
• EASY_TICKS defines when to change to Easy difficulty.
• NORMAL_TICKS defines when to change to Normal difficulty.
• The game starts at 0 ticks and transitions to Easy after 1 day (24000 ticks), and to
Normal after 6 days (144000 ticks).
3. Handling Sleeping: The onSleepFinished method resets the world time when players
finish sleeping, adjusting the difficulty based on the new time. This ensures that sleeping does
not disrupt the difficulty progression schedule.

Full Updated Code Overview


1. Main Mod Class: No changes needed.
java
Copy code
// com.example.zombiemod.ZombieMod.java
package com.example.zombiemod;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(ZombieMod.MODID)
public class ZombieMod {
public static final String MODID = "zombiemod";

public ZombieMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new DifficultyChanger());
MinecraftForge.EVENT_BUS.register(new ZombieDoorBreaking());
}

private void setup(final FMLCommonSetupEvent event) {


}

private void doClientStuff(final FMLClientSetupEvent event) {


}

@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {

event.getServer().getWorldData().setDifficulty(net.minecraft.world.Difficulty.PEACE
FUL);
}
}

2. Zombie Behavior: No changes needed.


java
Copy code
// com.example.zombiemod.ZombieDoorBreaking.java
package com.example.zombiemod;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.monster.ZombieEntity;
import net.minecraft.world.Difficulty;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ZombieMod.MODID, bus =


Mod.EventBusSubscriber.Bus.FORGE)
public class ZombieDoorBreaking {

@SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof ZombieEntity) {
ZombieEntity zombie = (ZombieEntity) event.getEntity();
World world = event.getWorld();

if (world.getDifficulty() == Difficulty.NORMAL) {
zombie.goalSelector.addGoal(1, new
net.minecraft.entity.ai.goal.BreakDoorGoal(zombie,
net.minecraft.block.Blocks.OAK_DOOR));
}
}
}
}

3. Difficulty Changer: Updated to handle sleeping.


java
Copy code
// com.example.zombiemod.DifficultyChanger.java
package com.example.zombiemod;

import net.minecraft.world.Difficulty;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.world.SleepFinishedTimeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ZombieMod.MODID, bus =


Mod.EventBusSubscriber.Bus.FORGE)
public class DifficultyChanger {
private static final long DAY_TICKS = 24000;
private static final long EASY_TICKS = DAY_TICKS; // 1 day
private static final long NORMAL_TICKS = DAY_TICKS * 6; // 6 days

@SubscribeEvent
public static void onWorldTick(TickEvent.WorldTickEvent event) {
if (event.phase == TickEvent.Phase.START || !(event.world instanceof
ServerWorld)) {
return;
}

ServerWorld world = (ServerWorld) event.world;


long time = world.getDayTime(); // Get the in-game time

if (time >= EASY_TICKS && time < NORMAL_TICKS) {


world.getServer().getWorldData().setDifficulty(Difficulty.EASY);
} else if (time >= NORMAL_TICKS) {
world.getServer().getWorldData().setDifficulty(Difficulty.NORMAL);
}
}

@SubscribeEvent
public static void onSleepFinished(SleepFinishedTimeEvent event) {
long time = event.getNewTime();
long day = time / DAY_TICKS;
long easyDay = EASY_TICKS / DAY_TICKS;
long normalDay = NORMAL_TICKS / DAY_TICKS;

if (day >= easyDay && day < normalDay) {

event.getWorld().getServer().getWorldData().setDifficulty(Difficulty.EASY);
} else if (day >= normalDay) {

event.getWorld().getServer().getWorldData().setDifficulty(Difficulty.NORMAL);
}
}
}

Additional Notes
• Testing: After building and placing your mod .jar file in the mods folder, you can test it in
Minecraft. Ensure you test by changing the time manually and sleeping to verify the difficulty
changes correctly.
• Debugging: Use log statements if needed to check the time and difficulty transitions.
Feel free to further customize the mod or add more features as you see fit!
4o

ChatGPT can make mistakes. Check important info.

You might also like