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

[1.15] Rendering Blocks/QUADS (GlStateManager, tessellator, bufferBuilder) - Client Side


M1ntcraft3r
 Share

Recommended Posts

Hi all,

 

I was working on a custom mod in 1.14 which finds blocks (chests, ores etc.) around the player, adds them to an array and then renders those blocks based on distance to the player.

The mod was working and the ores/chests were colored based on the type of block and alpha was applied based on the distance to the player.

 

However, in 1.15, it no longer works.

The blocks are still found (and the coordinates are corect) but when they are being rendered, it seems to render them in a very odd place even though the coordinates for x, y, z are correct.

When I say an odd place, it's a little difficult to explain:

  • when moving the head of the player, the render remains static
  • when moving around, the render does move, but it does not correspond to the position of the ores/chest
  • sometimes I can have the chest sittin in front of me, but the render is behind me and I have to move back to see it (still it does not correstpond to the location of the chest

I know this is probably a long shot for someone to help me with so little info, maybe I could post screenshots if you think this would help?

 

In 1.14, I used the GlStateManager/Tessellator to render all surfaces as quads, creating a box around the blocks of interest.

I am not actually sure if this is the best way of doing such renders or if there is a much easier way. I spent a lot of time looking online to find ways to render blocks (or surfaces) and this was the only way I found that actually worked reliably.

So please, if you know of a better, more efficient way, please share your thoughts here. I am very new to modding though and I would massively appreciate an example to render a block at 0, 65, 0.

 

I would like to point out that this is not something I am ever planning on releasing, but rather a mod I am using to learm Forge modding...

I started with blocks in the vasinity of the player (based on coordinates) to start off but wanted to get into trying to get this info from loaded chunks etc., however, since this no longer works properly in 1.15, I'm basically stuck where I was when I started the mod.

 

Below is the code I am using in 1.15 and the only changes to 1.14 I had to make was the getPosX(), getPosY() and getPosZ(), previously this was posX(), posY(), posZ().

 

package com.example.examplemod;

import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;

import java.util.List;

import static java.lang.Math.sqrt;
import static net.minecraft.block.Blocks.*;
import static net.minecraft.block.Blocks.CHEST;
import static net.minecraft.world.biome.Biome.LOGGER;

public class BlockRenderedBox {

    public static void renderBlockOutline(float partialTicks) {
        ClientPlayerEntity playerEntity = Minecraft.getInstance().player;
        double x = playerEntity.lastTickPosX + (playerEntity.getPosX() - playerEntity.lastTickPosX) * partialTicks;
        double y = playerEntity.lastTickPosY + (playerEntity.getPosY() - playerEntity.lastTickPosY) * partialTicks;
        double z = playerEntity.lastTickPosZ + (playerEntity.getPosZ() - playerEntity.lastTickPosZ) * partialTicks;


        if (ExampleMod.RedstoneOres.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.RedstoneOres, playerEntity);
        }
        if (ExampleMod.DiamondOres.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.DiamondOres, playerEntity);
        }
        if (ExampleMod.GoldOres.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.GoldOres, playerEntity);
        }
        if (ExampleMod.Chests.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.Chests, playerEntity);
        }
        if (ExampleMod.Heads.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.Heads, playerEntity);
        }
        if (ExampleMod.ClayBlocks.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.ClayBlocks, playerEntity);
        }
        if (ExampleMod.toRender.size() > 0) {
            BlockRenderedBox.render(x,y,z,ExampleMod.toRender, playerEntity);
        }

    }




    private static void render(double x, double y, double z, List<BlockPos> ore, ClientPlayerEntity player){
        for (int i = 0; i < ore.size(); i++) {
            GlStateManager.pushMatrix();

            Vec3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
            GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

            GlStateManager.enableBlend();
            GlStateManager.disableCull();
            GlStateManager.disableDepthTest();
            GlStateManager.disableTexture();
            GlStateManager.disableLighting();
            GlStateManager.disableAlphaTest();

            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bufferBuilder = tessellator.getBuffer();

            bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);

            Block block = player.world.getBlockState(ore.get(i)).getBlock();

            double distance_to_ore = sqrt(ore.get(i).distanceSq(player.getPosX(), player.getPosY(), player.getPosZ(), true));
            float alpha = 0.1f;
            if(distance_to_ore >= 30){
                GlStateManager.lineWidth(1);
                alpha = 1f;
            }
            if(distance_to_ore < 30 && distance_to_ore > 20){
                GlStateManager.lineWidth(5);
                alpha = 0.3f;
            }
            if(distance_to_ore > 10 && distance_to_ore < 20){
                GlStateManager.lineWidth(10);
                alpha = 0.2f;
            }
            if(distance_to_ore <= 10){
                GlStateManager.lineWidth(15);
                alpha = 0.1f;
            }

            if(block == REDSTONE_ORE){
                GL11.glColor4f(1f,0f,0f, alpha);
            }
            if(block == GOLD_ORE){
                GL11.glColor4f(0.95f,1f,0f,alpha);
            }
            if(block == DIAMOND_ORE){
                GL11.glColor4f(0f,0.968f,0.968f,alpha);
            }
            if(block == CHEST){
                GL11.glColor4f(0f,0.968f,0.968f,alpha);
            }
            if(block == PLAYER_HEAD){
                GL11.glColor4f(0f,1f,0f,alpha);
            }
            if(block == CLAY){
                GL11.glColor4f(0f,1f,0f,alpha);
            }

            // bottom
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();

            // top
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY()+ 1, ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY()+ 1, ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY()+ 1, ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY()+ 1, ore.get(i).getZ() + 1).endVertex();

            // left
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY() + 1, ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY() + 1, ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();

            // right
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY() + 1, ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY() + 1, ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();

            // front
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY() + 1, ore.get(i).getZ()).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY() + 1, ore.get(i).getZ()).endVertex();

            // back
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY(), ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX() + 1, ore.get(i).getY() + 1, ore.get(i).getZ() + 1).endVertex();
            bufferBuilder.pos(ore.get(i).getX(), ore.get(i).getY() + 1, ore.get(i).getZ() + 1).endVertex();


            tessellator.draw();
            GlStateManager.enableCull();
            GlStateManager.enableDepthTest();
            GlStateManager.enableTexture();
            GlStateManager.enableLighting();
            GlStateManager.disableBlend();
            GlStateManager.enableAlphaTest();
            GlStateManager.popMatrix();
        }
    }


}

 

