Jump to content

[1.16.5] Custom minecart overrides are not working


J3ramy

Recommended Posts

Hey guys,

I'm working on a new project where I have to create custom minecarts.

The cart shouldn't move when pushed by an entity. So, I did this:

Spoiler
@Override
    public boolean canBePushed() {
        return false;
    }

 

The custom cart will be initialized and I can place it on a rail. But the override doesn't work.

Further, I want to set the max speed of the cart, which is hard coded in the AbstractMinecartEntity. Can I change it?

 

This is the rest of my code:

TestCart

Spoiler
public class TestCart extends MinecartEntity {


    public TestCart(EntityType<?> type, World world) {
        super(type, world);
    }

    @Override
    public Type getMinecartType() {
        return Type.RIDEABLE;
    }

    @Override
    public boolean canBePushed() {
        return false;
    }


}

 

Register Cart

Spoiler
public class ModEntityTypes {
    public  static DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, EdomMod.MOD_ID);

    public static final RegistryObject<EntityType<TestCart>> TEST_CART = ENTITY_TYPES.register(("test_cart"), () -> EntityType.Builder.create(TestCart::new, EntityClassification.MISC).size(1f, 1f).build(new ResourceLocation(EdomMod.MOD_ID, "test_cart").toString()));

    public static void register(IEventBus eventBus){
        ENTITY_TYPES.register(eventBus);
    }
}

 

 

Link to comment
Share on other sites

28 minutes ago, J3ramy said:

The custom cart will be initialized and I can place it on a rail. But the override doesn't work.

there was a thread with the same problem, unfortunately i'm not be able to find this thread and I can't remember the solution
see next post

28 minutes ago, J3ramy said:

Further, I want to set the max speed of the cart, which is hard coded in the AbstractMinecartEntity. Can I change it?

override #getMaxCartSpeedOnRail, and return the speed you want

Edited by Luis_ST
Link to comment
Share on other sites

Thanks for your reply.

Sadly, none of above works. Neither the max speed nor the collision.

Did I miss something?:

public class TestCart extends MinecartEntity {

    public TestCart(EntityType<?> type, World world) {
        super(type, world);
    }

    @Override
    public Type getMinecartType() {
        return Type.RIDEABLE;
    }

    @Override
    public boolean canBePushed() {
        return false;
    }

    @Override
    public void applyEntityCollision(Entity entity) {
        
    }

    @Override
    public void addVelocity(double x, double y, double z) {
        
    }

    @Override
    public float getMaxCartSpeedOnRail() {
        return 1f;
    }
}

 

Link to comment
Share on other sites

Quote

this should work, note the default speed of the normale Minecart is 1.2F

I set it to .1f and there's no change

Quote

how did you test it?

I walked against the cart and it moved.

I built a test environment as well (see here). Left = custom, Right = default cart

Link to comment
Share on other sites

I also send my cart item. Maybe there's an error in it.

Item register

Spoiler
public static final RegistryObject<Item> TEST_CART = ITEMS.register("test_cart", 
() -> new TestCartItem(AbstractMinecartEntity.Type.RIDEABLE, new Item.Properties().group(ModItemGroup.EDOM_SAFETY_GROUP).maxStackSize(1)));

Cart item

Spoiler
public class TestCartItem extends MinecartItem {
    public TestCartItem(AbstractMinecartEntity.Type type, Item.Properties properties) {
        super(type, properties);
    }
}

EDIT: I tried to debug to the console in the constructor of TestCart but it seems like the constructor is not called. So, I guess I made a mistake within the item?

Edited by J3ramy
Link to comment
Share on other sites

My cart now gets created (Debug in constructor of TestCartEntity)

But the cart is not visible.

Here's my code:

 

Cart entity

Spoiler
public class TestCartEntity extends AbstractMinecartEntity {

    public TestCartEntity(EntityType<?> type, World world, double x, double y, double z) {
        super(type, world);
        System.out.println("CREATED");
    }

    @Override
    public IPacket<?> createSpawnPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }

    @Override
    public Type getMinecartType() {
        return Type.RIDEABLE;
    }

    @Override
    public EntitySize getSize(Pose p_213305_1_) {
        return new EntitySize(0.98F, 0.7F, true);
    }

    @Override
    public boolean canBePushed() {
        return false;
    }

    @Override
    public void applyEntityCollision(Entity entity) {

    }

    @Override
    public void addVelocity(double x, double y, double z) {

    }

    @Override
    public float getMaxCartSpeedOnRail() {
        return .1f;
    }
}

 

Renderer

Spoiler
public class TestCartRenderer<T extends TestCartEntity> extends MinecartRenderer<T> {

    private static final ResourceLocation TEXTURE_LOC = new ResourceLocation(EdomMod.MOD_ID,"minecraft:textures/entity/minecart.png");

    public TestCartRenderer(EntityRendererManager manager) {
        super(manager);
    }

    @Override
    public ResourceLocation getEntityTexture(T p_110775_1_) {
        return TEXTURE_LOC;
    }
}

 

