Jump to content

[1.7.10] Changing blockIcon on block placement


Cilka

Recommended Posts

Hello, I'm currently stuck trying to make a block to change its icon/texture based on a relative position to other blocks. Here is the code as it stands now. Any help would be appreciated. Thanks!

package com.hexopygate.Telgttatium;

import static net.minecraftforge.common.util.ForgeDirection.EAST;
import static net.minecraftforge.common.util.ForgeDirection.NORTH;
import static net.minecraftforge.common.util.ForgeDirection.SOUTH;
import static net.minecraftforge.common.util.ForgeDirection.WEST;

import java.util.HashMap;
import java.util.List;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPane;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class TelNormalGlassPane extends BlockPane {
	protected enum Position {
		None, Center, Top, Bottom, Left, Right, TopRight, TopLeft, BottomRight, BottomLeft, CenterFull, CenterWalledHorizontal, CenterWalledVertical, BottomWalled, TopWalled
	}
 
	public HashMap<String, IIcon>icons;
	String FaceTex;
	static String RimText = "Glass_Trim";
	String name = this.getClass().getSimpleName();
	private Position position;
	IIcon currentIcon;
	public TelNormalGlassPane(String faceTexture, String rimTexture) {

		super("tel:" + faceTexture, "tel:" + rimTexture, Material.glass, true);
		// TODO Auto-generated constructor stub
		position = Position.None;
		FaceTex = faceTexture;
		icons = new HashMap<String,IIcon>();
		this.setBlockName(name).setBlockTextureName("tel:" + name);
		GameRegistry.registerBlock(this, this.getUnlocalizedName().substring(5));

	}

	public TelNormalGlassPane(String texture) {
		this(texture, RimText);
	}

	@Override
	@SideOnly(Side.CLIENT)
	public int getRenderBlockPass() {
		return 1;
	}
	


	@Override
	public void onBlockPlacedBy(World world, int x, int y, int z,EntityLivingBase base, ItemStack itemstack ) {

		this.position = Position.None;
		System.out.println("Initial Position: " + this.position);
		HashMap<String, Block> neighboringBlocks = new HashMap<String, Block>();
		neighboringBlocks.put("north", world.getBlock(x, y + 1, z));
		neighboringBlocks.put("south", world.getBlock(x, y - 1, z));
		neighboringBlocks.put("east", world.getBlock(x + 1, y, z));
		neighboringBlocks.put("west", world.getBlock(x - 1, y, z));
		System.out.println("Set Neighboring Blocks");

		/*
		 * for(String s : neighboringBlocks.keySet()) {
		 * 
		 * if(neighboringBlocks.get(s).getMaterial() == Material.air) {
		 * neighboringBlocks.remove(s); continue; }
		 * 
		 * }
		 */
		
		SetPosition(neighboringBlocks, x, y);
		System.out.println("postiion for " + FaceTex + " is " +this.position + " at " + String.format("(%s,%s ,%s)", x,y,z));
		String texName =  FaceTex;
		switch(position)
		{
		case Top:
		texName +="_Top_Frame";
			break;
		case Bottom:
			texName +="_Down_Frame";
			break;
		case BottomLeft:
			texName +="_Left_Down_Corner_Frame";
			break;
		case BottomRight:
			texName +="_Right_Down_Corner_Frame";
			break;
		case BottomWalled:
			texName +="_Down_Single_Frame";
			break;
		case Center:
			texName +="_Middle_Frame";
			break;
		case CenterFull:
			texName +="_Full_Frame";
			break;
		case CenterWalledHorizontal:
			texName +="_Middle_Single_Frame";
			break;
		case CenterWalledVertical:
			texName += "_Vertical_Middle_Single_Frame";
			break;
		case Left:
			texName +="_Left_Frame";
			break;
		case Right:
			texName +="_Right_Frame";
			break;
		case TopLeft:
			texName +="_Left_Top_Frame";
			break;
		case TopRight:
			texName +="_Right_Top_Frame";
			break;
		case TopWalled:
			texName +="_Top_Single_Frame";
			break;
		default:
			break;
		}
		System.out.println("Texture name is " + texName);
		this.blockIcon = icons.get(texName);
		
	}
	   @SideOnly(Side.CLIENT)
	   @Override 
	   public IIcon func_150097_e()
	    {
	        return this.blockIcon;
	    }
	   @SideOnly(Side.CLIENT)
	    public void registerBlockIcons(IIconRegister registry)
	    {
		   icons.put(FaceTex+"_Full_Frame", registry.registerIcon("tel:"+FaceTex+"_Full_Frame"));
		   icons.put(FaceTex+"_Top_Frame", registry.registerIcon("tel:"+FaceTex+"_Top_Frame"));
		   icons.put(FaceTex+"_Down_Frame", registry.registerIcon("tel:"+FaceTex+"_Down_Frame"));
		   icons.put(FaceTex+"_Left_Down_Corner_Frame", registry.registerIcon("tel:"+FaceTex+"_Left_Down_Corner_Frame"));
		   icons.put(FaceTex+"_Right_Down_Corner_Frame", registry.registerIcon("tel:"+FaceTex+"_Right_Down_Corner_Frame"));
		   icons.put(FaceTex+"_Down_Single_Frame", registry.registerIcon("tel:"+FaceTex+"_Down_Single_Frame"));
		   icons.put(FaceTex+"_Middle_Frame", registry.registerIcon("tel:"+FaceTex+"_Middle_Frame"));
		   icons.put(FaceTex+"_Middle_Single_Frame", registry.registerIcon("tel:"+FaceTex+"_Middle_Single_Frame"));
		   icons.put(FaceTex+"_Vertical_Middle_Single_Frame", registry.registerIcon("tel:"+FaceTex+"_Vertical_Middle_Single_Frame"));
		   
		   icons.put(FaceTex+"_Left_Frame", registry.registerIcon("tel:"+FaceTex+"_Left_Frame"));
		   icons.put(FaceTex+"_Right_Frame", registry.registerIcon("tel:"+FaceTex+"_Right_Frame"));  
		   icons.put(FaceTex+"_Left_Top_Frame", registry.registerIcon("tel:"+FaceTex+"_Left_Top_Frame"));
		   icons.put(FaceTex+"_Right_Top_Frame", registry.registerIcon("tel:"+FaceTex+"_Right_Top_Frame"));
		   icons.put(FaceTex+"_Top_Single_Frame", registry.registerIcon("tel:"+FaceTex+"_Top_Single_Frame"));
		   this.blockIcon = icons.get(FaceTex+"_Full_Frame");
		   this.currentIcon =  this.blockIcon;
	    }
 
	private void SetPosition(HashMap<String, Block> neighbors, int x, int y) {
		if (this.position != Position.None) {
			return;
		}
/*
		if (neighbors.get("north") instanceof TelNormalGlassPane && neighbors.get("south") instanceof TelNormalGlassPane
				&& neighbors.get("east") instanceof TelNormalGlassPane
				&& neighbors.get("west") instanceof TelNormalGlassPane) {
			this.position = Position.Center;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)
				&& (neighbors.get("south") instanceof Block && neighbors.get("south").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.CenterFull;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)
				&& (neighbors.get("south") instanceof Block && neighbors.get("south").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof TelNormalGlassPane
						|| neighbors.get("east").getMaterial() == Material.air)
				&& (neighbors.get("west") instanceof TelNormalGlassPane
						|| neighbors.get("west").getMaterial() == Material.air)) {
			this.position = Position.CenterWalledHorizontal;
			return;
		}

		if ((neighbors.get("north") instanceof TelNormalGlassPane
				|| neighbors.get("north").getMaterial() == Material.air)
				&& (neighbors.get("south") instanceof TelNormalGlassPane
						|| neighbors.get("south").getMaterial() == Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.CenterWalledVertical;
			return;
		}

		if ((neighbors.get("south") instanceof Block && neighbors.get("south").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.BottomWalled;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.TopWalled;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)) {
			this.position = Position.TopLeft;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.TopRight;
			return;
		}
		if ((neighbors.get("south") instanceof Block && neighbors.get("south").getMaterial() != Material.air)
				&& (neighbors.get("west") instanceof Block && neighbors.get("west").getMaterial() != Material.air)) {
			this.position = Position.BottomRight;
			return;
		}
		if ((neighbors.get("south") instanceof Block && neighbors.get("south").getMaterial() != Material.air)
				&& (neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)) {
			this.position = Position.BottomLeft;
			return;
		}
		if ((neighbors.get("south") instanceof Block && (neighbors.get("south").getMaterial() != Material.air)||)) {
			this.position = Position.Bottom;
			return;
		}
		if ((neighbors.get("north") instanceof Block && neighbors.get("north").getMaterial() != Material.air)) {
			this.position = Position.Top;
			return;
		}
		if ((neighbors.get("east") instanceof Block && neighbors.get("east").getMaterial() != Material.air)) {
			this.position = Position.Left;
			return;
		}
		this.position = Position.Right;
		*/
		if(neighbors.get("north").getMaterial() == Material.air)
		{
			this.position = Position.Bottom;
		}
		else
		{
			this.position = Position.Top;
		}
	}

}

ย 

Link to comment
Share on other sites

1.7 is not supported on this forum. Update to 1.12 and use an ISmartModel

About Me

Spoiler

My Discordย -ย Cadiboo#8887

My Website -ย Cadiboo.github.io

My Mods -ย Cadiboo.github.io/projects

My Tutorials -ย Cadiboo.github.io/tutorials

Versions below 1.14.4ย are no longer supported on this forum.ย Use the latest version toย receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com).ย A list of bad sites can be foundย here, with more information available atย stopmodreposts.org

Edit your own signature atย www.minecraftforge.net/forum/settings/signature/ย (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working ย  I am not familiar with Linux - check for similar/related issues ย 
  • Topics

×
×
  • Create New...

Important Information

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