Skip to content

Commit

Permalink
修复漏斗对灶的错误行为
Browse files Browse the repository at this point in the history
修复灶内自动出现黑暗物质的bug
  • Loading branch information
Yuqi154 committed Jul 26, 2024
1 parent 5779c02 commit 57dcf74
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,14 @@ protected void setItems(NonNullList<ItemStack> stacks) {

@Override
public boolean canPlaceItem(int index, ItemStack stack) {
if (index == 6)
return false;
if (index == 7)
return false;
if (index == 8)
return false;
if (index == 9)
return false;
if (index == 10)
return false;
if (index == 11)
return false;
if (index == 12)
return false;
return true;
switch (index){
case 6,7,8,9,10,11,12 -> {
return false;
}
default -> {
return true;
}
}
}

@Override
Expand All @@ -129,25 +122,17 @@ public int[] getSlotsForFace(Direction side) {

@Override
public boolean canPlaceItemThroughFace(int index, ItemStack stack, @Nullable Direction direction) {
return this.canPlaceItem(index, stack);
//if(index==0)

return false;

//return this.canPlaceItem(index, stack);
}

@Override
public boolean canTakeItemThroughFace(int index, ItemStack stack, Direction direction) {
if (index == 7)
return false;
if (index == 8)
return false;
if (index == 9)
return false;
if (index == 10)
return false;
if (index == 11)
return false;
if (index == 12)
return false;
return true;
}
return index == 6;
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ public static void execute(LevelAccessor world, double x, double y, double z) {
}

util = GetItemStack.getItemStack(world, Pos.get(x, y, z), 0);
/*
if (util.getItem() == ItemStack.EMPTY.getItem()) {
SetSlotItem.setSlotItem(world, x, y, z, new ItemStack(ItemRegistery.HEI_AN_WU_ZHI.get()), 12, 1);
}
}*/

List<String> raws = new ArrayList<>();
List<ItemStack> ingredients = new ArrayList<>();
Expand Down Expand Up @@ -126,6 +127,8 @@ public static void execute(LevelAccessor world, double x, double y, double z) {
}
}

//SetSlotItem.setEmptySlot(world, x, y, z, 12);

// ItemStack cuisine = GetItemStack.getItemStack(world, Pos.get(x, y, z), 12);
// try {
// cuisine.inventoryTick(null, null, 0, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ public static ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slot
AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
BlockEntity _ent = world.getBlockEntity(pos);
if (_ent != null)
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null)
return getItemStack(_ent, slotid);
return _retval.get();
}
public static ItemStack getItemStack(BlockEntity be, int slotid) {
AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
if (be != null) {
be.getCapability(ForgeCapabilities.ITEM_HANDLER, null)
.ifPresent(capability -> _retval.set(capability.getStackInSlot(slotid).copy()));
}
return _retval.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@
import java.util.List;

public class SetSlotItem {
public static void setSlotItem(LevelAccessor world, double x, double y, double z, ItemStack itemStack, int slotid,
int count) {
public static void setSlotItem(LevelAccessor world, double x, double y, double z, ItemStack itemStack, int slotid, int count) {
BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z));
if (_ent != null) {
final int _slotid = slotid;
final ItemStack _setstack = itemStack;
_setstack.setCount(count);
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
if (capability instanceof IItemHandlerModifiable)
((IItemHandlerModifiable) capability).setStackInSlot(_slotid, _setstack );
});
setSlotItem(_ent, itemStack, slotid, count);
}
}
public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid,
int count) {
public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid, int count) {
if (be != null) {
final int _slotid = slotid;
final ItemStack _setstack = itemStack;
Expand All @@ -36,32 +28,45 @@ public static void setSlotItem(BlockEntity be, ItemStack itemStack, int slotid,
});
}
}
public static void querySlotItem(LevelAccessor world, double x, double y, double z, int slotid,int count) {
BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z));
if (_ent != null) {
querySlotItem(_ent, slotid, count);
}
}
public static void querySlotItem(BlockEntity be, int slotid,int count) {
if (be != null) {
ItemStack item = GetItemStack.getItemStack(be, slotid);
setSlotItem(be, item, slotid, item.getCount()-count);
}
}
public static void querySlotItem(BlockEntity be, int[] slotid,int[] count) {
if (be != null) {
for (int i = 0; i < slotid.length; i++) {
querySlotItem(be, slotid[i], count[i]);
}
}
}


public static void setEmptySlot(LevelAccessor world, double x, double y, double z, int slotid) {
BlockEntity _ent = world.getBlockEntity(Pos.get(x, y, z));
if (_ent != null) {
final int _slotid = slotid;
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
if (capability instanceof IItemHandlerModifiable)
((IItemHandlerModifiable) capability).setStackInSlot(_slotid, ItemStack.EMPTY);
});
setEmptySlot(_ent, slotid);
}
}
public static void setEmptySlot(BlockEntity be, int slotid) {
if (be != null) {
final int _slotid = slotid;
be.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
if (capability instanceof IItemHandlerModifiable)
((IItemHandlerModifiable) capability).setStackInSlot(_slotid, ItemStack.EMPTY);
((IItemHandlerModifiable) capability).setStackInSlot(slotid, ItemStack.EMPTY);
});
}
}
public static void setEmptySlot(BlockEntity be, int[] slotid) {
if (be != null) {
for (int slot : slotid) {
be.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
if (capability instanceof IItemHandlerModifiable)
((IItemHandlerModifiable) capability).setStackInSlot(slot, ItemStack.EMPTY);
});
setEmptySlot(be, slot);
};
}
}
Expand Down

0 comments on commit 57dcf74

Please sign in to comment.