The title says it all, basically I want to have a block, so when you right click it with an empty hand it changes to another block, and vice versa.
The blocks I'm using are Techne models.
In your block class, override the onBlockClicked (left-click) or onBlockActivated (right-click) method and use World#setBlock with the x/y/z coordinates from the method parameters.
In your block class, override the onBlockClicked (left-click) or onBlockActivated (right-click) method and use World#setBlock with the x/y/z coordinates from the method parameters.
Sorry, you might have to spell it out to me, so I put the onBlockActivated bit here?
public class TileEntityTrackPointRightBlock extends BlockContainer
{
public TileEntityTrackPointRightBlock(int id)
{
super(Material.iron);
this.setCreativeTab(CreativeTabs.tabTransport);
//wrong bounds this.setBlockBounds(0.4F, 0.0F, 0.4F, 0.6F, 3.0F, 0.6F);
float f = 0.5F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.15F, 0.5F + f);
}
@Override
public int getRenderType() {
return -1;
}
@Override
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
@SideOnly(Side.CLIENT)
private IIcon icon;
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister r)
{
this.icon = r.registerIcon(RefStrings.MODID + ":blockRailPointR");
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileEntityTrackPointRightEntity();
}
public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
{
int l = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 3, 2); // If you want your rail to be set crosswise to the player replace the 1 with a 0
}
if (l == 1)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 4, 2); // If you want your rail to be set crosswise to the player replace the 2 with a 1
}
if (l == 2)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 5, 2); // If you want your rail to be set crosswise to the player replace the 3 with a 2
}
if (l == 3)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 6, 2); // If you want your rail to be set crosswise to the player replace the 4 with a 3
}
}
public boolean onBlockActivated(World w, int x, int y, int z, EntityPlayer epl, int q, float r, float s, float t)
{
if(!w.isRemote)
{
w.setBlock(x, y, z, Blocks.stone);
return true;
}
return false;
}
That worked! Thanks again Tupelov.
I assume I change Blocks.stone with whatever I want the block to be changed to?
Edit: Having trouble finding how to call the right block, because its not in Blocks."listofblocks"
I have tried Entity."Stuff" and TileEntity."Stuff", but I can't find any trace of the Techne blocks. Which caller should I be using? I did find a w.setTileEntity
Would that have somethine to do with it?
Also, to add a sound effect when the block change happens would I add "w.playSound(x, y, z, Block.soundTypePiston ?
If it's just in techne, then it's not a block, it's a model for a block. You'll have to register a new block and code it's attributes and then bind the model to it.
If it's just in techne, then it's not a block, it's a model for a block. You'll have to register a new block and code it's attributes and then bind the model to it.
It's already an ingame block with a model. (Click my banner or his, both redirect to the same page if you want to see what he's making)
You have static references to your Block instances in your MainRegistry class, so you'd use MainRegistry.blockRailStraight instead of Blocks.stone in Tupolev144's code.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
You have static references to your Block instances in your MainRegistry class, so you'd use MainRegistry.blockRailStraight instead of Blocks.stone in Tupolev144's code.
Thanks, that worked! Thanks so much!
Edit:
Except when the block change happens, the new block orientates itself to be facing west, how can I bypass the auto orientation?
I don't think that is "auto" orientation so much as "default" orientation. The orientation for a block is generally in the metadata. I think it is the same numbering system you see when you press F3 to see your coordinates and which way you are facing 0 is South, 1 is West, 2, is North, and 3 is East.
For things in setBlock with metadata, add another parameter containing a number 0 - 3, for the direction you want it to face.
I don't think that is "auto" orientation so much as "default" orientation. The orientation for a block is generally in the metadata. I think it is the same numbering system you see when you press F3 to see your coordinates and which way you are facing 0 is South, 1 is West, 2, is North, and 3 is East.
For things in setBlock with metadata, add another parameter containing a number 0 - 3, for the direction you want it to face.
How would I get it to be in the same orientation the original was facing?
To do it, you have to make an if statement thats test if ther metadata is 1, then use w.setBlock(MainRegistering.yourBlock/1, x, y, z), but if the metadat is for example 2 then it is: w.setBlock(MainRegistering.yourBlock/2, x, y, z). So, it is w.setBlock(MainRegistering.yourBlock/METADATA, x, y, z).
do you understand?
(this works in 1.6, i havent tested it in 1.7...)
I understand, but I dont know how to write a statement. :/
Err no, check the methods for the actual Block instance - not your block registration. I.e. world.getBlock(x, y, z).something.
Seriously though, how did you get this far without knowing basic Java :\
So this?
if (w.getBlockMetadata(x, y, z) == 1);
w.setBlock(MainRegistry.blockRailPointROpen/.1, x, y, z);
return true;
Then I have to define "/" for the argument, which I assume goes something like this?
if(!/.isMetadata)
And then I have to do that for each metadata variation? 1,2,3,4?
As for not knowing basic java, I only learnt a little, and I got this far from tutorials. I should probably make more of an effort to learn, but I learn by doing.
The blocks I'm using are Techne models.
Sorry, you might have to spell it out to me, so I put the onBlockActivated bit here?
package com.modelrailway.track.pointR;
import com.modelrailway.lib.RefStrings;
import com.modelrailway.track.normal.TileEntityTrackBufferEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class TileEntityTrackPointRightBlock extends BlockContainer
{
public TileEntityTrackPointRightBlock(int id)
{
super(Material.iron);
this.setCreativeTab(CreativeTabs.tabTransport);
//wrong bounds this.setBlockBounds(0.4F, 0.0F, 0.4F, 0.6F, 3.0F, 0.6F);
float f = 0.5F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.15F, 0.5F + f);
}
@Override
public int getRenderType() {
return -1;
}
@Override
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
@SideOnly(Side.CLIENT)
private IIcon icon;
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister r)
{
this.icon = r.registerIcon(RefStrings.MODID + ":blockRailPointR");
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileEntityTrackPointRightEntity();
}
public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
{
int l = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 3, 2); // If you want your rail to be set crosswise to the player replace the 1 with a 0
}
if (l == 1)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 4, 2); // If you want your rail to be set crosswise to the player replace the 2 with a 1
}
if (l == 2)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 5, 2); // If you want your rail to be set crosswise to the player replace the 3 with a 2
}
if (l == 3)
{
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 6, 2); // If you want your rail to be set crosswise to the player replace the 4 with a 3
}
}
private void func_149930_e(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_)
{
if (!p_149930_1_.isRemote)
{
Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1);
Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1);
Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_);
Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2);
}
}
Then what?
World#setBlock(TileEntityblockname)thensomecoords
I'm a beginner coder :/
That worked! Thanks again Tupelov.
I assume I change Blocks.stone with whatever I want the block to be changed to?
Edit: Having trouble finding how to call the right block, because its not in Blocks."listofblocks"
I have tried Entity."Stuff" and TileEntity."Stuff", but I can't find any trace of the Techne blocks. Which caller should I be using? I did find a w.setTileEntity
Would that have somethine to do with it?
Also, to add a sound effect when the block change happens would I add "w.playSound(x, y, z, Block.soundTypePiston ?
In other words, learn basic modding via some guides first - creating new blocks is often the first lesson.
I already have my block, but its a techne block and not registered like a normal minecraft block.
Well when I type Blocks. a list of vanilla MC blocks show up, but my techne blocks aren't in the list.
It's already an ingame block with a model. (Click my banner or his, both redirect to the same page if you want to see what he's making)
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks, that worked! Thanks so much!
Edit:
Except when the block change happens, the new block orientates itself to be facing west, how can I bypass the auto orientation?
For things in setBlock with metadata, add another parameter containing a number 0 - 3, for the direction you want it to face.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
How would I get it to be in the same orientation the original was facing?
Rotate it in the model code instead, to change the default orientation.
This isnt right is it :/
I understand, but I dont know how to write a statement. :/
An if statment is when you type "if (a == doSomething();"
Well, I had a go, and I dont think this is right :/
Seriously though, how did you get this far without knowing basic Java :\
So this?
Then I have to define "/" for the argument, which I assume goes something like this?
And then I have to do that for each metadata variation? 1,2,3,4?
As for not knowing basic java, I only learnt a little, and I got this far from tutorials. I should probably make more of an effort to learn, but I learn by doing.
I have no idea about the block rotation part, though sorry.
That's fair enough, you found world.getBlockMetadata after I incorrectly said to use world.getBlock so you're doing alright heh.