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'm making a block that acts like a fan, and uses meta data to orientate itself.

package fans.tileentity;

import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import fans.block.BlockFan;

public class TileEntityFan extends TileEntity {
@Override
public void updateEntity() {
	if(BlockFan.isPowered(worldObj, xCoord, yCoord, zCoord)) {
		int current = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
		switch(current) {
		case (0): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + );
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		case (1): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 8, yCoord + 1, zCoord - 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		case (2): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord - );
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		case (3): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord - 8, yCoord + 1, zCoord - 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		case (4): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 8, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		case (5): {
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord - 8, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
		}
		}
	}
}
}

 

For some reason, when its oriented in a horizontal position and I'm standing on top of it, it slows me down. Also, when I jump, I get launched as if the fan oriented upwards.

Kain

  • Author

Here's some updated code:

package fans.tileentity;

import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import fans.block.BlockFan;

public class TileEntityFan extends TileEntity {
@Override
public void updateEntity() {
	if(BlockFan.isPowered(worldObj, xCoord, yCoord, zCoord)) {
		int current = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
		switch(current) {
		case (0): { //Front
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 9));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (1): { //Right
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 9, yCoord + 1, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (2): { //Back
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord - );
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (3): { //Left
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord - 8, yCoord + 1, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (4): { //Top
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 9, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (5): { //Bottom
			System.err.println("CURRENT: " + current);
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord - 8, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		}
	}
}
}

 

I got the bug fixed, I forgot to add breaks in the cases. :P

 

My new problem is that the front, right, and top code work, but not he back, left, and bottom code.

Kain

  • Author

Fixed it, I don't know exactly what was wrong, but my friend suggested moving the x/y/z coord changes in the nonworking sides to the minimum coords.

package fans.tileentity;

import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import fans.block.BlockFan;

public class TileEntityFan extends TileEntity {
@Override
public void updateEntity() {
	if(BlockFan.isPowered(worldObj, xCoord, yCoord, zCoord)) {
		int current = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
		switch(current) {
		case (0): { //Front
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 9));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (1): { //Right
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 9, yCoord + 1, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (2): { //Back
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord - 8, xCoord + 1, yCoord + 1, zCoord));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionZ -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (3): { //Left
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord - 8, yCoord, zCoord, xCoord, yCoord + 1, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionX -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (4): { //Top
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 9, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY += ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		case (5): { //Bottom
			List entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord - 8, zCoord, xCoord + 1, yCoord, zCoord + 1));
			if(!entities.isEmpty()) {
				for(Object obj : entities) {
					if(obj instanceof Entity && !((Entity) obj).isSneaking()) {
						((Entity) obj).motionY -= ((BlockFan) this.getBlockType()).getPower();
					}
				}
			}
			break;
		}
		}
	}
}
}

Kain

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.