Jump to content

A "final" reference to textures.


CJCutrone9

Recommended Posts

Hello again, so, recently I decided to "compress" my mod and use as few classes as physically possible, to do this, I made one generic block with a few extra parameters in the main method. Some of which allow me to define if the block hurts the player, etc.

 

But, one of them, I wanted to allow me to choose a connected texture. Now I got the connected texture to work, but, when I tell it to use the connected texture for my block, it replaces all the other blocks extending that class with my connected texture, instead of the ones they should be using.

 

To explain in more depth:

 

I have 3 blocks, all three extend this class:

 

 

package net.Cutrone.LegoUniverse.blocks;

 

import java.util.List;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

import net.CJCutrone.LegendofZelda.common.LegendofZelda;

import net.Cutrone.LegoUniverse.common.LegoUniverse;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.item.ItemStack;

import net.minecraft.util.DamageSource;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

 

public class GenericBlock extends Block{

 

public static boolean hasConnectedTexture = false;

public static boolean isMaelstrom = false;

 

public static Icon[] textures = new Icon[47];

 

public static int[] textureRefByID = { 0, 0, 6, 6, 0, 0, 6, 6, 3, 3, 19, 15, 3, 3,

19, 15, 1, 1, 18, 18, 1, 1, 13, 13, 2, 2, 23, 31, 2, 2, 27, 14, 0, 0, 6, 6, 0,

0, 6, 6, 3, 3, 19, 15, 3, 3, 19, 15, 1, 1, 18, 18, 1, 1, 13, 13, 2, 2, 23, 31,

2, 2, 27, 14, 4, 4, 5, 5, 4, 4, 5, 5, 17, 17, 22, 26, 17, 17, 22, 26, 16, 16,

20, 20, 16, 16, 28, 28, 21, 21, 46, 42, 21, 21, 43, 38, 4, 4, 5, 5, 4, 4, 5, 5,

9, 9, 30, 12, 9, 9, 30, 12, 16, 16, 20, 20, 16, 16, 28, 28, 25, 25, 45, 37, 25,

25, 40, 32, 0, 0, 6, 6, 0, 0, 6, 6, 3, 3, 19, 15, 3, 3, 19, 15, 1, 1, 18, 18, 1,

1, 13, 13, 2, 2, 23, 31, 2, 2, 27, 14, 0, 0, 6, 6, 0, 0, 6, 6, 3, 3, 19, 15, 3,

3, 19, 15, 1, 1, 18, 18, 1, 1, 13, 13, 2, 2, 23, 31, 2, 2, 27, 14, 4, 4, 5, 5, 4,

4, 5, 5, 17, 17, 22, 26, 17, 17, 22, 26, 7, 7, 24, 24, 7, 7, 10, 10, 29, 29, 44,

41, 29, 29, 39, 33, 4, 4, 5, 5, 4, 4, 5, 5, 9, 9, 30, 12, 9, 9, 30, 12, 7, 7, 24,

24, 7, 7, 10, 10, 8, 8, 36, 35, 8, 8, 34, 11 };

 

public GenericBlock(int id, Material material, boolean connectedTexture, boolean hurtPlayer) {

super(id, material);

hasConnectedTexture = connectedTexture;

isMaelstrom = hurtPlayer;

 

}

 

@Override

public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity e) {

 

if(this.isMaelstrom){

e.attackEntityFrom(DamageSource.generic, 1);

}else{

 

}

 

}

public void registerIcons(IconRegister iconRegistry){

 

blockIcon = iconRegistry.registerIcon(LegoUniverse.modid +":" +this.getTextureName());

 

if(this.hasConnectedTexture){

for (int i = 0; i < 47; i++){

textures = iconRegistry.registerIcon(LegoUniverse.modid +":"+this.getTextureName() + "_" + (i+1));

}

}

 

}

 

public Icon getIcon(int side, int meta){

if(this.hasConnectedTexture){

return textures[0];

}else{

return blockIcon;

}

}

 

