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.

Featured Replies

Posted

Hi all, sorry, but hopefully this question is a quickie.. does anyone know how to get the int of the side that was clicked during an onBlockClicked() call?

Here's the class I'm working on, apologies for the poor code annotation, it's a block of cork that can be moved with a mallet and if it detects planks above it, will check for a valid barrel structure (up next).

 

Cheers in advance!

Nick B (Minothor)

 

package minothor.bab.blocks;

import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;

public class blockCork extends Block{
public blockCork(){
super(Material.wood);
setBlockName("BlockCork");
setHarvestLevel("axe",0);
setHardness(0.5F);
setStepSound(Block.soundTypeCloth);
};
@Override
public void onBlockClicked(World CurrentWorld, int x, int y, int z, EntityPlayer player) {
// TODO Auto-generated method stub
if(player.inventory.getStackInSlot(player.inventory.currentItem).getUnlocalizedName().equals("item.WoodenMallet")){
System.out.println("Ow! what was that for?"); //Testing Mallet Recognition
//Test side 4
shunt(CurrentWorld,x,y,z,4);
}
}

public void checkStructure(int x, int y, int z){

}

public void shunt(World CurrentWorld,int x, int y, int z, int side){
boolean flood = false;
//(whether or not to fill space with water)
int OldX = x, OldY = y, OldZ = z;
int ShuntAxis = (int) Math.floor(side/2);
// 0 = Y, 1 = Z, 2 = X;
int ShuntDir = side % 2;
// 0 = Negative Direction, 1 = Positive
if (ShuntDir==0){
//Turns the 0 into -1.
ShuntDir--;
}
switch(ShuntAxis){
case 0: y = y-ShuntDir;
break;

case 1: z = z-ShuntDir;
break;

case 2: x = x-ShuntDir;
break;
}
if((CurrentWorld.getBlock(x, y, z)==Blocks.air)||(CurrentWorld.getBlock(x, y, z)==Blocks.water)){
if(CurrentWorld.getBlock(x, y, z)==Blocks.water){
flood = true;
}
CurrentWorld.setBlock(x, y, z, this);
CurrentWorld.setBlockToAir(OldX, OldY, OldZ);
if(flood){
CurrentWorld.setBlock(OldX, OldY, OldZ, Blocks.water);
//Add Splash Sound Here
}else{
//Add Sand/Gravel Step Sound Here
}
if(CurrentWorld.getBlock(x, (y+1), z)==Blocks.planks){
checkStructure(x,y,z);
}
}
}
}[/Code]

You could handle this event: ForgeEventFactory.onPlayerInteract(thisPlayerMP, Action.LEFT_CLICK_BLOCK, par1, par2, par3, par4);

 

It happens in the code that calls onBlockClicked. The parameters might tell you something.

  • 1 month later...

Hi, I know maybe it's too late to reply to your question but I've got the solution.

For the glitchy shadow you have to add this line in your constructor of your slab class:

useNeighborBrightness = true;

 

And to prevent the 0.5 blocks upper positioning you have to follow what says "MCZaphelon" in this post:

http://www.minecraftforum.net/topic/2432754-172forge-modding-slab-problem/

 

I hope this could help you and anyone else who have the same problem.

 

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.