Jump to content

(SOLVED) [1.10.2] Custom block rendering with weird black stuff?


Recommended Posts

Posted

Hello,

 

I've been working on modding for some time now (very basic, nothing special) but I've decided to upgrade to 1.10 and try working with TileEntities. I have a cardboard box which has some issues (not opening GUI) but I'll get that solved later. For now, my block model is rendering weirdly, with odd black scratches that show up based on the direction I'm facing. Here is an album of the images: http://imgur.com/a/eTKQ2

 

And now the .jsons:

 

block.cardboard_box.json

 

 

{

    "parent": "block/cube_all",

    "textures": {

        "up": "arborcraft:blocks/cardboard_box_top",

        "north": "arborcraft:blocks/cardboard_box_front",

        "south": "arborcraft:blocks/cardboard_box_front",

        "east": "arborcraft:blocks/cardboard_box_front",

        "west": "arborcraft:blocks/cardboard_box_front",

        "down": "arborcraft:blocks/cardboard_box_side",

        "particle": "arborcraft:blocks/cardboard_box_side"

    }

}

 

 

 

item.cardboard_box.json

 

 

{

    "parent": "arborcraft:block/cardboard_box"

    "display": {

        "thirdperson": {

            "rotation": [ 10, -45, 170 ],

            "translation": [ 0, 1.5, -2.75 ],

            "scale": [ 0.375, 0.375, 0.375 ]

        }

    }

}

 

 

 

blockstates.cardboard_box.json

 

 

{

    "variants": {

        "normal" : {

            "model": "arborcraft:cardboard_box"

        },

        "inventory" : {

            "model": "arborcraft:cardboard_box"

        }

    }

}

 

 

 

NOTE: The inventory variant in the blockstate is the same because Forge needed one, so I just used the same as the normal. It doesn't do anything special when it opens.

 

Any help is appreciated, I can supply any other files as necessary. Sorry if it's a stupid issue that I just don't see  :-\.

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

Yes, here is the TESR file:

 

 

 

package com.Noxilus.arborcraft.render;

 

import org.lwjgl.opengl.GL11;

 

import com.Noxilus.arborcraft.model.ModelCardboardBox;

 

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

 

public class TileEntityCardboardBoxRenderer extends TileEntitySpecialRenderer

{

 

ResourceLocation texture = new ResourceLocation("mineboard:textures/entity/cardboard_box.png");

private ModelCardboardBox model;

 

public TileEntityCardboardBoxRenderer()

{

this.model = new ModelCardboardBox();

}

@Override

public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage)

{

GL11.glPushMatrix();

GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);

GL11.glRotatef(180, 0F, 0F, 1F);

this.bindTexture(texture);

GL11.glPushMatrix();

this.model.renderModel(0.0625F);

GL11.glPopMatrix();

GL11.glPopMatrix();

}

 

}

 

 

 

and the ModelCardboardBox class:

 

 

package com.Noxilus.arborcraft.model;

 

import net.minecraft.client.model.ModelBase;

import net.minecraft.client.model.ModelRenderer;

import net.minecraft.entity.Entity;

 

public class ModelCardboardBox extends ModelBase

{

    ModelRenderer Shape1;

 

  public ModelCardboardBox()

  {

    textureWidth = 64;

    textureHeight = 32;

   

      Shape1 = new ModelRenderer(this, 0, 0);

      Shape1.addBox(0F, 0F, 0F, 16, 16, 16);

      Shape1.setRotationPoint(-8F, 8F, -8F);

      Shape1.setTextureSize(64, 32);

      Shape1.mirror = true;

      setRotation(Shape1, 0F, 0F, 0F);

  }

 

  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)

  {

    super.render(entity, f, f1, f2, f3, f4, f5);

    setRotationAngles(f, f1, f2, f3, f4, f5, entity);

    Shape1.render(f5);

  }

 

  public void renderModel(float f5)

  {

  Shape1.render(f5);

  }

 

  private void setRotation(ModelRenderer model, float x, float y, float z)

  {

    model.rotateAngleX = x;

    model.rotateAngleY = y;

    model.rotateAngleZ = z;

  }

 

  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)

  {

    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);

  }

 

}

 

 

 

Hope those help.

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

Of course, here it is:

 

ArborCraftBlocks:

 

 

package com.Noxilus.arborcraft.registry;

 

import com.Noxilus.arborcraft.block.BlockCardboardBox;

import com.Noxilus.arborcraft.tileentity.TileEntityCardboardBox;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBlock;

import net.minecraftforge.fml.common.registry.GameRegistry;

 

public class ArborCraftBlocks {

public static Block cardboardBox;

public static ItemBlock cardboardBox_itemblock;

 

public static void setup() {

init();

register();

}

 

public static void init() {

cardboardBox = new BlockCardboardBox(Material.CLOTH, "cardboard_box", 0.3F, 0.3F).setRegistryName("cardboard_box");

cardboardBox_itemblock = (ItemBlock) new ItemBlock(cardboardBox).setRegistryName("cardboard_box");

}

 

public static void register() {

GameRegistry.register(cardboardBox);

GameRegistry.register(cardboardBox_itemblock);

GameRegistry.registerTileEntity(TileEntityCardboardBox.class, "tile_entity_cardboard_box");

}

 

public static void registerRenders() {

registerRender(cardboardBox);

}

 

public static void registerRender(Block block) {

Item item = Item.getItemFromBlock(block);

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));

}

}

 

 

 

BlockCardboardBox:

 

 

package com.Noxilus.arborcraft.block;

 

import com.Noxilus.arborcraft.ArborCraft;

