From da99bb16d55ceaf2f923df069e953e285d4d80f7 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 13:37:27 -0400 Subject: [PATCH 1/7] Cat work --- .../connector/entity/living/animal/tameable/CatEntity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 5a8a1dcf2..964b82cf4 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -44,8 +45,11 @@ public class CatEntity extends TameableEntity { } if (entityMetadata.getId() == 21) { // FIXME: Colors the whole animal instead of just collar + System.out.println("Color: " + (int) entityMetadata.getValue()); + metadata.getFlags().setFlag(EntityFlag.TAMED, true); metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } + System.out.println("ID: " + entityMetadata.getId() + " Value: " + entityMetadata.getValue()); super.updateBedrockMetadata(entityMetadata, session); } } From af4edf159a61606060a12062b2643d09cba04a85 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:06:00 -0400 Subject: [PATCH 2/7] Add tameable entity features --- .../living/animal/tameable/CatEntity.java | 22 +++++++++++++----- .../living/animal/tameable/ParrotEntity.java | 23 +++++++++++++++++++ .../living/animal/tameable/WolfEntity.java | 10 ++++++-- .../connector/entity/type/EntityType.java | 6 ++--- 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 964b82cf4..6c7d73536 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -41,15 +41,25 @@ public class CatEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { if (entityMetadata.getId() == 18) { - metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + // Different colors in Java and Bedrock for some reason + if ((int) entityMetadata.getValue() == 0) { + metadata.put(EntityData.VARIANT, 8); + } else if ((int) entityMetadata.getValue() == 8) { + // Assumption, need to test + metadata.put(EntityData.VARIANT, 0); + } else if ((int) entityMetadata.getValue() == 9) { + metadata.put(EntityData.VARIANT, 7); + } else { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { - // FIXME: Colors the whole animal instead of just collar - System.out.println("Color: " + (int) entityMetadata.getValue()); - metadata.getFlags().setFlag(EntityFlag.TAMED, true); - metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + // Needed or else wild cats are that color + if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { + metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + } } - System.out.println("ID: " + entityMetadata.getId() + " Value: " + entityMetadata.getValue()); super.updateBedrockMetadata(entityMetadata, session); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java new file mode 100644 index 000000000..0ee13867b --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java @@ -0,0 +1,23 @@ +package org.geysermc.connector.entity.living.animal.tameable; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class ParrotEntity extends TameableEntity { + + public ParrotEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + // Parrot color + if (entityMetadata.getId() == 18) { + metadata.put(EntityData.VARIANT, entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index 6f6ab15f8..ac8ef6659 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -39,9 +40,14 @@ public class WolfEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); + // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head + if (entityMetadata.getId() == 18) { + metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); + } if (entityMetadata.getId() == 19) { - // FIXME: Colors the whole animal instead of just collar - // metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + metadata.put(EntityData.INTERACTIVE_TAG, "action.interact.dye"); + metadata.put(EntityData.COLOR, entityMetadata.getValue()); } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 500aa1a2e..4af044701 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -29,10 +29,8 @@ import lombok.Getter; import org.geysermc.connector.entity.*; import org.geysermc.connector.entity.living.*; import org.geysermc.connector.entity.living.animal.*; -import org.geysermc.connector.entity.living.animal.tameable.CatEntity; -import org.geysermc.connector.entity.living.animal.tameable.TameableEntity; import org.geysermc.connector.entity.living.animal.horse.*; -import org.geysermc.connector.entity.living.animal.tameable.WolfEntity; +import org.geysermc.connector.entity.living.animal.tameable.*; import org.geysermc.connector.entity.living.monster.*; import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity; import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity; @@ -62,7 +60,7 @@ public enum EntityType { POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f), LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f), TRADER_LLAMA(TraderLlamaEntity.class, 29, 1.187f, 0.9f), - PARROT(TameableEntity.class, 30, 0.9f, 0.5f), + PARROT(ParrotEntity.class, 30, 0.9f, 0.5f), DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f), ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f), CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), From c2fc3a78738b15da3c9d73e5bc1d33263a02cd86 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:09:03 -0400 Subject: [PATCH 3/7] Add copyright --- .../living/animal/tameable/ParrotEntity.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java index 0ee13867b..e02b3e7be 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; From c1dbd64f12d1554ade12d9564d220633907f202e Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:36:30 -0400 Subject: [PATCH 4/7] Add wolf collar support --- .../connector/entity/living/animal/tameable/CatEntity.java | 2 +- .../entity/living/animal/tameable/TameableEntity.java | 4 ++++ .../connector/entity/living/animal/tameable/WolfEntity.java | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 6c7d73536..f380360ca 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -55,7 +55,7 @@ public class CatEntity extends TameableEntity { System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { - // Needed or else wild cats are that color + // Needed or else wild cats are a red color if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index 2f212595b..19ac8178e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -27,6 +27,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.type.EntityType; @@ -45,6 +46,9 @@ public class TameableEntity extends AnimalEntity { metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); + if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { + metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId()); + } } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index ac8ef6659..9796d364f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -40,14 +40,12 @@ public class WolfEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { - System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head if (entityMetadata.getId() == 18) { metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); } if (entityMetadata.getId() == 19) { - metadata.put(EntityData.INTERACTIVE_TAG, "action.interact.dye"); - metadata.put(EntityData.COLOR, entityMetadata.getValue()); + metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } super.updateBedrockMetadata(entityMetadata, session); } From c777641a9000a7ddedc794b86a28494298ef18be Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 17:53:38 -0400 Subject: [PATCH 5/7] Changes? --- .../connector/entity/living/animal/tameable/CatEntity.java | 5 +++-- .../entity/living/animal/tameable/TameableEntity.java | 4 +++- .../connector/entity/living/animal/tameable/WolfEntity.java | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index f380360ca..dcfdf841e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -45,10 +45,11 @@ public class CatEntity extends TameableEntity { if ((int) entityMetadata.getValue() == 0) { metadata.put(EntityData.VARIANT, 8); } else if ((int) entityMetadata.getValue() == 8) { - // Assumption, need to test metadata.put(EntityData.VARIANT, 0); } else if ((int) entityMetadata.getValue() == 9) { - metadata.put(EntityData.VARIANT, 7); + metadata.put(EntityData.VARIANT, 10); + } else if ((int) entityMetadata.getValue() == 10) { + metadata.put(EntityData.VARIANT, 9); } else { metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index 19ac8178e..2d3e0b1d1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -46,9 +46,11 @@ public class TameableEntity extends AnimalEntity { metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); + // Must be set for wolf collar color to work + // Extending it to all entities to prevent future bugs if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId()); - } + } // Can't de-tame an entity so no resetting the owner ID } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index 9796d364f..0ac49d55d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -44,6 +44,8 @@ public class WolfEntity extends TameableEntity { if (entityMetadata.getId() == 18) { metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); } + // Wolf collar color + // Relies on EntityData.OWNER_EID being set in TameableEntity.java if (entityMetadata.getId() == 19) { metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } From 8f735ae4530df105049c97f882ca054632c5566a Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 18:12:53 -0400 Subject: [PATCH 6/7] Remove debug code --- .../connector/entity/living/animal/tameable/CatEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index dcfdf841e..1c160e82e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -53,7 +53,6 @@ public class CatEntity extends TameableEntity { } else { metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); } - System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { // Needed or else wild cats are a red color From 6359fd4e836477103401ccab3abc1c66f844aeab Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 20:23:52 -0400 Subject: [PATCH 7/7] Use switch statement for cat variant color --- .../living/animal/tameable/CatEntity.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 1c160e82e..63a67a0a7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -42,17 +42,24 @@ public class CatEntity extends TameableEntity { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { if (entityMetadata.getId() == 18) { // Different colors in Java and Bedrock for some reason - if ((int) entityMetadata.getValue() == 0) { - metadata.put(EntityData.VARIANT, 8); - } else if ((int) entityMetadata.getValue() == 8) { - metadata.put(EntityData.VARIANT, 0); - } else if ((int) entityMetadata.getValue() == 9) { - metadata.put(EntityData.VARIANT, 10); - } else if ((int) entityMetadata.getValue() == 10) { - metadata.put(EntityData.VARIANT, 9); - } else { - metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + int variantColor; + switch ((int) entityMetadata.getValue()) { + case 0: + variantColor = 8; + break; + case 8: + variantColor = 0; + break; + case 9: + variantColor = 10; + break; + case 10: + variantColor = 9; + break; + default: + variantColor = (int) entityMetadata.getValue(); } + metadata.put(EntityData.VARIANT, variantColor); } if (entityMetadata.getId() == 21) { // Needed or else wild cats are a red color