Skip to content

Commit

Permalink
Merge branch 'zeta120' of https://github.com/VazkiiMods/Quark into ze…
Browse files Browse the repository at this point in the history
…ta120
  • Loading branch information
MehVahdJukaar committed Jan 6, 2024
2 parents 253cce5 + 786f59a commit dd722cf
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@

package org.violetmoon.quark.content.automation.block.be;

import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;

import org.violetmoon.quark.content.automation.block.CrafterBlock;
import org.violetmoon.quark.content.automation.inventory.CrafterMenu;
import org.violetmoon.quark.content.automation.module.CrafterModule;

import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockSource;
import net.minecraft.core.BlockSourceImpl;
import net.minecraft.core.Direction;
import net.minecraft.core.*;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.NonNullList;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -56,17 +43,21 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.StackedContents;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.violetmoon.quark.content.automation.block.CrafterBlock;
import org.violetmoon.quark.content.automation.inventory.CrafterMenu;
import org.violetmoon.quark.content.automation.module.CrafterModule;

import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;

public class CrafterBlockEntity extends BaseContainerBlockEntity implements CraftingContainer, WorldlyContainer {
private static final DispenseItemBehavior BEHAVIOR = new CraftDispenseBehavior();
Expand All @@ -76,6 +67,7 @@ public class CrafterBlockEntity extends BaseContainerBlockEntity implements Craf
public final ContainerData delegate;
private boolean didInitialScan = false;


public CrafterBlockEntity(BlockPos pos, BlockState state) {
super(CrafterModule.blockEntityType, pos, state);
delegate = new ContainerData() {
Expand Down Expand Up @@ -152,6 +144,7 @@ public void craft() {
}
}
takeItems();
update();
}
}
}
Expand Down Expand Up @@ -236,8 +229,6 @@ public static ItemStack getResult(Level world, CraftingContainer craftingInvento
}
}
return ItemStack.EMPTY;
// handler.setPreviousTrackedSlot(0, itemStack);
// serverPlayerEntity.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(handler.syncId, handler.nextRevision(), 0, itemStack));
}

public void update() {
Expand Down Expand Up @@ -303,7 +294,7 @@ public void clearContent() {

@Override
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
return new CrafterMenu(syncId, playerInventory, this, result, delegate);
return new CrafterMenu(syncId, playerInventory, (it) -> new TransientCraftingContainer(it, 3, 3, stacks), result, delegate, ContainerLevelAccess.create(level, getBlockPos()));
}

@Override
Expand All @@ -313,8 +304,9 @@ protected Component getDefaultName() {

@Override
public void fillStackedContents(StackedContents finder) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'provideRecipeInputs'");
for(ItemStack itemstack : stacks) {
finder.accountSimpleStack(itemstack);
}
}

@Override
Expand Down Expand Up @@ -352,18 +344,18 @@ public boolean canPlaceItem(int slot, ItemStack stack) {
for(int i = 0; i < 9; i++) {
if(blocked[i])
continue;

ItemStack testStack = getItem(i);
if(testStack.isEmpty() || ItemStack.isSameItemSameTags(stackInSlot, testStack))
min = Math.min(min, testStack.getCount());
}

return stackInSlot.getCount() == min;
}

boolean blockedSlot = blocked[slot];
boolean powered = level.getBlockState(worldPosition).getValue(CrafterBlock.POWER).powered();

return allowed && !blockedSlot && (CrafterModule.allowItemsWhilePowered || !powered);
}

