mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-15 23:56:14 +01:00
Phantom Slots
- Corrected DeployerItemHandler to reserve slots for overflow items - Fixed Deployer not allowing overflow items to be extracted in some cases
This commit is contained in:
parent
21ad6125f5
commit
596802d3cc
2 changed files with 32 additions and 41 deletions
|
@ -1,7 +1,5 @@
|
||||||
package com.simibubi.create.content.contraptions.components.deployer;
|
package com.simibubi.create.content.contraptions.components.deployer;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour;
|
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour;
|
||||||
|
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
@ -21,12 +19,12 @@ public class DeployerItemHandler implements IItemHandlerModifiable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSlots() {
|
public int getSlots() {
|
||||||
return 1;
|
return 1 + te.overflowItems.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot) {
|
||||||
return getHeld();
|
return slot >= te.overflowItems.size() ? getHeld() : te.overflowItems.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getHeld() {
|
public ItemStack getHeld() {
|
||||||
|
@ -47,14 +45,18 @@ public class DeployerItemHandler implements IItemHandlerModifiable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||||
ItemStack held = getHeld();
|
if (slot < te.overflowItems.size())
|
||||||
|
return stack;
|
||||||
if (!isItemValid(slot, stack))
|
if (!isItemValid(slot, stack))
|
||||||
return stack;
|
return stack;
|
||||||
|
|
||||||
|
ItemStack held = getHeld();
|
||||||
if (held.isEmpty()) {
|
if (held.isEmpty()) {
|
||||||
if (!simulate)
|
if (!simulate)
|
||||||
set(stack);
|
set(stack);
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ItemHandlerHelper.canItemStacksStack(held, stack))
|
if (!ItemHandlerHelper.canItemStacksStack(held, stack))
|
||||||
return stack;
|
return stack;
|
||||||
|
|
||||||
|
@ -78,36 +80,18 @@ public class DeployerItemHandler implements IItemHandlerModifiable {
|
||||||
if (amount == 0)
|
if (amount == 0)
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
|
||||||
ItemStack extractedFromOverflow = ItemStack.EMPTY;
|
if (slot < te.overflowItems.size()) {
|
||||||
ItemStack returnToOverflow = ItemStack.EMPTY;
|
ItemStack itemStack = te.overflowItems.get(slot);
|
||||||
|
int toExtract = Math.min(amount, itemStack.getCount());
|
||||||
for (Iterator<ItemStack> iterator = te.overflowItems.iterator(); iterator.hasNext();) {
|
ItemStack extracted = simulate ? itemStack.copy() : itemStack.split(toExtract);
|
||||||
ItemStack existing = iterator.next();
|
extracted.setCount(toExtract);
|
||||||
if (existing.isEmpty()) {
|
if (!simulate && itemStack.isEmpty())
|
||||||
iterator.remove();
|
te.overflowItems.remove(slot);
|
||||||
continue;
|
if (!simulate && !extracted.isEmpty())
|
||||||
|
te.setChanged();
|
||||||
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
int toExtract = Math.min(amount, existing.getMaxStackSize());
|
|
||||||
if (existing.getCount() <= toExtract) {
|
|
||||||
if (!simulate)
|
|
||||||
iterator.remove();
|
|
||||||
extractedFromOverflow = existing;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!simulate) {
|
|
||||||
iterator.remove();
|
|
||||||
returnToOverflow = ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract);
|
|
||||||
}
|
|
||||||
extractedFromOverflow = ItemHandlerHelper.copyStackWithSize(existing, toExtract);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!returnToOverflow.isEmpty())
|
|
||||||
te.overflowItems.add(returnToOverflow);
|
|
||||||
if (!extractedFromOverflow.isEmpty())
|
|
||||||
return extractedFromOverflow;
|
|
||||||
|
|
||||||
ItemStack held = getHeld();
|
ItemStack held = getHeld();
|
||||||
if (amount == 0 || held.isEmpty())
|
if (amount == 0 || held.isEmpty())
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
|
@ -126,7 +110,7 @@ public class DeployerItemHandler implements IItemHandlerModifiable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSlotLimit(int slot) {
|
public int getSlotLimit(int slot) {
|
||||||
return Math.min(getHeld().getMaxStackSize(), 64);
|
return Math.min(getStackInSlot(slot).getMaxStackSize(), 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,6 +121,10 @@ public class DeployerItemHandler implements IItemHandlerModifiable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStackInSlot(int slot, ItemStack stack) {
|
public void setStackInSlot(int slot, ItemStack stack) {
|
||||||
|
if (slot < te.overflowItems.size()) {
|
||||||
|
te.overflowItems.set(slot, stack);
|
||||||
|
return;
|
||||||
|
}
|
||||||
set(stack);
|
set(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,6 @@ public class BeltInventory {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Belt Funnels
|
// Belt Funnels
|
||||||
if (BeltFunnelInteractionHandler.checkForFunnels(this, currentItem, nextOffset))
|
if (BeltFunnelInteractionHandler.checkForFunnels(this, currentItem, nextOffset))
|
||||||
continue;
|
continue;
|
||||||
|
@ -217,7 +216,8 @@ public class BeltInventory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean handleBeltProcessingAndCheckIfRemoved(TransportedItemStack currentItem, float nextOffset, boolean noMovement) {
|
protected boolean handleBeltProcessingAndCheckIfRemoved(TransportedItemStack currentItem, float nextOffset,
|
||||||
|
boolean noMovement) {
|
||||||
int currentSegment = (int) currentItem.beltPosition;
|
int currentSegment = (int) currentItem.beltPosition;
|
||||||
|
|
||||||
// Continue processing if held
|
// Continue processing if held
|
||||||
|
@ -315,7 +315,8 @@ public class BeltInventory {
|
||||||
if (inputBehaviour != null)
|
if (inputBehaviour != null)
|
||||||
return Ending.INSERT;
|
return Ending.INSERT;
|
||||||
|
|
||||||
if (BlockHelper.hasBlockSolidSide(world.getBlockState(nextPosition), world, nextPosition, belt.getMovementFacing()
|
if (BlockHelper.hasBlockSolidSide(world.getBlockState(nextPosition), world, nextPosition,
|
||||||
|
belt.getMovementFacing()
|
||||||
.getOpposite()))
|
.getOpposite()))
|
||||||
return Ending.BLOCKED;
|
return Ending.BLOCKED;
|
||||||
|
|
||||||
|
@ -405,9 +406,11 @@ public class BeltInventory {
|
||||||
ItemStack ejected = stack.stack;
|
ItemStack ejected = stack.stack;
|
||||||
Vec3 outPos = BeltHelper.getVectorForOffset(belt, stack.beltPosition);
|
Vec3 outPos = BeltHelper.getVectorForOffset(belt, stack.beltPosition);
|
||||||
float movementSpeed = Math.max(Math.abs(belt.getBeltMovementSpeed()), 1 / 8f);
|
float movementSpeed = Math.max(Math.abs(belt.getBeltMovementSpeed()), 1 / 8f);
|
||||||
Vec3 outMotion = Vec3.atLowerCornerOf(belt.getBeltChainDirection()).scale(movementSpeed)
|
Vec3 outMotion = Vec3.atLowerCornerOf(belt.getBeltChainDirection())
|
||||||
|
.scale(movementSpeed)
|
||||||
.add(0, 1 / 8f, 0);
|
.add(0, 1 / 8f, 0);
|
||||||
outPos = outPos.add(outMotion.normalize().scale(0.001));
|
outPos = outPos.add(outMotion.normalize()
|
||||||
|
.scale(0.001));
|
||||||
ItemEntity entity = new ItemEntity(belt.getLevel(), outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
|
ItemEntity entity = new ItemEntity(belt.getLevel(), outPos.x, outPos.y + 6 / 16f, outPos.z, ejected);
|
||||||
entity.setDeltaMovement(outMotion);
|
entity.setDeltaMovement(outMotion);
|
||||||
entity.setDefaultPickUpDelay();
|
entity.setDefaultPickUpDelay();
|
||||||
|
|
Loading…
Reference in a new issue