Jump to content

Toggle visibility of a block based on equipped tool


Bregor

Recommended Posts

Hi,

 

can someone give me a hint on how this could be accomplished: I want a block of my mod by default to be invisible - but it should show up if a specific tool is equipped by the player (active tool in the quick-bar, another item of my mod).

 

As this should be an multiplayer compatible mod, the visibility toggle should only be on the client side (as only a player with the tool equipped should see the blocks).

 

Thanks.

Link to comment
Share on other sites

If possible I would like to have a block without a corresponding tile entity, as there is no additional data required, the 4bit metadata are fine for me.

 

So I experimented with normal blocks based on this tutorial http://www.minecraftforge.net/wiki/Multiple_Pass_Render_Blocks, but to my surprise the renderWorldBlock from the interface ISimpleBlockRenderingHandler is not called each frame but seems to be cached somehow.

 

Is there a possibility to invalidate the state of a renderer on the client? So that the tool itself invalidates the renderer for the target block if it is equipped or unequipped by the player.

 

The rendering code i used, it should render a bedrock block if the tool is equipped and an invisible block if not:

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
//which render pass are we doing?
if(ClientProxy.renderPass == 0)
{
	EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
	ItemStack currentPlayerItemStack = player.getHeldItem();
	if(currentPlayerItemStack.itemID == targetItemId) {
		renderer.renderStandardBlock(Block.bedrock, x, y, z);
	}
}                  

return true;
}

Link to comment
Share on other sites

my surprise the renderWorldBlock from the interface ISimpleBlockRenderingHandler is not called each frame but seems to be cached somehow.

this is why i hate ISBRH, the only you CAN do to force a re-render is world.markBlockForUpdate(x, y, z) client side

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I now went down the TileEntitySpecialRenderer road, and it works quite well. Thanks a lot for the tip with the TileEntitySpecialRenderer.

 

Just got one related question, if i want some sort of texture particle effect in my TileEntitySpecialRenderer, should i create it myself or is it possible to use something like EntityFX for it?

If drawing it myself is the way to go, which time reference is best used to get a time base for the animation in the render method? And is there an easy way to get the camera vector to orient the texture perpendicular to the looking direction of the player?

 

 

For reference if someone else may need it, this is how the toggling is done:

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {

EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
ItemStack currentPlayerItemStack = player.getHeldItem();
if(currentPlayerItemStack == null || currentPlayerItemStack.itemID != requiredItemId) {
	return;
}

//Rendering code ...
}

Link to comment
Share on other sites

And is there an easy way to get the camera vector to orient the texture perpendicular to the looking direction of the player?

"billboarding" is the word you are looking for :P

heres how to do it (in minecraft, in an actual opengl program there are better way to do this):

 

 

EntityPlayer p = Minecraft.getMinecraft().thePlayer;
GL11.glRotated(-p.rotationYaw, 0, 1, 0);
GL11.glRotated(p.rotationPitch, 1, 0, 0);

 

i only did a small amount of research on particle but i can tell you this

 

every particle are child class of Entity and they can only spawn in client world (as the server doesn't give a **** about particle and doesn't want to update+sync them) and they are spherically billboarded.

 

i never tried to actually create a new EntityFX (a new particle), might be possible, might not be

 

but what I personally did for one of my TESR (TileEntitySpecialRenderer) was to have an internal list of particle inside the TESR and render+update them inside the TESR. Might not be the best way but for my case it was good enough

 

edit: btw the billboard "technique" i show earlier is fake billboarding, which is 99% of the minecraft case "good enough" true billboarding is a biiiiit more compilcated

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

But how did you time the animation of the texture

can you give me your deffinition of that, because we could think 2 different stuff when we read that

im thinking 3d texture or multiple texture that gets dispalyed one after the other

 

how did I do it? well i personally like to use cyclic animation (the same thing over and over)

since all i want is somethign that moves, i usually take the system and transform it into the matrix transform i want to apply it to

 

hard to type but heres a real live example from my mod:

 

//sorry about extremmelly shitty quality

 

code that does that:

 

import org.lwjgl.opengl.GL11;

