Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Apr 1, 2016
1 parent a3c8f76 commit 71df972
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 35 deletions.
53 changes: 33 additions & 20 deletions 19/src/main/java/mobi/omegacentauri/raspberryjammod/APIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -434,29 +436,40 @@ protected void spawnEntity(Scanner scan) {
Vec3w pos = Location.decodeVec3w(serverWorlds, x0, y0, z0);
String tagString = getRest(scan);
Entity entity;
if (tagString.length() > 0) {
NBTTagCompound tags;
try {
tags = JsonToNBT.getTagFromJson(tagString);
} catch (NBTException e) {
fail("Cannot parse tags");
return;
boolean fixGravity = false;

try {
if (tagString.length() > 0) {
NBTTagCompound tags;
try {
tags = JsonToNBT.getTagFromJson(tagString);
if (tags.hasKey("NoAI")) {
System.out.println("Has NoAI");
fixGravity = tags.getBoolean("NoAI");
System.out.println("NoAI "+fixGravity);
}
} catch (NBTException e) {
fail("Cannot parse tags");
return;
}
tags.setString("id", entityId);
entity = EntityList.createEntityFromNBT(tags, pos.world);
}
tags.setString("id", entityId);
entity = EntityList.createEntityFromNBT(tags, pos.world);
}
else {
entity = EntityList.createEntityByName(entityId, pos.world);
}

if (entity == null) {
else {
entity = EntityList.createEntityByName(entityId, pos.world);
}
if (entity == null) {
throw new Exception();
}
} catch(Exception e) {
fail("Cannot create entity");
return;
}
else {
entity.setPositionAndUpdate(pos.xCoord, pos.yCoord, pos.zCoord);
pos.world.spawnEntityInWorld(entity);
sendLine(entity.getEntityId());
}

entity.setPositionAndUpdate(pos.xCoord, pos.yCoord, pos.zCoord);
pos.world.spawnEntityInWorld(entity);
sendLine(entity.getEntityId());

//TODO: antigravity for NoAI:1
}
Expand Down
Binary file modified python2-scripts.zip
Binary file not shown.
Binary file added python2-scripts/mcpipy/ovalegg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python2-scripts/mcpipy/pysanka.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 51 additions & 6 deletions python2-scripts/mcpipy/pysanka.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def getBestColor(rgb):

def getPixel(image, x, y):
rgb = image.getpixel(( floor( x * image.size[0] ), image.size[1]-1-floor( y * image.size[1] ) ))
return getBestColor(rgb)
return getBestColor(rgb)[0:2]

mc = Minecraft()

Expand All @@ -94,20 +94,65 @@ def getPixel(image, x, y):
else:
filename = os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + "pysanka.jpg"

image = Image.open(filename).convert('RGB')

if len(sys.argv) > 2:
height = int(sys.argv[2])
else:
height = 100

oval = False

if len(sys.argv) > 3:
repeat = int(sys.argv[3])
if sys.argv[3] == "oval":
oval = True
else:
repeat = int(sys.argv[3])
else:
repeat = 2

pos = mc.player.getPos()

for (x,y,z,block,theta) in egg(h=height,block=None):
mc.setBlock(x+pos.x,y+pos.y,z+pos.z,getPixel(image, (theta * repeat / (2*pi)) % 1, y / float(height)))
if oval:
image = Image.open(filename).convert('RGBA')

first = None
last = None

start = [None] * image.size[1]
stop = [None] * image.size[1]

for y in range(image.size[1]):
for x in range(image.size[0]):
_,_,_,alpha = image.getpixel((x,y))
if alpha == 255:
start[y] = x
break
for x in range(image.size[0]-1,-1,-1):
_,_,_,alpha = image.getpixel((x,y))
if alpha == 255:
stop[y] = x
break
if start[y] is not None:
if first is None:
first = y
last = y

assert first is not None

for (x,y,z,block,theta) in egg(h=height,block=None):
imageY = first + int(float(y)/height*(last-first+1))
if imageY < first:
imageY = first
if imageY > last:
imageY = last
imageX = start[imageY]+ int((0.5 + 0.5 * sin(theta)) * (stop[imageY]-start[imageY]))
if imageX < start[imageY]:
imageX = start[imageY]
if imageX > stop[imageY]:
imageX = stop[imageY]
mc.setBlock(x+pos.x,y+pos.y,z+pos.z, getBestColor(image.getpixel((imageX,imageY))[0:3])[0:2])
else:
image = Image.open(filename).convert('RGB')

for (x,y,z,block,theta) in egg(h=height,block=None):
mc.setBlock(x+pos.x,y+pos.y,z+pos.z,getPixel(image, (theta * repeat / (2*pi)) % 1, y / float(height)))

Binary file modified python2-scripts/mcpipy/pysanka2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python3-scripts.zip
Binary file not shown.
Binary file added python3-scripts/mcpipy/ovalegg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python3-scripts/mcpipy/pysanka.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 53 additions & 8 deletions python3-scripts/mcpipy/pysanka.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def radius(y):

for y in range(0,h):
r = radius(y)
minimumr = min(r-3,radius(y-1),radius(y+1))
minimumr = min(r-2,radius(y-1),radius(y+1))
for x in range(-h,h+1):
for z in range(-h,h+1):
myr = sqrt(x*x + z*z)
Expand Down Expand Up @@ -82,8 +82,8 @@ def getBestColor(rgb):
return bestColor

def getPixel(image, x, y):
rgb = image.getpixel(( int( x * image.size[0] ), int( y * image.size[1] ) ))
return getBestColor(rgb)
rgb = image.getpixel(( floor( x * image.size[0] ), image.size[1]-1-floor( y * image.size[1] ) ))
return getBestColor(rgb)[0:2]

mc = Minecraft()

Expand All @@ -94,20 +94,65 @@ def getPixel(image, x, y):
else:
filename = os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + "pysanka.jpg"

image = Image.open(filename).convert('RGB')

if len(sys.argv) > 2:
height = int(sys.argv[2])
else:
height = 100

oval = False

if len(sys.argv) > 3:
repeat = int(sys.argv[3])
if sys.argv[3] == "oval":
oval = True
else:
repeat = int(sys.argv[3])
else:
repeat = 2

pos = mc.player.getPos()

for (x,y,z,block,theta) in egg(h=height,block=None):
mc.setBlock(x+pos.x,y+pos.y,z+pos.z,getPixel(image, (theta * repeat / (2*pi)) % 1, y / float(height)))
if oval:
image = Image.open(filename).convert('RGBA')

first = None
last = None

start = [None] * image.size[1]
stop = [None] * image.size[1]

for y in range(image.size[1]):
for x in range(image.size[0]):
_,_,_,alpha = image.getpixel((x,y))
if alpha == 255:
start[y] = x
break
for x in range(image.size[0]-1,-1,-1):
_,_,_,alpha = image.getpixel((x,y))
if alpha == 255:
stop[y] = x
break
if start[y] is not None:
if first is None:
first = y
last = y

assert first is not None

for (x,y,z,block,theta) in egg(h=height,block=None):
imageY = first + int(float(y)/height*(last-first+1))
if imageY < first:
imageY = first
if imageY > last:
imageY = last
imageX = start[imageY]+ int((0.5 + 0.5 * sin(theta)) * (stop[imageY]-start[imageY]))
if imageX < start[imageY]:
imageX = start[imageY]
if imageX > stop[imageY]:
imageX = stop[imageY]
mc.setBlock(x+pos.x,y+pos.y,z+pos.z, getBestColor(image.getpixel((imageX,imageY))[0:3])[0:2])
else:
image = Image.open(filename).convert('RGB')

for (x,y,z,block,theta) in egg(h=height,block=None):
mc.setBlock(x+pos.x,y+pos.y,z+pos.z,getPixel(image, (theta * repeat / (2*pi)) % 1, y / float(height)))

Binary file modified python3-scripts/mcpipy/pysanka2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion python3-scripts/mcpipy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def message(m):
found = re.match('([^\\s]+) (.*)$', line)
if found:
def getString():
if found.group(2).startswith('"') or found.group(2).startswith("'"):
if found.group(2).startswith('"') or found.group(2).startswith("'") or found.group(2).startswith('u"') or found.group(2).startswith("u'"):
return safeEval(found.group(2))
else:
return found.group(2)
Expand Down

0 comments on commit 71df972

Please sign in to comment.