Jump to content

Recommended Posts

Posted

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

}

 

Posted

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

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @Tsuk1 Also, new note, you can use blockbench to make the custom item model for when it is not on the head.   EDIT: Funny story, I am making a mod similar to yours! Mine is called NorseMC.
    • @Nood_dev Could you send a screenshot of your weapon code? Here is the one I made (for a dagger): The specific UUID does not matter, just that it is the same every time, which is why UUID#randomUUID does not work public class DaggerItem extends TieredItem implements Vanishable { protected static final double REACH_MODIFIER = -1.5D; protected final Multimap<Attribute, AttributeModifier> defaultModifiers; protected final UUID BASE_ATTACK_REACH_UUID = UUID.fromString("6fe75b5c-9d1b-4e83-9eea-a1d5a94e8dd5") public DaggerItem(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModifier, Properties pProperties) { super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); this.attackDamage = (float) pAttackDamageModifier + pTier.getAttackDamageBonus(); ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder(); builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", this.attackDamage, AttributeModifier.Operation.ADDITION)); builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", pAttackSpeedModifier, AttributeModifier.Operation.ADDITION)); // THE ONE YOU WANT: builder.put(ForgeMod.ENTITY_REACH.get(), new AttributeModifier(BASE_ATTACK_REACH_UUID, "Weapon modifier", REACH_MODIFIER, AttributeModifier.Operation.ADDITION)); this.defaultModifiers = builder.build(); } @Override public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot pEquipmentSlot) { return pEquipmentSlot == EquipmentSlot.MAINHAND ? this.defaultModifiers : super.getDefaultAttributeModifiers(pEquipmentSlot); } }
    • https://images.app.goo.gl/1PxFKdxByTgkxvSu6
    • That's what we'll try out. I could never figure out how to recreate the crash, so I'll just have to wait and see.
    • Ok, I updated to the latest version and now the models are visible, the problem now is that the glowing eyes are not rendered nor any texture I render there when using shaders, even using the default Minecraft eyes RenderType, I use entityTranslucent and entityCutout, but it still won't render. Something I noticed when using shaders is that a texture, instead of appearing at the world position, would appear somewhere on the screen, following a curved path, it was strange, I haven't been able to reproduce it again. I thought it could be that since I render the texture in the AFTER ENTITIES stage which is posted after the batches used for entity rendering are finished, maybe that was the reason why the render types were not being drawn correctly, so I tried injecting code before finishing the batches but it still didn't work, plus the model was invisible when using shaders, there was a bug where if I look at the model from above it is visible but if I look at it from below it is invisible. So in summary, models are now visible but glowing eyes and textures are not rendered, that hasn't changed.
  • Topics

×
×
  • Create New...

Important Information

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