import com.hydroflame.mod.ForgeRevCommonProxy;
import com.hydroflame.mod.TheMod;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class RenderTeleporter extends TileEntitySpecialRenderer{
private IModelCustom teleporter;
private ResourceLocation texture = new ResourceLocation(TheMod.modid, "/models/textures/teleporter.png");
private float[] pos;
int displayList = -1;

public RenderTeleporter(){
	teleporter = AdvancedModelLoader.loadModel("/teleporter.obj");
	pos = new float[30];
	for(int i = 0; i < pos.length; i++){
		pos[i] = (float) Math.random()*2;
	}
}

@Override
public void renderTileEntityAt(TileEntity tileentity, double d0, double d1,
		double d2, float f) {


	//here
	for(int i =0; i < pos.length; i++){
	}
	float size = 0.1f;
	Tessellator tess = Tessellator.instance;
	for(int i = 0; i < pos.length; i++){
		pos[i]+=0.01f;
		if(pos[i] > 2){ 
			pos[i] = 0;
		}
	}
	Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.portalParticle);
	GL11.glPushMatrix();
	GL11.glTranslated(d0+0.5, d1+1, d2+0.5);
	for(int i = 0; i < pos.length; i++){
		GL11.glRotated(360/pos.length, 0, 1, 0);
		GL11.glPushMatrix();
		GL11.glTranslated(0, pos[i], 1);
		tess.startDrawingQuads();
		tess.addVertexWithUV(-size, -size, 0, 0, 0);
		tess.addVertexWithUV(-size, size, 0, 0, 1);
		tess.addVertexWithUV(size, size, 0, 1, 1);
		tess.addVertexWithUV(size, -size, 0, 1, 0);

		tess.addVertexWithUV(-size, -size, 0, 0, 0);
		tess.addVertexWithUV(size, -size, 0, 1, 0);
		tess.addVertexWithUV(size, size, 0, 1, 1);
		tess.addVertexWithUV(-size, size, 0, 0, 1);
		tess.draw();
		GL11.glPopMatrix();
	}
	GL11.glPopMatrix();
	GL11.glColor3f(1, 1, 1);
	Minecraft.getMinecraft().renderEngine.func_110577_a(texture);
	GL11.glPushMatrix();
	GL11.glTranslated(d0+0.5, d1+1, d2+0.5);
	GL11.glScaled(1.3, 1.3, 1.3);
	Tessellator.instance.setColorOpaque_F(1, 1, 1);
	teleporter.renderAll();
	Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.portalRune);
	GL11.glTranslated(0, 0.2, 0);
	GL11.glRotated(System.nanoTime()/100000000f, 0, 1, 0);
	tess.startDrawingQuads();
	tess.addVertexWithUV(-0.5, 0, -0.5, 0, 0);
	tess.addVertexWithUV(-0.5, 0, 0.5, 0, 1);
	tess.addVertexWithUV(0.5, 0, 0.5, 1, 1);
	tess.addVertexWithUV(0.5, 0, -0.5, 1, 0);
	tess.draw();
	GL11.glPopMatrix();
}
}

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

just little warning, if you use System.nanoTime, ALL your block will be extremelly synchronized

when i mean extremmelly, i mean like very very synchro

(btw my code is synchonized but thats just because i did not have time to implement the synchro break

to "break" this synchro you will need to use value that change from one block to another, the one i recommend using is x, y, z that is coviniently given to you by the method

 

now we need to use those to differentiate one animation from the other

imagine that all our animation are based on one factor

 

lets say:

float f = System.nanoTime()/1000000f;

now that would mean everything is synchro, what would happen if we were to add somethign to differentiate them from one another:

int loopFactor = 50;
float f = System.nanoTime()/1000000f + (x%loopFactor)/attenuationFactor;

and attenuationFactor im not sure what is a good value, to high will make it look weird, too low too :P

 

basicly we introduced the x variable of the TE to make sure 2 TE with 2 different x will not be in synchronization, repeat for y and z to make sure that nothign is synchro ever

 

of course this will only make the animation be at different "time" in their loop, but at least it looks nice

 

now i know this isnt very clear, please ask if you want another explanation :)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The future of Bitcoin recovery is a topic of great interest and excitement, particularly with the emergence of innovative companies like Dexdert Net Pro Recovery leading the charge. As the cryptocurrency market continues to evolve and face new challenges, the need for effective solutions to help users recover lost or stolen Bitcoin has become increasingly critical. Dexdert Net Pro, a specialized firm dedicated to this very purpose, has positioned itself at the forefront of this emerging field. Through their proprietary techniques and deep expertise in blockchain technology, Dexdert Net Pro has developed a comprehensive approach to tracking down and retrieving misplaced or compromised Bitcoin, providing a lifeline to individuals and businesses who have fallen victim to the inherent risks of the digital currency landscape. Their team of seasoned investigators and cryptography experts employ a meticulous, multi-pronged strategy, leveraging advanced data analysis, forensic techniques, and collaborative partnerships with law enforcement to painstakingly trace the movement of lost or stolen coins, often recovering funds that would otherwise be considered irrecoverable. This pioneering work not only restores financial assets but also helps to bolster confidence and trust in the long-term viability of Bitcoin, cementing Dexdert Net Pro role as a crucial player in shaping the future of cryptocurrency recovery and security. As the digital finance ecosystem continues to evolve, the importance of innovative solutions like those offered by Dexdert Net Pro will only grow, ensuring that users can navigate the complexities of Bitcoin with greater peace of mind and protection. Call Dexdert Net Pro now     
    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
  • Topics

×
×
  • Create New...

Important Information

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