Expand Down Expand Up @@ -398,8 +390,7 @@ public final ItemStack dispense(BlockSource blockSource, ItemStack itemStack) {
protected ItemStack dispenseSilently(BlockSource pointer, ItemStack stack) {
Direction direction = pointer.getBlockState().getValue(CrafterBlock.FACING);
Position position = getOutputLocation(pointer);
ItemStack itemStack = stack.split(1);
spawnItem(pointer.getLevel(), itemStack, 6, direction, position);
spawnItem(pointer.getLevel(), stack, 6, direction, position);
return stack;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,49 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.violetmoon.quark.content.automation.block.be.CrafterBlockEntity;
import org.violetmoon.quark.content.automation.module.CrafterModule;

import javax.annotation.Nonnull;
import java.util.function.Function;

public class CrafterMenu extends AbstractContainerMenu {
public Container crafter;
public ContainerData delegate;
public final Container crafter;
public final ContainerData delegate;

private final ContainerLevelAccess access;

public CrafterMenu(int syncId, Inventory player) {
super(CrafterModule.menuType, syncId);
init(player, new TransientCraftingContainer(this, 3, 3), new ResultContainer(), new SimpleContainerData(1));
this(syncId, player, (it) -> new TransientCraftingContainer(it, 3, 3), new ResultContainer(), new SimpleContainerData(1), ContainerLevelAccess.NULL);
}

public CrafterMenu(int syncId, Inventory player, CraftingContainer crafter, ResultContainer result, ContainerData delegate) {
public CrafterMenu(int syncId, Inventory player, Function<CrafterMenu, CraftingContainer> crafterProvider, ResultContainer result, ContainerData delegate, ContainerLevelAccess access) {
super(CrafterModule.menuType, syncId);
init(player, crafter, result, delegate);
}

public static CrafterMenu fromNetwork(int windowId, Inventory playerInventory, FriendlyByteBuf buf) {
return new CrafterMenu(windowId, playerInventory);
}
CraftingContainer crafter = crafterProvider.apply(this);

@Override
public boolean clickMenuButton(Player player, int id) {
if (id >= 0 && id < 9 && crafter instanceof CrafterBlockEntity cbe) {
cbe.blocked[id] = !cbe.blocked[id];
cbe.update();
cbe.setChanged();
return true;
}
return super.clickMenuButton(player, id);
}
this.access = access;

public void init(Inventory player, CraftingContainer crafter, ResultContainer result, ContainerData delegate) {
checkContainerSize(crafter, 9);
this.crafter = crafter;
crafter.startOpen(player.player);
this.delegate = delegate;
this.addDataSlots(delegate);
this.addSlot(new ResultSlot(player.player, crafter, result, 0, 26 + 18 * 6, 17 + 1 * 18));

this.addSlot(new ResultSlot(player.player, crafter, result, 0, 26 + 18 * 6, 17 + 18));

int i;
int j;
for(i = 0; i < 3; ++i) {
for(j = 0; j < 3; ++j) {
this.addSlot(new Slot(crafter, j + i * 3, 26 + j * 18, 17 + i * 18));
int index = j + i * 3;
this.addSlot(new Slot(crafter, index, 26 + j * 18, 17 + i * 18) {
@Override
public boolean mayPlace(@Nonnull ItemStack stack) {
return (delegate.get(0) & (1 << index)) == 0;
}
});
}
}

Expand All @@ -91,7 +88,42 @@ public void init(Inventory player, CraftingContainer crafter, ResultContainer re
for(i = 0; i < 9; ++i) {
this.addSlot(new Slot(player, i, 8 + i * 18, 142));
}

}

public static CrafterMenu fromNetwork(int windowId, Inventory playerInventory, FriendlyByteBuf buf) {
return new CrafterMenu(windowId, playerInventory);
}

@Override
public boolean clickMenuButton(Player player, int id) {
if (id >= 0 && id < 9) {
access.execute((level, pos) -> {
if (!level.isClientSide) {
BlockEntity be = level.getBlockEntity(pos);
if (be instanceof CrafterBlockEntity cbe) {
cbe.blocked[id] = !cbe.blocked[id];
cbe.update();
cbe.setChanged();
}
}
});
return true;
}

return super.clickMenuButton(player, id);
}

@Override
public void slotsChanged(Container container) {
super.slotsChanged(container);
access.execute((level, pos) -> {
if (!level.isClientSide) {
BlockEntity be = level.getBlockEntity(pos);
if (be instanceof CrafterBlockEntity cbe) {
cbe.update();
}
}
});
}

@Override
Expand All @@ -116,7 +148,7 @@ public ItemStack quickMoveStack(Player player, int index) {
stack.getItem().onCraft(stack, world, player);
});*/
} else if (index < 10) {
if (this.moveItemStackTo(stack, 10, 46, false)) {
if (!this.moveItemStackTo(stack, 10, 46, false)) {
return ItemStack.EMPTY;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@
import org.violetmoon.zeta.client.event.load.ZClientSetup;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZRegister;
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;

//fixme Fix crafter PITA atm and frankly not worth delaying a stable release over
//@ZetaLoadModule(category = "automation")
@ZetaLoadModule(category = "automation")
public class CrafterModule extends ZetaModule {

public static Block block;
public static MenuType<CrafterMenu> menuType;
public static BlockEntityType<CrafterBlockEntity> blockEntityType;

Block crafter;

@Config(description = "Setting this to true will change the Crafter to use Emi's original design instead of Mojang's.\n"
+ "Emi's design allows only one item per slot, instead of continuing to fill it round robin.\n"
+ "If this is enabled, Allow Items While Powered should also be set to false for the full design.")
public static boolean useEmiLogic = false;

@Config(description = "Set to false to allow items to be inserted into the Crafter even while it's powered.")
public static boolean allowItemsWhilePowered = true;

@LoadEvent
public final void register(ZRegister event) {
crafter = block = new CrafterBlock("crafter", this,
Expand Down

0 comments on commit dd722cf

Please sign in to comment.