Jump to content

X-Lomir

Members
  • Posts

    97
  • Joined

  • Last visited

Everything posted by X-Lomir

  1. Because I actually use them also to render. I had changed my code to make so that my vertical slabs refer the slab and not the block to fix some issues, however this caused some problems in rendering. So I needed the maps during rendering to go from slab to block whenever possible, and also I have a map holding all the translucent slabs.
  2. The volatile immutable slab maps used to go from block to slab and vice versa, the ones instantiated in the ServerAboutToStart event.
  3. Thanks, it works now! I found another problem unfortunately: when the version of the mod that's on the client tries to access the volatile immutable maps the game crashes. The issue is that those maps are never instantiated on the client. How do I fix this? Do I have to register a packet and every time I want to access those maps I must send and receive a packet? Or is there a smarter way? Also I'm wondering why on the Forge docs it's written to use a separate class when creating a simple channel object. Wouldn't it be okay if I did it in my JustVerticalSlabsLoader?
  4. Here the code of the handler class. It is not updated with the annotation, however all I did in local was to add the annotation as shown before and remove the line to register that class in my mod loader class. Before this change it would crash when server side only, but would color correctly in single player. After this change it's not coloring correctly in single player. I didn't check if it fixed the crash server side.
  5. I did this: @EventBusSubscriber(value = Dist.CLIENT, bus = Bus.MOD) public class ColorHandlerEventHandler And removed the manual subscribing in my mod loader class. However now in single player my grass vertical slabs are back to being greyscale.
  6. I'm trying to put my mod on a server and I get this error: -- Head -- Thread: main Stacktrace: at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:138) ~[securejarhandler-1.0.3.jar:?] {} -- MOD justverticalslabs -- Details: Caused by 0: java.lang.reflect.InvocationTargetException at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {} at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {} at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {} at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {} at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:67) ~[javafmllanguage-1.18.2-40.1.20.jar%23126!/:?] {} at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:106) ~[fmlcore-1.18.2-40.1.20.jar%23125!/:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {} at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {} at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {} at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} Caused by 1: java.lang.NoClassDefFoundError: net/minecraft/client/color/item/ItemColor at crystalspider.justverticalslabs.JustVerticalSlabsLoader.<init>(JustVerticalSlabsLoader.java:159) ~[justverticalslabs-1.18.2-3.0.0.0.jar%2390!/:1.18.2-3.0.0.0] {re:classloading} at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {} at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {} at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {} at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {} at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:67) ~[javafmllanguage-1.18.2-40.1.20.jar%23126!/:?] {} at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:106) ~[fmlcore-1.18.2-40.1.20.jar%23125!/:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {} at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {} at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {} at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} Mod File: justverticalslabs-1.18.2-3.0.0.0.jar Failure message: Just Vertical Slabs (justverticalslabs) has failed to load correctly java.lang.reflect.InvocationTargetException: null Mod Version: 1.18.2-3.0.0.0 Mod Issue URL: https://github.com/Nyphet/just-vertical-slabs/issues Exception message: java.lang.ClassNotFoundException: net.minecraft.client.color.item.ItemColor Stacktrace: at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:138) ~[securejarhandler-1.0.3.jar:?] {} at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {} at crystalspider.justverticalslabs.JustVerticalSlabsLoader.<init>(JustVerticalSlabsLoader.java:159) ~[justverticalslabs-1.18.2-3.0.0.0.jar%2390!/:1.18.2-3.0.0.0] {re:classloading} at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {} at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {} at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {} at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {} at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:67) ~[javafmllanguage-1.18.2-40.1.20.jar%23126!/:?] {} at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:106) ~[fmlcore-1.18.2-40.1.20.jar%23125!/:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {} at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {} at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {} at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames} at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} How do I fix this? Should I put a @OnlyIn(Dist.CLIENT) in my color event handler class? Or add a check for the side in the methods that register BlockColors and ItemColors? Or something else entirely?
  7. I'm wondering... Couldn't I put a property into my BlockState that will hold the referredBlockState? Basically in VerticalSlabBlock#getStateForPlacement I could read the NBT tag from the itemstack and save it in my BlockState, the same way I do for light. This way I could get rid of BEs altogether and make better use of BlockState chaching system. Also it would allow my blocks to be pushed by pistons and to mimic properties I currently cannot mimic because their getter only takes a BlockState as input. The only problem I can see would be how to handle VerticalSlabBakedModel#getQuads because of that thing with the breaking progress animation.
  8. I managed to solve the issue. The fix was actually quite simple, and I'm also not exactly sure why it works, but it does and I'm satisfied with it 🤣 I think it works because the BLOCK VertexFormat has, in order, a position element, a color element and the 2 UVs elements. A position elements uses 3 vertex elements (x, y and z), a color element takes 1 vertex element, U and V elements take 1 vertex element each. So the index for U is 3 + 1 + vertexIndex, where vertexIndex is the index of the current vertex, which increases every iteration by the size each vertex takes in the vertices array. Similarly, the index for V is 3 + 1 + vertexIndex + 1, accounting for the previous U vertex element. However I'm not sure this is the correct explanation, but I'll leave here my intuition and the fixed method to update vertices: private int[] updateVertices(int[] vertices, int[] referredVertices, TextureAtlasSprite oldSprite, TextureAtlasSprite newSprite, boolean faceUp) { int[] updatedVertices = vertices.clone(); for (int vertexIndex = 0; vertexIndex < DefaultVertexFormat.BLOCK.getVertexSize(); vertexIndex += DefaultVertexFormat.BLOCK.getIntegerSize()) { float y = Float.intBitsToFloat(referredVertices[vertexIndex + 1]); // Lower only top face since RenderType CutoutMipped will remove extra transparent texture bits that go out of the shape. if (faceUp && y > 0 && y < 0.5) { updatedVertices[vertexIndex + 1] = Float.floatToRawIntBits(y + 0.5F); } updatedVertices[vertexIndex + 4] = changeUVertexSprite(oldSprite, newSprite, updatedVertices[vertexIndex + 4]); updatedVertices[vertexIndex + 5] = changeVVertexSprite(oldSprite, newSprite, updatedVertices[vertexIndex + 5]); } return updatedVertices; }
  9. It was pointed out to me a bug my mod has when using shaders other than Minecraft defaults, for example with Optifine internal shaders and BSL Shaders. The bug consists in all textures, apart from the oak planks, for my vertical slabs to be completely messed up. I guess this has to do with how I'm forcefully writing in the vertexes of my model. Is there a way to test and debug my mod with Optifine and, optionally, an external shader pack? Do you have any suggestions or insights about what may be causing the problem and how to fix it? I'm also trying to ask for some help on Minecraft Shaders Discord, I'll update here if I find a solution.
  10. I added a class for transparent vertical slabs. Everything works fine so far except one thing that is transparent vertical slabs still cull their faces and the faces of their neighboring blocks. Is there some method or property I can override in my new class or do I necessarily have to duplicate my JSON models and remove the cullfaces? EDIT: I found getOcclusionShape and it looks like it's working.
  11. Okay, I figured out as much. I guess I will make another kind of block and use it for certain blocks on a best-effort base, like checking if the ID of the mimicked block contains "glass", "leaf", "leaves", or something like that. Maybe add a config option to add another keyword to use to render a specific kind of block with the translucent layer.
  12. Okay, thanks, it works. I'm testing my mod with transparent slabs, like glass, and, as I expected given I set the render layer as cutout mipped, transparent blocks don't work well at all. Is there a way to set the render layer depending on the block entity? Or what else could I do to make so that only vertical slabs referring transparent blocks are rendered in translucent render layer?
  13. I noticed that some mods can add slabs for blocks that are not full height, like soulsand and dirt path. That caused a couple of problems with my vertical slabs, however I managed to make so that vertical slabs can also be not full height and their textures adapt too. There is one problem that arose which is that vertical slabs not full height still make other blocks cull their faces: https://imgur.com/a/ZBUpszZ I don't know why this is happening nor how to solve this. You can see the textures and the shape of the vertical slab being correct, however it's as if it's considered as a full height block. Code is here.
  14. Yeah you're right. I thought I would break colors of normal blocks if I did that, I don't know why.
  15. In the end it was just me being stupid. What you said I had already did by using the tint index of the referred sprite rather than of my model JSON. The real problem was that I was checking instanceof on the slab, but I needed to check on the block. I changed my code to this and it works: public class ColorHandlerEventHandler { @SubscribeEvent public void onColorHandlerEventBlock(ColorHandlerEvent.Block event) { event.getBlockColors().register(new BlockColor() { public int getColor(BlockState state, @Nullable BlockAndTintGetter getter, @Nullable BlockPos pos, int tintIndex) { if (getter != null && pos != null) { BlockState referredSlabState = VerticalSlabUtils.getReferredSlabState(getter, pos); if (referredSlabState != null) { // Edited here Block block = Block.byItem(VerticalSlabUtils.slabMap.get(referredSlabState.getBlock().asItem())); if (block instanceof GrassBlock || block instanceof LeavesBlock) { return event.getBlockColors().getColor(block.defaultBlockState(), getter, pos, tintIndex); } } } return -1; } }, JustVerticalSlabsLoader.VERTICAL_SLAB_BLOCK.get()); } @SubscribeEvent public void onColorHandlerEventItem(ColorHandlerEvent.Item event) { event.getItemColors().register(new ItemColor() { public int getColor(ItemStack itemStack, int tintIndex) { BlockState referredSlabState = VerticalSlabUtils.getReferredSlabState(itemStack); if (referredSlabState != null) { // Edited here Block block = Block.byItem(VerticalSlabUtils.slabMap.get(referredSlabState.getBlock().asItem())); if (block instanceof GrassBlock || block instanceof LeavesBlock) { return event.getItemColors().getColor(block.asItem().getDefaultInstance(), tintIndex); } } return -1; } }, JustVerticalSlabsLoader.VERTICAL_SLAB_ITEM.get()); } } The correct bus seems to be FMLJavaModLoadingContext.get().getModEventBus().
  16. I managed to solve the overlay texture problem by doing this: public class FMLClientSetupEventHandler { /** * Sets the correct {@link RenderType} for {@link crystalspider.justverticalslabs.blocks.VerticalSlabBlock VerticalSlabBlocks}. * * @param event */ @SubscribeEvent public void setup(FMLClientSetupEvent event) { event.enqueueWork(() -> { // TODO: Check if it works also for translucent blocks. ItemBlockRenderTypes.setRenderLayer(JustVerticalSlabsLoader.VERTICAL_SLAB_BLOCK.get(), RenderType.cutoutMipped()); }); } } I also tried to solve the color problem by doing this: public class ColorHandlerEventHandler { @SubscribeEvent public void onColorHandlerEventBlock(ColorHandlerEvent.Block event) { event.getBlockColors().register(new BlockColor() { public int getColor(BlockState state, @Nullable BlockAndTintGetter getter, @Nullable BlockPos pos, int tintIndex) { if (getter != null && pos != null) { BlockState referredSlabState = VerticalSlabUtils.getReferredSlabState(getter, pos); if (referredSlabState != null) { Block slab = referredSlabState.getBlock(); if (slab instanceof GrassBlock || slab instanceof LeavesBlock) { return event.getBlockColors().getColor(Block.byItem(VerticalSlabUtils.slabMap.get(slab.asItem())).defaultBlockState(), getter, pos, tintIndex); } } } return -1; } }, JustVerticalSlabsLoader.VERTICAL_SLAB_BLOCK.get()); } @SubscribeEvent public void onColorHandlerEventItem(ColorHandlerEvent.Item event) { event.getItemColors().register(new ItemColor() { public int getColor(ItemStack itemStack, int tintIndex) { BlockState referredSlabState = VerticalSlabUtils.getReferredSlabState(itemStack); if (referredSlabState != null) { Block slab = referredSlabState.getBlock(); if (slab instanceof GrassBlock || slab instanceof LeavesBlock) { return event.getItemColors().getColor(VerticalSlabUtils.slabMap.get(slab.asItem()).getDefaultInstance(), tintIndex); } } return -1; } }, JustVerticalSlabsLoader.VERTICAL_SLAB_ITEM.get()); } } And I tried registering this class first with FMLJavaModLoadingContext.get().getModEventBus().register(new ColorHandlerEventHandler()); and after with MinecraftForge.EVENT_BUS.register(new ColorHandlerEventHandler()); however either way I get this (and no errors): https://imgur.com/a/M9sfwVw EDIT: I forgot to add that I moved the code in this new branch.
  17. I was testing my mod with other mods and it works fine, I have a few notes on some points I'd like to improve it in the future, but for now it's just fine. Apart from one thing: texture overlays. I was testing my mod with SlabGen and I noticed the vertical slab grass block had 2 issues with its texture: Grass color was grayscale Side overlays were not showing For point 1 I found out that grass color depends on the biome and biome blend setting, while the sprite is in grayscale. The same thing goes on for foliage. I would like to get the correct tint index, but I don't know how to do that. It seemed to me that grass/foliage color is based on the biome and position the block is being rendered, however I can't find a way to get both info in my baked model. I'm not even sure getting them in the baked model is correct, since I would then cache the color. It would be nice to find a way to take advantage of whatever Minecraft does to set the correct color simply by adding vertical slabs to blocks that need grass/foliage color and then get the biome color if the referring block is instanceof GrassBlock or LeavesBlock, otherwise get the default sprite color. For point 2 I remembered we had said that in my baked model I'd settle with taking the first referring sprite for the given direction. So I changed my getQuads code to take into account all BakedQuads for the given direction: @Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData modelData) { BlockState referringBlockState = modelData.getData(VerticalSlabUtils.REFERRING_BLOCK_STATE); if (referringBlockState != null) { VerticalSlabModelKey verticalSlabModelKey = new VerticalSlabModelKey(side, referringBlockState); if (!bakedQuadsCache.containsKey(verticalSlabModelKey)) { ArrayList<BakedQuad> bakedQuads = new ArrayList<BakedQuad>(); for (BakedQuad jsonBakedQuad : jsonBakedModel.getQuads(state, side, rand, modelData)) { Direction orientation = jsonBakedQuad.getDirection(); for (BakedQuad referringBakedQuad : getReferringBakedQuads(referringBlockState, orientation, rand, modelData)) { bakedQuads.add(getNewBakedQuad(jsonBakedQuad, referringBakedQuad.getSprite(), orientation)); JustVerticalSlabsLoader.LOGGER.warn(side + " " + referringBakedQuad.getSprite().toString()); // Added only for tests. To be removed. } } bakedQuadsCache.put(verticalSlabModelKey, bakedQuads); } return bakedQuadsCache.get(verticalSlabModelKey); } return jsonBakedModel.getQuads(state, side, rand, modelData); } private List<BakedQuad> getReferringBakedQuads(BlockState referringBlockState, Direction side, Random rand, IModelData modelData) { BakedModel referringBakedModel = getReferringBakedModel(referringBlockState); IModelData referringModelData = getReferringModelData(referringBlockState, modelData); List<BakedQuad> referringBakedQuads = referringBakedModel.getQuads(referringBlockState, side, rand, referringModelData); for (BakedQuad referringBakedQuad : referringBakedModel.getQuads(referringBlockState, null, rand, referringModelData)) { if (referringBakedQuad.getDirection() == side) { referringBakedQuads.add(referringBakedQuad); } } if (referringBakedQuads.size() == 0) { JustVerticalSlabsLoader.LOGGER.warn("Referred Block has no texture for " + side + " face. No texture will be generated for that face."); } return referringBakedQuads; } // Updates vertices as I had explained in a previous post. private BakedQuad getNewBakedQuad(BakedQuad jsonBakedQuad, TextureAtlasSprite referringSprite, Direction orientation) { return new BakedQuad(updateVertices(jsonBakedQuad.getVertices(), jsonBakedQuad.getSprite(), referringSprite), jsonBakedQuad.getTintIndex(), orientation, referringSprite, jsonBakedQuad.isShade()); } And it still worked fine for all Vanilla blocks and more, however with grass now I get the overlay on the side, which is in grayscale (see point 1), but the background is black: https://imgur.com/a/BLoHmQx However the sprites, and so the vertices, are correct: [11:59:19] [Worker-Main-34/WARN]: down TextureAtlasSprite{name='minecraft:block/dirt', frameCount=1, x=192, y=416, height=16, width=16, u0=0.1875, u1=0.203125, v0=0.40625, v1=0.421875} [11:59:19] [Worker-Main-34/WARN]: up TextureAtlasSprite{name='minecraft:block/grass_block_top', frameCount=1, x=512, y=272, height=16, width=16, u0=0.5, u1=0.515625, v0=0.265625, v1=0.28125} [11:59:19] [Worker-Main-34/WARN]: south TextureAtlasSprite{name='minecraft:block/grass_block_side', frameCount=1, x=512, y=224, height=16, width=16, u0=0.5, u1=0.515625, v0=0.21875, v1=0.234375} [11:59:19] [Worker-Main-34/WARN]: south TextureAtlasSprite{name='minecraft:block/grass_block_side_overlay', frameCount=1, x=512, y=240, height=16, width=16, u0=0.5, u1=0.515625, v0=0.234375, v1=0.25} [11:59:19] [Worker-Main-34/WARN]: west TextureAtlasSprite{name='minecraft:block/grass_block_side', frameCount=1, x=512, y=224, height=16, width=16, u0=0.5, u1=0.515625, v0=0.21875, v1=0.234375} [11:59:19] [Worker-Main-34/WARN]: west TextureAtlasSprite{name='minecraft:block/grass_block_side_overlay', frameCount=1, x=512, y=240, height=16, width=16, u0=0.5, u1=0.515625, v0=0.234375, v1=0.25} [11:59:19] [Worker-Main-34/WARN]: east TextureAtlasSprite{name='minecraft:block/grass_block_side', frameCount=1, x=512, y=224, height=16, width=16, u0=0.5, u1=0.515625, v0=0.21875, v1=0.234375} [11:59:19] [Worker-Main-34/WARN]: east TextureAtlasSprite{name='minecraft:block/grass_block_side_overlay', frameCount=1, x=512, y=240, height=16, width=16, u0=0.5, u1=0.515625, v0=0.234375, v1=0.25} [11:59:19] [Worker-Main-34/WARN]: null TextureAtlasSprite{name='minecraft:block/grass_block_side', frameCount=1, x=512, y=224, height=16, width=16, u0=0.5, u1=0.515625, v0=0.21875, v1=0.234375} [11:59:19] [Worker-Main-34/WARN]: null TextureAtlasSprite{name='minecraft:block/grass_block_side_overlay', frameCount=1, x=512, y=240, height=16, width=16, u0=0.5, u1=0.515625, v0=0.234375, v1=0.25} My guess is that the wrong RenderType is being used for my vertical slabs and I should use CUTOUT rather than SOLID. But I'm not sure how to do that and if it's correct. EDIT: This is what I get when I print out MinecraftForgeClient.getRenderType().toString() in my baked model: RenderType[solid:CompositeState[[texture[Optional[minecraft:textures/atlas/blocks.png](blur=false, mipmap=true)], shader[Optional[net.minecraft.client.renderer.RenderStateShard$$Lambda$4781/0x0000000800bcc238@3d572b5f]], no_transparency, depth_test[<=], cull[true], lightmap[true], overlay[false], no_layering, main_target, default_texturing, write_mask_state[writeColor=true, writeDepth=true], line_width[1.0]], outlineProperty=affects_outline]] So yes it is SOLID and maybe CUTOUT is not needed but just a way to set that overlay property to true? Also I think a similar problem will arise when vertical slabs will need to mimic blocks that have transparency, but I couldn't find any mod that adds transparent slabs to test it out.
  18. Sure thing, I need to add some logs here and there throughout my code, I will start from here.
  19. What if I were to wrap referringBlockState.getLightEmission(level, pos) with a try & catch, catching any Exception that may arise, and if I get an exception I call the bare getLightEmission instead? Something like this basically: try { blockstate = blockstate.setValue(LEVEL, referringBlockState.getLightEmission(level, pos)); } catch (Exception e) { blockstate = blockstate.setValue(LEVEL, referringBlockState.getLightEmission()); } To have my mod to its best to get as accurate as possible.
  20. Honestly I have no idea, I saw around in Minecraft code that whenever BlockState#setValue was used to set some primitive property the value was always wrapped like that, so I assumed there was a reason for that. Then what should I do? Should I call the deprecated BlockStateBase#getLightEmission?
  21. Okay, I updated my code as follows and now it works! I also removed my override of getLightEmission. @Override public BlockState getStateForPlacement(BlockPlaceContext placeContext) { BlockPos pos = placeContext.getClickedPos(); Level level = placeContext.getLevel(); BlockState blockstate = this.defaultBlockState().setValue(FACING, placeContext.getHorizontalDirection()).setValue(WATERLOGGED, Boolean.valueOf(level.getFluidState(pos).getType() == Fluids.WATER)); BlockState referringBlockState = VerticalSlabUtils.getReferringBlockState(placeContext.getItemInHand()); if (referringBlockState != null) { blockstate = blockstate.setValue(LEVEL, Integer.valueOf(referringBlockState.getLightEmission(level, pos))); } return blockstate.setValue(SHAPE, getStairsShape(blockstate, level, pos)); }
  22. Perfect, done! I tried to do this and I failed... I changed VerticalSlabBlock#getLightEmission to: @Override public int getLightEmission(BlockState state, BlockGetter getter, BlockPos pos) { BlockState referringBlockState = VerticalSlabUtils.getReferringBlockState(getter, pos); if (referringBlockState != null) { int lightLevel = 15; // int lightLevel = referringBlockState.getLightEmission(getter, pos); state.setValue(LEVEL, Integer.valueOf(lightLevel)); return lightLevel; } return super.getLightEmission(state, getter, pos); } and I added the LEVEL property initialization like so: public VerticalSlabBlock() { super( BlockBehaviour.Properties.of(Material.AIR) .isValidSpawn((state, getter, pos, entityType) -> false) .isRedstoneConductor((state, getter, pos) -> false) .isSuffocating((state, getter, pos) -> false) .lightLevel(LightBlock.LIGHT_EMISSION) ); this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH).setValue(SHAPE, StairsShape.STRAIGHT).setValue(WATERLOGGED, Boolean.valueOf(false)).setValue(LEVEL, Integer.valueOf(0))); } and LEVEL is just BlockStateProperties#LEVEL. However nothing changed, I have the same problem. Also I would like that the item too has the correct light emission, so that it works with shaders that add dynamic lighting. And I would really love to do that, if only I knew how 🤣 I will try to look up how other hooks are implemented to see if I can do it. Do you have any insight about the recipe book? I'm sorry for asking so many questions every time, but it's really my first mod this complex and I'm discovering many things as I go, and know I'm really grateful because I couldn't have done without your help. I added you in the mod credits and I can't wait to finally publish this mod!
  23. This works, thanks! I understand. Then I will just go making available only the main block recipe, for example stone into stone vertical slab, but no stone into stone brick vertical slab. Anyway it's just for stonecutting, so it's important to at least have the vertical slab of the block you're using. Then it's not that important to have also all the variants mostly because normal slab variants will be available and so you can just craft them into the desired vertical slab with a single extra step. I'll consider this a small price to pay for scalability. I have now a few things left to do for this mod: Add in-world recipes for waxing. I have already added crafting waxing recipes and they correctly depend on the waxing crafting recipes of normal slabs. I would like to do the same but with the in-world waxing recipe, that is right-clicking with an honeycomb to wax a vertical slab that mimics a block that has a slab that can be in-world waxed. I would go with listening to the right-click block event and do my logic there, but I saw on Forge docs that there is a way to reuse my recipe logic to create a in-world recipe. So if there's a way to do that I'd kindly ask some suggestions on how to do that, otherwise I will just subscribe to the event and that's it. Integrate my recipes with Minecraft Vanilla recipes book. I don't know what to do for this to be honest. Fix a problem I found out when placing a vertical slab that's supposed to emit light: when first placed the texture of the vertical slab looks like it's light up however the vertical slab is not emitting light at all, indeed the light level is 0 all around. When placing another block next to it the vertical slab starts to emit light correctly, same goes on with reloading the world. I saw that VerticalSlabBlock#getLightEmission is called several times when placing/updating the vertical slab, many times with 0 and many times with the correct light level. I don't know how to fix this. This can be tested changing the return value of VerticalSlabBlock#getLightEmission to 15 when referringBlockState != null. Make so that jumpFactor and speedFactor come from the mimicked block. But this we said that can't be changed unless Forge adds hooks for them, however I was thinking that maybe there's a way to override Entity#getBlockJumpFactor and Entity#getBlockSpeedFactor so that if a vertical slab is involved they pass to my VerticalSlabBlock the level and position that allow to mimic the correct block? P.S. would you like to be listed as co-author or in credits (your choice)? Because none of this would have been possible without you so I would like to give you the credit you deserve, of course only if you want ot.
  24. I did this: @Override public BlockToVerticalSlabStonecutterRecipe fromNetwork(ResourceLocation resourceLocation, FriendlyByteBuf friendlyByteBuf) { return new BlockToVerticalSlabStonecutterRecipe(true); } Where that true is the value for a private final boolean field of my BlockToVerticalSlabStonecutterRecipe, but it appears that the field is always false and my Serializer#fromNetwork is never getting called (I put some breakpoints and they never got activated). I'm probably missing out once again something obvious. Mmh... I will try to explain myself better: there are cases where a block can be stonecut into 2 different kind of slabs, so I need to have 2 different vertical slab recipes for that block too. However this, like the rest of this mod, must be dynamic, I can't go with a solution that will work when there are 2 slabs but not 3 or more, I'd need a way to dynamically add the stonecutting vertical slab recipes. For example let's take stone: it can be stonecut into stone slab and brick stone slab, so I need that also a vertical slab mimicking stone and a vertical slab mimicking stone bricks can be stonecut from stone. Let's suppose another mod adds a new stone variant, which we'll call stone tiles. Now the stonecutting recipes for stone have an extra slab, the stone tiles slab. Without any extra step also a vertical slab for stone tiles should be present in the stonecutting menu.
×
×
  • Create New...

Important Information

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