Поворот json модели как бошки.

Версия Minecraft
1.12.2
5,018
47
783
Привет вам. Потребовалось сделать мой блок вертящимся не только по сторонам света, но и по разным углам, как головы в игре. В общем, залез, сделал блок -
Java:
public class BlockComp extends BlockContainer
{
    public static final PropertyDirection FACING = BlockDirectional.FACING;
    protected static final AxisAlignedBB DEFAULT_AABB = new AxisAlignedBB(0.25D, 0.0D, 0.25D, 0.75D, 0.5D, 0.75D);
    protected static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.5D, 0.75D, 0.75D, 1.0D);
    protected static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.25D, 0.25D, 0.0D, 0.75D, 0.75D, 0.5D);
    protected static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.5D, 0.25D, 0.25D, 1.0D, 0.75D, 0.75D);
    protected static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.0D, 0.25D, 0.25D, 0.5D, 0.75D, 0.75D);
    private BlockPattern witherBasePattern;
    private BlockPattern witherPattern;

    public BlockComp(String name)
    {
        super(Material.CIRCUITS);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
        this.setRegistryName(name);
        this.setUnlocalizedName(name);
    }

    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }

    public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    @SideOnly(Side.CLIENT)
    public boolean hasCustomBreakingProgress(IBlockState state)
    {
        return true;
    }

    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        switch ((EnumFacing)state.getValue(FACING))
        {
            case UP:
            default:
                return DEFAULT_AABB;
            case NORTH:
                return NORTH_AABB;
            case SOUTH:
                return SOUTH_AABB;
            case WEST:
                return WEST_AABB;
            case EAST:
                return EAST_AABB;
        }
    }

    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing());
    }

    public TileEntity createNewTileEntity(World worldIn, int meta)
    {
        return new TileEntityComp();
    }

    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(RegBlocks.comp, 1, 0);
    }

    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
    {
        if (player.capabilities.isCreativeMode)
        {
            worldIn.setBlockState(pos, state, 4);
        }
        this.dropBlockAsItem(worldIn, pos, state, 0);

        super.onBlockHarvested(worldIn, pos, state, player);
    }

    public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
    {
        super.breakBlock(worldIn, pos, state);
    }
  
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Items.SKULL;
    }

    public boolean canDispenserPlace(World worldIn, BlockPos pos, ItemStack stack)
    {
        if (stack.getMetadata() == 1 && pos.getY() >= 2 && worldIn.getDifficulty() != EnumDifficulty.PEACEFUL && !worldIn.isRemote)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
    }

    public int getMetaFromState(IBlockState state)
    {
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();

            i |= 8;
    
        return i;
    }

    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }

    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING});
    }


 

    public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
    {
        return BlockFaceShape.UNDEFINED;
    }
}
И тайл - (подозреваю что где то наговнокодил с нбтшками)
Код:
public class TileEntityComp extends TileEntity
{
    private int skullRotation;

    public NBTTagCompound writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);
        compound.setByte("Rot", (byte)(this.skullRotation & 255));

        NBTTagCompound nbttagcompound = new NBTTagCompound();
        compound.setTag("Owner", nbttagcompound);


        return compound;
    }

    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);

        this.skullRotation = compound.getByte("Rot");

    }

    @Nullable
    public SPacketUpdateTileEntity getUpdatePacket()
    {
        return new SPacketUpdateTileEntity(this.pos, 4, this.getUpdateTag());
    }

    public NBTTagCompound getUpdateTag()
    {
        return this.writeToNBT(new NBTTagCompound());
    }
    @SideOnly(Side.CLIENT)
    public int getSkullRotation()
    {
        return this.skullRotation;
    }

    public void setSkullRotation(int rotation)
    {
        this.skullRotation = rotation;
    }

    public void mirror(Mirror mirrorIn)
    {
        if (this.world != null && this.world.getBlockState(this.getPos()).getValue(BlockSkull.FACING) == EnumFacing.UP)
        {
            this.skullRotation = mirrorIn.mirrorRotation(this.skullRotation, 16);
        }
    }

    public void rotate(Rotation rotationIn)
    {
        if (this.world != null && this.world.getBlockState(this.getPos()).getValue(BlockSkull.FACING) == EnumFacing.UP)
        {
            this.skullRotation = rotationIn.rotate(this.skullRotation, 16);
        }
    }
}
И Следом, конечно же TESR -
Код:
@SideOnly(Side.CLIENT)
public class TileEntityCompRenderer extends TileEntitySpecialRenderer<TileEntityComp>
{
    private static final ResourceLocation SKELETON_TEXTURES = new ResourceLocation("textures/entity/skeleton/skeleton.png");
    
