Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update for block controllers #1853

Merged
merged 1 commit into from

2 participants

@windy1
Collaborator
@windy1 windy1 BlockControllers
Signed-off-by: Windwaker <wjcrouse913@aim.com>
5176cfa
@RoyAwesome RoyAwesome merged commit 2d4d460 into SpoutDev:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 17, 2012
  1. @windy1

    BlockControllers

    windy1 authored
    Signed-off-by: Windwaker <wjcrouse913@aim.com>
This page is out of date. Refresh to see the latest.
View
30 src/main/java/org/spout/engine/world/SpoutBlock.java
@@ -26,6 +26,8 @@
package org.spout.engine.world;
import org.spout.api.Source;
+import org.spout.api.entity.BlockController;
+import org.spout.api.entity.Entity;
import org.spout.api.geo.World;
import org.spout.api.geo.cuboid.Block;
import org.spout.api.geo.cuboid.Chunk;
@@ -38,11 +40,11 @@
import org.spout.api.math.Vector3;
public class SpoutBlock implements Block {
-
protected int x, y, z;
- private World world;
- private Chunk chunk;
- private Source source;
+ protected World world;
+ protected Chunk chunk;
+ protected Source source;
+ protected BlockController controller;
public SpoutBlock(Block source) {
this(source.getWorld(), source.getX(), source.getY(), source.getZ(), source.getSource());
@@ -53,11 +55,16 @@ public SpoutBlock(Point position, Source source) {
}
public SpoutBlock(World world, int x, int y, int z, Source source) {
+ this(world, x, y, z, source, null);
+ }
+
+ public SpoutBlock(World world, int x, int y, int z, Source source, BlockController controller) {
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.source = source == null ? world : source;
+ this.controller = controller;
}
public Point getPosition() {
@@ -228,6 +235,21 @@ public void setData(short data, boolean update) {
}
@Override
+ public BlockController getController() {
+ return controller;
+ }
+
+ @Override
+ public void setController(BlockController controller) {
+ this.controller = controller;
+ }
+
+ @Override
+ public boolean hasController() {
+ return controller != null;
+ }
+
+ @Override
public short getData() {
return this.getChunk().getBlockData(this.x, this.y, this.z);
}
View
22 src/main/java/org/spout/engine/world/SpoutRegion.java
@@ -30,7 +30,9 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -40,6 +42,7 @@
import java.util.logging.Level;
import org.spout.api.Spout;
+import org.spout.api.entity.BlockController;
import org.spout.api.entity.Controller;
import org.spout.api.entity.Entity;
import org.spout.api.entity.PlayerController;
@@ -49,6 +52,7 @@
import org.spout.api.geo.cuboid.Block;
import org.spout.api.geo.cuboid.Chunk;
import org.spout.api.geo.cuboid.Region;
+import org.spout.api.geo.discrete.Point;
import org.spout.api.io.bytearrayarray.BAAWrapper;
import org.spout.api.material.BlockMaterial;
import org.spout.api.protocol.NetworkSynchronizer;
@@ -171,6 +175,8 @@
private final Queue<Entity> spawnQueue = new ConcurrentLinkedQueue<Entity>();
private final Queue<Entity> removeQueue = new ConcurrentLinkedQueue<Entity>();
+
+ private final Map<Point, BlockController> blockControllers = new HashMap<Point, BlockController>();
public SpoutRegion(SpoutWorld world, float x, float y, float z, RegionSource source) {
this(world, x, y, z, source, false);
@@ -496,6 +502,11 @@ protected void queueLighting(SpoutChunk c) {
}
public void addEntity(Entity e) {
+ Controller controller = e.getController();
+ if (controller instanceof BlockController) {
+ blockControllers.put(e.getPosition(), (BlockController) controller);
+ }
+
if (spawnQueue.contains(e))
return;
if (removeQueue.contains(e)) {
@@ -506,6 +517,10 @@ public void addEntity(Entity e) {
}
public void removeEntity(Entity e) {
+ if (e.getController() instanceof BlockController) {
+ blockControllers.remove(e.getPosition());
+ }
+
if (removeQueue.contains(e))
return;
if (spawnQueue.contains(e)) {
@@ -712,6 +727,11 @@ public SpoutEntity getEntity(int id) {
return entityManager.getEntity(id);
}
+ @Override
+ public BlockController getBlockController(Point pos) {
+ return blockControllers.get(pos);
+ }
+
/**
* Allocates the id for an entity.
*
@@ -802,7 +822,7 @@ public DataOutputStream getChunkOutputStream(Chunk c) {
* <br>
* The stream is based on a snapshot of the array.
*
- * @param c the chunk
+ * @param x the chunk
* @return the DataInputStream
*/
public DataInputStream getChunkInputStream(int x, int y, int z) {
View
9 src/main/java/org/spout/engine/world/SpoutWorld.java
@@ -46,6 +46,7 @@
import org.spout.api.collision.CollisionVolume;
import org.spout.api.datatable.Datatable;
import org.spout.api.datatable.DatatableMap;
+import org.spout.api.entity.BlockController;
import org.spout.api.entity.Controller;
import org.spout.api.entity.Entity;
import org.spout.api.generator.WorldGenerator;
@@ -197,7 +198,13 @@ public SpoutBlock getBlock(int x, int y, int z) {
@Override
public SpoutBlock getBlock(int x, int y, int z, Source source) {
- return new SpoutBlock(this, x, y, z, source);
+ SpoutBlock block = new SpoutBlock(this, x, y, z, source);
+ BlockController controller = block.getChunk().getRegion().getBlockController(x, y, z);
+ if (controller != null) {
+ block.setController(controller);
+ }
+
+ return block;
}
@Override
Something went wrong with that request. Please try again.