Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I just want to get if the player is placed that block or its generated by a structure;

Right now its not working.

 

My block code:

 

 

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)

{

Random fuel = new Random();

int randomfuel = fuel.nextInt(Lantern.barrelFuelCapacity * 60);

 

int rotation = MathHelper.floor_double((double)((par5EntityLivingBase.rotationYaw * 4F) / 360F) + 0.5D) & 3;

 

if (rotation == 0)

{

par1World.setBlockMetadataWithNotify(par2, par3, par4, rotation - 2, 2);

}

 

if (rotation == 1)

{

par1World.setBlockMetadataWithNotify(par2, par3, par4, rotation - 2, 2);

}

 

if (rotation == 2)

{

par1World.setBlockMetadataWithNotify(par2, par3, par4, rotation + 2, 2);

}

 

if (rotation == 3)

{

par1World.setBlockMetadataWithNotify(par2, par3, par4, rotation + 2, 2);

}

 

if(par5EntityLivingBase instanceof EntityPlayer){

}else{

((TileEntityBarrel)par1World.getBlockTileEntity(par2, par3, par4)).barrelOilLevel = randomfuel;

}

}

 

 

Hi

 

What are the symptoms?  Perhaps it crashes if not placed by a player?

 

Based on the JavaDoc, par5EntityLivingBase should be null if placed by a structure.

 

-TGG

  • Author

Okey i have a new village house thats generates perfectly.

I want to get a block tile entity in that structure, but i can't because i don't know how to search for a block in that structure and get the block XYZ pos.

 

My strucutre code():

 

 

package fluffy.lantern.events;

 

import java.util.List;

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.world.World;

import net.minecraft.world.gen.structure.ComponentVillage;

import net.minecraft.world.gen.structure.ComponentVillageStartPiece;

import net.minecraft.world.gen.structure.StructureBoundingBox;

import net.minecraft.world.gen.structure.StructureComponent;

import fluffy.lantern.Lantern;

import fluffy.lantern.render.TileEntityBarrel;

 

public class ComponentBarrelGen extends ComponentVillage

{

public ComponentBarrelGen() {}

 

public ComponentBarrelGen(ComponentVillageStartPiece par1ComponentVillageStartPiece, int par2, Random par3Random, StructureBoundingBox par4StructureBoundingBox, int par5)

{

super(par1ComponentVillageStartPiece, par2);

this.coordBaseMode = par5;

this.boundingBox = par4StructureBoundingBox;

}

 

public static ComponentBarrelGen func_74898_a(ComponentVillageStartPiece par0ComponentVillageStartPiece, List par1List, Random par2Random, int par3, int par4, int par5, int par6, int par7)

{

StructureBoundingBox structureboundingbox = StructureBoundingBox.getComponentToAddBoundingBox(par3, par4, par5, 0, 0, 0, 9, 9, 6, par6);

return canVillageGoDeeper(structureboundingbox) && StructureComponent.findIntersecting(par1List, structureboundingbox) == null ? new ComponentBarrelGen(par0ComponentVillageStartPiece, par7, par2Random, structureboundingbox, par6) : null;

}

 

/**

* second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at

* the end, it adds Fences...

*/

public boolean addComponentParts(World par1World, Random par2Random, StructureBoundingBox par3StructureBoundingBox)

{

Random fuel = new Random();

int randomfuel = fuel.nextInt(Lantern.barrelFuelCapacity * 60);

 

if (this.field_143015_k < 0)

{

this.field_143015_k = this.getAverageGroundLevel(par1World, par3StructureBoundingBox);

 

if (this.field_143015_k < 0)

{

return true;

}

 

this.boundingBox.offset(0, this.field_143015_k - this.boundingBox.maxY + 9 - 1, 0);

}

 

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 1, 1, 7, 5, 4, 0, 0, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 0, 0, 8, 0, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 5, 0, 8, 5, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 6, 1, 8, 6, 4, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 7, 2, 8, 7, 3, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

int i = this.getMetadataWithOffset(Block.stairsWoodOak.blockID, 3);

int j = this.getMetadataWithOffset(Block.stairsWoodOak.blockID, 2);

int k;

int l;

 

for (k = -1; k <= 2; ++k)

{

for (l = 0; l <= 8; ++l)

{

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, i, l, 6 + k, k, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, j, l, 6 + k, 5 - k, par3StructureBoundingBox);

}

}

 

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 1, 0, 0, 1, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 1, 5, 8, 1, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 8, 1, 0, 8, 1, 4, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 2, 1, 0, 7, 1, 0, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 2, 0, 0, 4, 0, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 2, 5, 0, 4, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 8, 2, 5, 8, 4, 5, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 8, 2, 0, 8, 4, 0, Block.cobblestone.blockID, Block.cobblestone.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 0, 2, 1, 0, 4, 4, Block.planks.blockID, Block.planks.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 2, 5, 7, 4, 5, Block.planks.blockID, Block.planks.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 8, 2, 1, 8, 4, 4, Block.planks.blockID, Block.planks.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 2, 0, 7, 4, 0, Block.planks.blockID, Block.planks.blockID, false);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 4, 2, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 5, 2, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 6, 2, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 4, 3, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 5, 3, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 6, 3, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 0, 2, 2, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 0, 2, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 0, 3, 2, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 0, 3, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 8, 2, 2, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 8, 2, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 8, 3, 2, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 8, 3, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 2, 2, 5, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 3, 2, 5, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 5, 2, 5, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.thinGlass.blockID, 0, 6, 2, 5, par3StructureBoundingBox);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 4, 1, 7, 4, 1, Block.planks.blockID, Block.planks.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 4, 4, 7, 4, 4, Block.planks.blockID, Block.planks.blockID, false);

