Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED][1.7.10] Detect Neighboring Block Name

Featured Replies

Posted

Hello all!

 

I am building a mod that contains a 3D model "multiblock". Basically, its a table. But as you add more tables, it changes what model gets rendered to make it look connected.

 

I know I am going to have to do something with onNeighborBlockChange() but when I do simple tests printing the block parameter, I'm getting what was there before I placed the block IE Air, not the block that was just added.

 

So my question is, how would I go about detecting all four sides for a specific block?

 

Thanks in advance.

  • Author

I may have not understood your answer then. If you are saying to use onNeighborBlockChange, when I tried doing my tests, it wouldn't show the block I had placed until I removed it.

 

For example, I had a table, and when I put a table next to it, the read out on the console said tile.block.air. It wasn't until I broke the table I put down that it returned, tile.block.table.

  • Author
package com.misccraft.mod.blocks;

import com.misccraft.mod.Misccraft;
import com.misccraft.mod.tileentity.TileEntityOfficeDesk;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class OfficeDesk extends BlockContainer {

private int side;

public OfficeDesk(Material material) {
	super(material);

	this.setHardness(1.0F);
	this.setResistance(5.0F); // To be changed
	this.setBlockBounds(0F, 0F, 0F, 1F, 0.8125F, 1F); // To be changed
	this.setCreativeTab(Misccraft.misccraftTab);
}

public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityOfficeDesk();
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) {
	if(entityplayer == null) {
		return;
	}

	TileEntityOfficeDesk perf = (TileEntityOfficeDesk)world.getTileEntity(x,y,z);
	perf.direction = MathHelper.floor_double((double)((entityplayer.rotationYaw*4F)/360F) + 0.5D) & 3;
	perf.side = 2; // Static for testing
}

public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
	System.out.println(block.getLocalizedName()); // Test to check neighboring block.
}
}

  • Author

So I take it onNeighborBlockChange is usually used last then. So what method would I use to get the block that was just placed?

  • Author

You said that onNeighborBlockChange is intended to work via re-checking your surroundings. I assumed this is done at the end of whatever you are processing.

 

I don't get how what I want to do is not possible. Chest's do the same thing I'm trying to do,  they detect a chest next to themselves, and alter their model accordingly. I'm new to the modding scene and not as experienced in Java as others, so when I look at the Chest/Fence/Pane source code, I see the code, but I don't understand what it is doing.

 

I guess what I am trying to say is, how would I go about detecting a CERTAIN block when its placed next to my block?

  • Author

Thank you for being patient with me. You have solved my question. Thanks again!

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.