Cart item

Spoiler
public class TestCartItem extends Item {

    private final EntityType<?> cartType;

    public TestCartItem(EntityType<?> type, Item.Properties properties) {
        super(properties);
        this.cartType = type;
    }

    @Override
    public ActionResultType onItemUse(ItemUseContext context) {
        World world = context.getWorld();
        BlockPos blockpos = context.getPos();
        BlockState blockstate = world.getBlockState(blockpos);

        if (!blockstate.isIn(BlockTags.RAILS)) {
            return ActionResultType.FAIL;
        } else {
            ItemStack itemstack = context.getItem();

            if (!world.isRemote) {
                RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, world, blockpos, null) : RailShape.NORTH_SOUTH;
                double yOffset = 0.0D;

                if (railshape.isAscending()) {
                    yOffset = 0.5D;
                }

                TestCartEntity cart = new TestCartEntity(this.cartType, world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + yOffset, (double) blockpos.getZ() + 0.5D);

                if (itemstack.hasDisplayName()) {
                    cart.setCustomName(itemstack.getDisplayName());
                }

                world.addEntity(cart);
            }

            itemstack.shrink(1);
            return ActionResultType.func_233537_a_(world.isRemote);
        }
    }
}

 

Register

Spoiler
private static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, EdomMod.MOD_ID);

    public static final RegistryObject<EntityType<?>> TEST_CART = ENTITIES.register("test_cart",
            () -> EntityType.Builder.create(EntityClassification.MISC).setTrackingRange(8).build("test_cart"));

    public static void register(IEventBus eventBus) {
        ENTITIES.register(eventBus);
    }

 

Mod class

Spoiler
RenderingRegistry.registerEntityRenderingHandler((EntityType<TestCartEntity>)ModEntityTypes.TEST_CART.get(), TestCartRenderer::new);

 

 

Link to comment
Share on other sites

I changed it to follwing and added the texture

private static final ResourceLocation TEXTURE_LOC = new ResourceLocation(EdomMod.MOD_ID,"textures/entity/minecart.png");

 

But it is still not working. When I right click, it debugs the constructor, but I can go through it and it's not visible... It acts like it is not getting created

Link to comment
Share on other sites

That makes sense.

Now I changed the ModItems.java to this:

Spoiler
private static final EntityType<TestCartEntity> TEST_CART_ENTITY_TYPE = Registry.register(Registry.ENTITY_TYPE, "test_cart", EntityType.Builder.<TestCartEntity>create(TestCartEntity::new, EntityClassification.MISC).size(0.98F, 0.7F));
    public static final RegistryObject<Item> TEST_CART = ITEMS.register("test_cart", () -> new TestCartItem(TEST_CART_ENTITY_TYPE, new Item.Properties().group(ModItemGroup.EDOM_SAFETY_GROUP).maxStackSize(1)));

 

But there's an error: Cannot resolve method 'register(DefaultedRegistry<EntityType<?>>, String, Builder<TestCartEntity>)'

I used the EntityType-class as a reference.

Link to comment
Share on other sites

Quote

You need to use DeferredRegister for all registrations.

I use now TEST_CART.get() from ModEntityTypes for the item registration (I assume this is the Custom Entity Type):

Spoiler
public static final RegistryObject<Item> TEST_CART = ITEMS.register("test_cart", () -> new TestCartItem(ModEntityTypes.TEST_CART.get(), new Item.Properties().group(ModItemGroup.EDOM_SAFETY_GROUP).maxStackSize(1)));

 

No compile errors but one runtime error:

Spoiler

---- Minecraft Crash Report ----
// I let you down. Sorry :(

Time: 18.05.22 21:17
Description: Mod loading error has occurred

java.lang.Exception: Mod Loading has failed
    at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:85) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.client.ClientModLoader.completeModLoading(ClientModLoader.java:188) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.lambda$null$1(Minecraft.java:513) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.util.Util.acceptOrElse(Util.java:323) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:509) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.gui.ResourceLoadProgressGui.render(ResourceLoadProgressGui.java:113) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:493) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1003) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.run(Minecraft.java:612) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:184) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_332] {}
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_332] {}
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_332] {}
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_332] {}
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {}
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
    at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_332] {}
-- MOD edom --
Details:
    Mod File: main
    Failure message: Edom Mod (edom) encountered an error during the load_registries event phase
        java.lang.NullPointerException: Registry Object not present: edom:test_cart
    Mod Version: 1.16.5
    Mod Issue URL: NOT PROVIDED
    Exception message: java.lang.NullPointerException: Registry Object not present: edom:test_cart

