Skip to content

Commit

Permalink
Work on deprecations for 1.19.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jan 15, 2023
1 parent dd6a323 commit 868a983
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package appeng.menu.me.interaction;
package appeng.api.behaviors;

import com.google.common.base.Preconditions;

import org.jetbrains.annotations.Nullable;

import net.minecraft.world.entity.player.Player;

import appeng.api.behaviors.ContainerItemStrategy;
import appeng.api.config.Actionable;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appeng.menu.me.interaction;
package appeng.api.behaviors;

import java.util.List;
import java.util.Set;
Expand All @@ -11,15 +11,16 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategy;
import appeng.api.stacks.AEFluidKey;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyType;
import appeng.api.stacks.GenericStack;
import appeng.util.CowMap;

// TODO 1.20: Rename -> ContainerItemStrategies, make API. This is not purely for UI now.
public class StackInteractions {
/**
* Manages {@link ContainerItemStrategy} registrations for {@linkplain AEKeyType key types}.
*/
public class ContainerItemStrategies {
private static final CowMap<AEKeyType, ContainerItemStrategy<?, ?>> strategies = CowMap.identityHashMap();

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyType;
import appeng.api.stacks.GenericStack;
import appeng.menu.me.interaction.StackInteractions;

/**
* Strategy to interact with the non-item keys held by container items, for example the fluid contained in a bucket.
Expand Down Expand Up @@ -44,7 +43,7 @@ default C findPlayerSlotContext(Player player, int slot) {
GenericStack getExtractableContent(C context);

static <T extends AEKey> void register(AEKeyType keyType, Class<T> keyClass, ContainerItemStrategy<T, ?> strategy) {
StackInteractions.register(keyType, keyClass, strategy);
ContainerItemStrategies.register(keyType, keyClass, strategy);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appeng.menu.me.interaction;
package appeng.api.behaviors;

import net.minecraft.network.chat.Component;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package appeng.menu.me.interaction;
package appeng.api.behaviors;

import org.jetbrains.annotations.Nullable;

Expand All @@ -13,14 +13,13 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategy;
import appeng.api.config.Actionable;
import appeng.api.stacks.AEFluidKey;
import appeng.api.stacks.GenericStack;
import appeng.util.GenericContainerHelper;
import appeng.util.fluid.FluidSoundHelper;

public class FluidContainerItemStrategy implements ContainerItemStrategy<AEFluidKey, Storage<FluidVariant>> {
class FluidContainerItemStrategy implements ContainerItemStrategy<AEFluidKey, Storage<FluidVariant>> {
@Override
public @Nullable GenericStack getContainedStack(ItemStack stack) {
return GenericContainerHelper.getContainedFluidStack(stack);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/appeng/client/gui/AEBaseScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.behaviors.EmptyingAction;
import appeng.api.client.AEStackRendering;
import appeng.api.stacks.GenericStack;
import appeng.client.Point;
Expand All @@ -79,8 +81,6 @@
import appeng.menu.AEBaseMenu;
import appeng.menu.SlotSemantic;
import appeng.menu.SlotSemantics;
import appeng.menu.me.interaction.EmptyingAction;
import appeng.menu.me.interaction.StackInteractions;
import appeng.menu.slot.AppEngSlot;
import appeng.menu.slot.CraftingTermSlot;
import appeng.menu.slot.DisabledSlot;
Expand Down Expand Up @@ -260,7 +260,7 @@ protected EmptyingAction getEmptyingAction(Slot slot, ItemStack carried) {
}

// See if we should offer the left-/right-click differentiation for setting a different filter
var emptyingAction = StackInteractions.getEmptyingAction(carried);
var emptyingAction = ContainerItemStrategies.getEmptyingAction(carried);
if (emptyingAction != null) {
var wrappedStack = GenericStack.wrapInItemStack(new GenericStack(emptyingAction.what(), 1));
if (configInv.isItemValid(slot.slot, wrappedStack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.client.AEStackRendering;
import appeng.api.config.ActionItems;
import appeng.api.config.Setting;
Expand Down Expand Up @@ -83,7 +84,6 @@
import appeng.menu.me.common.GridInventoryEntry;
import appeng.menu.me.common.MEStorageMenu;
import appeng.menu.me.crafting.CraftingStatusMenu;
import appeng.menu.me.interaction.StackInteractions;
import appeng.util.ExternalSearch;
import appeng.util.IConfigManagerListener;
import appeng.util.Platform;
Expand Down Expand Up @@ -219,7 +219,7 @@ protected void handleGridInventoryEntryMouseClick(@Nullable GridInventoryEntry e

// Is there an emptying action? If so, send it to the server
if (mouseButton == 1 && clickType == ClickType.PICKUP && !menu.getCarried().isEmpty()) {
var emptyingAction = StackInteractions.getEmptyingAction(menu.getCarried());
var emptyingAction = ContainerItemStrategies.getEmptyingAction(menu.getCarried());
if (emptyingAction != null && menu.isKeyVisible(emptyingAction.what())) {
menu.handleInteraction(-1, InventoryAction.EMPTY_ITEM);
return;
Expand Down Expand Up @@ -612,7 +612,7 @@ protected void renderTooltip(PoseStack poseStack, int x, int y) {
if (this.hoveredSlot instanceof RepoSlot repoSlot) {
var carried = menu.getCarried();
if (!carried.isEmpty()) {
var emptyingAction = StackInteractions.getEmptyingAction(carried);
var emptyingAction = ContainerItemStrategies.getEmptyingAction(carried);
if (emptyingAction != null && menu.isKeyVisible(emptyingAction.what())) {
drawTooltip(
poseStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.behaviors.EmptyingAction;
import appeng.api.config.ActionItems;
import appeng.api.stacks.GenericStack;
import appeng.client.gui.me.common.MEStorageScreen;
Expand All @@ -45,8 +47,6 @@
import appeng.core.sync.packets.InventoryActionPacket;
import appeng.helpers.InventoryAction;
import appeng.menu.SlotSemantics;
import appeng.menu.me.interaction.EmptyingAction;
import appeng.menu.me.interaction.StackInteractions;
import appeng.menu.me.items.PatternEncodingTermMenu;
import appeng.parts.encoding.EncodingMode;

Expand Down Expand Up @@ -141,7 +141,7 @@ protected EmptyingAction getEmptyingAction(Slot slot, ItemStack carried) {
// does not work out of the box.
if (menu.isProcessingPatternSlot(slot)) {
// See if we should offer the left-/right-click differentiation for setting a different filter
var emptyingAction = StackInteractions.getEmptyingAction(carried);
var emptyingAction = ContainerItemStrategies.getEmptyingAction(carried);
if (emptyingAction != null) {
return emptyingAction;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/core/localization/Tooltips.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import net.minecraft.network.chat.TextColor;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.EmptyingAction;
import appeng.api.config.PowerUnits;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AmountFormat;
import appeng.api.stacks.GenericStack;
import appeng.core.AEConfig;
import appeng.menu.me.interaction.EmptyingAction;

/**
* Static utilities for constructing tooltips in various places.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ interface CraftingDifferenceListener {
}

this.finalOutput = GenericStack.readTag(data.getCompound(NBT_FINAL_OUTPUT));
// TODO 1.20: Remove
if (data.contains(NBT_REMAINING_AMOUNT)) {
this.remainingAmount = data.getLong(NBT_REMAINING_AMOUNT);
} else {
this.remainingAmount = this.finalOutput.amount();
}
this.remainingAmount = data.getLong(NBT_REMAINING_AMOUNT);
this.waitingFor = new ListCraftingInventory(postCraftingDifference::onCraftingDifference);
this.waitingFor.readFromNBT(data.getList(NBT_WAITING_FOR, Tag.TAG_COMPOUND));
this.timeTracker = new ElapsedTimeTracker(data.getCompound(NBT_TIME_TRACKER));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/appeng/crafting/pattern/AECraftingPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import javax.annotation.Nullable;

import net.minecraft.client.player.Input;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.CraftingContainer;
Expand All @@ -39,6 +38,7 @@
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.level.Level;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.crafting.IPatternDetails;
import appeng.api.stacks.AEFluidKey;
import appeng.api.stacks.AEItemKey;
Expand All @@ -48,7 +48,6 @@
import appeng.api.stacks.KeyCounter;
import appeng.blockentity.crafting.IMolecularAssemblerSupportedPattern;
import appeng.menu.AutoCraftingMenu;
import appeng.menu.me.interaction.StackInteractions;

public class AECraftingPattern implements IPatternDetails, IMolecularAssemblerSupportedPattern {
public static final int CRAFTING_GRID_DIMENSION = 3;
Expand Down Expand Up @@ -451,7 +450,7 @@ private GenericStack getItemOrFluidInput(int slot, GenericStack item) {
return item;
}

var containedFluid = StackInteractions.getContainedStack(itemKey.toStack(), AEKeyType.fluids());
var containedFluid = ContainerItemStrategies.getContainedStack(itemKey.toStack(), AEKeyType.fluids());
// Milk is not natively a fluid container, but it might be made one by other mods
var isBucket = itemKey.getItem() instanceof BucketItem || itemKey.getItem() instanceof MilkBucketItem;

Expand Down
14 changes: 1 addition & 13 deletions src/main/java/appeng/facade/FacadeContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -47,13 +46,6 @@ public class FacadeContainer implements IFacadeContainer {
.map(d -> "facade" + StringUtils.capitalize(d.getSerializedName()))
.toArray(String[]::new);

/**
* Key names to store facades (the old ones pre 1.20). TODO: Remove in 1.20
*/
private static final String[] NBT_KEY_OLD_NAMES = Arrays.stream(Direction.values())
.map(d -> "facade:" + d.ordinal())
.toArray(String[]::new);

private final CableBusStorage storage;
private final Consumer<Direction> changeCallback;

Expand Down Expand Up @@ -98,11 +90,7 @@ public void readFromNBT(CompoundTag c) {
for (var side : Direction.values()) {
this.storage.removeFacade(side);

Tag tag = c.get(NBT_KEY_NAMES[side.ordinal()]);
if (tag == null) {
tag = c.get(NBT_KEY_OLD_NAMES[side.ordinal()]);
}

var tag = c.get(NBT_KEY_NAMES[side.ordinal()]);
if (tag instanceof CompoundTag facadeTag) {
var is = ItemStack.of(facadeTag);
if (!is.isEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/items/misc/WrappedGenericStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.config.Actionable;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.GenericStack;
import appeng.core.AppEng;
import appeng.core.definitions.AEItems;
import appeng.items.AEBaseItem;
import appeng.menu.me.interaction.StackInteractions;
import appeng.util.Platform;

/**
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean overrideOtherStackedOnMe(ItemStack itemInSlot, ItemStack otherSta
// Allow picking up fluids items with a fluid container, this is a special case for fluids
var what = unwrapWhat(itemInSlot);
if (clickAction == ClickAction.PRIMARY) {
var heldContainer = StackInteractions.findCarriedContextForKey(what, player, player.containerMenu);
var heldContainer = ContainerItemStrategies.findCarriedContextForKey(what, player, player.containerMenu);
if (heldContainer != null) {
long amount = unwrapAmount(itemInSlot);
long inserted = heldContainer.insert(what, amount, Actionable.MODULATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.level.Level;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.config.Actionable;
import appeng.api.implementations.menuobjects.IMenuItem;
import appeng.api.stacks.AEItemKey;
Expand All @@ -39,7 +40,6 @@
import appeng.me.helpers.PlayerSource;
import appeng.menu.MenuOpener;
import appeng.menu.locator.MenuLocators;
import appeng.menu.me.interaction.StackInteractions;
import appeng.util.InteractionUtil;

public abstract class AbstractPortableCell extends AEBasePoweredItem
Expand Down Expand Up @@ -241,7 +241,7 @@ protected boolean tryInsertFromPlayerOwnedItem(Player player,
ItemStack cellStack,
ItemStack otherStack) {
// Try all available strategies
for (var keyType : StackInteractions.getSupportedKeyTypes()) {
for (var keyType : ContainerItemStrategies.getSupportedKeyTypes()) {
if (tryInsertFromPlayerOwnedItem(player, cellStack, otherStack, keyType)) {
return true;
}
Expand All @@ -266,7 +266,7 @@ protected boolean tryInsertFromPlayerOwnedItem(Player player,
ItemStack cellStack,
ItemStack otherStack,
AEKeyType keyType) {
var context = StackInteractions.findOwnedItemContext(keyType, player, otherStack);
var context = ContainerItemStrategies.findOwnedItemContext(keyType, player, otherStack);
if (context != null) {
var containedStack = context.getExtractableContent();
if (containedStack != null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/appeng/menu/AEBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.implementations.menuobjects.ItemMenuHost;
Expand All @@ -63,7 +64,6 @@
import appeng.me.helpers.PlayerSource;
import appeng.menu.guisync.DataSynchronization;
import appeng.menu.locator.MenuLocator;
import appeng.menu.me.interaction.StackInteractions;
import appeng.menu.slot.AppEngSlot;
import appeng.menu.slot.CraftingMatrixSlot;
import appeng.menu.slot.CraftingTermSlot;
Expand Down Expand Up @@ -617,7 +617,7 @@ protected interface FillingSource {
}

protected final void handleFillingHeldItem(FillingSource source, AEKey what) {
var ctx = StackInteractions.findCarriedContextForKey(what, getPlayer(), this);
var ctx = ContainerItemStrategies.findCarriedContextForKey(what, getPlayer(), this);
if (ctx == null) {
return;
}
Expand Down Expand Up @@ -656,7 +656,7 @@ protected interface EmptyingSink {
}

protected final void handleEmptyHeldItem(EmptyingSink sink) {
var ctx = StackInteractions.findCarriedContext(null, getPlayer(), this);
var ctx = ContainerItemStrategies.findCarriedContext(null, getPlayer(), this);
if (ctx == null) {
return;
}
Expand Down Expand Up @@ -720,7 +720,7 @@ private void handleFakeSlotAction(FakeSlot fakeSlot, InventoryAction action) {

break;
case EMPTY_ITEM: {
var emptyingAction = StackInteractions.getEmptyingAction(hand);
var emptyingAction = ContainerItemStrategies.getEmptyingAction(hand);
if (emptyingAction != null) {
fakeSlot.set(GenericStack.wrapInItemStack(emptyingAction.what(), emptyingAction.maxAmount()));
}
Expand Down
Loading

0 comments on commit 868a983

Please sign in to comment.