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



×
×
  • Create New...

Important Information

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