Skip to content

Commit

Permalink
Reimplement mistakenly-removed Scribes' Table integration
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Oct 23, 2024
1 parent 83aed8d commit 69cc667
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
98 changes: 98 additions & 0 deletions src/main/java/gripe/_90/arseng/mixin/ScribesTileMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package gripe._90.arseng.mixin;

import java.util.List;
import java.util.Objects;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.hollingsworth.arsnouveau.common.block.tile.ModdedTile;
import com.hollingsworth.arsnouveau.common.block.tile.ScribesTile;
import com.hollingsworth.arsnouveau.common.entity.EntityFlyingItem;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import appeng.api.AECapabilities;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.stacks.AEItemKey;
import appeng.api.storage.MEStorage;

@Mixin(value = ScribesTile.class, remap = false)
public abstract class ScribesTileMixin extends ModdedTile {
@Shadow
public List<ItemStack> consumedStacks;

public ScribesTileMixin(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

@Shadow
public abstract boolean canConsumeItemstack(ItemStack stack);

@Inject(method = "takeNearby", at = @At("TAIL"))
private void takeFromInterfaces(CallbackInfo ci) {
if (level == null) {
return;
}

var area = BlockPos.betweenClosed(
worldPosition.north(6).east(6).below(2),
worldPosition.south(6).west(6).above(2));

for (var pos : area) {
var be = level.getBlockEntity(pos);

if (be != null) {
var hasExtracted = false;

if (level.getCapability(AECapabilities.ME_STORAGE, pos, level.getBlockState(pos), be, null)
instanceof MEStorage storage) {
arseng$extract(storage, pos);
hasExtracted = true;
}

if (hasExtracted) {
return;
}

for (var side : Direction.values()) {
if (level.getCapability(AECapabilities.ME_STORAGE, pos, level.getBlockState(pos), be, side)
instanceof MEStorage storage) {
arseng$extract(storage, pos);
hasExtracted = true;
}

if (hasExtracted) {
return;
}
}
}
}
}

@Unique
private void arseng$extract(MEStorage storage, BlockPos pos) {
for (var stored : storage.getAvailableStacks()) {
if (stored.getKey() instanceof AEItemKey item && canConsumeItemstack(item.wrapForDisplayOrFilter())) {
var extracted = storage.extract(item, 1, Actionable.MODULATE, IActionSource.empty());
var taken = item.toStack((int) extracted);
consumedStacks.add(taken);

var flyingItem = new EntityFlyingItem(level, pos, getBlockPos());
flyingItem.setStack(taken);
Objects.requireNonNull(level).addFreshEntity(flyingItem);
updateBlock();
return;
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/arseng.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"minVersion": "0.8.5",
"required": true,
"package": "gripe._90.arseng.mixin",
"mixins": ["ConfigInventoryMixin"],
"mixins": ["ConfigInventoryMixin", "ScribesTileMixin"],
"injectors": {
"defaultRequire": 1
}
Expand Down

0 comments on commit 69cc667

Please sign in to comment.