Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Custom minecart overrides are not working


J3ramy
 Share

Recommended Posts

Posted (edited)

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

You are spawning your cart entity at 0, 0, 0. While you are passing in the desired x, y and z coordinates to the constructor, the constructor entirely ignores them. The cart is therefore at the default position (0, 0, 0) and you are forcing it to spawn in a potentially unloaded chunk, which will create weirdness. Even if the chunk is loaded, the entity will immediately die due to being in the void.

Link to comment
Share on other sites

Posted (edited)

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

 Share



×
×
  • Create New...

Important Information

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