Jump to content

place a block facing player<SOLVED>


RafaelVN

Recommended Posts

hi, I'm trying to create a block that when in the world he is facing the player who placed it (as well as furnaces etc ...).

 

Follow my code:

 

Block class:

package teste;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class InductionFurnace extends Block implements ITileEntityProvider {

public final static int BOTTOM_SIDE = 0;
public final static int TOP_SIDE = 1;
public final static int NORTH_SIDE = 2;
public final static int SOUTH_SIDE = 3;
public final static int WEST_SIDE = 4;
public final static int EAST_SIDE = 5;

private IIcon top;
private IIcon bottom;
private IIcon left;
private IIcon right;
private IIcon front;
private IIcon back;
private IIcon skinBase;

public static boolean isBurning = true;

protected InductionFurnace(Material mat) {
	super(mat);
	System.out.println("Block criado :" + toString());
}

@Override
public boolean onBlockActivated(World p_149727_1_, int p_149727_2_,
		int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_,
		int p_149727_6_, float p_149727_7_, float p_149727_8_,
		float p_149727_9_) {
	// Minecraft.getMinecraft().displayGuiScreen(new GuiBasic());

	return super.onBlockActivated(p_149727_1_, p_149727_2_, p_149727_3_,
			p_149727_4_, p_149727_5_, p_149727_6_, p_149727_7_,
			p_149727_8_, p_149727_9_);
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
	System.out.println(meta);
	System.out.println("Tile Entity criado :" + toString());
	Item.getItemFromBlock(this);
	return new MyFirstTileEntity();
	// this.getDrops(world, x, y, z, metadata, fortune)

}

@Override
public void registerBlockIcons(IIconRegister iconRegister) {
	top = iconRegister.registerIcon("testemod:MachinePlateBorded");
	bottom = iconRegister.registerIcon("testemod:MachineLogisticEntrance");
	left = iconRegister.registerIcon("testemod:MachinePlateFanLeft");
	right = iconRegister.registerIcon("testemod:MachinePlateFanRight");
	back = iconRegister.registerIcon("testemod:MachineBack");
	front = iconRegister.registerIcon("testemod:"
			+ (isBurning ? "InductionFurnaceFrontActive"
					: "InductionFurnaceFront"));
	skinBase = iconRegister.registerIcon("testemod:MachinePlateBorded");
}

@Override
public IIcon getIcon(int side, int meta) {
	switch (side) {
	case InductionFurnace.BOTTOM_SIDE:
		return bottom;

	case InductionFurnace.TOP_SIDE:
		return top;

	case InductionFurnace.NORTH_SIDE:
		return back;

	case InductionFurnace.SOUTH_SIDE:
		return front;

	case InductionFurnace.WEST_SIDE:
		return right;

	case InductionFurnace.EAST_SIDE:
		return left;
	}
	return skinBase;
}

@Override
public Item getItemDropped(int par1, Random random, int par3) {
	return Item.getItemFromBlock(testemod.myFirstContainerBlock);
}

@Override
public Item getItem(World world, int par2, int par3, int par4) {
	return Item.getItemFromBlock(testemod.myFirstContainerBlock);
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	super.onBlockAdded(world, x, y, z);
	direction(world, x, y, z);
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
		EntityLivingBase player, ItemStack p_149689_6_) {
	int l = MathHelper
			.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

	if (l == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}

	if (l == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}

	if (l == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}

	if (l == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}
}

public void direction(World world, int x, int y, int z) {
	if (!world.isRemote) {
		Block direction1 = world.getBlock(x, y, z - 1);
		Block direction2 = world.getBlock(x, y, z + 1);
		Block direction3 = world.getBlock(x - 1, y, z - 1);
		Block direction4 = world.getBlock(x + 1, y, z - 1);

		byte byte0 = 3;

		if (direction1.func_149730_j() && !direction2.func_149730_j()) {
			byte0 = 3;
		}

		if (direction2.func_149730_j() && !direction1.func_149730_j()) {
			byte0 = 2;
		}

		if (direction3.func_149730_j() && !direction4.func_149730_j()) {
			byte0 = 5;
		}

		if (direction4.func_149730_j() && !direction3.func_149730_j()) {
			byte0 = 4;
		}

		world.setBlockMetadataWithNotify(x, y, z, byte0, 2);
	}
}

public static void updateFurnaceBlockState(boolean p_149931_0_,
		World world, int x, int y, int z) {
	int direction = world.getBlockMetadata(x, y, z);
	// TileEntity tileentity = world.getTileEntity(p_149931_2_, p_149931_3_,
	// p_149931_4_);
	// field_149934_M = true;

	// if (p_149931_0_) {
	// world.setBlock(p_149931_2_, p_149931_3_, p_149931_4_,
	// Blocks.lit_furnace);
	// } else {
	// world.setBlock(p_149931_2_, p_149931_3_, p_149931_4_,
	// Blocks.furnace);
	// }

	// field_149934_M = false;
	world.setBlockMetadataWithNotify(x, y, z, direction, 2);

	// if (tileentity != null)
	// {
	// tileentity.validate();
	// p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_,
	// tileentity);
	// }
}

// @Override
// public void breakBlock(World world, int x, int y, int z, Block block,
// int meta) {
// }

@Override
public void randomDisplayTick(World world, int x, int y, int z,
		Random random) {
	int direction = world.getBlockMetadata(x, y, z);
	float xx = (float) (x + 0.5F);
	float yy = (float) (y + random.nextFloat() * 6.0F / 16.0F);
	float zz = (float) (z + 0.5F);
	float zz2 = 0.52F;
	float xx2 = random.nextFloat() * 0.6F - 0.3F;

	switch (direction) {
	case 4: {
		world.spawnParticle("smoke", (double) (xx - zz2), (double) yy,
				(double) (zz + xx2), 0.0D, 0.0D, 0.0D);
		world.spawnParticle("flame", (double) (xx - zz2), (double) yy,
				(double) (zz + xx2), 0.0D, 0.0D, 0.0D);
	}
	case 5: {
		world.spawnParticle("smoke", (double) (xx + zz2), (double) yy,
				(double) (zz + xx2), 0.0D, 0.0D, 0.0D);
		world.spawnParticle("flame", (double) (xx + zz2), (double) yy,
				(double) (zz + xx2), 0.0D, 0.0D, 0.0D);
	}
	case 2: {
		world.spawnParticle("smoke", (double) (xx + xx2), (double) yy,
				(double) (zz - zz2), 0.0D, 0.0D, 0.0D);
		world.spawnParticle("flame", (double) (xx + xx2), (double) yy,
				(double) (zz - zz2), 0.0D, 0.0D, 0.0D);
	}
	case 3: {
		world.spawnParticle("smoke", (double) (xx + xx2), (double) yy,
				(double) (zz + zz2), 0.0D, 0.0D, 0.0D);
		world.spawnParticle("flame", (double) (xx + xx2), (double) yy,
				(double) (zz + zz2), 0.0D, 0.0D, 0.0D);
	}
	}
}
}

 

