Jump to content

Recommended Posts

Posted (edited)

The title basically says it. Similar to what you might see in a Tinkers Construct lava tank.

I have basically no knowledge of custom block rendering, and looking online I've only found nothing super useful. Yes, I'm aware TC is open source, but it's hard to learn something from example when you have no knowledge to kick off from.

 

Here's what I already have:

  • I already have some variable that represents the water level stored in a tile entity. I can easily convert this number to a percentage.
  • I already have block model and block state json files, which I have responding to IProperties.

 

Here's what I want to know how to do:

  • I want to render water on the sides and top (the user can only look in from the north, south, and top, but since the block can be rotated it might be easier to render on all sides) with a height according to water level value
  • I want to register my custom renderer if necessary (this is something I haven't managed to find anywhere)
  • I would prefer if I could do this algorithmically rather than needing to make a ton of block model files because I'm sure this can be done algorithmically
  • I do NOT need to have support for any liquid other than water

 

Again, emphasis on I've never touched custom block renderers before, even in older versions of forge.

If there's already a really good explanation out there of how to do this, feel free to link me to that.

Thanks in advance to anyone who helps.

Edited by TheUnlocked
Posted

I haven't done anything like this myself, but have you looked at how Minecraft handles the standard water block?  IIRC it has a concept of how much space is left in the block based on the metadata.

Posted (edited)

BlockFluidRenderer does appear to have code for rendering fluids based on height, but it's generalized for ALL fluids, takes things like slope into account, and is completely unreadable to someone who has no experience with the specific topic. It's the same reason that reading the TC code is hard, but to an extreme.

Edited by TheUnlocked
Posted

See the blockstates and model JSONs for cauldron

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
26 minutes ago, jeffryfisher said:

See the blockstates and model JSONs for cauldron

I want a smooth animation, so blockstates/models are basically out of the option. From my OP:

18 hours ago, TheUnlocked said:
  • I would prefer if I could do this algorithmically rather than needing to make a ton of block model files because I'm sure this can be done algorithmically

 

Posted

Depends on what exactly do you want to acheve here and how do you want it to look. 

For a fluid tank I would use either a cusom IBakedModel (if I do not need the client to see smooth water level transitions in real time as the fluid level raises/loweres through say a pipe) or a FastTESR, and I think that you want the later.

Register your TESR using ClientRegistry::bindTileEntitySpecialRenderer. In the renderer itself use water texture UVs and render your desired image at desired positions with Tessellator(or rather put your vertex data in Tessellator's buffer). You can get the water texture using BlockModelShapes::getTexture(state). BlockModelShapes can be obtained through BlockRendererDispatcher::getBlockModelShapes and BlockRendererDispatcher lies at Minecraft::getBlockRendererDispatcher. You can see how exactly to use tessellator in vanilla TESRs. Or you might ask here for more clarification ;)

Just remember that with FastTESR you do not need to bind your textures or call neither begin nor draw methods.

  • Like 1
Posted (edited)
1 hour ago, V0idWa1k3r said:

You can see how exactly to use tessellator in vanilla TESRs. Or you might ask here for more clarification ;)

So I've made... a thing. It doesn't work, but to be fair I also didn't really expect it to. Where do I go from here?

 

Inside of renderTileEntityFast

final float PX = 1f / 16f; // Aligning with the block models
final float YOFF = 1 * PX;
final float BORDER = 2 * PX;
final float MAXHEIGHT = 10 * PX;

float actualHeight = (MAXHEIGHT * te.waterLevel) + YOFF;
BlockModelShapes bm = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
TextureAtlasSprite still =  bm.getTexture(Blocks.WATER.getDefaultState()); // What do I do with this?

//vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); // It complained at me (aka crashed) when I tried to use this
vertexBuffer.pos(BORDER, actualHeight, BORDER).tex(still.getMinU(), still.getMinV()).endVertex(); // I feel like I'm doing this all wrong
vertexBuffer.pos(1 - BORDER, actualHeight, BORDER).tex(still.getMaxU(), still.getMinV()).endVertex();
vertexBuffer.pos(1 - BORDER, actualHeight, 1 - BORDER).tex(still.getMaxU(), still.getMaxV()).endVertex();
vertexBuffer.pos(BORDER, actualHeight, 1 - BORDER).tex(still.getMinU(), still.getMaxV()).endVertex();

 

Inside of preInit

ClientRegistry.bindTileEntitySpecialRenderer(BlockExample.TileEntityExample.class, new RenderExample());

 

Edited by TheUnlocked
Posted (edited)
10 minutes ago, TheUnlocked said:

TextureAtlasSprite still = bm.getTexture(Blocks.WATER.getDefaultState()); // What do I do with this?

This is fine, you do not need to do anything with this ;)

It is not rendering because it is... at 0,0,0. Why do you think there are x/y/z parameters given to you in renderTileEntityFast? :D

Vanilla translates TEs in it's rendering using GlStateManager, but you can't do that because of FastTESR. Simply translate your vertices.

Also the default vertexformat is BLOCK. Meaning that you need to specify more than xyz+uv in your vertices. You need to specify xyz + color(as 4 bytes(rgba)) + uv + lightmap

Edited by V0idWa1k3r
Posted (edited)
13 minutes ago, V0idWa1k3r said:

This is fine, you do not need to do anything with this ;)

After doing what you said, it does render the water, but why? It's very un-intuitive for a get function to set a value.

 

13 minutes ago, V0idWa1k3r said:

You need to specify xyz + color(as a hex integer) + uv + lightmap

I'm wonder what I'm supposed to put for the lightmap. My version of forge has those parameters obfuscated, and I don't completely get what the lightmap is. I think it has something to do with sun/artificial light, but ¯\_(ツ)_/¯

 

The same goes for color. I just stuck 

.color(1f,1f,1f,1f)

onto all of the vertices, but idk if that's what I'm supposed to do.

 

I have a feeling this is related to the lightmap and color, but the water texture is super dark (as seen in the attached image).

2017-05-14_13.58.49.png

Edited by TheUnlocked
Posted
1 minute ago, TheUnlocked said:

It's very un-intuitive for a get function to set a value.

It does not. It just takes a blockstate and returns a texture of that blockstate. Different blockstates can have different textures :) This is not the case for a water block, thus you do not have to do anything with it.

A lightmap is... kinda obscure but it just controls the 'final' brightness of your texture, it's exposure to light and light's color(you know how in vanilla torches, sun and moon slightly vary in color of light they cast? That is your lightmap coordinates.) You can see how lightmap is normally calculated at Particle::renderParticle. To be precise, the

int i = this.getBrightnessForRender(partialTicks);
int j = i >> 16 & 65535;
int k = i & 65535;

j and k are the lightmap coordinates here and getBrightnessForRender simply returns the combined light value for a specified block position(in particle's case the position the particle is at)

  • Like 1
Posted

Thanks so much for the help. One more question: How would I go about adding more faces? It feels a bit sketchy to just add more vertices because I don't really get where or when I would add them.

 

I'm fine with making a whole cube rather than just three faces if that's easier. If not, that's fine too.

Posted

A whole cube is 6 more faces. You would add them just after the 4 vertices definitions for your up face - add 4 more for 1 more face and so on. You might need to experiment a bit with UVs/positions to make your face render the correct way but is it quite easy once you get used to vertexbuffer :)

  • Like 1
Posted (edited)

Thanks for all the help! It works now! :D

 

For others who are looking for examples, here's my complete RenderExample class

public class RenderExample extends FastTESR<BlockExample.TileEntityExample>{
    @Override
    public void renderTileEntityFast(@Nonnull BlockExample.TileEntityExample te, double x, double y, double z, float partialTicks, int destroyStage, @Nonnull VertexBuffer vertexBuffer) {
        final float PX = 1f / 16f;
        final float YOFF = 1 * PX;
        final float BORDER = 1.9f * PX;
        final float MAXHEIGHT = 10 * PX;
        final float LOW = 5.9f * PX;

        float actualHeight = (MAXHEIGHT * te.waterLevel) + YOFF;
        BlockModelShapes bm = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
        TextureAtlasSprite still =  bm.getTexture(Blocks.WATER.getDefaultState());
        TextureAtlasSprite flow =  bm.getTexture(Blocks.FLOWING_WATER.getDefaultState());

        // Lightmap calculations
        int upCombined = getWorld().getCombinedLight(te.getPos().up(), 0);
        int upLMa = upCombined >> 16 & 65535;
        int upLMb = upCombined & 65535;

        int northCombined = getWorld().getCombinedLight(te.getPos().add(new BlockPos(0,0,1)), 0);
        int northLMa = northCombined >> 16 & 65535;
        int northLMb = northCombined & 65535;

        int southCombined = getWorld().getCombinedLight(te.getPos().add(new BlockPos(0,0,-1)), 0);
        int southLMa = southCombined >> 16 & 65535;
        int southLMb = southCombined & 65535;

        int westCombined = getWorld().getCombinedLight(te.getPos().add(new BlockPos(-1,0,0)), 0);
        int westLMa = westCombined >> 16 & 65535;
        int westLMb = westCombined & 65535;

        int eastCombined = getWorld().getCombinedLight(te.getPos().add(new BlockPos(1,0,0)), 0);
        int eastLMa = eastCombined >> 16 & 65535;
        int eastLMb = eastCombined & 65535;

        vertexBuffer.setTranslation(x,y,z);

        //UP face
        vertexBuffer.pos(BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(still.getMinU(), still.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(still.getMaxU(), still.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(still.getMaxU(), still.getMaxV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(still.getMinU(), still.getMaxV()).lightmap(upLMa,upLMb).endVertex();

        //NORTH face

        vertexBuffer.pos(BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, LOW, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMaxV()).lightmap(northLMa,northLMb).endVertex();
        vertexBuffer.pos(BORDER, LOW, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMaxV()).lightmap(northLMa,northLMb).endVertex();

        //SOUTH face
        vertexBuffer.pos(BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, LOW, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMaxV()).lightmap(southLMa,southLMb).endVertex();
        vertexBuffer.pos(BORDER, LOW, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMaxV()).lightmap(southLMa,southLMb).endVertex();

        //WEST face
        vertexBuffer.pos(BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(BORDER, LOW, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMaxV()).lightmap(westLMa,westLMb).endVertex();
        vertexBuffer.pos(BORDER, LOW, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMaxV()).lightmap(westLMa,westLMb).endVertex();

        //EAST face
        vertexBuffer.pos(1 - BORDER, actualHeight, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, actualHeight, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMinV()).lightmap(upLMa,upLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, LOW, 1 - BORDER).color(1f,1f,1f,0.8f).tex(flow.getMaxU(), flow.getMaxV()).lightmap(eastLMa,eastLMb).endVertex();
        vertexBuffer.pos(1 - BORDER, LOW, BORDER).color(1f,1f,1f,0.8f).tex(flow.getMinU(), flow.getMaxV()).lightmap(eastLMa,eastLMb).endVertex();
    }
}

 

And registering the FastTESR put this in preInit:

ClientRegistry.bindTileEntitySpecialRenderer(BlockCrystalGrowthChamber.TileEntityCrystalGrowthChamber.class, new RenderCrystalGrowthChamber());

 

And finally what it looks like (the rest of the model is registered like a regular block model):

2017-05-14_15.30.57.png

Edited by TheUnlocked

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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