Skip to content

Commit

Permalink
Updated for 1.13, comply with WorldEdit 7, reversed parts of previous…
Browse files Browse the repository at this point in the history
… commit on main branch to fix incorrect math
  • Loading branch information
bermudalocket committed Sep 16, 2018
1 parent f5469d9 commit 0d45a91
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Eclipse stuff:
.project
.settings
.classpath

# IntelliJ stuff:
.idea

# Build:
/classes/
target/
1 change: 0 additions & 1 deletion contributors.txt

This file was deleted.

14 changes: 6 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

<groupId>net.sothatsit</groupId>
<artifactId>blockstore</artifactId>
<version>1.5.0</version>

<version>1.6.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
Expand All @@ -35,7 +34,6 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>

<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo</url>
Expand All @@ -46,14 +44,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.1-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
Binary file removed releases/BlockStore 1.5.0.jar
Binary file not shown.
24 changes: 11 additions & 13 deletions src/main/java/net/sothatsit/blockstore/WorldEditHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.util.eventbus.Subscribe;

import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import net.sothatsit.blockstore.chunkstore.BlockLoc;
import net.sothatsit.blockstore.chunkstore.ChunkManager;
import net.sothatsit.blockstore.chunkstore.ChunkStore;

public class WorldEditHook {

public void register() {
void register() {
WorldEdit.getInstance().getEventBus().register(this);
}

@Subscribe
public void wrapForLogging(EditSessionEvent event) {
World world = event.getWorld();

if(world == null)
if (world == null) {
return;
}

final ChunkManager manager = BlockStore.getInstance().getManager(world.getName());

event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
@Override
protected void onBlockChange(Vector pos, BaseBlock newBlock) {
BlockLoc blockLoc = BlockLoc.fromLocation(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());

public boolean setBlock(Vector pos, BlockStateHolder block) throws WorldEditException {
BlockLoc blockLoc = BlockLoc.fromLocation(pos.getX(), pos.getY(), pos.getZ());
ChunkStore store = manager.getChunkStore(blockLoc.chunkLoc, true);

store.setPlaced(blockLoc, false);
return getExtent().setBlock(pos, block);
}
});
}

}
}
20 changes: 10 additions & 10 deletions src/main/java/net/sothatsit/blockstore/chunkstore/BlockLoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public boolean equals(Object obj) {
@Override
public String toString() {
return "{chunkLoc: " + chunkLoc
+ ", relx: " + relx
+ ", rely: " + rely
+ ", relz: " + relz
+ ", blockIndex: " + blockIndex + "}";
+ ", relx: " + relx
+ ", rely: " + rely
+ ", relz: " + relz
+ ", blockIndex: " + blockIndex + "}";
}

public static int calcBlockIndex(int relx, int rely, int relz) {
Expand All @@ -85,15 +85,15 @@ public static BlockLoc fromBlock(Block block) {
}

public static BlockLoc fromLocation(Location location) {
return fromLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return fromLocation(location.getX(), location.getY(), location.getZ());
}

public static BlockLoc fromLocation(int x, int y, int z) {
public static BlockLoc fromLocation(double x, double y, double z) {
ChunkLoc chunkLoc = ChunkLoc.fromLocation(x, y, z);

int relx = x - chunkLoc.getBlockX();
int rely = y - chunkLoc.getBlockY();
int relz = z - chunkLoc.getBlockZ();
int relx = (int) x - chunkLoc.getBlockX();
int rely = (int) y - chunkLoc.getBlockY();
int relz = (int) z - chunkLoc.getBlockZ();

return new BlockLoc(chunkLoc, relx, rely, relz);
}
Expand All @@ -107,4 +107,4 @@ public static BlockLoc fromBlockIndex(ChunkLoc chunkLoc, int blockIndex) {
return new BlockLoc(chunkLoc, relx, rely, relz);
}

}
}
12 changes: 8 additions & 4 deletions src/main/java/net/sothatsit/blockstore/chunkstore/ChunkLoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ public String toString() {
}

public static ChunkLoc fromLocation(Location location) {
return fromLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ());
return fromLocation(location.getX(), location.getY(), location.getZ());
}

public static ChunkLoc fromLocation(int x, int y, int z) {
return new ChunkLoc(x / 16, y / 64, z / 16);
public static ChunkLoc fromLocation(double x, double y, double z) {
int cx = (int) Math.floor(x / 16d);
int cy = (int) Math.floor(y / 64d);
int cz = (int) Math.floor(z / 16d);

return new ChunkLoc(cx, cy, cz);
}

}
}

0 comments on commit 0d45a91

Please sign in to comment.