Java tutorial
/* * Hakkit - A Minecraft plugin API and server extension. * * Copyright (C) Hakkit Development Team * * This file is part of Hakkit. * * Hakkit is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Hakkit is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Hakkit. If not, see <http://www.gnu.org/licenses/>. */ package org.hakkit.hakkitmc.entity; import net.minecraft.entity.Entity; import net.minecraft.util.Vec3; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.hakkit.Hakkit; import org.hakkit.Position; import org.hakkit.bounding.BoundingBox; import org.hakkit.entity.TeleportCause; import org.hakkit.event.type.entity.EntityTeleportEvent; import org.hakkit.hakkitmc.world.HakkitWorld; import org.hakkit.world.World; public abstract class HakkitEntity implements org.hakkit.entity.Entity { protected net.minecraft.entity.Entity handle; public HakkitEntity(net.minecraft.entity.Entity handle) { this.handle = handle; } @Override public int getEntityID() { return handle.getEntityId(); } @Override public String getEntityName() { return handle.getCommandSenderName(); } @Override public World getWorld() { return new HakkitWorld(handle.worldObj); } @Override public void setPosition(Position position) { handle.setLocationAndAngles(position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), position.getYaw(), position.getPitch()); } @Override public Position getPosition() { return new Position(new Vector3D(handle.posX, handle.posY, handle.posZ), handle.rotationYaw, handle.rotationPitch); } @Override public BoundingBox getBoundingBox() { return new BoundingBox( new Vector3D(handle.boundingBox.minX, handle.boundingBox.minY, handle.boundingBox.minZ), new Vector3D(handle.boundingBox.maxX, handle.boundingBox.maxY, handle.boundingBox.maxZ)); } @Override public Vector3D getVelocity() { return new Vector3D(handle.motionX, handle.motionY, handle.motionZ); } @Override public Vector3D getLookDirection() { Vec3 lookVector = handle.getLookVec(); return new Vector3D(lookVector.xCoord, lookVector.yCoord, lookVector.zCoord); } @Override public double getHeight() { return handle.height; } @Override public void setVelocity(Vector3D velocity) { //We may want to fire an event here. handle.motionX = velocity.getX(); handle.motionY = velocity.getY(); handle.motionZ = velocity.getZ(); } }