Jump to content

[1.10.2] Custom Block Model and onFallenUpon() Behavior


FenixFyreX

Recommended Posts

Hello, I've been writing new blocks and items into the game via forge that do various things as a way for me to get accustomed to the forge environment, and I've noticed some weird behavior when it comes to custom block models and various Block class methods like onFallenUpon().

 

I have a custom Block class called BlockPitTrap, and this pit trap's model has 1/16 block height (1 texel high, Minecraft blocks are 16x16x16 texels, right?), and the model is on the bottom of the render space (so the player's BlockPos is 'within' the 16x16x16 texel space of the block). Whenever any living entity falls on this block (either by falling, jumping, etc) then the block is supposed to break and let the entity fall down. However, this is not the case it seems. The block does not break, however if I place the same type of block above and jump on that one, the one below it breaks.

 

Here is my code:

public class BlockPitTrap extends Block
{
private static final AxisAlignedBB COLLISION_BOX = new AxisAlignedBB(0, 0, 0, 1.0, 0.0625 * 1, 1.0);
private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0, 0, 0, 1.0, 0.0625 * 2, 1.0);

public BlockPitTrap() {
	super(Material.WOOD);
	setUnlocalizedName(Reference.Blocks.TRAPBLOCK.getUnlocalizedName());
	setRegistryName(Reference.Blocks.TRAPBLOCK.getRegistryName());
	setCreativeTab(Tutorial.CREATIVE_TAB);
}

@Override
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance) {
	if(!worldIn.isRemote)
		worldIn.destroyBlock(pos, false);

	super.onFallenUpon(worldIn, pos, entityIn, fallDistance);
}

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
	return BOUNDING_BOX;
}

@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn)
{
	super.addCollisionBoxToList(pos, entityBox, collidingBoxes, COLLISION_BOX);
}

@Override
public boolean isFullCube(IBlockState state) {
	return false;
}

@Override
public boolean isOpaqueCube(IBlockState state) {
	return false;
}
}

 

Can anyone shed some light as to what is happening, and why the onFallenUpon() method only gets called when there is a second instance of my block above the first?

 

Also, I've noticed that if I move the model to the top of the block space in my *.json file, and edit the collision / bounding boxes accordingly, it works perfectly. This leads me to wonder if there is special code for blocks anchored to different sides of the block space, or if Forge has a bug~ (possibly rounding the entity's BlockPos down instead of up?)

 

I can also upload screenshot(s) and json files if need be, no privacy needed for tutorial stuffs :P

Link to comment
Share on other sites

I doubt it is a bug because if you do round the players position, it would round down after being near the bottom. Just use pos.up () instead of pos. But use a print line to check if the code gets called with just one. Mainly because i dont know how onFallen works.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

That's why I mentioned it before; the code does not get called when there is just one present; however, it does get called if the model is at the top of the texel space. It's very odd. Also, that's why I think if there is a bug, it'd be a rounding issue, because if I jump on just one of my blocks, I think the block below it is actually getting the onFallenUpon() event? At least when I place a second pit trap above the first, the one below breaks when the one on top is jumped on. It is pretentious of me to label this as a bug on Forge's part, as I'm sure I am just missing something. Just thought I'd throw it out in case.

 

EDIT: Confirmed, I've created a new block solely to test whether or not the block below the pit trap is receiving the onFallenUpon, and I was right; it seems that if the collision box of the block is lower than the top half of the cube space, then the block below is the one that receives the event? Which doesn't make any sense at all...hmmm

 

EDIT 2: It seems that if a block's collision box top is not higher than the bottom quarter of any given block space, onFallenUpon() is called for the block below the one the entity is standing, which seems to be a bug. This issue is nonexistent when using onEntityCollidedWithBlock(), so I'll be using that for the time being. I'll go report/query this to Forge's github soon.

Link to comment
Share on other sites

