first set of Urbanism experiments
This commit is contained in:
parent
db943bff47
commit
b4a668e91f
4 changed files with 204 additions and 20 deletions
121
common/buildcraft/builders/urbanism/Urbanist.java
Executable file
121
common/buildcraft/builders/urbanism/Urbanist.java
Executable file
|
@ -0,0 +1,121 @@
|
|||
package buildcraft.builders.urbanism;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.EntityEnergyLaser;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class Urbanist extends EntityLivingBase {
|
||||
|
||||
|
||||
private EntityEnergyLaser laser = null;
|
||||
|
||||
public Urbanist(World par1World) {
|
||||
super(par1World);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHeldItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCurrentItemOrArmor(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItemOrArmor(int i, ItemStack itemstack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getLastActiveItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void createLaser() {
|
||||
if (laser == null) {
|
||||
laser = new EntityEnergyLaser(worldObj, new Position(posX, posY, posZ), new Position(posX, posY, posZ));
|
||||
worldObj.spawnEntityInWorld(laser);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLaser () {
|
||||
createLaser();
|
||||
}
|
||||
|
||||
public MovingObjectPosition rayTraceMouse()
|
||||
{
|
||||
createLaser();
|
||||
//double posAdjust = -1F;
|
||||
double posAdjust = 0F;
|
||||
|
||||
double distance = 1000;
|
||||
|
||||
float width = Minecraft.getMinecraft().displayWidth;
|
||||
float height = Minecraft.getMinecraft().displayHeight;
|
||||
|
||||
float diffX = ((float) Mouse.getX() / width) * 2F - 1F;
|
||||
float diffY = ((float) Mouse.getY() / height) * 2F - 1F;
|
||||
|
||||
diffX *= 1.70F;
|
||||
diffY *= 0.89F; // < 0.90
|
||||
//diffY = (diffY + 0.2F);
|
||||
|
||||
Vec3 pos = this.getPosition(1.0F);
|
||||
Vec3 look = this.getLook(1.0F).normalize();
|
||||
|
||||
/*float f1;
|
||||
float f2;
|
||||
float f3;
|
||||
float f4;
|
||||
|
||||
f1 = MathHelper.cos(-this.rotationYaw - (float)Math.PI);
|
||||
f2 = MathHelper.sin(-this.rotationYaw - (float)Math.PI);
|
||||
f3 = -MathHelper.cos(-this.rotationPitch);
|
||||
f4 = MathHelper.sin(-this.rotationPitch);
|
||||
Vec3 look = this.worldObj.getWorldVec3Pool().getVecFromPool((double)(f2 * f3), (double)f4, (double)(f1 * f3));*/
|
||||
|
||||
|
||||
Vec3 worldUp = worldObj.getWorldVec3Pool().getVecFromPool(0, 1, 0);
|
||||
Vec3 side = worldUp.crossProduct(look).normalize();
|
||||
Vec3 up = side.crossProduct(look).normalize();
|
||||
|
||||
pos = pos.addVector(up.xCoord * posAdjust, up.yCoord * posAdjust, up.zCoord * posAdjust);
|
||||
|
||||
look = look.addVector(side.xCoord * -diffX, side.yCoord * -diffX, side.zCoord * -diffX);
|
||||
look = look.addVector(up.xCoord * -diffY, up.yCoord * -diffY, up.zCoord * -diffY);
|
||||
|
||||
Vec3 vec32 = pos.addVector(look.xCoord * distance, look.yCoord * distance, look.zCoord * distance);
|
||||
|
||||
//laser.setPositions (new Position(pos.xCoord, pos.yCoord, pos.zCoord), new Position(aimed.xCoord, aimed.yCoord, aimed.zCoord));
|
||||
|
||||
//Debug.log (aimed.xCoord + ", " + aimed.yCoord + ", " + aimed.zCoord);
|
||||
|
||||
//laser.setPositions (new Position(pos.xCoord, pos.yCoord, pos.zCoord), new Position(pos.xCoord + 1, pos.yCoord, pos.zCoord + 1));
|
||||
|
||||
MovingObjectPosition result = this.worldObj.clip(pos, vec32);
|
||||
|
||||
pos = this.getPosition(1.0F);
|
||||
pos = pos.addVector(up.xCoord * posAdjust, up.yCoord * posAdjust, up.zCoord * posAdjust);
|
||||
Vec3 aimed = pos.addVector (look.xCoord * 200, look.yCoord * 200, look.zCoord * 200);
|
||||
pos = this.getPosition(1.0F);
|
||||
pos = pos.addVector(up.xCoord * posAdjust, up.yCoord * posAdjust, up.zCoord * posAdjust);
|
||||
laser.setPositions (new Position(pos.xCoord, pos.yCoord, pos.zCoord), new Position(aimed.xCoord, aimed.yCoord, aimed.zCoord));
|
||||
//laser.setPositions (new Position(pos.xCoord, pos.yCoord, pos.zCoord), new Position(result.blockX + 0.5F, result.blockY + 0.5F, result.blockZ + 0.5F));
|
||||
|
||||
if (!laser.isVisible()) {
|
||||
laser.show();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -73,9 +73,9 @@ public abstract class EntityLaser extends Entity {
|
|||
needsUpdate = false;
|
||||
}
|
||||
|
||||
if (CoreProxy.proxy.isRenderWorld(worldObj)) {
|
||||
updateDataClient();
|
||||
}
|
||||
//if (CoreProxy.proxy.isRenderWorld(worldObj)) {
|
||||
// updateDataClient();
|
||||
//}
|
||||
|
||||
boundingBox.minX = Math.min(head.x, tail.x);
|
||||
boundingBox.minY = Math.min(head.y, tail.y);
|
||||
|
|
|
@ -1,39 +1,100 @@
|
|||
package buildcraft.core;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import buildcraft.builders.urbanism.Urbanist;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCMessageInfo;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.MouseHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
|
||||
public class TilePingPong extends TileBuildCraft {
|
||||
|
||||
@RPC
|
||||
public void ping (int time, RPCMessageInfo info) {
|
||||
System.out.println ("ping " + time);
|
||||
static class UrbanistMouseHelper extends MouseHelper {
|
||||
|
||||
RPCHandler.rpcPlayer(this, "pong", info.sender, time);
|
||||
@Override
|
||||
public void grabMouseCursor() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@RPC
|
||||
public void pong (int time) {
|
||||
System.out.println ("pong " + time);
|
||||
}
|
||||
|
||||
SafeTimeTracker tracker;
|
||||
Urbanist urbanist;
|
||||
EntityLivingBase player;
|
||||
|
||||
|
||||
double posX, posY, posZ;
|
||||
float yaw;
|
||||
|
||||
boolean buttonDown = true;
|
||||
|
||||
@RPC (RPCSide.SERVER)
|
||||
public void setBlock (int x, int y, int z) {
|
||||
worldObj.setBlock(x, y + 1, z, Block.brick.blockID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
if (tracker == null) {
|
||||
tracker = new SafeTimeTracker();
|
||||
tracker.markTimeIfDelay(worldObj, 50);
|
||||
if (urbanist == null) {
|
||||
urbanist = new Urbanist(worldObj);
|
||||
player = Minecraft.getMinecraft().renderViewEntity;
|
||||
|
||||
urbanist.copyLocationAndAnglesFrom(player);
|
||||
|
||||
|
||||
urbanist.rotationYaw = 0;
|
||||
urbanist.rotationPitch = 0;
|
||||
|
||||
Minecraft.getMinecraft().renderViewEntity = urbanist;
|
||||
Minecraft.getMinecraft().gameSettings.thirdPersonView = 8;
|
||||
Minecraft.getMinecraft().mouseHelper = new UrbanistMouseHelper();
|
||||
Minecraft.getMinecraft().setIngameNotInFocus();
|
||||
|
||||
posX = urbanist.posX;
|
||||
posY = urbanist.posY + 10;
|
||||
posZ = urbanist.posZ;
|
||||
|
||||
yaw = 0;
|
||||
}
|
||||
|
||||
if (tracker.markTimeIfDelay(worldObj, 50)) {
|
||||
RPCHandler.rpcServer(this, "ping", (int) worldObj.getWorldTime());
|
||||
urbanist.setPositionAndRotation(posX, posY, posZ, yaw, 50);
|
||||
urbanist.setPositionAndUpdate(posX, posY, posZ);
|
||||
|
||||
|
||||
float width = Minecraft.getMinecraft().displayWidth;
|
||||
float height = Minecraft.getMinecraft().displayHeight;
|
||||
|
||||
/*System.out.println (Mouse.getX() + ", " + Mouse.getX());
|
||||
|
||||
yaw += Minecraft.getMinecraft().mouseHelper.deltaX;
|
||||
|
||||
while (yaw > 360) {
|
||||
yaw -= 360;
|
||||
}
|
||||
|
||||
while (yaw < -360) {
|
||||
yaw += 360;
|
||||
}*/
|
||||
|
||||
MovingObjectPosition pos = urbanist.rayTraceMouse();
|
||||
|
||||
if (Mouse.getEventButton() == 0) {
|
||||
if (buttonDown) {
|
||||
if (pos != null) {
|
||||
RPCHandler.rpcServer(this, "setBlock", pos.blockX, pos.blockY, pos.blockZ);
|
||||
}
|
||||
|
||||
buttonDown = false;
|
||||
}
|
||||
} else {
|
||||
buttonDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ public class RenderLaser extends Render {
|
|||
GL11.glRotatef((float) laser.angleZ, 0, 1, 0);
|
||||
GL11.glRotatef((float) laser.angleY, 0, 0, 1);
|
||||
|
||||
//System.out.println ("RENDER LASER: " + laser.angleZ + ", " + laser.angleY);
|
||||
|
||||
renderManager.renderEngine.bindTexture(laser.getTexture());
|
||||
|
||||
float factor = (float) (1.0 / 16.0);
|
||||
|
|
Loading…
Reference in a new issue