Jump to content

Recommended Posts

Posted

I'm new to minecraft modding and java, so bear with me:

I've been trying to register an entity. Simple enough, I suppose. I've been cobbling together some code from different sources, and ended up with this:

package com.tfcraft.transformacraft.registry;

import com.tfcraft.transformacraft.entities.PlayerEntityReplace;

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class EntityReg {
	
	private static final DeferredRegister<EntityType<?>> RegEnt = DeferredRegister.create(ForgeRegistries.ENTITIES, "transformacraft");
	
	public static RegistryObject<EntityType<PlayerEntityReplace>> PLRREPLACE_ENTITY = RegEnt.register("player_replace",
	        () -> EntityType.Builder.<PlayerEntityReplace>of(PlayerEntityReplace::new, EntityClassification.MISC)
	                .build(new ResourceLocation("transformacraft", "player_replace").toString()));
	
	public static void register() {
		RegEnt.register(FMLJavaModLoadingContext.get().getModEventBus());
	}
	
}

There was some problems with figuring this out (Mainly the fact that the EntityType.Builder.create() method apparently no longer exists, .of() seemed functionally identical, correct me if I'm wrong),

HOWEVER

PlayerEntityReplace::new apparently doesn't work as an IFactory?

Every source I found for registering entities simply used (InsertGenericEntityExampleClassHere)::new for that part of the create() method, and it apparently worked for them fine. But, using it in my project simply has my IDE (Eclipse) underline it in red with the message "The type PlayerEntityReplace does not define PlayerEntityReplace(EntityType<PlayerEntityReplace>, World) that is applicable here" (Which I found to be the create() method of an IFactory?)

What am I doing wrong here?

Posted (edited)

I think I can rig one up, but how would I get a World variable for the IFactory.create() method during registry?

Or, is there a different way to create an IFactory during/for registry?

Edit: I don't know what I'm doing, but I tried to rig up a variation of the PlayerEnityReplace constructor that produces an IFactory:

public IFactory<T extends Entity> PlayerEntityReplace(World p_i241920_1_, BlockPos p_i241920_2_, float p_i241920_3_, GameProfile p_i241920_4_, EntityType<T> p_create_1_, World p_create_2_) {
	super(p_i241920_1_, p_i241920_2_, p_i241920_3_, p_i241920_4_);
	return EntityType.IFactory.<PlayerEntityReplace>create(p_create_1_, p_create_2_);
}

Believe it or not, it doesn't compile. It's expecting a comma where extends is (in <T extends Entity>), and I'm not entirely sure how to make a non-static reference to the create() method.

I am 100% certain I'm doing this wrong, but I don't know what I'm supposed to do.

Edited by FerroCentric
Posted (edited)

Check out Java lambda.

IFactory is an interface that has an abstract method create(EntityType, World) that you need to implement it your self.

class MyEntityFactory implements IFactory<MyEntity>
{
  @Override
  MyEntity create(EntityType<MyEntity> type, World world)
  {
    return new MyEntity(type, world);
  }
}

register(new MyEntityFactory(), ....)

->

register(new IFactory<MyEntity>() {
  	@Override
    MyEntity create(EntityType<MyEntity> type, World world)
    {
      return new MyEntity(type, world);
    }
}, ....)

->

register((type, world) -> new MyEntity(type, world), ....)

->

register(MyEntity::new, ....)

 

However vanilla is passing in null as Players are kinda different to other entities (they don't spawn naturally, no spawn eggs..etc). They are created and added with a totally different way.

Edited by poopoodice
Posted

I think I understand. So, almost all entity types are constructed with an EntityType and a world, and as such their constructors, when the IFactory interface is implemented, can be used to construct an IFactory with create().

However, players don't construct with an EntityType variable, and therefore cannot be used easily with the IFactory interface.

So, this begs the question: How would I register a new PlayerEntity type entity? I tried some of your methods, but each one requires a PlayerEntity superconstructor with an EntityType variable, which don't exist. Is there some way to skip up to the LivingEntity superconstructor, or something?

Or, better yet, is there any easy way to override the PlayerEntity class directly (without making compatibility issues) to get it to implement an interface and to change certain methods? (I'm trying to make the player be animatable by GeckoLib, so I've been making this entity to replace the normal PlayerEntity, hence the name of the entity)

Posted
1 hour ago, poopoodice said:

However vanilla is passing in null as Players are kinda different to other entities (they don't spawn naturally, no spawn eggs..etc). They are created and added with a totally different way.

Vanilla uses the builder that returned null for the factory because players shouldn't be spawned in usual ways.

Posted (edited)

Am I looking for a Static Entity, a T, or a Private Static Entity? I presume it's the 4th in the picture, since its the only one fulfillable by the PlayerEntity constructor?

I have no idea at this point.

create methods.png

Edited by FerroCentric
Posted

I looked in EntityType.java before and couldn't find it, but for some reason I found the register now.

Apparently it uses createNothing(), which was one of the first methods I ruled out trying to figure out how to register it.

Thanks for the info on IFactories tho, it helped me better understand some more things regarding constructors and implementing.

 

Posted

I'm trying to replace the default player entity with a custom entity that implements the GeckoLib IAnimatable interface and has the necessary methods for GeckoLib animation. However, things are only being added, not modified. As such, there's probably an easier (and more reasonable) way to make these things part of the basic playerentity. If you have any way to do either, I'm all ears.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Well, when I log in to the server, sometimes within an hour, sometimes within a minute, the server closes and informs me that there was a Ticking entity error. Below is the crash report
    • Try switching to Windowed or Borderless Window mode in Minecraft. These modes make it easier for the recorder to capture gameplay, as it still has access to the display without the game taking up all of the graphics resources.
    • This forum is for Forge, not NeoForge. Please go to them for support.
    • Forge version: 55.0.0 Minecraft version: 1.21.5 Downloads: As this is the start of a new version, it is recommended that you check the downloads page and use the latest version to receive any bug fixes. Downloads page Intro: Good evening! Today, we have released our initial build of Forge 55.0 for Minecraft 1.21.5. 1.21.5 is the newest member of the 1.21 family of versions, which was released yesterday on March 25, 2025. As a reminder, the first minor (X.0) of a Forge version is a beta. Forge betas are marked as such on the bottom left of the title screen and are candidates for any breaking changes. Additionally, there are a couple of important things to note about this update, which I've made sure to mention in this post as well. Feel free to chat with us about bugs or these implementation changes on GitHub and in our Discord server. As always, we will continue to keep all versions of 1.21 and 1.20 in active support as covered by our tiered support policy. Cheers, happy modding, and good luck porting! Rendering Refactor For those who tuned in to Minecraft Live on March 22, 2025, you may already know that Mojang have announced their intention to bring their new Vibrant Visuals overhaul to Java in the future. They've taken the first steps toward this by refactoring how rendering pipelines and render types are handled internally. This has, in turn, made many of Forge's rendering APIs that have existed for years obsolete, as they (for the most part) can be done directly in vanilla. If there was a rendering API that was provided by Forge which you believe should be re-implemented, we're happy to discuss on GitHub through an issue or a pull request. Deprecation of weapon-like ToolActions In 1.21.5, Minecraft added new data components for defining the characteristics of weapons in data. This includes attack speed, block tags which define efficient blocks, and more. As such, we will begin marking our ToolActions solution for this as deprecated. ToolActions were originally added to address the problem of creating modded tools that needed to perform the same actions as vanilla tools. There are still a few tool actions that will continue to be used, such as the shears tool action for example. There are some existing Forge tool actions that are currently obsolete and have no effect given the way the new data components are implemented. We will continue to work on these deprecations and invite you to chat with us on GitHub or Discord if you have any questions.
    • In summary, a full mod to adjust mining progress in such a specific way does not yet exist in its exact form, but it is possible to find mods that change certain aspects of progression (e.g. "Harder Ores").
  • Topics

×
×
  • Create New...

Important Information

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