Jump to content

Adding items to blockcontainer Inventories created during worldgen


Draco18s

Recommended Posts

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.

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.

Link to comment
Share on other sites

((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.

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.

Link to comment
Share on other sites

((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.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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."

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.

Link to comment
Share on other sites

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 :)

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
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.
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, Hi and I am making a forge 1.12.2 mod and also trying to get a custom model helmet item (I made a joker mask) and exported it to .json format and put it in the ~/namespace/models/item folder. Though, I'm struggling to get the item to render what I want it to be rendered like as I've positioned it in the 'head' window view in blockbench. How did you render out your model? I checked your code and it looks like no references to the actual model are being made. I'm new to this forge modding stuff (was a fabric modder) and I desperately need some help. Is there a way to standardly render out armor models made using blockbench? any methods that one can use? My model in JSON: ```json { "credit": "Made with Blockbench", "texture_size": [160, 160], "textures": { "0": "ydyrn:items/joker_mask_texture", "particle": "ydyrn:items/joker_mask_texture" }, "elements": [ { "from": [0, 0, 0], "to": [16, 16, 1], "faces": { "north": {"uv": [0, 1.7, 16, 14.2], "texture": "#0"}, "east": {"uv": [0, 4, 0.9, 5.6], "texture": "#0"}, "south": {"uv": [0, 5.8, 1.6, 7.4], "texture": "#0"}, "west": {"uv": [0, 1.9, 1.3, 3.5], "texture": "#0"}, "up": {"uv": [0, 3.4, 1.6, 4.2], "texture": "#0"}, "down": {"uv": [0, 9, 1.6, 9.7], "texture": "#0"} } }, { "from": [15.8, 11, 0.5], "to": [16.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } }, { "from": [0.2, 11, 14.6], "to": [15.8, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 9.46, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 9.46, 7.94], "texture": "#0"} } }, { "from": [-0.2, 11, 0.5], "to": [0.2, 13, 15], "faces": { "north": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "east": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "south": {"uv": [7.9, 7.9, 7.94, 8.1], "texture": "#0"}, "west": {"uv": [7.9, 7.9, 9.35, 8.1], "texture": "#0"}, "up": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"}, "down": {"uv": [7.9, 7.9, 7.94, 9.35], "texture": "#0"} } } ], "display": { "thirdperson_righthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "thirdperson_lefthand": { "translation": [-0.25, -2.75, 0], "scale": [0.3, 0.3, 0.3] }, "firstperson_righthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "firstperson_lefthand": { "rotation": [-9, 115, 15], "translation": [0, 1.25, -1.75], "scale": [0.5, 0.5, 0.5] }, "ground": { "rotation": [40, 0, 0], "translation": [0, -2.5, 0], "scale": [0.5, 0.5, 0.5] }, "gui": { "rotation": [0, 180, 0] }, "head": { "translation": [0, 0, 0.25], "scale": [0.82773, 0.73594, 0.9] }, "fixed": { "translation": [0, 0, 8.75] } }, "groups": [ 0, { "name": "straps", "origin": [0, 0, 0], "color": 0, "children": [1, 2, 3] } ] } ```
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • In your config folder, delete the sophisticatedcore-common.toml file and test it again
    • Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I am getting an error message that my mods and my server are not on the same minecraft version when they clearly are. My server and my mods are on 1.20.1 and the error says that the server is 1.20 even though it's on forge 47.2.30.  
  • Topics

×
×
  • Create New...

Important Information

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