public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side){

if(this.hasConnectedTexture){

boolean[] bitMatrix = new boolean[8];               

if (side == 0 || side == 1){               

bitMatrix[0] = world.getBlockId(x-1, y, z-1) == this.blockID; 

bitMatrix[1] = world.getBlockId(x, y, z-1) == this.blockID; 

bitMatrix[2] = world.getBlockId(x+1, y, z-1) == this.blockID;

bitMatrix[3] = world.getBlockId(x-1, y, z) == this.blockID; 

bitMatrix[4] = world.getBlockId(x+1, y, z) == this.blockID; 

bitMatrix[5] = world.getBlockId(x-1, y, z+1) == this.blockID;

bitMatrix[6] = world.getBlockId(x, y, z+1) == this.blockID; 

bitMatrix[7] = world.getBlockId(x+1, y, z+1) == this.blockID;

}       

if (side == 2 || side == 3){

bitMatrix[0] = world.getBlockId(x+(side==2?1:-1), y+1, z) == this.blockID;

bitMatrix[1] = world.getBlockId(x, y+1, z)== this.blockID;

bitMatrix[2] = world.getBlockId(x+(side==3?1:-1), y+1, z) == this.blockID;

bitMatrix[3] = world.getBlockId(x+(side==2?1:-1), y, z) == this.blockID; 

bitMatrix[4] = world.getBlockId(x+(side==3?1:-1), y, z) == this.blockID; 

bitMatrix[5] = world.getBlockId(x+(side==2?1:-1), y-1, z) == this.blockID;

bitMatrix[6] = world.getBlockId(x, y-1, z) == this.blockID; 

bitMatrix[7] = world.getBlockId(x+(side==3?1:-1), y-1, z) == this.blockID;

}       

if (side == 4 || side == 5){   

bitMatrix[0] = world.getBlockId(x, y+1, z+(side==5?1:-1)) == this.blockID;

bitMatrix[1] = world.getBlockId(x, y+1, z) == this.blockID; 

bitMatrix[2] = world.getBlockId(x, y+1, z+(side==4?1:-1)) == this.blockID;

bitMatrix[3] = world.getBlockId(x, y, z+(side==5?1:-1)) == this.blockID;

bitMatrix[4] = world.getBlockId(x, y, z+(side==4?1:-1)) == this.blockID;

bitMatrix[5] = world.getBlockId(x, y-1, z+(side==5?1:-1)) == this.blockID;

bitMatrix[6] = world.getBlockId(x, y-1, z)== this.blockID;

bitMatrix[7] = world.getBlockId(x, y-1, z+(side==4?1:-1)) == this.blockID;

}               

int idBuilder = 0;       

for (int i = 0; i <= 7; i++)

idBuilder = idBuilder + (bitMatrix?(i==0?1:(i==1?2:(i==2?4:(i==3?8:(i==4?16:(i==5?32:(i==6?64:128))))))):0);

return idBuilder>255||idBuilder<0?textures[0]:textures[textureRefByID[idBuilder]];

}else{

return blockIcon;

}

}

 

}

 

 

 

This is what my "blocks" class looks like:

 

 

package net.Cutrone.LegoUniverse.common;

 

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

import net.Cutrone.LegoUniverse.blocks.GenericBlock;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraftforge.common.MinecraftForge;

 

public class LegoUniverseBlocks {

 

 

public static final Block Maelstrom = new GenericBlock(3000, Material.cloth, false, true).setHardness(-1F).setLightValue(.5F).setStepSound(Block.soundClothFootstep).setUnlocalizedName("Maelstrom").setCreativeTab(CreativeTabs.tabBlock).setTextureName("Maelstrom");

public static final Block MaelstromOre = new GenericBlock(3001, Material.rock, false, true).setHardness(3F).setLightValue(.4F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("Maelstrom_Ore").setCreativeTab(CreativeTabs.tabBlock).setTextureName("Maelstrom_Ore");

public static final Block SteelPlating = new GenericBlock(3002, Material.iron, true, true).setHardness(3F).setLightValue(0F).setStepSound(Block.soundMetalFootstep).setUnlocalizedName("Steel_Plating").setCreativeTab(CreativeTabs.tabBlock).setTextureName("Steel_Plating");

 

public static void registerBlocks(){

 

GameRegistry.registerBlock(Maelstrom, "Maelstrom");

GameRegistry.registerBlock(MaelstromOre, "Maelstrom Ore");

GameRegistry.registerBlock(SteelPlating, "Steel Plating");

}

 

public static void languageRegistery(){

 

LanguageRegistry.addName(Maelstrom, "Maelstrom");

LanguageRegistry.addName(MaelstromOre, "Maelstrom Ore");

LanguageRegistry.addName(SteelPlating, "Steel Plating");

 

}

public static void registerBlockHarndess(){

 

MinecraftForge.setBlockHarvestLevel(Maelstrom, "", -1);

MinecraftForge.setBlockHarvestLevel(MaelstromOre, "pickaxe", 2);

MinecraftForge.setBlockHarvestLevel(SteelPlating, "pickaxe", 2);

 

}

public static void shapedRecipe(){

 

}

public static void shapelessRecipe(){

 

}

public static void smeltingRecipe(){

 

}

}

 

 

Now, the third parameter of GenericBlock tells the game if it should use a connected texture or not for said block. So, I decided to use a connected texture of my steel plating. I type true into that parameter leaving the other 2 false, and then register the block and all that fun stuff. when I go into the game however, all three blocks use this connected texture, where as before they each had their own. Now they all use the steel plating texture. They aren't connecting to each other (only themselves) so I know they are each registered each correctly. I am thinking I have to make the texture for each block dependant on only that block, but I can't figure out how to do that. Any help would be GREATLY appreciated as I would seriously love having only one or two different block classes.

Link to comment
Share on other sites

Okay found a temporary fix. I changed up the code in the getIcon method to look like this:

 

 

 

 

if(this.blockID == LegoUniverseBlocks.Maelstrom.blockID ||

  this.blockID == LegoUniverseBlocks.MaelstromOre.blockID){

return blockIcon;

}else{

return textures[0];

}

 

 

 

instead of

 

 

 

if(this.hasConnectedTexture){

return textures[0];

}else{

return blockIcon;

}

 

 

 

But I would like to not have to go and add a Block Id to the check every time I add a new Block...

Link to comment
Share on other sites

public static boolean hasConnectedTexture = false;

public static boolean isMaelstrom = false;

 

 

Mmmm....static....

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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