Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API bumped to 1.13.2, now supports pocket editions with Nukkit/Pokkit #86

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# RaspberryJuice

A Bukkit plugin which implements the Minecraft Pi Socket API.
Also supports Nukkit (server for pocket edition clients).

## Commands

Expand Down Expand Up @@ -50,11 +51,11 @@ Modify config.yml:

- port: 4711 - the default tcp port can be changed in config.yml
- location: RELATIVE - determine whether locations are RELATIVE to the spawn point (default like pi) or ABSOLUTE
- hitclick: RIGHT - determine whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH
- hitclick: RIGHT - determine whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH

## Libraries

To use the extra features an modded version of the java and python libraries that were originally supplied by Mojang with the Pi is required, [github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi](https://github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi).
To use the extra features an modded version of the java and python libraries that were originally supplied by Mojang with the Pi is required, [github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi](https://github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi).

You only need the modded libraries to use the extra features, the original libraries supplied with Minecraft Pi edition still work, you just wont be able to use the extra features

Expand All @@ -68,6 +69,35 @@ cd RaspberryJuice
mvn package
```

## Pocket edition clients

Mobile clients (also known as Bedrock edition) are supported using [Nukkit]
server and [Pokkit] plugin that provides interoperability between Nukkit and
Bukkit.

I made sure the following versions work together: Minecraft PE for Android
1.12.1, Nukkit server 1.0-SNAPSHOT, Pokkit plugin 0.9 and this RaspberryJuice
plugin 1.11-pe.

Running the server is easy. First run the server:

java -jar nukkit-1.0-SNAPSHOT.jar

Then stop it, note the `plugins` directory appeared next to it. Put Pokkit jar
there and run the server again. Then stop it again and note new directories
`plugins/Pokkit/bukkitPlugins/` appeared. Put RaspberryJuice jar there and
eventually run the server again. Connect your mobile client to the server at
port 19132 by default. To manually check the setup, you may do the following:

nc localhost 4711
player.getTile()
75,-5,-5 <-- your coordinates
world.setBlock(75,-6,-5,3) <-- will add a dirt block below you
world.spawnEntity(75,-4,-5,93) <-- will spawn a chicken above you

[Nukkit]: https://github.com/NukkitX/Nukkit
[Pokkit]: https://github.com/PetteriM1/Pokkit

## Version history

- 1.11 - spawnEntity, setDirection, setRotation, setPitch
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.zhuoweizhang</groupId>
<artifactId>raspberryjuice</artifactId>
<version>1.11</version>
<version>1.11.pe</version>
<name>RaspberryJuice</name>
<repositories>
<repository>
Expand All @@ -27,8 +27,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -37,7 +37,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class RaspberryJuicePlugin extends JavaPlugin implements Listener {

public static final Set<Material> blockBreakDetectionTools = EnumSet.of(
Material.DIAMOND_SWORD,
Material.GOLD_SWORD,
Material.LEGACY_GOLD_SWORD,
Material.IRON_SWORD,
Material.STONE_SWORD,
Material.WOOD_SWORD);
Material.LEGACY_WOOD_SWORD);

public ServerListenerThread serverThread;

Expand Down
28 changes: 21 additions & 7 deletions src/main/java/net/zhuoweizhang/raspberryjuice/RemoteSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class RemoteSession {

public RaspberryJuicePlugin plugin;

public Map<Integer, Material> materialById;

protected ArrayDeque<PlayerInteractEvent> interactEventQueue = new ArrayDeque<PlayerInteractEvent>();

protected ArrayDeque<AsyncPlayerChatEvent> chatPostedQueue = new ArrayDeque<AsyncPlayerChatEvent>();
Expand All @@ -60,6 +62,10 @@ public void init() throws IOException {
socket.setTrafficClass(0x10);
this.in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
this.materialById = new HashMap<Integer, Material>();
for (Material m : Material.values()) {
this.materialById.put(m.getId(), m);
}
startThreads();
plugin.getLogger().info("Opened connection to" + socket.getRemoteSocketAddress() + ".");
}
Expand Down Expand Up @@ -146,7 +152,7 @@ protected void handleCommand(String c, String[] args) {
// world.getBlock
if (c.equals("world.getBlock")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
send(world.getBlockTypeIdAt(loc));
send(world.getBlockAt(loc).getType().getId());

// world.getBlocks
} else if (c.equals("world.getBlocks")) {
Expand All @@ -157,7 +163,8 @@ protected void handleCommand(String c, String[] args) {
// world.getBlockWithData
} else if (c.equals("world.getBlockWithData")) {
Location loc = parseRelativeBlockLocation(args[0], args[1], args[2]);
send(world.getBlockTypeIdAt(loc) + "," + world.getBlockAt(loc).getData());
Block block = world.getBlockAt(loc);
send(block.getType().getId() + "," + block.getData());

// world.setBlock
} else if (c.equals("world.setBlock")) {
Expand Down Expand Up @@ -478,8 +485,8 @@ protected void handleCommand(String c, String[] args) {
//facing direction for wall sign : 2=north, 3=south, 4=west, 5=east
//rotation 0 - to 15 for standing sign : 0=south, 4=west, 8=north, 12=east
byte blockData = Byte.parseByte(args[4]);
if ((thisBlock.getTypeId() != blockType) || (thisBlock.getData() != blockData)) {
thisBlock.setTypeIdAndData(blockType, blockData, true);
if ((thisBlock.getType().getId() != blockType) || (thisBlock.getData() != blockData)) {
updateBlock(thisBlock, blockType, blockData);
}
//plugin.getLogger().info("Creating sign at " + loc);
if ( thisBlock.getState() instanceof Sign ) {
Expand Down Expand Up @@ -559,7 +566,7 @@ private String getBlocks(Location pos1, Location pos2) {
for (int y = minY; y <= maxY; ++y) {
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
blockData.append(new Integer(world.getBlockTypeIdAt(x, y, z)).toString() + ",");
blockData.append(new Integer(world.getBlockAt(x, y, z).getType().getId()).toString() + ",");
}
}
}
Expand All @@ -579,9 +586,16 @@ private void updateBlock(World world, int x, int y, int z, int blockType, byte b
}

private void updateBlock(Block thisBlock, int blockType, byte blockData) {
if (blockData != 0) {
plugin.getLogger().warning(
"Block data byte (" + blockData + ") " +
"is no longer supported by API, ignored. " +
"Use materials instead.");
}
// check to see if the block is different - otherwise leave it
if ((thisBlock.getTypeId() != blockType) || (thisBlock.getData() != blockData)) {
thisBlock.setTypeIdAndData(blockType, blockData, true);
if (thisBlock.getType().getId() != blockType) {
Material material = this.materialById.get(blockType);
thisBlock.setType(material, true);
}
}

Expand Down