Jump to content

Recommended Posts

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

Posted

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

Posted

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

×   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



×
×
  • Create New...

Important Information

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