Jump to content
  • Home
  • Files
  • Docs
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
  • Adding items to blockcontainer Inventories created during worldgen
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Draco18s

Adding items to blockcontainer Inventories created during worldgen

By Draco18s, June 17, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted June 17, 2013

I know about ChestGenHooks, but I don't want to add items to chests.  I want to add them to dispensers (actually a custom block, but it uses the Dispenser's TE).

 

If ChestGenHooks can do this, I haven't figured out how.

 

Additionally, I can't seem to get the block to be oriented the way I want...it's weird:

 

world.setBlock(x, y, z, TrapsBase.TrapBlock.blockID, 1, 3); //metadata 1 means it should point up

 

Doing that in worldgen doesn't make it point up, it points south...which is metadata 3...and it doesn't matter what direction I tell it to face, it always faces south.

  • Quote

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.

Share this post


Link to post
Share on other sites

ObsequiousNewt    84

ObsequiousNewt

ObsequiousNewt    84

  • Dragon Slayer
  • ObsequiousNewt
  • Forge Modder
  • 84
  • 751 posts
Posted June 17, 2013

((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack);

Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever.

 

As for the orientation: getIcon() code?

  • Quote

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted June 17, 2013

((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack);

Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever.

 

world.getBlockTileEntity(x,y,z) returns null:

 

			world.setBlock((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, TrapsBase.arrowSlot.blockID, 1, 3);
		TileEntityDispenser dis = (TileEntityDispenser)world.getBlockTileEntity((int)c.xCoord, (int)c.yCoord, (int)c.zCoord);
		if(dis != null) {
			addTrapItem(dis);
		}
		else {
			System.out.print("Boo."); //this runs
		}

 

Yes, that's the right TE.

 

    public TileEntity createNewTileEntity(World par1World)
    {
        return new TileEntityDispenser();
    }

 

As for the orientation: getIcon() code?

 

getIcon won't help you.  I'm using a custom renderer and yes I checked that it wasn't just rendering wrong.  It was still shooting arrows in the incorrect direction.

  • Quote

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.

Share this post


Link to post
Share on other sites

ObsequiousNewt    84

ObsequiousNewt

ObsequiousNewt    84

  • Dragon Slayer
  • ObsequiousNewt
  • Forge Modder
  • 84
  • 751 posts
Posted June 18, 2013

((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack);

Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever.

 

world.getBlockTileEntity(x,y,z) returns null:

 

			world.setBlock((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, TrapsBase.arrowSlot.blockID, 1, 3);
		TileEntityDispenser dis = (TileEntityDispenser)world.getBlockTileEntity((int)c.xCoord, (int)c.yCoord, (int)c.zCoord);
		if(dis != null) {
			addTrapItem(dis);
		}
		else {
			System.out.print("Boo."); //this runs
		}

 

Yes, that's the right TE.

Perhaps you might try removing the "-1"? Or adding one in the next line?

    public TileEntity createNewTileEntity(World par1World)
    {
        return new TileEntityDispenser();
    }

 

As for the orientation: getIcon() code?

 

getIcon won't help you.  I'm using a custom renderer and yes I checked that it wasn't just rendering wrong.  It was still shooting arrows in the incorrect direction.

If you're sure, then I don't know.

  • Quote

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted June 18, 2013

Perhaps you might try removing the "-1"? Or adding one in the next line?

 

Frakking hell.  Thanks for spotting that. >..x

The -1 should actually be on another line entirely.

 

If you're sure, then I don't know.

 

public Icon getIcon(int par1, int par2)
    {
    		if(par2 <= 1)
    			return verticalFront;
	return blockIcon;
    }

 

All it does it determine which overlay to use.  The four horizontal facings have one icon (four "holes") the vertical one has another (two "holes").

 

The renderer is a tad bit more complex.

 

 

package draco18s.traps.client;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import draco18s.traps.TrapsBase;

public class RenderArrowTrap implements ISimpleBlockRenderingHandler {
private int renderType;

public RenderArrowTrap(int r) {
	renderType = r;
}

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
	renderer.renderBlockAsItem(TrapsBase.pseudoAT, 3, 1.0F);
}

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
	int l = world.getBlockMetadata(x, y, z);
	l = l & 7;
	int i = x;
	int j = y;
	int k = z;
	int xm = 0;
	int zm = 0;
	switch(l) {
		case 0: 
        case 2:
        case 3:
        	xm = 1;
        	break;
        case 1:
        case 4:
        case 5:
        	zm = 1;
        	break;
    }
	int meta = 0;
	int wid1 = world.getBlockId(x+xm, y, z+zm);
	int wid2 = world.getBlockId(x-xm, y, z-zm);
	int wid = 0;
	if(wid1 != block.blockID && Block.blocksList[wid1] != null && Block.blocksList[wid1].isOpaqueCube()) {
		wid = wid1;
		meta = world.getBlockMetadata(x+xm, y, z+zm);
	}
	else if(wid2 != block.blockID && Block.blocksList[wid2] != null && Block.blocksList[wid2].isOpaqueCube()) {
		wid = wid2;
		meta = world.getBlockMetadata(x-xm, y, z-zm);
	}
	else {
		if(l <= 1) {
			wid1 = world.getBlockId(x+zm, y, z+xm);
			wid2 = world.getBlockId(x-zm, y, z-xm);
			if(wid1 != block.blockID && Block.blocksList[wid1] != null && Block.blocksList[wid1].isOpaqueCube()) {
				wid = wid1;
				meta = world.getBlockMetadata(x+zm, y, z+xm);
			}
			else if(wid2 != block.blockID && Block.blocksList[wid2] != null && Block.blocksList[wid2].isOpaqueCube()) {
				wid = wid2;
				meta = world.getBlockMetadata(x-zm, y, z-xm);
			}
			else {
				wid = Block.stoneBrick.blockID;
			}
		}
		else {
			wid = Block.stoneBrick.blockID;
		}
	}
	Icon camo = Block.blocksList[wid].getIcon(l, meta);
	Icon furnace = Block.furnaceIdle.getIcon(2,3);
	Icon top = Block.furnaceIdle.getIcon(1,0);
	Icon self = block.getIcon(0, l);
	renderer.renderBlockUsingTexture(Block.stone, x, y, z, camo);
	switch(l) {
		case 0:
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
		case 1:
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
		case 2:
			renderer.renderFaceZNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceZPos(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace);
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
		case 3:
			renderer.renderFaceZPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceZNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace);
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
		case 4:
			renderer.renderFaceXNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceXPos(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace);
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
		case 5:
			renderer.renderFaceXPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self);
			renderer.renderFaceXNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace);
			renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top);
			break;
	}

	return true;
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}

