Skip to content

Commit

Permalink
fix armorstand inventory and body parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Sep 2, 2020
1 parent 257b32e commit 0a60c31
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ private BodyPartStreamGenerator() {

public static Stream<BodyPart> stream() {
return Stream.of(
new SpongeBodyPart(ResourceKey.minecraft("chest")),
new SpongeBodyPart(ResourceKey.minecraft("head")),
new SpongeBodyPart(ResourceKey.minecraft("body")),
new SpongeBodyPart(ResourceKey.minecraft("left_arm")),
new SpongeBodyPart(ResourceKey.minecraft("right_arm")),
new SpongeBodyPart(ResourceKey.minecraft("left_leg")),
new SpongeBodyPart(ResourceKey.minecraft("right_arm")),
new SpongeBodyPart(ResourceKey.minecraft("right_leg"))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package org.spongepowered.common.mixin.inventory.api;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ArmorStandEntity;
import net.minecraft.inventory.container.Container;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
Expand All @@ -40,7 +42,8 @@
@Mixin(value = {
Container.class,
CarriedWrapperInventory.class,
CustomInventory.class
CustomInventory.class,
ArmorStandEntity.class
})
public abstract class TraitMixin_Carried_Inventory_API implements CarriedInventory<Carrier> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package org.spongepowered.common.mixin.inventory.api;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.item.ArmorStandEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -33,7 +32,11 @@
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.common.bridge.inventory.InventoryBridge;
import org.spongepowered.common.inventory.adapter.InventoryAdapter;
import org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens;
import org.spongepowered.common.item.util.ItemStackUtil;
import org.spongepowered.common.mixin.inventory.api.inventory.EquipmentSlotTypeMixin_Inventory_API;
import org.spongepowered.common.util.MissingImplementationException;

import java.util.Optional;
Expand Down Expand Up @@ -62,12 +65,16 @@ public boolean canEquip(final EquipmentType type, @Nullable final ItemStack equi

@Override
public Optional<ItemStack> getEquipped(final EquipmentType type) {
throw new MissingImplementationException("TraitMixin_Equipable_Inventory_API", "getEquipped");
final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
final EquipmentInventoryLens lens = (EquipmentInventoryLens) inv.inventoryAdapter$getRootLens();
return Optional.of(ItemStackUtil.fromNative(lens.getStack(inv.inventoryAdapter$getFabric(), ((EquipmentSlotType) (Object) type).getSlotIndex())));
}

@Override
public boolean equip(final EquipmentType type, @Nullable final ItemStack equipment) {
throw new MissingImplementationException("TraitMixin_Equipable_Inventory_API", "equip");
final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter();
final EquipmentInventoryLens lens = (EquipmentInventoryLens) inv.inventoryAdapter$getRootLens();
return lens.setStack(inv.inventoryAdapter$getFabric(), ((EquipmentSlotType) (Object) type).getSlotIndex(), ItemStackUtil.toNative(equipment));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.common.mixin.inventory.api.entity;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ArmorStandEntity;
import org.spongepowered.api.entity.living.ArmorStand;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.common.inventory.adapter.impl.DefaultImplementedAdapterInventory;

@Mixin(LivingEntity.class)
public abstract class LivingEntity_Inventory_API implements DefaultImplementedAdapterInventory {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* 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 org.spongepowered.common.mixin.inventory.api.entity.item;

import net.minecraft.entity.item.ArmorStandEntity;
import org.spongepowered.api.entity.living.ArmorStand;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(ArmorStandEntity.class)
public abstract class ArmorStandEntityMixin_Carrier_Inventory_API implements ArmorStand {

@Override
public CarriedInventory<? extends Carrier> getInventory() {
return (CarriedInventory<? extends Carrier> ) this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package org.spongepowered.common.mixin.inventory.impl;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ArmorStandEntity;
import net.minecraft.entity.item.minecart.ContainerMinecartEntity;
import net.minecraft.entity.merchant.villager.AbstractVillagerEntity;
import net.minecraft.entity.player.PlayerInventory;
Expand Down Expand Up @@ -62,9 +64,10 @@
SpongeUserInventory.class,
CraftingInventory.class,
CraftResultInventory.class,
ContainerMinecartEntity.class
ContainerMinecartEntity.class,
ArmorStandEntity.class
}, priority = 999)
public abstract class TraitMixin_InventoryBrige_Inventory implements InventoryAdapter, InventoryBridge {
public abstract class TraitMixin_InventoryBridge_Inventory implements InventoryAdapter, InventoryBridge {

@Nullable private SlotLensProvider impl$provider;
@Nullable private Lens impl$lens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,31 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.api.item.inventory.equipment.EquipmentTypes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.bridge.inventory.CarriedBridge;
import org.spongepowered.common.bridge.inventory.InventoryBridge;
import org.spongepowered.common.bridge.inventory.LensGeneratorBridge;
import org.spongepowered.common.inventory.adapter.InventoryAdapter;
import org.spongepowered.common.inventory.fabric.Fabric;
import org.spongepowered.common.inventory.lens.Lens;
import org.spongepowered.common.inventory.lens.impl.LensRegistrar;
import org.spongepowered.common.inventory.lens.impl.comp.EquipmentInventoryLens;
import org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens;
import org.spongepowered.common.inventory.lens.impl.slot.SlotLensProvider;
import org.spongepowered.common.inventory.lens.slots.SlotLens;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin_EquipmentFabric_Inventory implements Fabric, InventoryBridge {
public abstract class LivingEntityMixin_EquipmentFabric_Inventory implements Fabric, InventoryBridge, LensGeneratorBridge, CarriedBridge {

@Shadow public abstract ItemStack getItemStackFromSlot(EquipmentSlotType slotIn);

Expand Down Expand Up @@ -93,4 +108,24 @@ public abstract class LivingEntityMixin_EquipmentFabric_Inventory implements Fab
@Override
public void fabric$markDirty() {
}

@Override
public SlotLensProvider lensGeneratorBridge$generateSlotLensProvider() {
return new LensRegistrar.BasicSlotLensProvider(this.fabric$getSize());
}

@Override
public Lens lensGeneratorBridge$generateLens(SlotLensProvider slotLensProvider) {
Map<EquipmentType, SlotLens> equipmentLenses = new LinkedHashMap<>();
for (int i = 0, slotsLength = SLOTS.length; i < slotsLength; i++) {
EquipmentSlotType slot = SLOTS[i];
equipmentLenses.put((EquipmentType) (Object) slot, slotLensProvider.getSlotLens(i));
}
return new EquipmentInventoryLens(equipmentLenses);
}

@Override
public Optional<Carrier> bridge$getCarrier() {
return Optional.of((Carrier) this);
}
}
4 changes: 3 additions & 1 deletion src/mixins/resources/mixins.common.inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"api.TraitMixin_Viewable_Inventory_API",
"api.common.entity.player.SpongeUserInventoryMixin_Carried_Inventory_API",
"api.common.entity.player.SpongeUserInventoryMixin_Inventory_API",
"api.entity.item.ArmorStandEntityMixin_Carrier_Inventory_API",
"api.entity.item.minecart.ContainerMinecartEntityMixin_Carried_Inventory_API",
"api.entity.item.minecart.ContainerMinecartEntityMixin_Carrier_Inventory_API",
"api.entity.LivingEntity_Inventory_API",
"api.entity.merchant.villager.AbstractVillagerEntity_Carrier_Inventory_API",
"api.entity.passive.horse.AbstractHorseEntityMixin_Carrier_Inventory_API",
"api.entity.player.PlayerEntityMixin_Inventory_API",
Expand Down Expand Up @@ -53,7 +55,7 @@
"event.network.play.ServerPlayNetHandlerMixin_Inventory",
"event.tileentity.HopperTileEntityMixin_Inventory",
"impl.TraitMixin_ContainerBridge_Inventory",
"impl.TraitMixin_InventoryBrige_Inventory",
"impl.TraitMixin_InventoryBridge_Inventory",
"impl.TraitMixin_Lens_Inventory",
"impl.TraitMixin_ViewableBridge_Inventory",
"impl.common.entity.player.SpongeUserInventoryMixin_Lens_Bridge",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.spongepowered.test.datatest;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import net.kyori.adventure.text.TextComponent;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -44,6 +45,8 @@
import org.spongepowered.api.data.type.ArtTypes;
import org.spongepowered.api.data.type.AttachmentSurfaces;
import org.spongepowered.api.data.type.BannerPatternShapes;
import org.spongepowered.api.data.type.BodyParts;
import org.spongepowered.api.data.type.ChestAttachmentType;
import org.spongepowered.api.data.type.DyeColors;
import org.spongepowered.api.data.type.FoxTypes;
import org.spongepowered.api.data.type.MooshroomTypes;
Expand Down Expand Up @@ -72,6 +75,7 @@
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.explosive.EnderCrystal;
import org.spongepowered.api.entity.living.ArmorStand;
import org.spongepowered.api.entity.living.animal.Sheep;
import org.spongepowered.api.entity.living.animal.Turtle;
import org.spongepowered.api.entity.living.monster.Patroller;
Expand All @@ -87,7 +91,11 @@
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.enchantment.Enchantment;
import org.spongepowered.api.item.enchantment.EnchantmentTypes;
import org.spongepowered.api.item.inventory.Carrier;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.item.inventory.equipment.EquipmentTypes;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
import org.spongepowered.api.item.merchant.TradeOffer;
import org.spongepowered.api.util.Axis;
import org.spongepowered.api.util.Color;
Expand Down Expand Up @@ -252,17 +260,22 @@ public void testData(final ServerPlayer player) {

// TODO Keys.BLOCK_LIGHT

final Entity fallingBlock = world.createEntity(EntityTypes.FALLING_BLOCK.get(), position);
final Entity fallingBlock = world.createEntity(EntityTypes.FALLING_BLOCK.get(), position.add(0,5,0));
final BlockState sandState = BlockTypes.SAND.get().getDefaultState();
this.checkOfferData(fallingBlock, Keys.BLOCK_STATE, sandState);
this.checkOfferData(minecartEntity, Keys.BLOCK_STATE, dirtState);

// TODO Keys.BLOCK_TEMPERATURE

// TODO missing BodyPart registration
final Entity armorStand = world.createEntity(EntityTypes.ARMOR_STAND.get(), position);
// armorStand.offer(Keys.BODY_ROTATIONS, ImmutableMap.of(BodyParts.CHEST.get(), Vector3d.RIGHT));
// world.spawnEntity(armorStand);
final ArmorStand armorStand = (ArmorStand) world.createEntity(EntityTypes.ARMOR_STAND.get(), position);
armorStand.equip(EquipmentTypes.CHEST.get(), ItemStack.of(ItemTypes.LEATHER_CHESTPLATE));
armorStand.equip(EquipmentTypes.FEET.get(), ItemStack.of(ItemTypes.CHAINMAIL_BOOTS));
armorStand.equip(EquipmentTypes.HEAD.get(), ItemStack.of(ItemTypes.GOLDEN_HELMET));
armorStand.equip(EquipmentTypes.LEGS.get(), ItemStack.of(ItemTypes.DIAMOND_LEGGINGS));
armorStand.equip(EquipmentTypes.MAIN_HAND.get(), ItemStack.of(ItemTypes.DIAMOND));
armorStand.equip(EquipmentTypes.OFF_HAND.get(), ItemStack.of(ItemTypes.DIAMOND));

armorStand.offer(Keys.BODY_ROTATIONS, ImmutableMap.of(BodyParts.CHEST.get(), Vector3d.RIGHT));

// TODO wither.get(Keys.BOSS_BAR)

Expand Down Expand Up @@ -328,7 +341,7 @@ public void testData(final ServerPlayer player) {
// final Optional<ChestAttachmentType> chestAttachmentType = world.get(blockPos, Keys.CHEST_ATTACHMENT_TYPE);
// world.setBlock(blockPos.add(0, 0, 1), BlockTypes.CHEST.get().getDefaultState());

// TODO Keys.CHEST_ROTATION
this.checkOfferData(armorStand, Keys.CHEST_ROTATION, Vector3d.from(0, 90, 0));

final ItemStack leatherBoots = ItemStack.of(ItemTypes.LEATHER_BOOTS);
final ItemStack potion = ItemStack.of(ItemTypes.POTION);
Expand Down Expand Up @@ -532,11 +545,11 @@ public void testData(final ServerPlayer player) {
this.checkGetData(dirtState, Keys.HARDNESS, 0.5);
this.checkGetData(bricksState, Keys.HARDNESS, 2.0);

this.checkOfferData(armorStand, Keys.HAS_ARMS, true);
this.checkOfferData(armorStand, Keys.HAS_ARMS, false);
this.checkOfferData(armorStand, Keys.HAS_ARMS, true);

this.checkGetData(armorStand, Keys.HAS_BASE_PLATE, true);
this.checkOfferData(armorStand, Keys.HAS_BASE_PLATE, false);
this.checkOfferData(armorStand, Keys.HAS_BASE_PLATE, true);

this.checkGetData(donkey, Keys.HAS_CHEST, false);
this.checkOfferData(donkey, Keys.HAS_CHEST, true);
Expand All @@ -548,6 +561,7 @@ public void testData(final ServerPlayer player) {
this.checkOfferData(dolphin, Keys.HAS_FISH, true);

this.checkOfferData(armorStand, Keys.HAS_MARKER, true);
this.checkOfferData(armorStand, Keys.HAS_MARKER, false);

final BlockState mushroomBlockState = BlockTypes.BROWN_MUSHROOM_BLOCK.get().getDefaultState();
this.checkGetData(mushroomBlockState, Keys.HAS_PORES_DOWN, true);
Expand All @@ -559,8 +573,8 @@ public void testData(final ServerPlayer player) {

this.checkOfferData(player, Keys.HAS_VIEWED_CREDITS, true);

// TODO armorStand Keys.HEAD_ROTATION
this.checkOfferData(sheep, Keys.HEAD_ROTATION, position);
this.checkOfferData(armorStand, Keys.HEAD_ROTATION, Vector3d.from(0, 90, 0));
this.checkOfferData(sheep, Keys.HEAD_ROTATION, Vector3d.from(0, 90, 0));

// TODO Keys.HEALING_CRYSTAL

Expand Down Expand Up @@ -814,6 +828,7 @@ public void testData(final ServerPlayer player) {
// this.checkOfferData(player, Keys.IS_SLEEPING_IGNORED, true);

this.checkOfferData(armorStand, Keys.IS_SMALL, true);
this.checkOfferData(armorStand, Keys.IS_SMALL, false);

this.checkGetData(player, Keys.IS_SNEAKING, false);

Expand Down Expand Up @@ -893,8 +908,8 @@ public void testData(final ServerPlayer player) {

// TODO Keys.LEASH_HOLDER

// TODO Keys.LEFT_ARM_ROTATION
// TODO Keys.LEFT_LEG_ROTATION
this.checkOfferData(armorStand, Keys.LEFT_ARM_ROTATION, Vector3d.from(0, -90, -90));
this.checkOfferData(armorStand, Keys.LEFT_LEG_ROTATION, Vector3d.from(0, -90, -45));

final Entity vex = world.createEntity(EntityTypes.VEX.get(), position);
this.checkOfferData(vex, Keys.LIFE_TICKS, 10);
Expand Down Expand Up @@ -1054,8 +1069,8 @@ public void testData(final ServerPlayer player) {

// Keys.RESPAWN_LOCATIONS

this.checkOfferData(armorStand, Keys.RIGHT_ARM_ROTATION, Vector3d.UP);
this.checkOfferData(armorStand, Keys.RIGHT_LEG_ROTATION, Vector3d.UP);
this.checkOfferData(armorStand, Keys.RIGHT_ARM_ROTATION, Vector3d.from(0, 90, 90));
this.checkOfferData(armorStand, Keys.RIGHT_LEG_ROTATION, Vector3d.from(0, 90, 45));

this.checkOfferData(ravager, Keys.ROARING_TIME, 20);

Expand Down

0 comments on commit 0a60c31

Please sign in to comment.