That's why I mentioned it before; the code does not get called when there is just one present; however, it does get called if the model is at the top of the texel space. It's very odd. Also, that's why I think if there is a bug, it'd be a rounding issue, because if I jump on just one of my blocks, I think the block below it is actually getting the onFallenUpon() event? At least when I place a second pit trap above the first, the one below breaks when the one on top is jumped on. It is pretentious of me to label this as a bug on Forge's part, as I'm sure I am just missing something. Just thought I'd throw it out in case.

 

EDIT: Confirmed, I've created a new block solely to test whether or not the block below the pit trap is receiving the onFallenUpon, and I was right; it seems that if the collision box of the block is lower than the top half of the cube space, then the block below is the one that receives the event? Which doesn't make any sense at all...hmmm

 

EDIT 2: It seems that if a block's collision box top is not higher than the bottom quarter of any given block space, onFallenUpon() is called for the block below the one the entity is standing, which seems to be a bug. This issue is nonexistent when using onEntityCollidedWithBlock(), so I'll be using that for the time being. I'll go report/query this to Forge's github soon.

It is most likely not a forge bug, it is most likely a Minecraft bug. Not sure if they will/can help.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • Ok yeah I think this might be where the problem starts. For starters, I think you can get rid of your RecipeType impl and make it a static constant instead. I'm not 100% sure this will fix it but it's posssible. RuneInscribingRecipe public class RuneInscribingRecipe implements Recipe<SimpleContainer> { public static final RecipeType<RuneInscribingRecipe> RECIPE_TYPE = new RecipeType<>(){}; // .... @Override public RecipeType<?> getType() { return RECIPE_TYPE; } // .... } RuneInscriberMenu private Optional<RecipeHolder<RuneInscribingRecipe>> getCurrentRecipe() { SimpleContainer inventory = new SimpleContainer(2); inventory.setItem(BASE_INPUT_SLOT, this.inventory.getStackInSlot(BASE_INPUT_SLOT)); inventory.setItem(TEMPLATE_INPUT_SLOT, this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); List<RecipeHolder<RuneInscribingRecipe>> list = this.blockEntity.getLevel().getRecipeManager().getRecipesFor(RuneInscribingRecipe.RECIPE_TYPE, inventory, this.blockEntity.getLevel()); if (list.isEmpty()) { return Optional.empty(); } return Optional.of(list.get(0)); }   Also, this here is a little suspicious where you're getting the `this.inventory.getStackInSlot` calls. I'd try and make sure those are what you expect they are with either a Debug line in IDE or print statement SimpleContainer inventory = new SimpleContainer(2); inventory.setItem(BASE_INPUT_SLOT, this.inventory.getStackInSlot(BASE_INPUT_SLOT)); System.out.printf("CHECKING BASE INPUT OF RECIPE: %s\n", this.inventory.getStackInSlot(BASE_INPUT_SLOT)); inventory.setItem(TEMPLATE_INPUT_SLOT, this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); System.out.printf("CHECKING TEMPLATE INPUT OF RECIPE: %s\n", this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); ^ See what the result of those print statements are, make sure they're right
    • Upon testing again after adding them, the game still doesn't crash however the resource packs are still unfortunately broken.
    • Hi! Can someone please point me to the correct FAQ or place? I'm not able do DuckDuckGo myself out of this one. As you can hopefully see, chunks are not rendered. I run a forge server, fresh install on a linux VM. Curseforge on the Win11 client with Embeddium, Oculus and Unbound shader. No mods. Forge 47.2.23 on server & client.  No errors, no crashes, no apparent CPU or RAM issues with the VM. This screenshot was captured while creative, but the same happens when flying in survival. Waiting (floating) for a few minutes sooner or (often) later, lets the missing chunks appear. Usually takes 5-10 minutes.  When on a local game, the chunks appear slowly, but they do appear without pause.   This must be something simple, obvious, but I can't find the correct "search words" to find my way out. "Chunks not loading / rendering" didn't help. Browsing several forums neither. 
    • This is the Forge forums. We only support Forge here. Read the FAQ
    • 1.The game doesn't crash, everything seems normal, but when i insert the designated items into the block entity, the result item does not show up. 2.Yes, I'm using a custom menu, here's the source code:  
  • Topics

×
×
  • Create New...

Important Information

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