[Решено] Поворот блока к игроку.

Версия Minecraft
1.7.10

Ari

38
0
Вот есть код
Код:
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]
 
Решение
RE: Поворот блока к игроку.

Потому-что ты ставишь метадату, но не делаешь как-бы поворота. У тебя getIcon возвращает объект IIcon только по side, а надо ещё и по метадате.
RE: Поворот блока к игроку.

Потому-что ты ставишь метадату, но не делаешь как-бы поворота. У тебя getIcon возвращает объект IIcon только по side, а надо ещё и по метадате.
 
RE: Поворот блока к игроку.

timaxa007 написал(а):
Потому-что ты ставишь метадату, но не делаешь как-бы поворота. У тебя getIcon возвращает объект IIcon только по side, а надо ещё и по метадате.

А примера как это сделать у вас случайно нет ?


timaxa007 написал(а):
Потому-что ты ставишь метадату, но не делаешь как-бы поворота. У тебя getIcon возвращает объект IIcon только по side, а надо ещё и по метадате.

Нашел. Вот ссылка на тему http://forum.mcmodding.ru/Тема-1-6-4-Просто-блок-Как-повернуть-блок-лицом-к-игроку Спасибо за подсказку.

Если кому то надо то вот код поворота блока. :3
Код:
 @Override
    public IIcon getIcon(int side, int meta) {
        ForgeDirection block_dir = ForgeDirection.getOrientation(meta);
        ForgeDirection dir = meta != 0 ? ForgeDirection.getOrientation(side) : ForgeDirection.WEST;
        if(dir == block_dir) return иконкаПереда;
        else if(dir == block_dir.getOpposite()) return иконкаЗада;
        else if(dir == ForgeDirection.DOWN) return иконкаНиза;
        else if(dir == ForgeDirection.UP) return иконкаВерха;
        else return иконкаБоковыхСторон;
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
        int dir = (MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
        int[] rotation = {2, 5, 3, 4};
        world.setBlockMetadataWithNotify(x, y, z, rotation[dir], 3);
    }
 
Ari написал(а):
Если кому то надо то вот код поворота блока. :3
Код:
 @Override
    public IIcon getIcon(int side, int meta) {
        ForgeDirection block_dir = ForgeDirection.getOrientation(meta);
        ForgeDirection dir = meta != 0 ? ForgeDirection.getOrientation(side) : ForgeDirection.WEST;
        if(dir == block_dir) return иконкаПереда;
        else if(dir == block_dir.getOpposite()) return иконкаЗада;
        else if(dir == ForgeDirection.DOWN) return иконкаНиза;
        else if(dir == ForgeDirection.UP) return иконкаВерха;
        else return иконкаБоковыхСторон;
    }

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
        int dir = (MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
        int[] rotation = {2, 5, 3, 4};
        world.setBlockMetadataWithNotify(x, y, z, rotation[dir], 3);
    }

я извиняюсь за очень очень очень тупой вопрос, но... там где иконкаПереда и т п. как указать иконку? как-бы объяснить... у меня текстура всех сторон блока лежит в assets.hackmod.textures.blocks и там есть 6 файлов с текстурой сторон. знаю, что я тупой...
 
Doc написал(а):
asdqwertypro написал(а):
знаю, что я тупой...

А зачем тогда ты кодишь, если ты .. ?

вообще я не тупой и в кодинге тоже уже чуть чуть да разбираюсь. просто тут я понимаю что ошибка тупая но тем не менее я не могу сам её решить. вот именно в этом коде я тупой. я иконки ещё никогда не делал... даж толком не понимаю что это такое... а вообще есть уже неплохой для новичка мод...
 
Назад
Сверху