import com.Noxilus.arborcraft.gui.CardboardBoxGuiHandler;

import com.Noxilus.arborcraft.tileentity.TileEntityCardboardBox;

 

import net.minecraft.block.Block;

import net.minecraft.block.ITileEntityProvider;

import net.minecraft.block.material.Material;

import net.minecraft.block.state.IBlockState;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.InventoryHelper;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

 

public class BlockCardboardBox extends Block implements ITileEntityProvider

{

 

public BlockCardboardBox(Material materialIn, String name, float hardness, float resistance)

{

super(materialIn);

this.setUnlocalizedName(name);

this.setHardness(hardness);

this.setResistance(resistance);

this.setCreativeTab(ArborCraft.tabArborCraft);

}

 

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)

{

if(!world.isRemote)

{

player.openGui(ArborCraft.MODID, CardboardBoxGuiHandler.CARDBOARD_BOX_GUI, world, pos.getX(), pos.getY(), pos.getZ());

}

return true;

}

 

public int getRenderType()

{

return 3;

}

 

@Override

public void breakBlock(World world, BlockPos pos, IBlockState state)

{

TileEntityCardboardBox te = (TileEntityCardboardBox)world.getTileEntity(pos);

InventoryHelper.dropInventoryItems(world, pos, te);

super.breakBlock(world, pos, state);

}

 

@Override

public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack)

{

if (stack.hasDisplayName())

{

((TileEntityCardboardBox)world.getTileEntity(pos)).setCustomName(stack.getDisplayName());

}

}

 

@Override

public TileEntity createNewTileEntity(World worldIn, int meta) {

return new TileEntityCardboardBox();

}

 

}

 

 

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

Couple things I'm seeing that aren't related to your problem, but you should change anyway:

 

1) Use of Minecraft.getMinecraft() in common code (this will crash the dedicated server). This is why the proxy system exists.

2) Use of getItemModelMesher() you should be using ModelLoader.setCustomModelResourceLocation() instead (called during preInit only!)

3) Use removedByPlayer() instead of breakBlock().  removedByPlayer() is called before the block is actually set to air, avoiding problems of trying to get a blockstate from air (actually it is set to air by the base implementation of removedByPlayer(), so remember to call super).

4) Do not implement ITileEntityProvider, the methods it "supplies" are already part of the Block class (the interface is not used anymore)

 

JSON changes:

 

5) You don't want parent:"block/cube_all" if you're going to specify sides.  Use parent:"block/cube".  cube_all is to specify a single texture to use for all six sides + particle (e.g. stone, wool, planks).

6) You can simplify your blockstate variants, specifying the model once (you can put textures here too, this way the variant overrides the default and different variants can supply different and possibly combinatorial differences):

 

{
    "defaults": {
            "model": "arborcraft:cardboard_box"
    }
    "variants": {
        "normal" : {

        },
        "inventory" : {

        }
    }
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

 

3) Use removedByPlayer() instead of breakBlock().  removedByPlayer() is called before the block is actually set to air, avoiding problems of trying to get a blockstate from air (actually it is set to air by the base implementation of removedByPlayer(), so remember to call super).

 

 

Thanks! Only issue is I can't figure out which methods to call in order to get the required EntityPlayer and boolean parameters. All other changes are accounted for. (I can't believe I missed that I was calling cube_all ><)

 

EDIT: It seems that I have another issue now: createNewTileEntity was implemented earlier and isn't replaced by Block. Is there a replacement function?

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

Block#createTileEntity()

 

It doesn't seem to like that, claiming that TileEntityCardboardBox() is not a TileEntity, and it's trying to get me to change the return type. which is false. It won't let me override without the Block# notation either.

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

Block#createTileEntity()

 

It doesn't seem to like that, claiming that TileEntityCardboardBox() is not a TileEntity, and it's trying to get me to change the return type. which is false. It won't let me override without the Block# notation either.

 

Block#createTileEntity()

is notation for the method called

createTileEntity

in the class

Block

. It has parameters, but I didn't specify them as it has no overloads(methods with the same name but different parameters). If you type a method name in a class and press the autocomplete keybind(Ctrl+Space in Eclipse), your IDE will display all methods with that name that you can override.

Posted

Block#createTileEntity()

 

It doesn't seem to like that, claiming that TileEntityCardboardBox() is not a TileEntity, and it's trying to get me to change the return type. which is false. It won't let me override without the Block# notation either.

 

Block#createTileEntity()

is notation for the method called

createTileEntity

in the class

Block

. It has parameters, but I didn't specify them as it has no overloads(methods with the same name but different parameters). If you type a method name in a class and press the autocomplete keybind(Ctrl+Space in Eclipse), your IDE will display all methods with that name that you can override.

 

Great, that's fixed now. Thanks!

 

As for your rendering issue: That is because you are rendering both a normal block model and a TESR-based model. Why?

 

I was following a TileEntity with GUI tutorial (I can't remember which, it was a while ago, and I ported the code over. I recall it not working then either.) Is the normal block model just in the json? Because the TESR uses the ModelCardboardBox class for itself.

Developer of small, unreleased, basic, and incomplete mods since 2014!

Posted

So what changes should I make to the json model? Sorry about all of the issues, I'm new to Minecraft's TileEntities and rendering.

 

 

EDIT: Somehow it's working now. First issue I just had while running was missing textures and wrong models for everything, so I just reinput the model call into the variants (the ModelLoader was complaining that there was no model for them, even though I set the default.) When I fixed that, after all other changes, the z-fighting went away. Thank you all for your help, now I'm going to get started on making the GUI work!

Developer of small, unreleased, basic, and incomplete mods since 2014!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.