Stacktrace:
    at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_332] {}
    at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:120) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at de.j3ramy.edom.item.ModItems.lambda$static$15(ModItems.java:40) ~[main/:?] {re:classloading}
    at net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:124) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:200) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.registries.DeferredRegister.access$000(DeferredRegister.java:61) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.registries.DeferredRegister$EventDispatcher.handleEvent(DeferredRegister.java:172) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.eventbus.ASMEventHandler_2_EventDispatcher_handleEvent_Register.invoke(.dynamic) ~[?:?] {}
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-4.0.0.jar:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?] {}
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?] {}
    at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:36.2] {re:classloading}
    at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:121) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640) ~[?:1.8.0_332] {}
    at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:249) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:236) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:202) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading}
    at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$1(ClientModLoader.java:103) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:123) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:103) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.client.Minecraft.<init>(Minecraft.java:442) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
    at net.minecraft.client.main.Main.main(Main.java:149) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_332] {}
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_332] {}
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_332] {}
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_332] {}
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:52) ~[forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {}
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-recomp.jar:?] {}


-- System Details --
Details:
    Minecraft Version: 1.16.5
    Minecraft Version ID: 1.16.5
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_332, Temurin
    Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Temurin
    Memory: 1128331320 bytes (1076 MB) / 1719664640 bytes (1640 MB) up to 3679977472 bytes (3509 MB)
    CPUs: 16
    JVM Flags: 2 total; -XX:+IgnoreUnrecognizedVMOptions -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    ModLauncher: 8.1.3+8.1.3+main-8.1.x.c94d18ec
    ModLauncher launch target: fmluserdevclient
    ModLauncher naming: mcp
    ModLauncher services:
        /mixin-0.8.4.jar mixin PLUGINSERVICE
        /eventbus-4.0.0.jar eventbus PLUGINSERVICE
        /forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-launcher.jar object_holder_definalize PLUGINSERVICE
        /forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-launcher.jar runtime_enum_extender PLUGINSERVICE
        /accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE
        /forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-launcher.jar capability_inject_definalize PLUGINSERVICE
        /forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-launcher.jar runtimedistcleaner PLUGINSERVICE
        /mixin-0.8.4.jar mixin TRANSFORMATIONSERVICE
        /forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16.5-launcher.jar fml TRANSFORMATIONSERVICE
    FML: 36.2
    Forge: net.minecraftforge:36.2.34
    FML Language Providers:
        javafml@36.2
        minecraft@1
    Mod List:
        client-extra.jar                                  |Minecraft                     |minecraft                     |1.16.5              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f
        main                                              |Edom Mod                      |edom                          |1.16.5              |VALIDATE  |Manifest: NOSIGNATURE
        forge-1.16.5-36.2.34_mapped_snapshot_20210309-1.16|Forge                         |forge                         |36.2.34             |COMMON_SET|Manifest: NOSIGNATURE
    Crash Report UUID: ba4d8a03-0ed5-496b-b292-84533288c6d6

 

Link to comment
Share on other sites

I changed the class to this:

Spoiler
public class TestCartItem extends Item {

    private final RegistryObject<?> registryObject;

    public TestCartItem(RegistryObject<?> registryObject, Item.Properties properties) {
        super(properties);
        this.registryObject = registryObject;
    }

    @Override
    public ActionResultType onItemUse(ItemUseContext context) {
        World world = context.getWorld();
        BlockPos blockpos = context.getPos();
        BlockState blockstate = world.getBlockState(blockpos);

        if (!blockstate.isIn(BlockTags.RAILS)) {
            return ActionResultType.FAIL;
        } else {
            ItemStack itemstack = context.getItem();

            if (!world.isRemote) {
                RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, world, blockpos, null) : RailShape.NORTH_SOUTH;
                double yOffset = 0.0D;

                if (railshape.isAscending()) {
                    yOffset = 0.5D;
                }

                TestCartEntity cart = new TestCartEntity((EntityType<?>) this.registryObject.get(), world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + yOffset, (double) blockpos.getZ() + 0.5D);

                if (itemstack.hasDisplayName()) {
                    cart.setCustomName(itemstack.getDisplayName());
                }

                world.addEntity(cart);
            }

            itemstack.shrink(1);
            return ActionResultType.func_233537_a_(world.isRemote);
        }
    }
}

 

The error disappeared but still no cart is spawning...

 

EDIT: I pushed to the repo again

Edited by J3ramy
Link to comment
Share on other sites

Thanks.

I changed the constrcutor to

Spoiler
public TestCartEntity(World world, double x, double y, double z) {
        super(ModEntityTypes.TEST_CART.get(), world);
        
        this.setPosition(x, y, z);
    }

 

Actually, now the cart is kinda there. If I place it on a rail and place another block (e.g. dirt) there, the dirt block disappears, which indicates that the cart is more or less there.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

EDIT:

I changed the super call to

Spoiler
super(EntityType.MINECART, world, x, y, z);

 

And now it works perfectly fine. But now the registration of the custom entity type seems useless to me? Is it the "correct" solution or is it weird?

Edited by J3ramy
Link to comment
Share on other sites

The overrides in TestCartEntity are working when I use EntityType.MINECART in the constructor super call.

If I change it to ModEntityTypes.TEST_CART then there's the weird "bug" that it gets placed but its not visible/clickable

Link to comment
Share on other sites

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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