use of org.spongepowered.api.item.inventory.Slot in project SpongeCommon by SpongePowered.
the class MixinEntityPlayer method onSetItemStackToSlot.
@Inject(method = "setItemStackToSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/NonNullList;set(ILjava/lang/Object;)Ljava/lang/Object;"))
private void onSetItemStackToSlot(EntityEquipmentSlot slotIn, ItemStack stack, CallbackInfo ci) {
if (((IMixinInventoryPlayer) this.inventory).capturesTransactions()) {
if (slotIn == EntityEquipmentSlot.MAINHAND) {
ItemStack orig = this.inventory.mainInventory.get(this.inventory.currentItem);
Slot slot = ((PlayerInventory) this.inventory).getMain().getHotbar().getSlot(SlotIndex.of(this.inventory.currentItem)).get();
((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
} else if (slotIn == EntityEquipmentSlot.OFFHAND) {
ItemStack orig = this.inventory.offHandInventory.get(0);
Slot slot = ((PlayerInventory) this.inventory).getOffhand();
((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
} else if (slotIn.getSlotType() == EntityEquipmentSlot.Type.ARMOR) {
ItemStack orig = this.inventory.armorInventory.get(slotIn.getIndex());
Slot slot = ((PlayerInventory) this.inventory).getEquipment().getSlot(SlotIndex.of(slotIn.getIndex())).get();
((IMixinInventoryPlayer) this.inventory).getCapturedTransactions().add(new SlotTransaction(slot, ItemStackUtil.snapshotOf(orig), ItemStackUtil.snapshotOf(stack)));
}
}
}
use of org.spongepowered.api.item.inventory.Slot in project SpongeCommon by SpongePowered.
the class MixinInventoryPlayer method onConstructed.
@Inject(method = "<init>*", at = @At("RETURN"), remap = false)
private void onConstructed(EntityPlayer playerIn, CallbackInfo ci) {
// Find offhand slot
for (NonNullList<ItemStack> inventory : this.allInventories) {
if (inventory == this.offHandInventory) {
break;
}
this.offhandIndex += inventory.size();
}
// Set Carrier if we got a real Player
if (playerIn instanceof EntityPlayerMP) {
this.carrier = (Player) playerIn;
this.inventory = new IInventoryFabric((IInventory) this);
Class clazz = this.getClass();
if (clazz == InventoryPlayer.class) {
// Build Player Lens
// We only care about Server inventories
this.slots = new SlotCollection.Builder().add(this.mainInventory.size()).add(this.offHandInventory.size()).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.BOOTS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.LEGGINGS)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.CHESTPLATE)).add(EquipmentSlotAdapter.class, index -> new EquipmentSlotLensImpl(index, i -> true, t -> true, e -> e == EquipmentTypes.HEADWEAR)).add(this.armorInventory.size() - 4, EquipmentSlotAdapter.class).add(this.getSizeInventory() - this.mainInventory.size() - this.offHandInventory.size() - this.armorInventory.size()).build();
this.lens = new PlayerInventoryLens(this, this.slots);
} else if (this.getSizeInventory() != 0) {
// Fallback OrderedLens when not 0 sized inventory
this.slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
this.lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
}
}
}
use of org.spongepowered.api.item.inventory.Slot in project SpongeCommon by SpongePowered.
the class MixinInventoryPlayer method onAdd.
@Redirect(method = "storePartialItemStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/InventoryPlayer;addResource(ILnet/minecraft/item/ItemStack;)I"))
public int onAdd(InventoryPlayer inv, int index, ItemStack stack) {
if (this.doCapture) {
// Capture items getting picked up
Slot slot = index == 40 ? this.getOffhand() : getSpongeSlot(index);
ItemStackSnapshot original = ItemStackUtil.snapshotOf(this.getStackInSlot(index));
int result = this.addResource(index, stack);
ItemStackSnapshot replacement = ItemStackUtil.snapshotOf(this.getStackInSlot(index));
this.capturedTransactions.add(new SlotTransaction(slot, original, replacement));
return result;
}
return this.addResource(index, stack);
}
use of org.spongepowered.api.item.inventory.Slot in project RedProtect by FabioZumbi12.
the class Region method denyEnterWithItens.
public boolean denyEnterWithItens(Player p) {
if (!flagExists("deny-enter-items")) {
return true;
}
if (checkAllowedPlayer(p)) {
return true;
}
Iterable<Slot> SlotItems = p.getInventory().slots();
String[] items = flags.get("deny-enter-items").toString().replace(" ", "").split(",");
for (Slot slot : SlotItems) {
if (slot.peek().isPresent()) {
String SlotType = slot.peek().get().getItem().getName();
for (String comp : items) {
if (SlotType.equalsIgnoreCase(comp)) {
return false;
}
}
}
}
return true;
}
use of org.spongepowered.api.item.inventory.Slot in project LanternServer by LanternPowered.
the class ConsumableInteractionBehavior method tryUse.
@Override
public BehaviorResult tryUse(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final Optional<Player> optPlayer = context.getContext(ContextKeys.PLAYER);
if (optPlayer.isPresent()) {
final Player player = optPlayer.get();
final ItemStack itemStack = context.requireContext(ContextKeys.USED_ITEM_STACK);
final FoodRestorationProperty foodRestorationProperty = itemStack.getProperty(FoodRestorationProperty.class).orElse(null);
if (foodRestorationProperty != null && foodRestorationProperty.getValue() != 0.0) {
final Optional<Integer> maxFood = player.get(LanternKeys.MAX_FOOD_LEVEL);
final Optional<Integer> optFoodLevel = player.get(Keys.FOOD_LEVEL);
if (optFoodLevel.isPresent()) {
player.offer(Keys.FOOD_LEVEL, Math.min(optFoodLevel.get() + foodRestorationProperty.getValue(), maxFood.orElse(Integer.MAX_VALUE)));
}
}
final HealthRestorationProperty healthRestorationProperty = itemStack.getProperty(HealthRestorationProperty.class).orElse(null);
if (healthRestorationProperty != null && healthRestorationProperty.getValue() != 0.0) {
final Optional<Double> maxHealth = player.get(Keys.MAX_HEALTH);
final Optional<Double> optHealth = player.get(Keys.HEALTH);
if (optHealth.isPresent()) {
player.offer(Keys.HEALTH, Math.min(optHealth.get() + healthRestorationProperty.getValue(), maxHealth.orElse(Double.MAX_VALUE)));
}
}
final SaturationProperty saturationProperty = itemStack.getProperty(SaturationProperty.class).orElse(null);
if (saturationProperty != null && saturationProperty.getValue() != 0.0) {
final Optional<Double> optSaturation = player.get(Keys.SATURATION);
if (optSaturation.isPresent()) {
player.offer(Keys.SATURATION, Math.min(optSaturation.get() + saturationProperty.getValue(), player.get(Keys.FOOD_LEVEL).orElse(20)));
}
}
final ApplicableEffectProperty applicableEffectProperty = itemStack.getProperty(ApplicableEffectProperty.class).orElse(null);
if (applicableEffectProperty != null && !applicableEffectProperty.getValue().isEmpty()) {
final List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).orElse(Collections.emptyList());
player.offer(Keys.POTION_EFFECTS, PotionEffectHelper.merge(potionEffects, applicableEffectProperty.getValue()));
}
if (this.consumer != null) {
this.consumer.apply(player, pipeline, context);
}
if (!player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
final Slot slot = context.requireContext(ContextKeys.USED_SLOT);
slot.poll(1);
if (this.restItemSupplier != null) {
if (slot.peek().isPresent()) {
((LanternPlayer) player).getInventory().getMain().offer(this.restItemSupplier.get());
} else {
slot.set(this.restItemSupplier.get());
}
}
}
return BehaviorResult.SUCCESS;
}
return BehaviorResult.PASS;
}
Aggregations