Skip to content

Commit

Permalink
1.21 Port XXXXIV
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 22, 2024
1 parent 0c65d1c commit bc5275b
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.simibubi.create.compat.Mods;
import com.simibubi.create.foundation.utility.RegisteredObjects;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.neoforged.neoforge.items.IItemHandler;

Expand All @@ -23,7 +24,7 @@ public boolean isFromThisMod(BlockEntity be) {

@Override
public long getSpaceInSlot(IItemHandler inv, int slot) {
return ((long) inv.getSlotLimit(slot) * inv.getStackInSlot(slot).getMaxStackSize()) / 64;
return ((long) inv.getSlotLimit(slot) * inv.getStackInSlot(slot).getOrDefault(DataComponents.MAX_STACK_SIZE, 64)) / 64;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.HashMap;

import org.jetbrains.annotations.Nullable;

import com.simibubi.create.content.contraptions.behaviour.MovementContext;
import com.simibubi.create.foundation.mixin.accessor.DispenserBlockAccessor;

Expand All @@ -18,6 +20,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -89,9 +92,11 @@ protected void activate(MovementContext context, BlockPos pos) {
state = context.state;
}

// FIXME 1.21: make sure this is correct
BlockSource blockSource = new BlockSource(serverLevel, pos, state, null);
//ContraptionBlockSource blockSource = new ContraptionBlockSource(context, pos, clostestFacing);
@Nullable DispenserBlockEntity blockEntity = null;
if (context.world.getBlockEntity(pos) instanceof DispenserBlockEntity dispenserBlockEntity)
blockEntity = dispenserBlockEntity;

BlockSource blockSource = new BlockSource(serverLevel, pos, state, blockEntity);

if (behavior.getClass() != DefaultDispenseItemBehavior.class) { // There is a dispense item behaviour registered for the vanilla dispenser
setItemStackAt(location, behavior.dispense(blockSource, itemStack), context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -40,10 +41,10 @@ public void visitNewPosition(MovementContext context, BlockPos pos) {
private void collectItems(MovementContext context) {
getStacks(context).stream()
.filter(itemStack -> !itemStack.isEmpty() && itemStack.getItem() != Items.AIR
&& itemStack.getMaxStackSize() > itemStack.getCount())
&& itemStack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) > itemStack.getCount())
.forEach(itemStack -> itemStack.grow(ItemHelper
.extract(context.contraption.getSharedInventory(), (otherItemStack) -> ItemStack.isSameItemSameComponents(itemStack, otherItemStack),
ItemHelper.ExtractionCountMode.UPTO, itemStack.getMaxStackSize() - itemStack.getCount(), false)
ItemHelper.ExtractionCountMode.UPTO, itemStack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) - itemStack.getCount(), false)
.getCount()));
}

Expand All @@ -68,7 +69,7 @@ private ArrayList<DispenseItemLocation> getUseableLocations(MovementContext cont
ItemStack testStack = getItemStackAt(location, context);
if (testStack == null || testStack.isEmpty())
continue;
if (testStack.getMaxStackSize() == 1) {
if (testStack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) == 1) {
location = new DispenseItemLocation(false, ItemHelper.findFirstMatchingSlotIndex(
context.contraption.getSharedInventory(), ItemHelper.sameItemPredicate(testStack)));
if (!getItemStackAt(location, context).isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.Container;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;


@MethodsReturnNonnullByDefault
Expand Down Expand Up @@ -92,7 +92,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate)
if (existing.isEmpty())
return ItemStack.EMPTY;

int toExtract = Math.min(amount, existing.getMaxStackSize());
int toExtract = Math.min(amount, existing.getOrDefault(DataComponents.MAX_STACK_SIZE, 64));

if (existing.getCount() <= toExtract)
{
Expand Down Expand Up @@ -135,6 +135,6 @@ private void validateSlotIndex(int slot)

private int getStackLimit(int slot, ItemStack stack)
{
return Math.min(getSlotLimit(slot), stack.getMaxStackSize());
return Math.min(getSlotLimit(slot), stack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -152,7 +153,7 @@ private void tickPlayers() {
}

int count = playerStack.getCount();
int targetAmount = (referenceItem.getMaxStackSize() + 1) / 2;
int targetAmount = (referenceItem.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) + 1) / 2;

if (count < targetAmount) {
int amountToReplenish = targetAmount - count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.simibubi.create.foundation.utility.NBTHelper;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void settle(int compartment) {
ItemStack stackInSlot = getStackInSlot(compartment * STACKS_PER_COMPARTMENT + i);
totalCount += stackInSlot.getCount();
if (!shouldBeEmpty)
shouldBeEmpty = stackInSlot.isEmpty() || stackInSlot.getCount() != stackInSlot.getMaxStackSize();
shouldBeEmpty = stackInSlot.isEmpty() || stackInSlot.getCount() != stackInSlot.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
else if (!stackInSlot.isEmpty()) {
valid = false;
sample = stackInSlot;
Expand All @@ -80,7 +81,7 @@ else if (!stackInSlot.isEmpty()) {
} else {
for (int i = 0; i < STACKS_PER_COMPARTMENT; i++) {
ItemStack copy = totalCount <= 0 ? ItemStack.EMPTY
: sample.copyWithCount(Math.min(totalCount, sample.getMaxStackSize()));
: sample.copyWithCount(Math.min(totalCount, sample.getOrDefault(DataComponents.MAX_STACK_SIZE, 64)));
setStackInSlot(compartment * STACKS_PER_COMPARTMENT + i, copy);
totalCount -= copy.getCount();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simibubi.create.content.kinetics.belt.transport;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;

Expand Down Expand Up @@ -64,7 +65,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {

@Override
public int getSlotLimit(int slot) {
return Math.min(getStackInSlot(slot).getMaxStackSize(), 64);
return Math.min(getStackInSlot(slot).getOrDefault(DataComponents.MAX_STACK_SIZE, 64), 64);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemHandlerHelper;

public class DeployerItemHandler implements IItemHandlerModifiable {

Expand Down Expand Up @@ -60,7 +60,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!ItemStack.isSameItemSameComponents(held, stack))
return stack;

int space = held.getMaxStackSize() - held.getCount();
int space = held.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) - held.getCount();
ItemStack remainder = stack.copy();
ItemStack split = remainder.split(space);

Expand Down Expand Up @@ -110,7 +110,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {

@Override
public int getSlotLimit(int slot) {
return Math.min(getStackInSlot(slot).getMaxStackSize(), 64);
return Math.min(getStackInSlot(slot).getOrDefault(DataComponents.MAX_STACK_SIZE, 64), 64);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simibubi.create.content.logistics.chute;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;

Expand Down Expand Up @@ -41,7 +42,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {

@Override
public int getSlotLimit(int slot) {
return Math.min(64, getStackInSlot(slot).getMaxStackSize());
return Math.min(64, getStackInSlot(slot).getOrDefault(DataComponents.MAX_STACK_SIZE, 64));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import net.neoforged.neoforge.items.ItemStackHandler;

@MethodsReturnNonnullByDefault
Expand All @@ -32,7 +32,7 @@ public ItemStack getStackInSlot(int slot) {
if (stack == null)
return ItemStack.EMPTY;
if (!stack.isEmpty())
return stack.copyWithCount(stack.getMaxStackSize());
return stack.copyWithCount(stack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64));
return stack;
}

Expand All @@ -52,7 +52,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (stack == null)
return ItemStack.EMPTY;
if (!stack.isEmpty())
return stack.copyWithCount(Math.min(stack.getMaxStackSize(), amount));
return stack.copyWithCount(Math.min(stack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64), amount));
return ItemStack.EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import com.simibubi.create.foundation.utility.Lang;

import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ShulkerBoxBlock;

Expand Down Expand Up @@ -91,22 +89,19 @@ private static boolean isShulker(ItemStack stack) {
public boolean canApply(ItemStack testStack) {
if (!isShulker(testStack))
return false;
// FIXME 1.21: Checkover, not sure if this is where all of this is stored - Might be in block entity data instead
CustomData data = testStack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY);
CompoundTag compoundnbt = data.copyTag();
if (compoundnbt == null || data == CustomData.EMPTY)
ItemContainerContents contents = testStack.getOrDefault(DataComponents.CONTAINER, ItemContainerContents.EMPTY);
if (contents == ItemContainerContents.EMPTY)
return requiredSize.test(0);
if (compoundnbt.contains("LootTable", 8))
if (testStack.has(DataComponents.CONTAINER_LOOT))
return false;
if (compoundnbt.contains("Items", 9)) {
int rawSize = compoundnbt.getList("Items", 10).size();
if (contents.getSlots() > 0) {
int rawSize = contents.getSlots();
if (rawSize < 27)
return requiredSize.test(rawSize);

NonNullList<ItemStack> inventory = NonNullList.withSize(27, ItemStack.EMPTY);
// FIXME 1.21: checkover
ContainerHelper.loadAllItems(compoundnbt, inventory, RegistryAccess.EMPTY);
boolean isFull = inventory.stream().allMatch(itemStack -> !itemStack.isEmpty() && itemStack.getCount() == itemStack.getMaxStackSize());
contents.copyInto(inventory);
boolean isFull = inventory.stream().allMatch(itemStack -> !itemStack.isEmpty() && itemStack.getCount() == itemStack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64));
return requiredSize.test(isFull ? Integer.MAX_VALUE : rawSize);
}
return requiredSize.test(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simibubi.create.content.logistics.tunnel;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.items.IItemHandler;

Expand Down Expand Up @@ -47,7 +48,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {

@Override
public int getSlotLimit(int slot) {
return blockEntity.stackToDistribute.isEmpty() ? 64 : blockEntity.stackToDistribute.getMaxStackSize();
return blockEntity.stackToDistribute.isEmpty() ? 64 : blockEntity.stackToDistribute.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void updateCurrentLevel() {
.filter(compat -> compat.isFromThisMod(targetBlockEntity))
.map(compat -> compat.getSpaceInSlot(inv, finalSlot))
.findFirst()
.orElseGet(() -> (long) Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(finalSlot)));
.orElseGet(() -> (long) Math.min(stackInSlot.getOrDefault(DataComponents.MAX_STACK_SIZE, 64), inv.getSlotLimit(finalSlot)));

int count = stackInSlot.getCount();
if (space == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import net.minecraft.ChatFormatting;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -52,7 +53,7 @@ protected boolean test(Level level, Train train, CompoundTag context) {
continue;

if (stacks)
foundItems += stackInSlot.getCount() == stackInSlot.getMaxStackSize() ? 1 : 0;
foundItems += stackInSlot.getCount() == stackInSlot.getOrDefault(DataComponents.MAX_STACK_SIZE, 64) ? 1 : 0;
else
foundItems += stackInSlot.getCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void applySettings(ServerPlayer player, StationBlockEntity be) {
if (doorControl != null)
be.doorControls.set(doorControl);

if (!name.isBlank())
if (name != null && !name.isBlank())
be.updateName(name);

if (!(blockState.getBlock() instanceof StationBlock))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -130,7 +131,7 @@ public void renderContents(PoseStack ms, MultiBufferSource buffer) {
return;

Font font = Minecraft.getInstance().font;
boolean wildcard = count == 0 || upTo && count >= stack.getMaxStackSize();
boolean wildcard = count == 0 || upTo && count >= stack.getOrDefault(DataComponents.MAX_STACK_SIZE, 64);
Component countString = Components.literal(wildcard ? "*" : count + "");
ms.translate(17.5f, -5f, 7f);

Expand Down
Loading

0 comments on commit bc5275b

Please sign in to comment.