Jump to content

Recommended Posts

Posted

I'm stuck on trying to detect a block in front of an entity. I have some code written for it but its acting really wierd and I can't figure out the error. I have tried to find it for over a day now, its driving me nuts.

 

So here is my code:

	public boolean checkFrontForBlock(){
	int i = (int)Math.round(getRotationY() * 2 / Math.PI) % 4;
	boolean detected = false;
	switch(i){
	case 0:
		detected = !worldObj.isAirBlock((int)(posX), (int)(posY), (int)(posZ)-1);
		break;
	case 1:
		detected = !worldObj.isAirBlock((int)(posX)+1, (int)(posY), (int)(posZ));
		break;
	case 2:
		detected = !worldObj.isAirBlock((int)(posX), (int)(posY), (int)(posZ)+1);
		break;
	case 3:
		detected = !worldObj.isAirBlock((int)(posX)-1, (int)(posY), (int)(posZ));
		break;
	default:
		System.out.println("Got to default statement");
	}
	System.out.println("Block in front: " + detected + ", i is " + i);
	return detected;
}

 

i is properly calculated and works, just theisAirBlock doesn't. Wich is wierd because the following movement code works no problem:

	public void moveForward(int distance, float speed){
	targetX = (float) (Math.floor(posX)+0.5F);
	targetZ = (float) (Math.floor(posZ)+0.5F);
	hasTarget = true;
	int i = (int)Math.round(getRotationY() * 2 / Math.PI) % 4;
	switch(i){
	case 0:
		motionZ = -speed;
		targetZ -= distance;
		break;
	case 1:
		motionX = speed;
		targetX += distance;
		break;
	case 2:
		motionZ = speed;
		targetZ += distance;
		break;
	case 3:
		motionX = -speed;
		targetX -= distance;
		break;
	}
}

 

A screenshot of the problem to show you how it's not working:

4jt1j7.png

 

The first and the last are detecting a block in front, the two in the middle don't.

The first one is facing north, the next one is rotated 90°(east) and so on.

So i is 0, 1, 2, 3 from left to right.

 

I hope somebody can help me, because Ijust can't figure it out. >.<

Posted

Hi

 

It's not obvious to me what's wrong from looking at your code, but I would suggest that you add a couple of diagnostics to help figure out what's going wrong.  For example, instead of calling isAirBlock, call

 

blockID = worldObj.getBlockId(..)

 

System.out.println("Block in front: " + blockID + ", i is " + i);

 

then put a variety of different block types in the vicinity and see whether they are correctly detected.

 

Alternatively, change your code to use worldObj.setBlock(...) to change the block "in front" of the entity.  You'll see pretty quickly whether the code is looking in the right place.

 

-TGG

 

 

Posted

Thanks a lot for the suggestions, I could fianlly figure it out. Looks like the positioning was off and I had to subtract 1 from posX and posZ to make it work. Don't know how that would make sense but it works now so I'm happy  :D

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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