#Workspace #mod-dev
24 messages · Page 1 of 1 (latest)
Like it's im not sure if my library is actually importing
i'll need more details before i even give you an answer
Hang on let me show you my code
package com.example.noleatherdamage;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
public class DamageBlockListener implements ModInitializer {
@Override
public void onInitialize() {
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
if (entity instanceof PlayerEntity targetPlayer) {
if (isWearingFullLeather(targetPlayer) && isBlockingWithSword(targetPlayer)) {
return ActionResult.FAIL; // cancel damage
}
}
return ActionResult.PASS;
});
}
private boolean isWearingFullLeather(PlayerEntity player) {
return isLeather(player.getEquippedStack(EquipmentSlot.HEAD).getItem()) &&
isLeather(player.getEquippedStack(EquipmentSlot.CHEST).getItem()) &&
isLeather(player.getEquippedStack(EquipmentSlot.LEGS).getItem()) &&
isLeather(player.getEquippedStack(EquipmentSlot.FEET).getItem());
}
private boolean isLeather(net.minecraft.item.Item item) {
return item instanceof ArmorItem armor && armor.getMaterial().getName().equals("leather");
}
private boolean isBlockingWithSword(PlayerEntity player) {
return player.isBlocking() && player.getActiveItem().getItem().toString().contains("sword");
}
}
All steps for do 1.21.1 workspace:
Instail Java
Instail JDK Java 21
Create and instail fabric template for 1.21.1 zip
Instail inteljia
Extract template zip into any folder
Open template folder from inteljia
Enter any class like Mod Main or ModClient and choice JDK above (I'm not sure, but it only seems to appear if you have a few JDKs)
Open console and enter .\gradlew genSources or ./gradlew genSources
Wait until all load
Press shift two times, place V on "show non project files" and input smth like PistonBlock or any other class from vanila minecraft, open that class and choice sources (jar that you load when used .\gradlew genSources, optional because it's just load documentation and make code more readable)
Close inteljia and open it, launch minecraft client, if you do all right you get fabric 1.21.1 minecraft without mods.
None of these imports are working etc
Wtf dude, why you do thst code in OnIntiliaze?
What guide did you even watch???
YouTube
🤦
You should input methods instance in onInitialize that name whatever your mod name
For example if I has mod name: MagicCreateAddon I has class in src MagicCreateAddon that implement ModIntiliaze and I put methods on it like:
onIntiliaze() {
MagicCreateAddonBlocks.register()
}
MagicCreateAddonBlocks In that example it's other class that register blocks for mod.
But you do all code in onIntiliaze...
I see @glacial cobalt make it more clean and organized
But would this import the libraries if I did it this way?
Nah, In theory, your Minecraft will not start at all.
Test your libraries with any easy code like just block without functional and texture
Actually I think this makes sense cus i dont think my logger message was printing
In this Minecraft Modding Tutorial, we are adding custom items to Minecraft using the Fabric API for Minecraft 1.21.
== 1.21 MODDING COURSES ==
▶️ NeoForge Modding with Minecraft 1.21.X:
https://url.kaupenjoe.net/CourseNeoForge121X
▶️ Fabric Modding with Minecraft 1.21.X:
https://url.kaupenjoe.net/CourseFabric121X
▶️ Forge Modding...
I will add something more, in the main in onIntiliaze you need input only register methods that register smth, like new block or new screen handler and e.t.c.