@Override
public int getRenderId() {
	return renderType;
}
}

 

 

 

But feel free.

  • Quote

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.

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15998 posts
Posted June 18, 2013

You'll never believe what fixed it.

 

world.setBlockMetadataWithNotify((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, 1, 3);

 

Had to forcibly set the metadata after creating the block.

 

Because dispensers do this:

 

public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
        this.setDispenserDefaultDirection(par1World, par2, par3, par4);
    }

 

Even the vanilla dispenser has this "problem."

  • Quote

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.

Share this post


Link to post
Share on other sites

ObsequiousNewt    84

ObsequiousNewt

ObsequiousNewt    84

  • Dragon Slayer
  • ObsequiousNewt
  • Forge Modder
  • 84
  • 751 posts
Posted June 18, 2013

You'll never believe what fixed it.

 

world.setBlockMetadataWithNotify((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, 1, 3);

 

Had to forcibly set the metadata after creating the block.

 

Because dispensers do this:

 

public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
        this.setDispenserDefaultDirection(par1World, par2, par3, par4);
    }

 

Even the vanilla dispenser has this "problem."

Lolz. Well, I'm glad I solved at least half of your problem :)

  • Quote

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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

    • Varzac
      Forge jar file not opening

      By Varzac · Posted 4 minutes ago

      I ran Jarfix and then tried installing again with the same results. Nothing happening I even tried using winrar, but as you said nothing happened
    • BeardlessBrady
      [1.16.4] Null when OpenGUI

      By BeardlessBrady · Posted 9 minutes ago

      Ah.. Thats what I get for stopping half way through and not double checking, thanks!
    • poopoodice
      [1.16.4] Null when OpenGUI

      By poopoodice · Posted 24 minutes ago

      https://github.com/Beardlessbrady/Currency-Mod/blob/master-1.16/src/main/java/com/beardlessbrady/gocurrency/blocks/vending/VendingTile.java#L68 This should not be null.
    • -MCS_Gaming-
      Matchmaking System?

      By -MCS_Gaming- · Posted 26 minutes ago

      I'm making an fps style mod and want to implement a matchmaking system, but I have absolutely no idea where to begin. Would anyone be able to give me some pointers as to how I would go about doing this?
    • BeardlessBrady
      [1.16.4] Null when OpenGUI

      By BeardlessBrady · Posted 49 minutes ago

      While trying to open a gui in my block my console returns with this error: https://pastebin.com/XNYzf9pe Its basically saying that something is null on line 51. I am checking if namedContainerProvider is null and its doubtful the player is null so that means the NetworkHooks is returning null? How does one fix that issue.   Below is a link to the line the error is referring to: https://github.com/Beardlessbrady/Currency-Mod/blob/master-1.16/src/main/java/com/beardlessbrady/gocurrency/blocks/vending/VendingBlock.java#L51
  • Topics

    • Varzac
      3
      Forge jar file not opening

      By Varzac
      Started 12 hours ago

    • BeardlessBrady
      2
      [1.16.4] Null when OpenGUI

      By BeardlessBrady
      Started 49 minutes ago

    • -MCS_Gaming-
      0
      Matchmaking System?

      By -MCS_Gaming-
      Started 26 minutes ago

    • Nyko
      1
      [1.16.5] Beacon Overwrite (Screen Error)

      By Nyko
      Started 15 hours ago

    • ThisIsNotOriginal
      0
      Error at load_registries event phase

      By ThisIsNotOriginal
      Started 1 hour ago

  • Who's Online (See full list)

    • AiresNor
    • Draco18s
    • BeardlessBrady
    • Varzac
    • -MCS_Gaming-
    • JackRaidenPH
    • Top_DawgsPM
    • Talp1
    • onyxwarrior117
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Adding items to blockcontainer Inventories created during worldgen
  • Theme

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