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.

Suncurve

Members
  • Joined

  • Last visited

Everything posted by Suncurve

  1. I know, but I'm still pretty new with forge. So how do I get the LivingEntity class itself?
  2. Ok. Do you know how to get the LivingEntity though? I need it for pathfinding
  3. So how would I do this?
  4. If it's not clear, what I'm trying to do is detect when the entity spawns, and get the "LivingEntity" from it. Any help? Thanks
  5. I'm pretty new to entity modding, and I've written the basic entity code, but for the pathfinding, I need to get the "LivingEntity" entity. How would I go about getting this? public class EntityFarmer extends AgeableMob implements Npc, IAnimatable { private AnimationFactory factory = GeckoLibUtil.createFactory(this); protected long nextPlayerCollisionTime = 0; public static final int TICKS_SECOND = 20; public EntityFarmer(EntityType<? extends AgeableMob> entityType, Level level) { super(entityType, level); } public static AttributeSupplier.Builder setAttributes() { return LivingEntity.createLivingAttributes() .add(Attributes.MAX_HEALTH, 20D) .add(Attributes.MOVEMENT_SPEED, 0.6D) .add(Attributes.FOLLOW_RANGE, 100); } public void pathToLocation(BlockPos pos) { } @Nullable @Override public AgeableMob getBreedOffspring(ServerLevel p_146743_, AgeableMob p_146744_) { return null; } @NotNull public BlockPos blockPosition() { return new BlockPos(getX(), getY(), getZ()); } @Override public boolean canBeLeashed(Player player) { return false; } } Essentially, in the "pathToLocation" procedure, I need to get the livingEntity entity. Any help? Thanks.
  6. Ah yes, thank you. I cannot believe I forgot to call it, just didn't cross my mind. It works fine now, thanks again.
  7. Ah yes, I am registering it here: package net.suncurve.truevillagers.entity; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import net.suncurve.truevillagers.TrueVillagers; import net.suncurve.truevillagers.entity.villager.EntityFarmer; public class ModEntityTypes { public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, TrueVillagers.MOD_ID); public static final RegistryObject<EntityType<EntityFarmer>> FARMER = ENTITY_TYPES.register("farmer", () -> EntityType.Builder.of(EntityFarmer::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(256).setUpdateInterval(2) .sized(0.6f, 1.8f) .build(new ResourceLocation(TrueVillagers.MOD_ID, "farmer").toString())); public static void register(IEventBus eventBus) { ENTITY_TYPES.register(eventBus); } }
  8. I'm trying to create my first entity "Farmer" But minecraft keeps crashing with this: "[Render thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: Registry Object not present: truevillagers:farmer Index: 1 Listeners: 0: NORMAL 1: ASM: class net.suncurve.truevillagers.client.events.ClientEvents entityAttributeEvent(Lnet/minecraftforge/event/entity/EntityAttributeCreationEvent;)V java.lang.NullPointerException: Registry Object not present: truevillagers:farmer at java.base/java.util.Objects.requireNonNull(Objects.java:334) at TRANSFORMER/[email protected]/net.minecraftforge.registries.RegistryObject.get(RegistryObject.java:320) at TRANSFORMER/[email protected]/net.suncurve.truevillagers.client.events.ClientEvents.entityAttributeEvent(ClientEvents.java:28) " Code in ModEventBusEvents: package net.suncurve.truevillagers.event; import net.minecraftforge.event.entity.EntityAttributeCreationEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.suncurve.truevillagers.TrueVillagers; import net.suncurve.truevillagers.entity.ModEntityTypes; import net.suncurve.truevillagers.entity.villager.EntityFarmer; import javax.annotation.Nonnull; @Mod.EventBusSubscriber(modid = TrueVillagers.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModEventBusEvents { @SubscribeEvent public static void entityAttributeEvent(EntityAttributeCreationEvent event) { event.put(ModEntityTypes.FARMER.get(), EntityFarmer.setAttributes().build()); } } EntityFarmer Code: package net.suncurve.truevillagers.entity.villager; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.AgeableMob; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.npc.Npc; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import software.bernie.geckolib3.GeckoLib; import software.bernie.geckolib3.core.IAnimatable; import software.bernie.geckolib3.core.PlayState; import software.bernie.geckolib3.core.builder.AnimationBuilder; import software.bernie.geckolib3.core.controller.AnimationController; import software.bernie.geckolib3.core.event.predicate.AnimationEvent; import software.bernie.geckolib3.core.manager.AnimationData; import software.bernie.geckolib3.core.manager.AnimationFactory; import software.bernie.geckolib3.util.GeckoLibUtil; public class EntityFarmer extends AgeableMob implements Npc, IAnimatable { private AnimationFactory factory = GeckoLibUtil.createFactory(this); public EntityFarmer(EntityType<? extends AgeableMob> entityType, Level level) { super(entityType, level); } public static AttributeSupplier.Builder setAttributes() { return LivingEntity.createLivingAttributes() .add(Attributes.MAX_HEALTH, 20D) .add(Attributes.MOVEMENT_SPEED, 0.6D) .add(Attributes.FOLLOW_RANGE, 100); } @Nullable @Override public AgeableMob getBreedOffspring(ServerLevel p_146743_, AgeableMob p_146744_) { return null; } private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) { if (event.isMoving()) { event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.farmer.walk", true)); return PlayState.CONTINUE; } event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.farmer.idle", true)); return PlayState.CONTINUE; } @Override public void registerControllers(AnimationData data) { data.addAnimationController(new AnimationController(this, "controller", 0, this::predicate)); } @Override public AnimationFactory getFactory() { return this.factory; } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return SoundEvents.VILLAGER_HURT; } } Init: private void clientSetup(final FMLClientSetupEvent event) { EntityRenderers.register(ModEntityTypes.FARMER.get(), FarmerRenderer::new); TownHallBorderRenderer.INSTANCE = new TownHallBorderRenderer(Minecraft.getInstance()); } I've no idea what's happening here, so some help would be appreciated! Thanks.
  9. I started my mod in 1.18.2, I'm not upgrading it. Do you know what's the way to use the iWorldReader then?
  10. I'm trying to use the iWorldReader (from "net.minecraft.world.IWorldReader;") in 1.18.2, yet it is somehow non-existent..? Not sure what's happening here. Some help would be appreciated.
  11. Hi, I've created a custom block (Called "Town Hall Block") and managed to detect when it's placed (using a setPlacedBy override) I'm still quite new to modding with forge, and essentially, what I'm trying to do is create a region (64 blocks in each direction, with the town hall being the center), and be able to search that region for a specific block. So far, I've got this: (borderDist is an int with a value of 64) @Override public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullable LivingEntity pPlacer, ItemStack pStack) { if (pLevel.isClientSide()) { System.out.println("Block Placed"); // Calculate Village Borders BlockPos borderNorth = pPos.north(borderDist); BlockPos borderSouth = pPos.south(borderDist); BlockPos borderEast = pPos.east(borderDist); BlockPos borderWest = pPos.west(borderDist); } super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); } The part I'm struggling with (I've done some research but couldn't find anything) is actually creating that region around the town hall block, and then working out if there's a block of a specific type there, but most importantly, actually working the region out. Does anyone know what's the right way to do this? Thanks.

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.