Any help is much appreciated!

 

Thanks in advance

 

Tim

Edited by M1ntcraft3r
Link to comment
Share on other sites

I actually just solved this problem with a very similar mod to yours here.

 

Shortened Version

If you are doing this from RenderWorldLastEvent, it no longer maintains the player's head rotation. To fix this, you need to rotate the matrix so it is correct.

 

ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
Vec3d projectedView = renderInfo.getProjectedView();
GlStateManager.rotatef(renderInfo.getPitch(), 1, 0, 0); // Fixes camera rotation.
GlStateManager.rotatef(renderInfo.getYaw() + 180, 0, 1, 0); // Fixes camera rotation.
GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

 

Edited by xChris6041x
Link to comment
Share on other sites

32 minutes ago, xChris6041x said:

I actually just solved this problem with a very similar mod to yours here.

 

Shortened Version

If you are doing this from RenderWorldLastEvent, it no longer maintains the player's head rotation. To fix this, you need to rotate the matrix so it is correct.

 


ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
Vec3d projectedView = renderInfo.getProjectedView();
GlStateManager.rotatef(renderInfo.getPitch(), 1, 0, 0); // Fixes camera rotation.
GlStateManager.rotatef(renderInfo.getYaw() + 180, 0, 1, 0); // Fixes camera rotation.
GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

 

Amazing!

I had a quick check and it seems to track it again!

 

Thanks so much for your reply mate!

Link to comment
Share on other sites

52 minutes ago, xChris6041x said:

I actually just solved this problem with a very similar mod to yours here.

 

Shortened Version

If you are doing this from RenderWorldLastEvent, it no longer maintains the player's head rotation. To fix this, you need to rotate the matrix so it is correct.

 


ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
Vec3d projectedView = renderInfo.getProjectedView();
GlStateManager.rotatef(renderInfo.getPitch(), 1, 0, 0); // Fixes camera rotation.
GlStateManager.rotatef(renderInfo.getYaw() + 180, 0, 1, 0); // Fixes camera rotation.
GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

 

