Skip to content

Commit

Permalink
Now compiles on Spout and basic block setting works
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Jan 20, 2013
1 parent a800ced commit 718457b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -279,7 +279,7 @@
<dependency>
<groupId>org.spout</groupId>
<artifactId>vanilla</artifactId>
<version>1.3.2-SNAPSHOT</version>
<version>1.4.7-SNAPSHOT</version>
<optional>true</optional>
</dependency>
</dependencies>
Expand Down
19 changes: 11 additions & 8 deletions src/spout/java/com/sk89q/worldedit/spout/SpoutPlayer.java
Expand Up @@ -31,15 +31,15 @@

import org.spout.api.Client;
import org.spout.api.chat.style.ChatStyle;
import org.spout.api.component.components.TransformComponent;
import org.spout.api.component.impl.TransformComponent;
import org.spout.api.geo.discrete.Point;
import org.spout.api.inventory.Inventory;
import org.spout.api.inventory.ItemStack;
import org.spout.api.entity.Player;
import org.spout.vanilla.component.inventory.PlayerInventory;
import org.spout.vanilla.component.living.neutral.Human;
import org.spout.vanilla.material.VanillaMaterial;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.api.inventory.Slot;
import org.spout.vanilla.plugin.component.inventory.PlayerInventory;
import org.spout.vanilla.plugin.component.living.neutral.Human;
import org.spout.vanilla.api.material.VanillaMaterial;
import org.spout.vanilla.plugin.material.VanillaMaterials;