    private final ModelDragonHead dragonHead = new ModelDragonHead(0.0F);
    public static TileEntityCompRenderer instance;
    private final ModelSkeletonHead skeletonHead = new ModelSkeletonHead(0, 0, 64, 32);
    private final ModelSkeletonHead humanoidHead = new ModelHumanoidHead();

    public void render(TileEntityComp te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
    {
        EnumFacing enumfacing = EnumFacing.getFront(te.getBlockMetadata() & 7);
        this.renderSkull((float)x, (float)y, (float)z, enumfacing, (float)(te.getSkullRotation() * 360) / 16.0F, destroyStage);
    }

    public void setRendererDispatcher(TileEntityRendererDispatcher rendererDispatcherIn)
    {
        super.setRendererDispatcher(rendererDispatcherIn);
        instance = this;
    }

    public void renderSkull(float x, float y, float z, EnumFacing facing, float rotationIn,  int destroyStage)
    {
        ModelBase modelbase = this.skeletonHead;

        if (destroyStage >= 0)
        {
            this.bindTexture(DESTROY_STAGES[destroyStage]);
            GlStateManager.matrixMode(5890);
            GlStateManager.pushMatrix();
            GlStateManager.scale(4.0F, 2.0F, 1.0F);
            GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
            GlStateManager.matrixMode(5888);
        }
        else
        {
                    this.bindTexture(SKELETON_TEXTURES);
      
        }

        GlStateManager.pushMatrix();
        GlStateManager.disableCull();

        if (facing == EnumFacing.UP)
        {
            GlStateManager.translate(x + 0.5F, y, z + 0.5F);
        }
        else
        {
            switch (facing)
            {
                case NORTH:
                    GlStateManager.translate(x + 0.5F, y + 0.25F, z + 0.74F);
                    break;
                case SOUTH:
                    GlStateManager.translate(x + 0.5F, y + 0.25F, z + 0.26F);
                    rotationIn = 180.0F;
                    break;
                case WEST:
                    GlStateManager.translate(x + 0.74F, y + 0.25F, z + 0.5F);
                    rotationIn = 270.0F;
                    break;
                case EAST:
                default:
                    GlStateManager.translate(x + 0.26F, y + 0.25F, z + 0.5F);
                    rotationIn = 90.0F;
            }
        }

        float f = 0.0625F;
        GlStateManager.enableRescaleNormal();
        GlStateManager.scale(-1.0F, -1.0F, 1.0F);
        GlStateManager.enableAlpha();


        modelbase.render((Entity)null,0.0F, 0.0F, rotationIn, 0.0F, 0.0625F, f);
        GlStateManager.popMatrix();

        if (destroyStage >= 0)
        {
            GlStateManager.matrixMode(5890);
            GlStateManager.popMatrix();
            GlStateManager.matrixMode(5888);
        }
    }
}

Обнаружилось ВНЕЗАПНО что там нужно свой класс extends ModelBase делать... Можно как то просто загрузить в TESR мою json модель и работать с ней? Там она довольно сложная, не какой то там кубик :(
 
5,018
47
783
5,018
47
783
3,005
192
592
от какого то TileBase которого нигде нету
Проорал!
Там есть импорт.
1520176529719.png
Так же в гит хабе есть поиск.
Technicalities/TileBase.java at master · amadornes/Technicalities · GitHub
Он унаследован от TileEntityBase, который находится в другой библиотеке..
Вот соурсы.
ElecCore/src/main/java/elec332/core at master · Elecs-Mods/ElecCore · GitHub
~~~
Сейчас бы писать копировать код, который не можешь скопировать...
 
3,005
192
592
5,018
47
783
Так, тогда еще вопрос. Как мне регистрировать TESR ? Здесь как то явно по другому, а на самом деле я не помню как регистрировал на 1.7.
 
3,005
192
592
TESR - это TileEntitySpecialRenderer?
ClientRegistry.bindTileEntitySpecialRenderer(TileEntity.class, new Render());
 
476
9
39
5,018
47
783
Возрождаю тему - новые вопросы.
1) Если я делаю блок через TESR, нужна ли ему json моделька? Нужно ли ее регистрировать как обычно?
2) У меня краш, не пойму в чем дело. В нбт плоховато очень шарю, глянбте чего тут не так... пожалуйста.
[09:44:57] [Server thread/ERROR] [FML]: A TileEntity type ru.lg.SovietMod.Blocks.TileEntity.TileEntityComp has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class ru.lg.SovietMod.Blocks.TileEntity.TileEntityComp is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:89) ~[TileEntity.class:?]
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:80) ~[TileEntity.class:?]
at ru.lg.SovietMod.Blocks.TileEntity.TileEntityComp.writeToNBT(TileEntityComp.java:21) ~[TileEntityComp.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:414) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:185) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:214) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:242) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1060) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:468) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:274) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:509) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:413) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:643) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Это все - скопированный тайл головы, в котором я убрал, по моему мнению, ненужные методы
Java:
public class TileEntityComp extends TileEntity
{
    private int skullRotation;