Interestingly it renders even over the players hand but I think I read something about that cuz its the RenderWorldLastEvent

Link to comment
Share on other sites

1 hour ago, xChris6041x said:

That is interesting, it doesn't do that on my mod. I tweaked mine to try and find the cause, but no luck.

Thanks for checking..

I'll have to search the web again cuz I know someone had a similar issue and if I recall correctly, there was a solution.

Hopefully I'll find it.

 

It is odd thought that you're not seeing it.

Anyway I'll post an update over the next few days!

 

Thanks again for your help Chris

Link to comment
Share on other sites

On 2/23/2020 at 4:51 AM, TheGreyGhost said:

Howdy

I haven't tried solving this problem myself, yet, but my research has found a relevant clue perhaps-?

Forge 1.15 update

 

You might need to make use of the event.getMatrix().

 

-TGG

Thanks Ghost!

This actually looks like what I need and also what Chris seemed to have tried in his thread (to some extend).

 

Unfortunately I have not been able to get it to work but it looks like the IRenderTypeBuffer is the new way to go and thats how it should be done, rather than the Tessellator, BufferBuilder and the GlStateManager!

 

If someone has a basic method which plots a few quads at a given location, that would be great.

 

I spend a few hours at the weekend trying to get this to work but unforunately I got nowhere. I also don't want to paste my old code which plotts all the quads but still doesn't have the players hand ocrrected becasue this seems to be the outdated way to do it anyway.

 

Thanks in advance

Link to comment
Share on other sites

On 2/22/2020 at 8:32 PM, xChris6041x said:

That is interesting, it doesn't do that on my mod. I tweaked mine to try and find the cause, but no luck.

So Chris, I think I have sort of worked it out... If I draw a single quad, the player hand reamains rendered but if I loop over an array, it disappears.

The way I am doing it is:

 

        ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
        Vec3d projectedView = renderInfo.getProjectedView();

        GlStateManager.rotatef(renderInfo.getPitch(), 1, 0, 0); // Fixes camera rotation.
        GlStateManager.rotatef(renderInfo.getYaw() + 180, 0, 1, 0); // Fixes camera rotation.
        GlStateManager.translated(-projectedView.x, -projectedView.y, -projectedView.z);

 

then for each box, I am calling:

            GlStateManager.pushMatrix();
            GlStateManager.enableBlend();
            GlStateManager.disableCull();
            GlStateManager.disableDepthTest();
            GlStateManager.disableTexture();
            GlStateManager.disableLighting();
            GlStateManager.disableAlphaTest();
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bufferBuilder = tessellator.getBuffer();

            bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
            Block block = player.world.getBlockState(oresBlockPosList.get(oreBlockPos)).getBlock();


            // bottom
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();

            // top
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY()+ 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY()+ 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY()+ 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY()+ 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();

            // left
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();

            // right
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();

            // front
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ()).endVertex();

            // back
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY(), oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX() + 1, oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();
            bufferBuilder.pos(oresBlockPosList.get(oreBlockPos).getX(), oresBlockPosList.get(oreBlockPos).getY() + 1, oresBlockPosList.get(oreBlockPos).getZ() + 1).endVertex();

            // Tessellator has to come before the rest or some of the GlStateManager stuff
            tessellator.draw();
            GlStateManager.enableCull();
            GlStateManager.enableDepthTest();
            GlStateManager.enableTexture();
            GlStateManager.enableLighting();
            GlStateManager.disableBlend();
            GlStateManager.enableAlphaTest();
            GlStateManager.popMatrix();

 

Basically I am not sure if I need to 

1) Push and Pop the matrix for each bufferBuilder?

2) Draw tessellator every time

3) Create a new BufferBuilder for each block (6 quads)

 

Also, if you worked out how to use the RenderSystem and the matrixStack, please share it with me, it'd be much appreachiated.

 

