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

    • that happens every time I enter a new dimension.
    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
  • Topics

×
×
  • Create New...

Important Information

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