    public NBTTagCompound writeToNBT(NBTTagCompound compound)
    {
        super.writeToNBT(compound);
        compound.setByte("Rot", (byte)(this.skullRotation & 255));

        NBTTagCompound nbttagcompound = new NBTTagCompound();
        compound.setTag("Owner", nbttagcompound);


        return compound;
    }

    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);

        this.skullRotation = compound.getByte("Rot");

    }

    @Nullable
    public SPacketUpdateTileEntity getUpdatePacket()
    {
        return new SPacketUpdateTileEntity(this.pos, 4, this.getUpdateTag());
    }

    public NBTTagCompound getUpdateTag()
    {
        return this.writeToNBT(new NBTTagCompound());
    }
    @SideOnly(Side.CLIENT)
    public int getCompRotation()
    {
        return this.skullRotation;
    }

    public void setCompRotation(int rotation)
    {
        this.skullRotation = rotation;
    }

    public void mirror(Mirror mirrorIn)
    {
        if (this.world != null && this.world.getBlockState(this.getPos()).getValue(BlockSkull.FACING) == EnumFacing.UP)
        {
            this.skullRotation = mirrorIn.mirrorRotation(this.skullRotation, 16);
        }
    }

    public void rotate(Rotation rotationIn)
    {
        if (this.world != null && this.world.getBlockState(this.getPos()).getValue(BlockSkull.FACING) == EnumFacing.UP)
        {
            this.skullRotation = rotationIn.rotate(this.skullRotation, 16);
        }
    }
}
 
5,018
47
783
UPD: Поубирал суперы в нбт методах - больше не крашит. Правда, не знаю как быть с моделью. Она не подгружается ... блокстейт нужен?
 
5,018
47
783
Вообще, есть какой то гайд нормальный, как пользоваться TESR?
Потому что сделал блокстейт, сделал модель и вот такое вот происходит...
Дело в том, что я вообще не понимаю, что тут и почему...
Time: 3/11/18 10:03 AM
Description: Generating mipmaps for frame

java.lang.ArrayIndexOutOfBoundsException: 1
at net.minecraft.client.renderer.texture.TextureUtil.generateMipmapData(TextureUtil.java:68)
at net.minecraft.client.renderer.texture.TextureAtlasSprite.generateMipmaps(TextureAtlasSprite.java:345)
at net.minecraft.client.renderer.texture.TextureMap.generateMipmaps(TextureMap.java:299)
at net.minecraft.client.renderer.texture.TextureMap.loadTexture(TextureMap.java:182)
at net.minecraft.client.renderer.texture.TextureMap.loadTextureAtlas(TextureMap.java:110)
at net.minecraft.client.renderer.texture.TextureMap.loadSprites(TextureMap.java:91)
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:172)
at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28)
at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121)
at net.minecraft.client.Minecraft.init(Minecraft.java:559)
at net.minecraft.client.Minecraft.run(Minecraft.java:421)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
at net.minecraft.client.renderer.texture.TextureUtil.generateMipmapData(TextureUtil.java:68)

-- Frame being iterated --
Details:
Frame index: 0
Frame sizes: 1, null, null, null, null
Stacktrace:
at net.minecraft.client.renderer.texture.TextureAtlasSprite.generateMipmaps(TextureAtlasSprite.java:345)

-- Sprite being mipmapped --
Details:
Sprite name: soviet:blocks/green_pixel
Sprite size: 1 x 1
Sprite frames: 1 frames
Mipmap levels: 4
Stacktrace:
at net.minecraft.client.renderer.texture.TextureMap.generateMipmaps(TextureMap.java:299)
at net.minecraft.client.renderer.texture.TextureMap.loadTexture(TextureMap.java:182)
at net.minecraft.client.renderer.texture.TextureMap.loadTextureAtlas(TextureMap.java:110)
at net.minecraft.client.renderer.texture.TextureMap.loadSprites(TextureMap.java:91)
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:172)
at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28)
at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121)
at net.minecraft.client.Minecraft.init(Minecraft.java:559)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:421)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
 
Последнее редактирование:
5,018
47
783
Ладно, в общем, я всю эту неработающую херню удалил, пусть поворачивается по дефолтным углам. Слишком мало времени чтобы сидеть разбираться с этим говном.
 

Icosider

Kotliner
Администратор
3,603
99
664
Вообще, есть какой то гайд нормальный, как пользоваться TESR?
Потому что сделал блокстейт, сделал модель и вот такое вот происходит...
Дело в том, что я вообще не понимаю, что тут и почему...
Создаешь теср, в рендер засовываешь заранее инициализированный класс модели или ModelBaked и делаешь что хочешь.
 
Сверху