Skip to content

Commit

Permalink
revert the Sammyning
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed May 29, 2024
1 parent c23a2e9 commit 75d9aed
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parchment_version=2023.09.03-1.20.1
# Mod Properties
mod_name=Lodestone
mod_id=lodestone
mod_version=1.4.37
mod_version=1.4.40
mod_license=GPLv3
mod_group_id=team.lodestar.lodestone
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ItemHolderBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState s

@Override
public InteractionResult onUse(Player player, InteractionHand hand) {
inventory.interact(player.level(), player, hand);
inventory.interact(this, player.level(), player, hand, s -> true);
return InteractionResult.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package team.lodestar.lodestone.systems.blockentity;

import io.github.fabricators_of_create.porting_lib.transfer.TransferUtil;
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemHandlerHelper;
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemStackHandlerContainer;
import io.github.fabricators_of_create.porting_lib.util.LazyOptional;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -151,24 +153,55 @@ public void dumpItems(Level level, Vec3 pos) {
}
}

public void interact(Level level, Player player, InteractionHand handIn) {
public boolean interact(LodestoneBlockEntity be, Level level, Player player, InteractionHand handIn, Predicate<ItemStack> predicate) {

if (!level.isClientSide) {
boolean res = false;
ItemStack held = player.getItemInHand(handIn);
player.swing(handIn, true);
int size = nonEmptyItemStacks.size() - 1;
if ((held.isEmpty() || firstEmptyItemIndex == -1) && size != -1) {
ItemStack takeOutStack = nonEmptyItemStacks.get(size);
if (takeOutStack.getItem().equals(held.getItem())) {
TransferUtil.insertItem(this, held);
return;
if (predicate.test(held)) {
player.swing(handIn, true);

if (held.isEmpty()) {
res = interactExtractInv(be, player);
} else {
res = interactInsertInv(be, held);
}
long extractedStack = TransferUtil.extractItem(this, held);
if (extractedStack > 0) {
TransferUtil.insertItem(this, held);
}
return res;
}
return false;
}

public boolean interactInsertInv(LodestoneBlockEntity be, ItemStack stack){
try (Transaction t = TransferUtil.getTransaction()){

long inserted = insert(ItemVariant.of(stack), stack.getCount(), t);
stack.shrink((int)inserted);
t.commit();

if (inserted > 0) {
setChanged();
be.notifyUpdate();
return true;
}
}
return false;
}

public boolean interactExtractInv(LodestoneBlockEntity be, Player player){
if (!nonEmptyItemStacks.isEmpty()) {
try (Transaction t = TransferUtil.getTransaction()) {
ItemStack takeOutStack = nonEmptyItemStacks.get(nonEmptyItemStacks.size() - 1);
long extracted = extract(ItemVariant.of(takeOutStack), takeOutStack.getCount(), t);
t.commit();
if (extracted > 0) {
ItemHandlerHelper.giveItemToPlayer(player, takeOutStack);
setChanged();
be.notifyUpdate();
return true;
}
} else {
TransferUtil.insertItem(this, held);
}
}
return false;
}
}

0 comments on commit 75d9aed

Please sign in to comment.