From ce89d1c724459f2742ed313b592b32440a34fa54 Mon Sep 17 00:00:00 2001 From: Matsv Date: Tue, 13 Jun 2017 16:32:43 +0200 Subject: [PATCH] Store Parrot tamed data --- .../data/ParrotStorage.java | 19 ++++++++++++++++++ .../packets/EntityPackets1_12.java | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/ParrotStorage.java diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/ParrotStorage.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/ParrotStorage.java new file mode 100644 index 00000000..3f3abd51 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/data/ParrotStorage.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2016 Matsv + * + * 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. + */ + +package nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data; + +import lombok.Data; +import nl.matsv.viabackwards.api.entities.storage.EntityStorage; + +@Data +public class ParrotStorage extends EntityStorage { + private boolean tamed = true; +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java index 6780cdeb..135a503a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/EntityPackets1_12.java @@ -15,8 +15,10 @@ import nl.matsv.viabackwards.api.entities.storage.EntityData; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.types.AbstractEntityType; import nl.matsv.viabackwards.api.entities.types.EntityType1_12; +import nl.matsv.viabackwards.api.exceptions.RemovedValueException; import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; +import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.ParrotStorage; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; @@ -368,9 +370,25 @@ public class EntityPackets1_12 extends EntityRewriter { registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 12).removed(); registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 13).handleIndexChange(12); + // Create Parrot storage + registerMetaHandler().filter(EntityType.PARROT, true).handle(e -> { + if (!e.getEntity().has(ParrotStorage.class)) + e.getEntity().put(new ParrotStorage()); + return e.getData(); + }); // Parrot remove animal metadata registerMetaHandler().filter(EntityType.PARROT, 12).removed(); // Is baby - registerMetaHandler().filter(EntityType.PARROT, 13).removed(); // Flags (Is sitting etc, might be useful in the future (bat inactive TODO do more research about this entity) + registerMetaHandler().filter(EntityType.PARROT, 13).handle(e -> { + ParrotStorage storage = e.getEntity().get(ParrotStorage.class); + boolean isTamed = (((byte) e.getData().getValue()) & 0x04) == 0x04; + + if (!storage.isTamed() && isTamed) { + // TODO do something to let the user know it's done + } + + storage.setTamed(isTamed); + throw new RemovedValueException(); + }); // Flags (Is sitting etc, might be useful in the future registerMetaHandler().filter(EntityType.PARROT, 14).removed(); // Owner registerMetaHandler().filter(EntityType.PARROT, 15).removed(); // Variant