Java help, converting lua script to java = Illegal start of expression
2 replies, posted
So, I'm fairly new to java but am fairly fluent in lua, so I started by writing my script in lua for testing purposes, and then moving it over to java in it's final form. The lua script worked great, but problems have arisen when trying to convert that into java. Specifically, I get an "Illegal start of expression" error on about line 14 of the code (Where it says "private vector Pop( i, j, k )"):
[code]
package net.minecraft.src;
import java.util.Random;
import java.util.Vector;
public class WorldGenOre extends WorldGenerator
{
public WorldGenOre(int i, int j)
{
minableBlockId = i;
rarity = j;
}
public boolean generate(World world, Random random, int i, int j, int k)
{
private vector Pop( i, j, k );
{
int is = (random.nextInt( 4 )-random.nextInt( 4 ))/4;
int js = (random.nextInt( 4 )-random.nextInt( 4 ))/4;
int ks = random.nextFloat( 0.5F )-random.nextFloat( 0.5F );
for (int z = 0; z < 400; z++)
{
int ii = i+(i*is)*4;
int ji = j+(i*js)*4;
int ki = k+(i*ks)*4;
int i1 = ii + (random.nextInt( 5 )-random.nextInt( 5 ));
int j1 = ji + (random.nextInt( 5 )-random.nextInt( 5 ));
int k1 = ki + (random.nextInt( 4 )-random.nextInt( 4 ));
if(world.getBlockId(i1, j1, k1) == Block.stone.blockID)
{
world.setBlock(i1,j1,k1, minableBlockId);
}
}
Vector vector = new Vector();
vector.add(is);
vector.add(js);
vector.add(ks);
return vector;
}
if (random.nextInt( 100000/rarity ) == 0 )
{
Vector v = new Vector();
v = Pop( i,j,k );
Vector endv = new Vector();
endv = Vector(i,j,k);
Vector v2 = new Vector();
v2 = Pop( endv.elementAt(1), endv.elementAt(2), endv.elementAt(3) );
Vector endv2 = new Vector();
endv2 = v2*1600+endv;
Vector v3 = new Vector();
v3 = Pop( endv2.elementAt(1), endv2.elementAt(2), endv2.elementAt(3) );
Vector endv3 = new Vector();
endv3 = v3*1600+endv2;
Vector v4 = new Vector();
v4 = Pop( endv3.elementAt(1), endv3.elementAt(2), endv3.elementAt(3) );
Vector endv4 = new Vector();
endv4 = v4*1600+endv3;
Pop( endv4.elementAt(1), endv4.elementAt(2), endv4.elementAt(3) );
for (int z = 0; z < 400; z++)
{
int i1 = i+random.nextInt(256)-random.nextInt(256);
int j1 = j+random.nextInt(256)-random.nextInt(256);
int k1 = k+random.nextInt(256)-random.nextInt(256);
for (int z = 0; z < 8; z++)
{
int i2 = i1+random.nextInt(3)-random.nextInt(3);
int j2 = j1+random.nextInt(3)-random.nextInt(3);
int k2 = k1+random.nextInt(3)-random.nextInt(3);
if(world.getBlockId(i1, j1, k1) == Block.stone.blockID)
{
world.setBlock(i1,j1,k1, minableBlockId);
}
}
}
}
return true;
}
private int minableBlockId;
private int rarity;
}
[/code]
You may have been able to guess that this is for minecraft. Anyway, here's the original, functional lua script:
[lua]
function Block( vec,r,b,g )
local ent = ents.Create( "prop_physics" )
ent:SetModel( "models/hunter/blocks/cube025x025x025.mdl" )
ent:SetPos( vec )
ent:Spawn()
local phys = ent:GetPhysicsObject()
ent:SetCollisionGroup( COLLISION_GROUP_WORLD )
ent:SetMoveType( MOVETYPE_NONE )
phys:Sleep()
ent:SetColor( r, b, g, 255 )
end
function Pop( x,y,z)
local t = 400
local xs = math.random( -4,4 )/4
local ys = math.random( -4,4 )/4
local zs = math.Rand( -0.5,0.5 )
for i=1, t do
local xi = x+(i*xs)*4
local yi = y+(i*ys)*4
local zi = z+(i*zs)*4
local x1 = xi + math.random( 11.5*-5, 11.5*5 )
local y1 = yi + math.random( 11.5*-5, 11.5*5 )
local z1 = zi + math.random( 11.5*-4, 11.5*4 )
if math.random(0,10) == 3 then
Block( Vector( x1,y1,z1), 255, 0, 0)
end
end
return Vector( xs, ys, zs )
end
function Populate( x, y, z )
local v = Pop( x,y,z )// getting slopes of pop1
local endv = Vector(x,y,z)// getting end vector of pop1
local v2 = Pop( endv.x, endv.y, endv.z )// getting slopes of pop2
local endv2 = v2*1600+endv// getting end vector of pop2
local v3 = Pop( endv2.x, endv2.y, endv2.z )
local endv3 = v3*1600+endv2
local v4 = Pop( endv3.x, endv3.y, endv3.z )
local endv4 = v4*1600+endv3
Pop( endv4.x, endv4.y, endv4.z )
for i=1, 200 do
local x1 = x+math.random(-256*11.5, 256*11.5)
local y1 = y+math.random(-256*11.5, 256*11.5)
local z1 = z+math.random(-256*11.5, 256*11.5)
for i=1, 4 do
local x2 = x1+math.random(-3*11.5, 3*11.5)
local y2 = y1+math.random(-3*11.5, 3*11.5)
local z2 = z1+math.random(-3*11.5, 3*11.5)
Block( Vector( x2, y2, z2 ), 0, 255, 0 )
end
end
end
[/lua]
Notice that the Block function is absent in the java code; That's because the minecraft java library already has an equivalent function. Anyway, could someone here tell me if I've done something horribly wrong in the translation process? How I can fix this? I've already tried posting this in a couple of other forums and have received little help.
You put the method Pop in your method generate.
Fix:
[code]
package net.minecraft.src;
import java.util.Random;
import java.util.Vector;
public class WorldGenOre extends WorldGenerator
{
public WorldGenOre(int i, int j)
{
minableBlockId = i;
rarity = j;
}
private vector Pop( i, j, k )
{
int is = (random.nextInt( 4 )-random.nextInt( 4 ))/4;
int js = (random.nextInt( 4 )-random.nextInt( 4 ))/4;
int ks = random.nextFloat( 0.5F )-random.nextFloat( 0.5F );
for (int z = 0; z < 400; z++)
{
int ii = i+(i*is)*4;
int ji = j+(i*js)*4;
int ki = k+(i*ks)*4;
int i1 = ii + (random.nextInt( 5 )-random.nextInt( 5 ));
int j1 = ji + (random.nextInt( 5 )-random.nextInt( 5 ));
int k1 = ki + (random.nextInt( 4 )-random.nextInt( 4 ));
if(world.getBlockId(i1, j1, k1) == Block.stone.blockID)
{
world.setBlock(i1,j1,k1, minableBlockId);
}
}
Vector vector = new Vector();
vector.add(is);
vector.add(js);
vector.add(ks);
return vector;
}
public boolean generate(World world, Random random, int i, int j, int k)
{
if (random.nextInt( 100000/rarity ) == 0 )
{
Vector v = new Vector();
v = Pop( i,j,k );
Vector endv = new Vector();
endv = Vector(i,j,k);
Vector v2 = new Vector();
v2 = Pop( endv.elementAt(1), endv.elementAt(2), endv.elementAt(3) );
Vector endv2 = new Vector();
endv2 = v2*1600+endv;
Vector v3 = new Vector();
v3 = Pop( endv2.elementAt(1), endv2.elementAt(2), endv2.elementAt(3) );
Vector endv3 = new Vector();
endv3 = v3*1600+endv2;
Vector v4 = new Vector();
v4 = Pop( endv3.elementAt(1), endv3.elementAt(2), endv3.elementAt(3) );
Vector endv4 = new Vector();
endv4 = v4*1600+endv3;
Pop( endv4.elementAt(1), endv4.elementAt(2), endv4.elementAt(3) );
for (int z = 0; z < 400; z++)
{
int i1 = i+random.nextInt(256)-random.nextInt(256);
int j1 = j+random.nextInt(256)-random.nextInt(256);
int k1 = k+random.nextInt(256)-random.nextInt(256);
for (int z = 0; z < 8; z++)
{
int i2 = i1+random.nextInt(3)-random.nextInt(3);
int j2 = j1+random.nextInt(3)-random.nextInt(3);
int k2 = k1+random.nextInt(3)-random.nextInt(3);
if(world.getBlockId(i1, j1, k1) == Block.stone.blockID)
{
world.setBlock(i1,j1,k1, minableBlockId);
}
}
}
}
return true;
}
private int minableBlockId;
private int rarity;
}
[/code]
Derp, I feel dumb now; That seems pretty obvious. Thanks though, that seems to have fixed it.
Just have my 20+ other syntax errors to deal with, lol.
Sorry, you need to Log In to post a reply to this thread.