- 5,018
- 47
- 783
Привет вам. Потребовалось сделать мой блок вертящимся не только по сторонам света, но и по разным углам, как головы в игре. В общем, залез, сделал блок -
И тайл - (подозреваю что где то наговнокодил с нбтшками)
И Следом, конечно же TESR -
Обнаружилось ВНЕЗАПНО что там нужно свой класс extends ModelBase делать... Можно как то просто загрузить в TESR мою json модель и работать с ней? Там она довольно сложная, не какой то там кубик
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);
}
}
}
Код:
@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 модель и работать с ней? Там она довольно сложная, не какой то там кубик