Thanks

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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hello everyone, like the title suggest, I've a problem running dedicated server for my mod "emomod, Emotion's Mod", I understand that the problem is caused by my containers because of invalid dist and I understand the concept of side but I really struggle to fix it, for the lore I'm developing this mod since 5 or 6 years from now so it's a huge one, I have like 281 block textures, 167 item textures, biomes, game mechanics, dimensions, entities etc.. I love it but I kept it private for the moment (I may send it public soon) and I use to get back on it sometimes when I want to update the version (I also rewrite everything once because I suck to do so for the version 1.8 to 1.12 / 1.14) or add stuff for example, here is the log of the server :   I'm registering Biome, Block, ContainerType, TileEntityType etc.. In differents class that I'm calling in my main one called "MainRegistry" with the method init().   Firstly, the classe where I'm registering ContainerType is modestly named "ContainerTypeRegistry" (this is my convention), I've currently three type of container, "CRAFTER" wich is a complex automatic crafting machine, "BAG" is a bag item storing stuff using "ItemStackHandler" and finally Nightstand is a basic chest with less slots (4) using different color GUIs based on the wood used to craft, here is the code :   @Mod.EventBusSubscriber(modid = MainRegistry.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ContainerTypeRegistry { private static final List<ContainerType<?>> containerTypeList = new ArrayList<ContainerType<?>>(); public static final ContainerType<CrafterContainer> CRAFTER = IForgeContainerType.create((windowId, inv, data) -> { BlockPos pos = data.readBlockPos(); return new CrafterContainer(windowId, MainRegistry.proxy.getClientWorld(), pos, MainRegistry.proxy.getClientPlayer()); }); public static final ContainerType<BagContainer> BAG = IForgeContainerType.create((windowId, inv, data) -> { return new BagContainer(windowId, inv); }); public static final ContainerType<NightstandContainer> NIGHTSTAND = IForgeContainerType.create((windowId, inv, data) -> { BlockPos pos = data.readBlockPos(); return new NightstandContainer(windowId, inv.player.getEntityWorld(), pos, inv); }); public static void init() { addContainerType(CRAFTER, "crafter"); addContainerType(BAG, "bag"); addContainerType(NIGHTSTAND, "nightstand"); } public static void addContainerType(ContainerType<?> tet, String name) { containerTypeList.add(tet.setRegistryName(name)); } @SubscribeEvent public static void registerContainerType(final RegistryEvent.Register<ContainerType<?>> e) { for (ContainerType<?> tet : containerTypeList) { e.getRegistry().register(tet); } } } Secondly, I'm using the same technique to register TileEntityType and I'm calling all those init methods but also ScreenManager.registerFactory() like I said in the main class just here :   @Mod(MainRegistry.MOD_ID) public class MainRegistry { public static final String MOD_ID = "emomod"; public static final Logger LOGGER = LogManager.getLogger(MOD_ID); public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy()); public static MainRegistry instance; public static WorldType PARCEL_TYPE = new ParcelWorldType(); public static WorldType DREAM_TYPE = new DreamWorldType(); public MainRegistry() { ItemRegistry.init(); BlockRegistry.init(); TileEntityTypeRegistry.init(); EntityTypeRegistry.init(); SurfaceBuilderRegistry.init(); PlacementRegistry.init(); FeatureRegistry.init(); FluidRegistry.init(); ContainerTypeRegistry.init(); DispenserBlock.registerDispenseBehavior(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.WATER).getItem(), new IInteractBehavior()); DispenserBlock.registerDispenseBehavior(Items.WHEAT_SEEDS, new IPlaceBehavior(Blocks.WHEAT, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.PUMPKIN_SEEDS, new IPlaceBehavior(Blocks.PUMPKIN_STEM, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.MELON_SEEDS, new IPlaceBehavior(Blocks.MELON_STEM, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.BEETROOT_SEEDS, new IPlaceBehavior(Blocks.BEETROOTS, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.CARROT, new IPlaceBehavior(Blocks.CARROTS, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.POTATO, new IPlaceBehavior(Blocks.POTATOES, Blocks.FARMLAND)); DispenserBlock.registerDispenseBehavior(Items.OAK_SAPLING, new IPlaceBehavior(Blocks.OAK_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.ACACIA_SAPLING, new IPlaceBehavior(Blocks.ACACIA_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.BIRCH_SAPLING, new IPlaceBehavior(Blocks.BIRCH_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.DARK_OAK_SAPLING, new IPlaceBehavior(Blocks.DARK_OAK_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.JUNGLE_SAPLING, new IPlaceBehavior(Blocks.JUNGLE_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.SPRUCE_SAPLING, new IPlaceBehavior(Blocks.SPRUCE_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.BAMBOO, new IPlaceBehavior(Blocks.BAMBOO_SAPLING, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); DispenserBlock.registerDispenseBehavior(Items.NETHER_WART, new IPlaceBehavior(Blocks.NETHER_WART, Blocks.SOUL_SAND, Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::serverSetup); MinecraftForge.EVENT_BUS.register(new EmotionOverlayEvent()); MinecraftForge.EVENT_BUS.register(new EmotionLivingEvent()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySign.class, new TileEntitySignRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrafter.class, new TileEntityCrafterRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPot.class, new TileEntityPotRenderer()); LootConditionManager.registerCondition(new HarvestLevelCondition.Serializer()); EmomodPacketHandler.registerMessages(); } private void setup(final FMLCommonSetupEvent e) { proxy.init(); RenderingRegistry.registerEntityRenderingHandler(OrbSpellEntity.class, render -> new SpriteRenderer<OrbSpellEntity>(render, Minecraft.getInstance().getItemRenderer())); RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, render -> new RendererButterfly(render)); RenderingRegistry.registerEntityRenderingHandler(EntityBeetle.class, render -> new RendererBasic<EntityBeetle, ModelBeetle>(render, new ModelBeetle(), 0.175f, new ResourceLocation(MainRegistry.MOD_ID, "textures/entity/beetle.png"))); RenderingRegistry.registerEntityRenderingHandler(EntityLightningBug.class, render -> new RendererBasic<EntityLightningBug, ModelLightningBug>(render, new ModelLightningBug(), 0.0f, new ResourceLocation(MainRegistry.MOD_ID, "textures/entity/lightning_bug.png"))); RenderingRegistry.registerEntityRenderingHandler(EntityBoat.class, RendererBoat::new); RenderingRegistry.registerEntityRenderingHandler(EntityChubby.class, render -> new RendererBasic<EntityChubby, ModelChubby>(render, new ModelChubby(), .2f, new ResourceLocation(MainRegistry.MOD_ID, "textures/entity/chubby.png"))); RenderingRegistry.registerEntityRenderingHandler(EntityMouse.class, render -> new RendererMouse(render, new ModelMouse(), 0.1f)); RenderingRegistry.registerEntityRenderingHandler(EntityOrchardSpider.class, render -> new RendererOrchardSpider<EntityOrchardSpider>(render)); EmoOreGeneration.setupOreGeneration(); // RecipeRegistry.init(); } private void clientSetup(final FMLClientSetupEvent e) { EmoStaff staff = (EmoStaff) ItemRegistry.PURPURA_STAFF; Minecraft.getInstance().getItemColors().register((item, tintIndex) -> { return staff.getColor(new ItemStack(staff), tintIndex); }, staff); Minecraft.getInstance().getItemColors().register((item, tintIndex) -> { return GrassColors.get(0.5D, 1.0D); }, BlockRegistry.FLOWER_TALLGRASS); Minecraft.getInstance().getItemColors().register((item, tintIndex) -> { BlockState blockstate = ((BlockItem) item.getItem()).getBlock().getDefaultState(); return Minecraft.getInstance().getBlockColors().getColor(blockstate, (IEnviromentBlockReader) null, (BlockPos) null, tintIndex); }, BlockRegistry.LEAVES_CHERRY, BlockRegistry.LEAVES_PEAR, BlockRegistry.LEAVES_ORANGE, BlockRegistry.LEAVES_ATLAS, BlockRegistry.LEAVES_PINE, BlockRegistry.LEAVES_COCO, BlockRegistry.LEAVES_DREAM); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return reader != null && pos != null ? BiomeColors.getGrassColor(reader, pos) : GrassColors.get(0.5D, 1.0D); }, BlockRegistry.FLOWER_TALLGRASS); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return reader != null && pos != null ? BiomeColors.getFoliageColor(reader, pos) : FoliageColors.getDefault(); }, BlockRegistry.LEAVES_PINE, BlockRegistry.LEAVES_COCO, BlockRegistry.LEAVES_DREAM); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return 0xac73af; }, BlockRegistry.LEAVES_CHERRY); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return 0x487748; }, BlockRegistry.LEAVES_PEAR); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return 0x45a14a; }, BlockRegistry.LEAVES_ORANGE); Minecraft.getInstance().getBlockColors().register((state, reader, pos, color) -> { return 0x4496c4; }, BlockRegistry.LEAVES_ATLAS); ScreenManager.<CrafterContainer, CrafterScreen>registerFactory(ContainerTypeRegistry.CRAFTER, (container, playerInventory, title) -> { return new CrafterScreen(container, playerInventory, title); }); ScreenManager.<BagContainer, BagScreen>registerFactory(ContainerTypeRegistry.BAG, (container, playerInventory, title) -> { return new BagScreen(container, playerInventory, title); }); ScreenManager.<NightstandContainer, NightstandScreen>registerFactory(ContainerTypeRegistry.NIGHTSTAND, (container, playerInventory, title) -> { return new NightstandScreen(container, playerInventory, title, container.getTileEntity().getColor()); }); } private void serverSetup(final FMLDedicatedServerSetupEvent e) { } } Finally for the specific class I'm only gonna send the Nightstand one in random way :   - Block class :   public class EmoNightstand extends Block { private static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; private static final VoxelShape NIGHTSTAND_SHAPE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 15.0D, 15.0D); private float[] color; public EmoNightstand(Properties properties, float[] color) { super(properties); this.getDefaultState().with(FACING, Direction.NORTH); this.color = color; } @Override public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return NIGHTSTAND_SHAPE; } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return NIGHTSTAND_SHAPE; } @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (!worldIn.isRemote) { TileEntity tileEntity = worldIn.getTileEntity(pos); if (tileEntity instanceof INamedContainerProvider) { NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos()); } } return true; } public BlockState getStateForPlacement(BlockItemUseContext context) { return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); } protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(FACING); } @Override public boolean hasTileEntity(BlockState state) { return true; } @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new TileEntityNightstand(this.color); } } - The ContainerScreen class :   public class NightstandScreen extends ContainerScreen<NightstandContainer> { private static final ResourceLocation NIGHTSTAND_GUI_SCREEN = new ResourceLocation(MainRegistry.MOD_ID, "textures/gui/container/nightstand.png"); private float[] color; public NightstandScreen(NightstandContainer screenContainer, PlayerInventory playerInventory, ITextComponent titleIn, float[] color) { super(screenContainer, playerInventory, titleIn); this.xSize = 176; this.ySize = 127; this.color = color; } protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.font.drawString(this.getTitle().getFormattedText(), 8, 4, 0); this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 2), 0); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { int xPos = (this.width - this.xSize) / 2; int yPos = (this.height - this.ySize) / 2; GlStateManager.color4f(1.0f, 1.0f, 1.0f, 1.0f); this.minecraft.getTextureManager().bindTexture(NIGHTSTAND_GUI_SCREEN); this.blit(xPos, yPos, 0, 0, this.xSize, this.ySize); GlStateManager.color4f(color[0] / 255, color[1] / 255, color[2] / 255, 1.0f); this.blit(xPos, yPos, 0, 0, this.xSize, this.ySize); GlStateManager.disableTexture(); GlStateManager.enableBlend(); GlStateManager.disableAlphaTest(); GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); GlStateManager.shadeModel(7425); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_COLOR); bufferbuilder.pos((double) xPos + this.xSize, (double) yPos, (double) this.blitOffset).color(0, 0, 0, 0).endVertex(); bufferbuilder.pos((double) xPos, (double) yPos, (double) this.blitOffset).color(0, 0, 0, 0).endVertex(); bufferbuilder.pos((double) xPos, (double) yPos + this.ySize, (double) this.blitOffset).color(0, 0, 0, 255 / 2).endVertex(); bufferbuilder.pos((double) xPos + this.xSize, (double) yPos + this.ySize, (double) this.blitOffset).color(0, 0, 0, 255 / 2).endVertex(); tessellator.draw(); GlStateManager.shadeModel(7424); GlStateManager.disableBlend(); GlStateManager.enableAlphaTest(); GlStateManager.enableTexture(); } } The Container class :   public class NightstandContainer extends Container { private TileEntity tileEntity; private int containerSlots = 0; public NightstandContainer(int id, World world, BlockPos pos, PlayerInventory playerInventory) { super(ContainerTypeRegistry.NIGHTSTAND, id); this.tileEntity = world.getTileEntity(pos); tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> { containerSlots = h.getSlots(); for (int i = 0; i < h.getSlots(); i++) { addSlot(new SlotItemHandler(h, i, 44 + (i * 18) + (i > 1 ? 18 : 0), 14)); } }); for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlot(new Slot(playerInventory, x + y * 9 + 9, 8 + (x * 18), 45 + (y * 18))); } } for (int k = 0; k < 9; ++k) { this.addSlot(new Slot(playerInventory, k, 8 + k * 18, 103)); } } @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { Slot slot = this.getSlot(index); if (!slot.canTakeStack(playerIn)) return slot.getStack(); if (!slot.getHasStack()) return ItemStack.EMPTY; ItemStack stack = slot.getStack(); ItemStack newStack = stack.copy(); if (index < containerSlots) { if (!this.mergeItemStack(stack, containerSlots, this.inventorySlots.size(), true)) return ItemStack.EMPTY; slot.onSlotChanged(); } else if (!this.mergeItemStack(stack, 0, containerSlots, false)) return ItemStack.EMPTY; if (stack.isEmpty()) slot.putStack(ItemStack.EMPTY); else slot.onSlotChanged(); return slot.onTake(playerIn, newStack); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return this.isUsable(playerIn); } protected boolean isUsable(PlayerEntity playerIn) { return IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()).applyOrElse((block, pos) -> { return !(block.getBlockState(pos).getBlock() instanceof EmoNightstand) ? false : playerIn.getDistanceSq((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D) <= 64.0D; }, true); } @Nullable public TileEntityNightstand getTileEntity() { if (this.tileEntity instanceof TileEntityNightstand) return (TileEntityNightstand) this.tileEntity; else return null; } } The TileEntity class :   public class TileEntityNightstand extends TileEntity implements INamedContainerProvider { private LazyOptional<IItemHandler> handler = LazyOptional.of(this::createHandler); private float[] color = new float[] { 0.0f, 255.0f, 0.0f}; public TileEntityNightstand(float[] color) { this(); this.color = color; } public TileEntityNightstand() { super(TileEntityTypeRegistry.NIGHTSTAND); } @SuppressWarnings("unchecked") @Override public void read(CompoundNBT compound) { CompoundNBT inventory = compound.getCompound("Inventory"); handler.ifPresent(h -> ((INBTSerializable<CompoundNBT>) h).deserializeNBT(inventory)); super.read(compound); } @SuppressWarnings("unchecked") @Override public CompoundNBT write(CompoundNBT compound) { handler.ifPresent(h -> { CompoundNBT nbt = ((INBTSerializable<CompoundNBT>) h).serializeNBT(); compound.put("Inventory", nbt); }); return super.write(compound); } private IItemHandler createHandler() { return new ItemStackHandler(4) { @Override protected void onContentsChanged(int slot) { markDirty(); } }; } @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return handler.cast(); return super.getCapability(cap, side); } @Override public ITextComponent getDisplayName() { return new TranslationTextComponent("container.emomod.nightstand"); } @Override public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity player) { return new NightstandContainer(windowId, this.getWorld(), this.getPos(), playerInventory); } public float[] getColor() { return this.color; } } And voilà, I think that everything is here and I will really appreciate some help, this mod is very important for me and I've put so many efforts in it, I've to update it soon to the latest version (I may also want some paid help for that if I can apply some sort of dev recrutment on this forum) and I will stop adding stuff but polish everything up to finally set it public. Thanks again for giving me some of your time, I can send the WIP version of the mod jar as demo when this will be fixed if some of you want it, and also if I find a way to protect my textures from being copied / reused or modified.
    • https://mcforge.readthedocs.io/en/latest/concepts/sides/#writing-one-sided-mods
    • What?! Just use RegisterCommandsEvent. FMLServerStartingEvent is not involved with registering commands at all.
    • Only ModelRegistryEvent is necessary. Call ModelLoader.addSpecialModel in there and the model will be baked as normal.
    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.