this.fillWithBlocks(par1World, par3StructureBoundingBox, 1, 3, 4, 7, 3, 4, Block.bookShelf.blockID, Block.bookShelf.blockID, false);

this.placeBlockAtCurrentPosition(par1World, Block.planks.blockID, 0, 7, 1, 4, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, this.getMetadataWithOffset(Block.stairsWoodOak.blockID, 0), 7, 1, 3, par3StructureBoundingBox);

k = this.getMetadataWithOffset(Block.stairsWoodOak.blockID, 3);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, k, 6, 1, 4, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, k, 5, 1, 4, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, k, 4, 1, 4, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.stairsWoodOak.blockID, k, 3, 1, 4, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, 6, 1, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.pressurePlatePlanks.blockID, 0, 6, 2, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.fence.blockID, 0, 4, 1, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.pressurePlatePlanks.blockID, 0, 4, 2, 3, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Block.workbench.blockID, 0, 7, 1, 1, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, Lantern.barrel.blockID, this.getMetadataWithOffset(Lantern.barrel.blockID, 1), 7, 2, 1, par3StructureBoundingBox);

((TileEntityBarrel)par1World.getBlockTileEntity(7, 2, 1)).barrelOilLevel = randomfuel;  //Problem

this.placeBlockAtCurrentPosition(par1World, 0, 0, 1, 1, 0, par3StructureBoundingBox);

this.placeBlockAtCurrentPosition(par1World, 0, 0, 1, 2, 0, par3StructureBoundingBox);

this.placeDoorAtCurrentPosition(par1World, par3StructureBoundingBox, par2Random, 1, 1, 0, this.getMetadataWithOffset(Block.doorWood.blockID, 1));

 

if (this.getBlockIdAtCurrentPosition(par1World, 1, 0, -1, par3StructureBoundingBox) == 0 && this.getBlockIdAtCurrentPosition(par1World, 1, -1, -1, par3StructureBoundingBox) != 0)

{

this.placeBlockAtCurrentPosition(par1World, Block.stairsCobblestone.blockID, this.getMetadataWithOffset(Block.stairsCobblestone.blockID, 3), 1, 0, -1, par3StructureBoundingBox);

}

 

for (l = 0; l < 6; ++l)

{

for (int i1 = 0; i1 < 9; ++i1)

{

this.clearCurrentPositionBlocksUpwards(par1World, i1, 9, l, par3StructureBoundingBox);

this.fillCurrentPositionBlocksDownwards(par1World, Block.cobblestone.blockID, 0, i1, -1, l, par3StructureBoundingBox);

}

}

 

this.spawnVillagers(par1World, par3StructureBoundingBox, 2, 1, 2, 1);

return true;

}

 

/**

* Returns the villager type to spawn in this component, based on the number of villagers already spawned.

*/

protected int getVillagerType(int par1)

{

return 1;

}

}

 

 

 

 

Crash because can't get the block tile entity.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.