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

[SOLVED]New texture when redstone powered


nicolapcweek94
 Share

Recommended Posts

Sorry if this question has already been asked a thousand times. I was not able to find anything with the search function.

 

I am making a mod that includes blocks reacting to redstone. One (very) basic type of reaction to redstone is changing the block texture. So, this is the way I implemented it:

@Override
public void onNeighborBlockChange(World world, int xCoord, int yCoord, int zCoord, int neighborID) {
	isRedstonePowered = world.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
	if (isRedstonePowered) {
		this.blockIndexInTexture = 0;
	} else {
		this.blockIndexInTexture = 1;
	}
}

where isRedstonePowered is a boolean declared in TestBlock.java (the block class from which this code is taken).

This code works perfectly, changing the texture of the block if it is activated and changing it back when it loses the redstone signal. But it works a bit too much, it actually changes the texture for all the same blocks in the world and even the block in the hotbar (by powering a single block, all the blocks of the same kind change texture) and i obviously do not want that, i only want the powered block to change... Is there a way to do that?

 

EDIT: i might end up using the vanilla furnace code if i don't find any other solution, but i don't like it very much because it implies adding some more blocks... (code in spoiler)

 

public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
    {
        int var5 = par1World.getBlockMetadata(par2, par3, par4);
        TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4);
        keepFurnaceInventory = true;

        if (par0)
        {
            par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenActive.blockID);
        }
        else
        {
            par1World.setBlockWithNotify(par2, par3, par4, Block.stoneOvenIdle.blockID);
        }

        keepFurnaceInventory = false;
        par1World.setBlockMetadataWithNotify(par2, par3, par4, var5);

        if (var6 != null)
        {
            var6.validate();
            par1World.setBlockTileEntity(par2, par3, par4, var6);
        }
    }

 

Link to comment
Share on other sites

When you do either

this.blockIndexInTexture = 0
or
this.blockIndexInTexture = 1

 

What class is "this". If it is changing the texture of every block in the world, you need to be selecting a specific block (x,y,z coords) and then changing the texture.

If I helped you, thank me. If I didn't, let me know.

Link to comment
Share on other sites

thanks for the answers, i actually ended up using a code similar to the one used in the furnace. i have 2 blocks and switch between them with setblockwithnotify(), and they have different textures.

@jammas615: i found out that it was exactly the "this" that was causing problem, because it pointed at TestBlock class which is the class for every Test Block in the world, not a single instance... thanks for making me understand that :)

Link to comment
Share on other sites

thanks for the answers, i actually ended up using a code similar to the one used in the furnace. i have 2 blocks and switch between them with setblockwithnotify(), and they have different textures.

@jammas615: i found out that it was exactly the "this" that was causing problem, because it pointed at TestBlock class which is the class for every Test Block in the world, not a single instance... thanks for making me understand that :)

 

It would probably be better to switch between metadata in this case, unless you change stuff like light level. It'll save a block id for something else

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

    • I downloaded the server files for a 1.16.5 forge server server (forge-1.16.5-36.2.20) but when i run the .jar file it doesn't start up.   I also tried running it with the following .bat script : "C:\Program Files\Java\jre1.8.0_321\bin\javaw.exe" -Xmx4096M -Xms4096M -jar forgeserver.jar pause when I run the server it gives this log: [25jan2022 14:41:46.874] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.20, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [25jan2022 14:41:46.876] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 1.8.0_321 by Oracle Corporation [25jan2022 14:41:47.215] [main/INFO] [net.minecraftforge.fml.loading.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [25jan2022 14:41:47.248] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.4 Source=file:/C:/Users/USER/Desktop/folder%20folder/servers/servers/lege%20folder/libraries/org/spongepowered/mixin/0.8.4/mixin-0.8.4.jar Service=ModLauncher Env=SERVER [25jan2022 14:41:48.005] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmlserver' with arguments [--gameDir, .] [25jan2022 14:41:48.063] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]: java.lang.NoSuchMethodError: sun.security.util.ManifestEntryVerifier.<init>(Ljava/util/jar/Manifest;)V [25jan2022 14:41:48.064] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.SecureJarHandler.createCodeSource(SecureJarHandler.java:66) [25jan2022 14:41:48.064] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:275) [25jan2022 14:41:48.065] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:136) [25jan2022 14:41:48.065] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:98) [25jan2022 14:41:48.065] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at java.lang.ClassLoader.loadClass(Unknown Source) [25jan2022 14:41:48.066] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at java.lang.Class.forName0(Native Method) [25jan2022 14:41:48.066] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at java.lang.Class.forName(Unknown Source) [25jan2022 14:41:48.066] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at net.minecraftforge.fml.loading.FMLServerLaunchProvider.lambda$launchService$0(FMLServerLaunchProvider.java:51) [25jan2022 14:41:48.067] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [25jan2022 14:41:48.067] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [25jan2022 14:41:48.067] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [25jan2022 14:41:48.068] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [25jan2022 14:41:48.068] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [25jan2022 14:41:48.068] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) [25jan2022 14:41:48.068] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) [25jan2022 14:41:48.069] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:-1]:     at net.minecraftforge.server.ServerMain.main(ServerMain.java:57)    
    • 1.7 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • Hello guys! I   tried to open a localhost Forge Server. I tried to open the universal jar but it appears nothing. Then i did it with a .bat file and there are only error things https://gyazo.com/beddeff2563ffe3059c7e632f0ec4eb6 I installed java 8 and but it won't help.. please help me xd
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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