From 4b2e63f57ef1f131323ba2595075b4bb7c8c644c Mon Sep 17 00:00:00 2001 From: eDroid Date: Fri, 2 Mar 2018 20:19:22 -0800 Subject: [PATCH] fix up some gameruless --- .../network/minecraft/protocol/DataPacket.js | 26 ++++++++----------- src/pocketnode/player/Player.js | 24 +++++++++++++++++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/pocketnode/network/minecraft/protocol/DataPacket.js b/src/pocketnode/network/minecraft/protocol/DataPacket.js index e2d4675..9be8aac 100644 --- a/src/pocketnode/network/minecraft/protocol/DataPacket.js +++ b/src/pocketnode/network/minecraft/protocol/DataPacket.js @@ -150,21 +150,17 @@ class DataPacket extends BinaryStream { writeGameRules(rules){ this.writeUnsignedVarInt(rules.length); - rules.forEach((rule, name) => { - this.writeString(name); - this.writeUnsignedVarInt(rule[0]); - switch(rule[0]){ - case 1: - this.writeBool(rule[1]); - break; - - case 2: - this.writeUnsignedVarInt(rule[1]); - break; - - case 3: - this.writeLFloat(rule[1]); - break; + rules.forEach(rule => { + this.writeString(rule.getName()); + if(typeof rule.getValue() === "boolean") { + this.writeByte(1); + this.writeBool(rule.getValue()); + }else if(Number.isInteger(rule.getValue())){ + this.writeByte(2); + this.writeUnsignedVarInt(rule.getValue()); + }else if(typeof rule.getValue() === "number" && !Number.isInteger(rule.getValue())){ + this.writeByte(3); + this.writeLFloat(rule.getValue()); } }); diff --git a/src/pocketnode/player/Player.js b/src/pocketnode/player/Player.js index 23154b7..b72cd1d 100644 --- a/src/pocketnode/player/Player.js +++ b/src/pocketnode/player/Player.js @@ -13,6 +13,8 @@ const ChunkRadiusUpdatedPacket = pocketnode("network/minecraft/protocol/ChunkRad const TextPacket = pocketnode("network/minecraft/protocol/TextPacket"); const FullChunkDataPacket = pocketnode("network/minecraft/protocol/FullChunkDataPacket"); +const GameRule = pocketnode("level/GameRule"); + const Vector3 = pocketnode("math/Vector3"); const Skin = pocketnode("entity/Skin"); @@ -488,6 +490,28 @@ class Player extends CommandSender { pk.enchantmentSeed = 123456; pk.time = 0; pk.hasAchievementsDisabled = true; + //pk.gameRules = this.getServer().getDefaultLevel().getGameRules(); + pk.gameRules = [ + new GameRule(GameRule.COMMAND_BLOCK_OUTPUT, true), + new GameRule(GameRule.DO_DAYLIGHT_CYCLE, true), + new GameRule(GameRule.DO_ENTITY_DROPS, true), + new GameRule(GameRule.DO_FIRE_TICK, true), + new GameRule(GameRule.DO_MOB_LOOT, true), + new GameRule(GameRule.DO_MOB_SPAWNING, true), + new GameRule(GameRule.DO_TILE_DROPS, true), + new GameRule(GameRule.DO_WEATHER_CYCLE, true), + new GameRule(GameRule.DROWNING_DAMAGE, true), + new GameRule(GameRule.FALL_DAMAGE, true), + new GameRule(GameRule.FIRE_DAMAGE, true), + new GameRule(GameRule.KEEP_INVENTORY, false), + new GameRule(GameRule.MOB_GRIEFING, true), + new GameRule(GameRule.NATURAL_REGENERATION, true), + new GameRule(GameRule.PVP, true), + new GameRule(GameRule.SEND_COMMAND_FEEDBACK, true), + new GameRule(GameRule.SHOW_COORDINATES, true), + new GameRule(GameRule.RANDOM_TICK_SPEED, 3), + new GameRule(GameRule.TNT_EXPLODES, true) + ]; this.dataPacket(pk); this.server.addOnlinePlayer(this);