Jump to content

[1.7.2] Getting the int of the side clicked.


Minothor

Recommended Posts

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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