public class SpoutPlayer extends LocalPlayer {
private Player player;
Expand All @@ -55,8 +55,11 @@ public SpoutPlayer(WorldEditPlugin plugin, ServerInterface server, Player player
@Override
public int getItemInHand() {
if (player.has(Human.class)) {
return ((VanillaMaterial) player.get(PlayerInventory.class).getQuickbar()
.getCurrentItem().getMaterial()).getMinecraftId();
Slot slot = player.get(PlayerInventory.class).getQuickbar().getSelectedSlot();
if (slot.get() == null) {
return 0;
}
return ((VanillaMaterial) slot.get().getMaterial()).getMinecraftId();
} else {
return 0;
}
Expand Down
Expand Up @@ -33,9 +33,9 @@
import org.spout.api.inventory.ItemStack;
import org.spout.api.material.Material;
import org.spout.api.entity.Player;
import org.spout.vanilla.component.inventory.PlayerInventory;
import org.spout.vanilla.component.living.neutral.Human;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.plugin.component.inventory.PlayerInventory;
import org.spout.vanilla.plugin.component.living.neutral.Human;
import org.spout.vanilla.plugin.material.VanillaMaterials;

public class SpoutPlayerBlockBag extends BlockBag {
/**
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.spout.api.material.Material;
import org.spout.api.material.MaterialRegistry;
import org.spout.api.scheduler.TaskPriority;
import org.spout.vanilla.material.VanillaMaterial;
import org.spout.vanilla.api.material.VanillaMaterial;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -76,7 +76,7 @@ public SpoutBiomeTypes getBiomes() {

@Override
public int schedule(long delay, long period, Runnable task) {
return game.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay * 50, period * 50, TaskPriority.NORMAL);
return game.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay * 50, period * 50, TaskPriority.NORMAL).getTaskId();
}

@Override
Expand Down
50 changes: 35 additions & 15 deletions src/spout/java/com/sk89q/worldedit/spout/SpoutWorld.java
Expand Up @@ -50,17 +50,18 @@
import org.spout.api.material.BlockMaterial;
import org.spout.api.material.Material;
import org.spout.api.math.Vector3;
import org.spout.vanilla.component.substance.Item;
import org.spout.vanilla.component.substance.Painting;
import org.spout.vanilla.component.substance.XPOrb;
import org.spout.vanilla.component.substance.object.Tnt;
import org.spout.vanilla.component.substance.object.projectile.Arrow;
import org.spout.vanilla.component.substance.object.vehicle.Boat;
import org.spout.vanilla.component.substance.object.vehicle.Minecart;
import org.spout.vanilla.material.VanillaMaterial;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.world.generator.normal.object.tree.TreeObject;
import org.spout.vanilla.world.generator.normal.object.tree.SmallTreeObject;
import org.spout.vanilla.plugin.component.substance.Item;
import org.spout.vanilla.plugin.component.substance.Painting;
import org.spout.vanilla.plugin.component.substance.XPOrb;
import org.spout.vanilla.plugin.component.substance.object.Tnt;
import org.spout.vanilla.plugin.component.substance.object.projectile.Arrow;
import org.spout.vanilla.plugin.component.substance.object.vehicle.Boat;
import org.spout.vanilla.plugin.component.substance.object.vehicle.Minecart;
import org.spout.vanilla.api.material.VanillaMaterial;
import org.spout.vanilla.plugin.material.VanillaMaterials;
import org.spout.vanilla.plugin.world.generator.normal.object.tree.TreeObject;
import org.spout.vanilla.plugin.world.generator.normal.object.tree.SmallTreeObject;
import org.spout.vanilla.plugin.world.generator.object.VanillaObjects;

import javax.annotation.Nullable;
import java.util.ArrayList;
Expand Down Expand Up @@ -97,6 +98,24 @@ public String getName() {
return world.getName();
}

public Material getSpoutMaterial(int id) {
switch (id) {
case 0:
return BlockMaterial.AIR;
default:
return VanillaMaterials.getMaterial((short) id);
}
}

public Material getSpoutMaterial(int id, int data) {
switch (id) {
case 0:
return BlockMaterial.AIR;
default:
return VanillaMaterials.getMaterial((short) id, (short) data);
}
}

/**
* Set block type.
*
Expand All @@ -106,7 +125,7 @@ public String getName() {
*/
@Override
public boolean setBlockType(Vector pt, int type) {
Material mat = VanillaMaterials.getMaterial((short) type);
Material mat = getSpoutMaterial(type);
if (mat != null && mat instanceof BlockMaterial) {
final int x = pt.getBlockX();
final int y = pt.getBlockY();
Expand Down Expand Up @@ -137,7 +156,7 @@ public boolean setBlockTypeFast(Vector pt, int type) {
*/
@Override
public boolean setTypeIdAndData(Vector pt, int type, int data) {
Material mat = VanillaMaterials.getMaterial((short) type, (short) data);
Material mat = getSpoutMaterial(type, data);
if (mat != null && mat instanceof BlockMaterial) {
final int x = pt.getBlockX();
final int y = pt.getBlockY();
Expand Down Expand Up @@ -454,6 +473,7 @@ public boolean clearContainerBlockContents(Vector pt) {
@Override
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt)
throws MaxChangedBlocksException {
//VanillaObjects.byName()
TreeObject tree = new SmallTreeObject(); //TODO: properly check for tree type
if (!tree.canPlaceObject(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ())) {
return false;
Expand Down Expand Up @@ -722,7 +742,7 @@ public int removeEntities(EntityType type, Vector origin, int radius) {
*/
@Override
public boolean isValidBlockType(int type) {
return VanillaMaterials.getMaterial((short)type) instanceof BlockMaterial;
return getSpoutMaterial(type) instanceof BlockMaterial;
}

@Override
Expand All @@ -745,7 +765,7 @@ public int hashCode() {

@Override
public int getMaxY() {
return world.getHeight() - 1;
return world.getHeight() - 1; //TODO: We have infinite-height worlds now
}

@Override
Expand Down
Expand Up @@ -51,6 +51,11 @@ public String toString() {
.toString();
}

@Override
public boolean isAsync() {
return false;
}

@Override
public int getChannelId() {
return DEFAULT_CHANNEL;
Expand Down
Expand Up @@ -144,7 +144,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
public void run() {
ignoreLeftClickAir = false;
}
}, 100, TaskPriority.NORMAL);
}, 100, TaskPriority.NORMAL).getTaskId();

if (taskId != -1) {
ignoreLeftClickAir = true;
Expand Down

0 comments on commit 718457b

Please sign in to comment.