Custom Portal Item causes error
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) ~[[email protected]:?]
at net.minecraft.world.chunk.ArrayPalette.readPacket(ArrayPalette.java:86) ~[[email protected]:?]
at net.minecraft.world.chunk.PalettedContainer.readPacket(PalettedContainer.java:196) ~[[email protected]:?]
at net.minecraft.world.chunk.ChunkSection.fromPacket(ChunkSection.java:145) ~[[email protected]:?]
at net.minecraft.world.chunk.WorldChunk.loadFromPacket(WorldChunk.java:400) ~[[email protected]:?]
at net.minecraft.client.world.ClientChunkManager.loadChunkFromPacket(ClientChunkManager.java:103) ~[[email protected]:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.loadChunk(ClientPlayNetworkHandler.java:619) ~[[email protected]:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.onChunkData(ClientPlayNetworkHandler.java:614) ~[[email protected]:?]
at net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.apply(ChunkDataS2CPacket.java:49) ~[[email protected]:?]
at net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket.apply(ChunkDataS2CPacket.java:25) ~[[email protected]:?]
at net.minecraft.network.NetworkThreadUtils.method_11072(NetworkThreadUtils.java:25) ~[[email protected]:?]
at net.minecraft.util.thread.ThreadExecutor.executeTask(ThreadExecutor.java:146) [[email protected]:?]
at net.minecraft.util.thread.ReentrantThreadExecutor.executeTask(ReentrantThreadExecutor.java:29) [[email protected]:?]
at net.minecraft.util.thread.ThreadExecutor.runTask(ThreadExecutor.java:122) [[email protected]:?]
at net.minecraft.util.thread.ThreadExecutor.runTasks(ThreadExecutor.java:116) [[email protected]:?]
at net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1024) [[email protected]:?]
at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:719) [[email protected]:?]
at net.minecraft.client.main.Main.main(Main.java:213) [[email protected]:?]
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.
Hmm that's not quite right. Can you post the code?
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();
Are you registering the Block correctly? This seems to be an error with the block, not to do with custom portal api.
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.
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)
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.
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();
}
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?