- 38
- 0
Вот есть код
Вопрос такой.
Почему блок ставится всегда одинаково ?
Смотрел на форумах там говорилось что использовать [font=Monaco, Consolas, Courier, monospace] world.setBlockMetadataWithNotify(x, y, z, l, 2);[/font]
[font=Monaco, Consolas, Courier, monospace]Для поворота. Но что то не работает.
Спасибо за ответ.[/font]
Код:
package com.example.examplemod;
import java.util.Random;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.event.ClickEvent.Action;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
public class BlockCreator extends Block {
public IIcon side0;
public IIcon side1;
public IIcon side2;
public IIcon side3;
public IIcon side4;
public IIcon side5;
protected BlockCreator(Material material) {
super(material);
this.setBlockName("Black");
this.setCreativeTab(CreativeTabs.tabMaterials);
this.setHardness(15F);
this.setResistance(1000F);
this.setLightLevel(150F);
this.setBlockTextureName(ExampleMod.MODID + ":Black1");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer Player, int X, float Y, float Z, float f)
{
if(!world.isRemote)
{
if(Player.inventory.getCurrentItem() != null){
ItemStack item = Player.inventory.getCurrentItem();
if(item.getItem() == Items.coal)
{
TileEntityChest tile = (TileEntityChest)world.getTileEntity(x, y + 1, z);
if(tile != null)
{
tile.setInventorySlotContents(0, new ItemStack(Items.diamond, randInt(1, 10)));
for(int i = 1; i < 15; i++)
{
world.setBlockToAir(x, y - i, z);
}
return false;
}
}
}
}
return false;
}
public void registerBlockIcons(IIconRegister reg)
{
side0 = reg.registerIcon(ExampleMod.MODID + ":Black0");
side1 = reg.registerIcon(ExampleMod.MODID + ":Black1");
side2 = reg.registerIcon(ExampleMod.MODID + ":Black2");
side3 = reg.registerIcon(ExampleMod.MODID + ":Black3");
side4 = reg.registerIcon(ExampleMod.MODID + ":Black4");
side5 = reg.registerIcon(ExampleMod.MODID + ":Black5");
}
public IIcon getIcon(int side, int meta)
{
switch(side)
{
case 0: return side0;
case 1: return side1;
case 2: return side2;
case 3: return side3;
case 4: return side4;
case 5: return side5;
default: return side0;
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemStack)
{
int l = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
world.setBlockMetadataWithNotify(x, y, z, l, 2);
}
public static int randInt(int min, int max) {
// NOTE: This will (intentionally) not run as written so that folks
// copy-pasting have to think about how to initialize their
// Random instance. Initialization of the Random instance is outside
// the main scope of the question, but some decent options are to have
// a field that is initialized once and then re-used as needed or to
// use ThreadLocalRandom (if using at least Java 1.7).
Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
}
Вопрос такой.
Почему блок ставится всегда одинаково ?
Смотрел на форумах там говорилось что использовать [font=Monaco, Consolas, Courier, monospace] world.setBlockMetadataWithNotify(x, y, z, l, 2);[/font]
[font=Monaco, Consolas, Courier, monospace]Для поворота. Но что то не работает.
Спасибо за ответ.[/font]