main class:

package teste;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;

@Mod(modid = testemod.MODID, name = testemod.NAME, version = testemod.VERSION)
public class testemod {
public static final String MODID = "testemod";
public static final String NAME = "Testemod";
public static final String VERSION = "1.0";

public static Block myFirstContainerBlock;

@Instance ( "testemod" )
    public static testemod instance;

    @SidedProxy ( clientSide = "teste.ClientProxy", serverSide = "teste.CommonProxy" )
    public static CommonProxy proxy;


@EventHandler
public void preinit(FMLPreInitializationEvent event) {

	myFirstContainerBlock = new InductionFurnace(Material.rock)
			.setHardness(0.5F).setStepSound(Block.soundTypeStone)
			.setBlockName("myFirstContainerBlock")
			.setCreativeTab(CreativeTabs.tabBlock);
	GameRegistry.registerBlock(myFirstContainerBlock,
			"myFirstContainerBlock");
	NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
}
}

 

Well, the problem is simple, do not block the orientation of the way I want, they just keep the default orientation.

 

see the result:

 

width=702 height=395https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xap1/t31.0-8/q83/p526x395/1801159_758967554192629_5029193513560918574_o.jpg[/img]

width=702 height=395https://scontent-a-mia.xx.fbcdn.net/hphotos-xfa1/t31.0-8/q83/p526x395/1655482_758967677525950_4610313450111996101_o.jpg[/img]

 

I wonder what's wrong in my code does not work the way I want, and I'm grateful for the help.

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.