Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I want my mobs to always spawn with armour using an event, so I used:

package com.example.examplemod.events;

import com.example.examplemod.DirtMod;
import com.example.examplemod.util.RegistryHandling;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.event.entity.*;

@Mod.EventBusSubscriber(modid = DirtMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ModClientEvents {

    @SubscribeEvent
    public static void onMobSpawn(EntityJoinWorldEvent event) {

        DirtMod.LOGGER.info(event.getEntity().getName().getString().toLowerCase());

        if (event.getEntity().getName().getString().toLowerCase() == "zombie") {

            DirtMod.LOGGER.info("Zombie equipped (almost)");

            event.getEntity().setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(() -> RegistryHandling.CDIRT_AXE.get(), 1));

            event.getEntity().setItemStackToSlot(EquipmentSlotType.HEAD, new ItemStack(() -> RegistryHandling.CDIRT_HELMET.get(), 1));

            DirtMod.LOGGER.info("Zombie equipped!");

        }

    }

}

 

It isn't working, and the log doesn't show "Zombie Equipped (almost)". Please help

 

P.S. CDIRT_HELMET and CDIRT_AXE are both custom armour, one of an armour type and one of a axe type.

5 hours ago, redtub345 said:

It isn't working, and the log doesn't show "Zombie Equipped (almost)". Please help

First of all, remove 

value = Dist.CLIENT

The client should not be the one giving items to mobs, that is the job of the server. You can get more details about that at the official forge documentation.

 

Second, you should not use reference equality (==) to check if two strings are equal. In this case, you should not compare strings at all, you probably want to use event.getEntity().getType() to compare entity types.

 

5 hours ago, redtub345 said:

Is this the wrong topic? I'm new here sorry.

Yes, you should have posted this in the 'Modder Support' forum and not here, but don't worry about it, a moderator can always move it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.