Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
Updated to the latest version of Nukkit. Needs testing!
Browse files Browse the repository at this point in the history
Fixes #90, #95, #96
  • Loading branch information
RaynLegends committed Jul 12, 2017
1 parent 4a4df8d commit 00f8050
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public final class PokkitDamageCause {

public static DamageCause toBukkit(cn.nukkit.event.entity.EntityDamageEvent.DamageCause nukkit) {
// TODO Direct mapping via DamageCause.valueOf?
switch (nukkit) {
case CONTACT:
return DamageCause.CONTACT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void onOpen(Player who) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.windowid = (byte) who.getWindowId(this);
containerOpenPacket.type = (byte) this.getType().getNetworkType();
containerOpenPacket.slots = this.getSize();

containerOpenPacket.x = (int) v.x;
containerOpenPacket.y = (int) v.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static ItemStack toBukkitCopy(cn.nukkit.item.Item nukkit) {
if (nukkit == null) {
return null;
}
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage());
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit);
Material material = materialData.getBukkitMaterial();
if (material == null) {
return null;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/nl/rutgerkok/pokkit/material/PokkitMaterialData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,23 @@ public static PokkitMaterialData fromBukkit(MaterialData materialData) {
* The Nukkit damage/block data.
* @return The universal material object.
*/
@Deprecated
public static PokkitMaterialData fromNukkit(int nukkitId, int nukkitDamage) {
return new PokkitMaterialData(nukkitId, nukkitDamage);
}

/**
* Creates a universal material object from a Nukkit item.
*
* @param nukkitId
* The Nukkit material.
* @param nukkitDamage
* The Nukkit damage/block data.
* @return The universal material object.
*/
public static PokkitMaterialData fromNukkit(cn.nukkit.item.Item item) {
return new PokkitMaterialData(item.getId(), item.getDamage());
}

private final int id;
private final int data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import cn.nukkit.event.block.ItemFrameDropItemEvent;
import cn.nukkit.item.Item;

@SuppressWarnings("deprecation")
public final class EntityEvents extends EventTranslator {

private static Map<DamageModifier, Double> getDamageMap(double baseDamage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ public void onSignChange(cn.nukkit.event.block.SignChangeEvent event) {
// event.setLines(bukkitEvent.getLines()) is unnecessary
}

private Action toBukkit(int nukkit) {
private Action toBukkit(cn.nukkit.event.player.PlayerInteractEvent.Action nukkit) {
// TODO Direct mapping via Action.valueOf?
switch (nukkit) {
case cn.nukkit.event.player.PlayerInteractEvent.LEFT_CLICK_AIR:
case LEFT_CLICK_AIR:
return Action.LEFT_CLICK_AIR;
case cn.nukkit.event.player.PlayerInteractEvent.RIGHT_CLICK_AIR:
case RIGHT_CLICK_AIR:
return Action.RIGHT_CLICK_AIR;
case cn.nukkit.event.player.PlayerInteractEvent.LEFT_CLICK_BLOCK:
case LEFT_CLICK_BLOCK:
return Action.LEFT_CLICK_BLOCK;
case cn.nukkit.event.player.PlayerInteractEvent.RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_BLOCK:
return Action.RIGHT_CLICK_BLOCK;
case cn.nukkit.event.player.PlayerInteractEvent.PHYSICAL:
case PHYSICAL:
return Action.PHYSICAL;
}
throw new RuntimeException("Unknown action: " + nukkit);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/nl/rutgerkok/pokkit/world/PokkitBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.plugin.Plugin;

import cn.nukkit.block.BlockAir;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;

/**
Expand Down Expand Up @@ -99,7 +100,7 @@ public Chunk getChunk() {

@Override
public byte getData() {
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage());
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(nukkit.toItem());
return (byte) materialData.getBukkitDamage();
}

Expand All @@ -122,11 +123,11 @@ private Collection<ItemStack> getDrops0(cn.nukkit.item.Item item) {
item = new ItemBlock(new BlockAir(), 0, 0);
}

int[][] drops = nukkit.getDrops(item);
Item[] drops = nukkit.getDrops(item);
List<ItemStack> result = new ArrayList<>();
for (int[] drop : drops) {
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(drop[0], drop[1]);
ItemStack stack = new ItemStack(materialData.getBukkitMaterial(), drop[2], materialData.getBukkitDamage());
for (Item drop : drops) {
PokkitMaterialData materialData = PokkitMaterialData.fromNukkit(drop);
ItemStack stack = new ItemStack(materialData.getBukkitMaterial(), drop.getCount(), materialData.getBukkitDamage());
result.add(stack);
}
this.drops = result;
Expand Down Expand Up @@ -222,7 +223,7 @@ public double getTemperature() {

@Override
public Material getType() {
return PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()).getBukkitMaterial();
return PokkitMaterialData.fromNukkit(nukkit.toItem()).getBukkitMaterial();
}

/**
Expand All @@ -231,7 +232,7 @@ public Material getType() {
* @return The material data.
*/
public MaterialData getTypeData() {
return PokkitMaterialData.fromNukkit(nukkit.getId(), nukkit.getDamage()).toBukkit();
return PokkitMaterialData.fromNukkit(nukkit.toItem()).toBukkit();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public final class PokkitBlockFace {

public static BlockFace toBukkit(cn.nukkit.math.BlockFace nukkit) {
// TODO Direct mapping via BlockFace.valueOf?
switch (nukkit) {
case DOWN:
return BlockFace.DOWN;
Expand Down

0 comments on commit 00f8050

Please sign in to comment.