- 6
- 0
Ну собственно есть блок, надо что-бы все стороны были одной текстуры, а лицевая другой. И что-бы лицевая сторона была с той стороны, с которой поставили блок.
Ну тогда подскажи, где выдрать её код, потому-что я последний раз кодил на 1.6.2, и там проще было найти net.minecraft, а на 1.7.10 я не нашел)Agravaine написал(а):Печка отлично подходит.
Вперёд!
ну просто шикарно, там все в class...Agravaine написал(а):Referenced libriaries
Forge начиная с 1.6.4 использует ForgeGradle а не MCP. Там не выйдет модифицировать сурсы майнкрафта, но просмотреть их все равно можно. В любой нормальной IDE можно перейти к файлу другого класса используя Ctrl+ЛКМ.OctaviaBrony написал(а):Ну тогда подскажи, где выдрать её код, потому-что я последний раз кодил на 1.6.2, и там проще было найти net.minecraft, а на 1.7.10 я не нашел)Agravaine написал(а):Печка отлично подходит.
Вперёд!
А поподробнее можно насчет getIconDefilak написал(а):Forge начиная с 1.6.4 использует ForgeGradle а не MCP. Там не выйдет модифицировать сурсы майнкрафта, но просмотреть их все равно можно. В любой нормальной IDE можно перейти к файлу другого класса используя Ctrl+ЛКМ.OctaviaBrony написал(а):Ну тогда подскажи, где выдрать её код, потому-что я последний раз кодил на 1.6.2, и там проще было найти net.minecraft, а на 1.7.10 я не нашел)Agravaine написал(а):Печка отлично подходит.
Вперёд!
В кратце, положение текстур устанавливается либо в зависимости от метадаты (В случае с печью), либо если есть TileEntity - в NBT-тегах. Так же есть класс ForgeDirection для удобства определения сторон света.
Для определения особенной текстуры для каждой стороны блока если выбран способ с метадатой стоит переопределить метод getIcon. В качестве входящего параметра он использует сторону блока и метадату, так что это самый простой выход.
Короче с текстурой я разобрался, а вот поворот к игроку ни как...Agravaine написал(а):Тебе все объяснили. Копируй с печки и все.
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) {
super.onBlockPlacedBy(world, i, j, k, entityliving, stack);
ForgeDirection orientation = Utils.get2dOrientation(entityliving);
world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1);
}
public static ForgeDirection get2dOrientation(EntityLivingBase entityliving) {
ForgeDirection[] orientationTable = { ForgeDirection.SOUTH,
ForgeDirection.WEST, ForgeDirection.NORTH, ForgeDirection.EAST };
int orientationIndex = MathHelper.floor_double((entityliving.rotationYaw + 45.0) / 90.0) & 3;
return orientationTable[orientationIndex];
}
LeonidM/Dasperal написал(а):Код из BuildCraft (https://github.com/BuildCraft/BuildCraft):
Код:@Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) { super.onBlockPlacedBy(world, i, j, k, entityliving, stack); ForgeDirection orientation = Utils.get2dOrientation(entityliving); world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1); }
Код:public static ForgeDirection get2dOrientation(EntityLivingBase entityliving) { ForgeDirection[] orientationTable = { ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.NORTH, ForgeDirection.EAST }; int orientationIndex = MathHelper.floor_double((entityliving.rotationYaw + 45.0) / 90.0) & 3; return orientationTable[orientationIndex]; }
Собственно, что не так?
Код:package mod.furnaceMod; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class FurnaceBlock extends Block{ public IIcon[] icons = new IIcon[6]; protected FurnaceBlock() { super(Material.rock); this.setBlockName("Furnace Block"); this.setCreativeTab(FurnaceMod.tabFurnaceMod); this.setHardness(15F); this.setResistance(10F); this.setHarvestLevel("pickaxe", 3); this.setLightLevel(0F); this.setBlockTextureName("furnaceMod:all"); } @Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) { super.onBlockPlacedBy(world, i, j, k, entityliving, stack); ForgeDirection orientation = get2dOrientation(entityliving); world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1); } public static ForgeDirection get2dOrientation(EntityLivingBase entityliving) { ForgeDirection[] orientationTable = { ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.NORTH, ForgeDirection.EAST }; int orientationIndex = MathHelper.floor_double((entityliving.rotationYaw + 45.0) / 90.0) & 3; return orientationTable[orientationIndex]; } public static Side get2dOrientation(double x1, double z1, double x2, double z2) { double dx = x1 - x2; double dz = z1 - z2; double angle = Math.atan2(dz, dx) / Math.PI * 180 + 180; if (angle < 45 || angle > 315) { // return -Math.PI; // East return Side.EAST; } else if (angle < 135) { return Side.SOUTH; } else if (angle < 225) { // return 0; // West return Side.WEST; } else { // return -(Math.PI / 2); // North return Side.NORTH; } } public enum Side { UP(1, 0, 1, 0), DOWN(2, 0, -1, 0), NORTH(4, 0, 0, -1), SOUTH(8, 0, 0, 1), EAST(16, -1, 0, 0), WEST(32, 1, 0, 0); public static final Side[] SIDES = {UP, DOWN, NORTH, SOUTH, EAST, WEST}; public static final Side[] OPPOSITE = {DOWN, UP, SOUTH, NORTH, WEST, EAST}; public final byte value; public final int offX; public final int offY; public final int offZ; Side(int value, int offX, int offY, int offZ) { this.value = (byte) value; this.offX = offX; this.offY = offY; this.offZ = offZ; } public static Side fromVanillaSide(int side) { return Side.OPPOSITE[side]; } public Side opposite() { return OPPOSITE[ordinal()]; } } @Override public void registerBlockIcons(IIconRegister reg) { for (int i = 0; i < 6; i ++) { this.icons[i] = reg.registerIcon(this.textureName + "_" + i); } } @Override public IIcon getIcon(int side, int meta) { return this.icons[side]; } }
public static Side get2dOrientation(double x1, double z1, double x2, double z2) {
double dx = x1 - x2;
double dz = z1 - z2;
double angle = Math.atan2(dz, dx) / Math.PI * 180 + 180;
if (angle < 45 || angle > 315) {
// return -Math.PI; // East
return Side.EAST;
} else if (angle < 135) {
return Side.SOUTH;
} else if (angle < 225) {
// return 0; // West
return Side.WEST;
} else {
// return -(Math.PI / 2); // North
return Side.NORTH;
}
}
public enum Side {
UP(1, 0, 1, 0),
DOWN(2, 0, -1, 0),
NORTH(4, 0, 0, -1),
SOUTH(8, 0, 0, 1),
EAST(16, -1, 0, 0),
WEST(32, 1, 0, 0);
public static final Side[] SIDES = {UP, DOWN, NORTH, SOUTH, EAST, WEST};
public static final Side[] OPPOSITE = {DOWN, UP, SOUTH, NORTH, WEST, EAST};
public final byte value;
public final int offX;
public final int offY;
public final int offZ;
Side(int value, int offX, int offY, int offZ) {
this.value = (byte) value;
this.offX = offX;
this.offY = offY;
this.offZ = offZ;
}
public static Side fromVanillaSide(int side) {
return Side.OPPOSITE[side];
}
public Side opposite() {
return OPPOSITE[ordinal()];
}
}
@SideOnly(Side.CLIENT)
private IIcon blockIcon;
private IIcon blockIcon_front;
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister iconReg)
{
blockIcon = iconReg.registerIcon("modid:texturename");
blockIcon_front = iconReg.registerIcon("modid:texturename_front");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
ForgeDirection dir = ForgeDirection.getOrientation(side);
ForgeDirection block_dir;
if (meta != 0)
block_dir = ForgeDirection.getOrientation(meta);
else
block_dir = ForgeDirection.WEST;
if (block_dir == dir) return blockIcon_front;
return blockIcon;
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
EntityLivingBase entity, ItemStack itemStack) {
super.onBlockPlacedBy(world, x, y, z, entity, itemStack);
int dir = (MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3);
int[] r = {2, 5, 3, 4};
world.setBlockMetadataWithNotify(x, y, z, r[dir], 3);
}