Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (SOLVED) [1.10.2] Custom block rendering with weird black stuff?
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
LazerBeans

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

By LazerBeans, July 30, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 30, 2016

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  :-\.

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 30, 2016

This is getting buried, so I'm bumping.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45644 posts
Posted July 30, 2016

Are you having a TESR active or something? What you see there is z-fighting, which occurs when there are 2 quads in almost the same space.

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    677

Animefan8888

Animefan8888    677

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 677
  • 5746 posts
Posted July 31, 2016

May i see your blocks class.

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

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();

}

 

}

 

 

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2091

Draco18s

Draco18s    2091

  • Reality Controller
  • Draco18s
  • Members
  • 2091
  • 14018 posts
Posted July 31, 2016

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" : {

        }
    }
}

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

 

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?

  • Quote

Share this post


Link to post
Share on other sites

Leviathan143    39

Leviathan143

Leviathan143    39

  • Creeper Killer
  • Leviathan143
  • Forge Modder
  • 39
  • 211 posts
Posted July 31, 2016

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

Block#createTileEntity()

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

Leviathan143    39

Leviathan143

Leviathan143    39

  • Creeper Killer
  • Leviathan143
  • Forge Modder
  • 39
  • 211 posts
Posted July 31, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45644 posts
Posted July 31, 2016

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

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

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.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45644 posts
Posted July 31, 2016

The normal block model is defined by the JSONs, yes.

  • Quote

Share this post


Link to post
Share on other sites

LazerBeans    0

LazerBeans

LazerBeans    0

  • Tree Puncher
  • LazerBeans
  • Members
  • 0
  • 48 posts
Posted July 31, 2016

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!

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 4 minutes ago

      I did it, but I think it's only clientside prevention. I gotta send real packet "close gui" to trigger serverside InventoryCloseEvent (or something like that).
    • diesieben07
      [1.12.2] How can I close GUI in Forge?

      By diesieben07 · Posted 14 minutes ago

      To prevent the GUI from opening in GuiOpenEvent you need to cancel the event.
    • diesieben07
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By diesieben07 · Posted 16 minutes ago

      The only way to make data persist is to write to to some form of file. Whether you do it explicitly, or implicitly. You cannot persist data by wishing really hard.
    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 20 minutes ago

      I am trying to write an Minecraft Forge (1.12.2) mod. It should work like that: OnGuiOpen: If GUI title is equals to constant string value then close GUI (like ESC). That must be known by the server exactly like closing a GUI by clicking E/ESC.   My code (doesn't work - I'm seeing 'Turning off' in console but gui is still turned on)   public class ModEventHandler { @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { if(event.getGui() instanceof GuiContainer) { checkGui((GuiContainer) event.getGui()); } } private void checkGui(GuiContainer gui) { if(gui.inventorySlots instanceof ContainerChest) { ContainerChest _gui = (ContainerChest)gui.inventorySlots; String text = _gui.getLowerChestInventory().getDisplayName().getUnformattedText().toString(); if(text.contains(" ")) { System.out.println("Turning off"); Minecraft.getMinecraft().player.closeScreen(); Minecraft.getMinecraft().displayGuiScreen(null); KeyBinding.onTick(Keyboard.KEY_ESCAPE); } } } }   Thank u in advance for help
    • Differentiation
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By Differentiation · Posted 41 minutes ago

      The thing is I was trying to figure out if there's any way to accomplish this without having to save data to a file.
  • Topics

    • Filip4223
      2
      [1.12.2] How can I close GUI in Forge?

      By Filip4223
      Started 20 minutes ago

    • Differentiation
      12
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By Differentiation
      Started 8 hours ago

    • DragonITA
      4
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started 2 hours ago

    • LachM
      5
      Issue loading 1.14.4 Server (No Issue with Client)

      By LachM
      Started 1 hour ago

    • RunKeish
      3
      Forge 14.4 crashes on statup

      By RunKeish
      Started 1 hour ago

  • Who's Online (See full list)

    • saxon564
    • Legenes
    • Filip4223
    • diesieben07
    • Differentiation
    • Enterman
    • zacisrelatable
    • LachM
    • Choonster
    • Lea9ue
    • MightyAhmed
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (SOLVED) [1.10.2] Custom block rendering with weird black stuff?
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community