13
0
geforkt von Mirrors/Paper

Painting improvements. Thanks CelticMinstrel!

Implement get/setArt and facing direction for paintings; expanded painting break causes; added painting support to World.spawn

By: EvilSeph <evilseph@gmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2011-10-01 13:31:28 -04:00
Ursprung d51a5ded5b
Commit 3ece4f6a1f
2 geänderte Dateien mit 142 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@ import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Boat;
import org.bukkit.Chunk;
import org.bukkit.inventory.ItemStack;
@ -755,7 +756,37 @@ public class CraftWorld implements World {
}
} else if (Painting.class.isAssignableFrom(clazz)) {
// negative
Block block = getBlockAt(location);
BlockFace face = BlockFace.SELF;
if (block.getRelative(BlockFace.EAST).getTypeId() == 0) {
face = BlockFace.EAST;
} else if (block.getRelative(BlockFace.NORTH).getTypeId() == 0) {
face = BlockFace.NORTH;
} else if (block.getRelative(BlockFace.WEST).getTypeId() == 0) {
face = BlockFace.WEST;
} else if (block.getRelative(BlockFace.SOUTH).getTypeId() == 0) {
face = BlockFace.SOUTH;
}
int dir;
switch(face) {
case EAST:
default:
dir = 0;
break;
case NORTH:
dir = 1;
break;
case WEST:
dir = 2;
break;
case SOUTH:
dir = 3;;
break;
}
entity = new EntityPainting(world, (int) x, (int) y, (int) z, dir);
if (!((EntityPainting)entity).i()) {
entity = null;
}
} else if (TNTPrimed.class.isAssignableFrom(clazz)) {
entity = new EntityTNTPrimed(world, x, y, z);
} else if (ExperienceOrb.class.isAssignableFrom(clazz)) {

Datei anzeigen

@ -1,8 +1,16 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityPainting;
import net.minecraft.server.EnumArt;
import net.minecraft.server.Packet25EntityPainting;
import net.minecraft.server.Packet29DestroyEntity;
import net.minecraft.server.WorldServer;
import org.bukkit.Art;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Painting;
public class CraftPainting extends CraftEntity implements Painting {
@ -12,8 +20,108 @@ public class CraftPainting extends CraftEntity implements Painting {
}
@Override
public String toString() {
return "CraftPainting";
public EntityPainting getHandle() {
return (EntityPainting) super.getHandle();
}
@Override
public String toString() {
return "CraftPainting[art=" + getArt() + "]";
}
public Art getArt() {
EnumArt art = getHandle().e;
// Since both EnumArt and Art have exactly the same enum constants, this works
return Art.getByName(art.toString());
}
public boolean setArt(Art art) {
return setArt(art, false);
}
public boolean setArt(Art art, boolean force) {
EntityPainting painting = getHandle();
EnumArt oldArt = painting.e;
EnumArt newArt = EnumArt.valueOf(art.toString());
painting.e = newArt;
painting.b(painting.a);
if(!force && !painting.i()) {
// Revert painting since it doesn't fit
painting.e = oldArt;
painting.b(painting.a);
return false;
}
this.update();
return true;
}
public BlockFace getAttachedFace() {
return getFacing().getOppositeFace();
}
public void setFacingDirection(BlockFace face) {
setFacingDirection(face, false);
}
public boolean setFacingDirection(BlockFace face, boolean force) {
Block block = getLocation().getBlock().getRelative(getAttachedFace()).getRelative(face.getOppositeFace()).getRelative(getFacing());
EntityPainting painting = getHandle();
int x = painting.b, y = painting.c, z = painting.d, dir = painting.a;
painting.b = block.getX();
painting.c = block.getY();
painting.d = block.getZ();
switch(face) {
case EAST:
default:
getHandle().b(0);
break;
case NORTH:
getHandle().b(1);
break;
case WEST:
getHandle().b(2);
break;
case SOUTH:
getHandle().b(3);
break;
}
if(!force && !painting.i()) {
// Revert painting since it doesn't fit
painting.b = x;
painting.c = y;
painting.d = z;
painting.b(dir);
return false;
}
this.update();
return true;
}
public BlockFace getFacing() {
switch(getHandle().a) {
case 0:
default:
return BlockFace.EAST;
case 1:
return BlockFace.NORTH;
case 2:
return BlockFace.WEST;
case 3:
return BlockFace.SOUTH;
}
}
private void update() {
WorldServer world = ((CraftWorld)getWorld()).getHandle();
EntityPainting painting = new EntityPainting(world);
painting.b = getHandle().b;
painting.c = getHandle().c;
painting.d = getHandle().d;
painting.e = getHandle().e;
painting.b(getHandle().a);
getHandle().die();
getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important
world.addEntity(painting);
this.entity = painting;
}
}