Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Portal Item causes error #45

Open
Friendly-Banana opened this issue Jan 16, 2022 · 8 comments
Open

Custom Portal Item causes error #45

Friendly-Banana opened this issue Jan 16, 2022 · 8 comments

Comments

@Friendly-Banana
Copy link

Friendly-Banana commented Jan 16, 2022

I have created a custom portal block inheriting from CustomPortalBlock. When placing it using the BlockItem of this block and then going through, I get an error. Also the chunk containing the portal behaves weird: it is not rendered / rendered as completely empty, F3 doesn't show any blocks, moving in creative is very jaggy while in survival you drown (because the chunk still contains blocks).
/setblock myCustomBlock also causes this error. Removing the portal restores normal chunk behaviour.

the error
[11:54:26] [Render thread/FATAL] (Minecraft) Error executing task on Client
 java.lang.IllegalArgumentException: No value with id -1
	at net.minecraft.util.collection.IndexedIterable.getOrThrow(IndexedIterable.java:27) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.world.chunk.ArrayPalette.readPacket(ArrayPalette.java:86) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.world.chunk.PalettedContainer.readPacket(PalettedContainer.java:196) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.world.chunk.ChunkSection.fromPacket(ChunkSection.java:145) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.world.chunk.WorldChunk.loadFromPacket(WorldChunk.java:400) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.world.ClientChunkManager.loadChunkFromPacket(ClientChunkManager.java:103) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.network.ClientPlayNetworkHandler.loadChunk(ClientPlayNetworkHandler.java:619) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.network.ClientPlayNetworkHandler.onChunkData(ClientPlayNetworkHandler.java:614) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.apply(ChunkDataS2CPacket.java:49) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.apply(ChunkDataS2CPacket.java:25) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.network.NetworkThreadUtils.method_11072(NetworkThreadUtils.java:25) ~[minecraft-project-@-mapped.jar:?]
	at net.minecraft.util.thread.ThreadExecutor.executeTask(ThreadExecutor.java:146) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.util.thread.ReentrantThreadExecutor.executeTask(ReentrantThreadExecutor.java:29) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.util.thread.ThreadExecutor.runTask(ThreadExecutor.java:122) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.util.thread.ThreadExecutor.runTasks(ThreadExecutor.java:116) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1024) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:719) [minecraft-project-@-mapped.jar:?]
	at net.minecraft.client.main.Main.main(Main.java:213) [minecraft-project-@-mapped.jar:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:608) [fabric-loader-0.12.12.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:77) [fabric-loader-0.12.12.jar:?]
	at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28) [fabric-loader-0.12.12.jar:?]
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86) [dev-launch-injector-0.2.1+build.8.jar:?]

I have also created Nether portal items. They work as intended.

@kyrptonaught
Copy link
Owner

Hmm that's not quite right. Can you post the code?

@Friendly-Banana
Copy link
Author

here is the block class

public class AetherPortalBlock extends CustomPortalBlock {
    public AetherPortalBlock() {
        super(FabricBlockSettings.of(Material.PORTAL).noCollision().ticksRandomly().strength(-1.0f).sounds(BlockSoundGroup.GLASS).luminance(state -> 13));
    }

    @Override
    public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) {
        return ModItems.AETHER_PORTAL_ITEM.getDefaultStack();
    }

    @Override
    public Block getPortalBase(World world, BlockPos pos) {
        return Blocks.GLOWSTONE;
    }
}

and that's the portal creation code

CustomPortalBuilder.beginPortal()
        .frameBlock(Blocks.GLOWSTONE)
        .lightWithWater()
        .destDimID(new Identifier("the_nether"))
        .returnDim(new Identifier("the_end"), false)
        .customPortalBlock(AETHER_PORTAL_BLOCK)
        .tintColor(18, 90, 150)
        .registerPortal();

@kyrptonaught
Copy link
Owner

Are you registering the Block correctly? This seems to be an error with the block, not to do with custom portal api.

@Friendly-Banana
Copy link
Author

Friendly-Banana commented Jan 22, 2022

The registering is done like with every other block, so this should be correct:
Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "aether_portal"), new AetherPortalBlock());

But I found some new errors:

  • the single portal blocks aren't linked, I get the wobble effect but not the teleportation.
  • even new CustomPortalBlock(FabricBlockSettings.of(Material.PORTAL).noCollision().ticksRandomly().strength(-1.0f) .sounds(BlockSoundGroup.GLASS).luminance(state -> 13) which is exactly the default portal definition causes chunk errors on going through.

I guess I'm just going to use the default block and either hope the feature gets implemented or just mix into your method.

@kyrptonaught
Copy link
Owner

kyrptonaught commented Jan 23, 2022

Ah I think I see the issue now.

The initial problem is a syncing issue, the server is telling the client to render a block here. But this block does not exist in the registry so it cannot find it, thus returning -1. This is caused by creating separate instances of the same block. You are creating a new instance when registering the block, and then creating another new instance when passing the block into the the portal construction. Instead you should create a variable with an instance of the block. And pass that variable to both the registry and portal construction.

(Sorry if that doesn't make sense, I am on mobile currently)

@Friendly-Banana
Copy link
Author

That does make sense, but I don't see where I'm doing wrong. I am registering my block into a variable and then pass this to the PortalBuilder. Might have to test a bit more.

@kyrptonaught
Copy link
Owner

kyrptonaught commented Jan 28, 2022

Like so:

 public static CustomPortalBlock AETHER_PORTAL_BLOCK = new CustomPortalBlock();
    
    @Override
    public void onInitialize() {
        Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "aether_portal"), AETHER_PORTAL_BLOCK);
        CustomPortalBuilder.beginPortal()
                .frameBlock(Blocks.GLOWSTONE)
                .lightWithWater()
                .destDimID(new Identifier("the_nether"))
                .returnDim(new Identifier("the_end"), false)
                .customPortalBlock(AETHER_PORTAL_BLOCK)
                .tintColor(18, 90, 150)
                .registerPortal();
        }

@Friendly-Banana
Copy link
Author

Friendly-Banana commented Feb 20, 2022

Ok, that works, but now I have my own block and thus missing textures. Is there a simple way to use your textures and custom color?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants