Jump to content

Recommended Posts

Posted (edited)

I'm trying to render a block's bounding box as a solid color cube that can be seen through other blocks. I've searched for a few hours for a method that is both up to date and working but have had no luck so far. I haven't worked with 3D rendering before, so I am trying to use this as a basis to get started, so please forgive me if I ask too many questions. If you are unsure what it is I am trying to accomplish, try googling "chest finder" and looking at the images. (P.S. No, I am not making another hacked client) I don't wish to be spoonfed code, but I need help getting pushed in the right direction. Cheers!

Edited by Crypnotic
Posted

You can render the outline in any of forge's rendering events. I would recommend RenderWorldLastEvent.

To make it render on top of everything just disable depth in the GlStateManager. Don't forget to re-enale it once you are done.

The TileEntityStructureRenderer can assist you with rendering the box itself - see how it is done there, in vanilla.

Once you piece it all together you can store the positions of the blocks you want to outline in any array and in the event iterate through that array, offset the gl matrix accordingly(again, look at how vanilla handles it, generic entity rendering is the example you need) and render your box. 

Posted
52 minutes ago, V0idWa1k3r said:

You can render the outline in any of forge's rendering events. I would recommend RenderWorldLastEvent.

To make it render on top of everything just disable depth in the GlStateManager. Don't forget to re-enale it once you are done.

The TileEntityStructureRenderer can assist you with rendering the box itself - see how it is done there, in vanilla.

Once you piece it all together you can store the positions of the blocks you want to outline in any array and in the event iterate through that array, offset the gl matrix accordingly(again, look at how vanilla handles it, generic entity rendering is the example you need) and render your box. 

2

I did, afaik, everything you explained. It's rendering lines now, but they're rather... weird. It should be outlining the Andesite block, but it definitely is not.

2017-04-30_11.21.05.png

Posted (edited)

You need to offset the vertexbuffer/gl matrix(whichever you are using) before rendering the lines at the desired position.

Think of it this way:

Every time MC renders the world it offsets everything based on the player's position.

The RenderWorldLast event is fired when those offsets are applied.

If you want your outline to be stationary and not follow the player you need to 'negate' them by offsetting your rendering back to where it was(0,0,0) and then render at the desired position(x,y,z).

So your rendering would then look like

calculate offsets

offset(-offsets)

render boxes loop

offset(offsets).

 

As I usually do, here is a simple example:

 

// your positions. You might want to shift them a bit too
int sX = yourX;
int sY = yourY;
int sZ = yourZ;
// Usually the player
Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
//Interpolating everything back to 0,0,0. These are transforms you can find at RenderEntity class
double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)evt.getPartialTicks();
double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)evt.getPartialTicks();
double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)evt.getPartialTicks();
//Apply 0-our transforms to set everything back to 0,0,0
Tessellator.getInstance().getBuffer().setTranslation(-d0, -d1, -d2);
//Your render function which renders boxes at a desired position. In this example I just copy-pasted the one on TileEntityStructureRenderer
renderBox(Tessellator.getInstance(), Tessellator.getInstance().getBuffer(), sX, sY, sZ, sX + 1, sY + 1, sZ + 1);
//When you are done rendering all your boxes reset the offsets. We do not want everything that renders next to still be at 0,0,0 :)
Tessellator.getInstance().getBuffer().setTranslation(0, 0, 0);

 

note that if you want to outline more than 1 box like this you would need to apply player offsets first, then render your boxes in a loop, then reset the offsets.

 

This is a result I get with my example:

 

2017-04-30_19.40.52.png

Edited by V0idWa1k3r
  • Like 1
  • 3 years later...
Posted

@V0idWa1k3r Hi. I know it's been a good few years since this thread was active but I can't seem to get this code to work. In the renderBox function I found, it takes 3 extra int arguments. I looked at the code and those seem to be color arguments(r, g, b). However, the color only shows up when I'm looking in the positive x, positive z direction. Otherwise, the outline is just black. Do you have any idea why this is happening?

Guest
This topic is now closed to further replies.

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.