Fix things working without power (#2710)

* fix various issues of things working without power

* changelog

* fix clear button

* fix scrolling error

* requested changes
This commit is contained in:
Darkere
2020-10-17 12:58:52 +02:00
committed by GitHub
parent 6d3b43d99e
commit fd7cb5d555
10 changed files with 55 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
### 1.9.8 ### 1.9.8
- Fixed server crash when scrolling in Grid (Darkere) - Fixed server crash when scrolling in Grid (Darkere)
- Fixed various issues of things working without power (Darkere)
### 1.9.7 ### 1.9.7
- Added functionality to move items in the Grid with shift/ctrl + scrolling (Darkere) - Added functionality to move items in the Grid with shift/ctrl + scrolling (Darkere)

View File

@@ -92,7 +92,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
int maxCrafted = crafted.getMaxStackSize(); int maxCrafted = crafted.getMaxStackSize();
int amountCrafted = 0; int amountCrafted = 0;
boolean useNetwork = network != null; boolean useNetwork = network != null && grid.isGridActive();
IStackList<ItemStack> availableItems = null; IStackList<ItemStack> availableItems = null;
if (useNetwork) { if (useNetwork) {
@@ -170,7 +170,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
// Only if we are a crafting grid. Pattern grids can just be emptied. // Only if we are a crafting grid. Pattern grids can just be emptied.
if (grid.getGridType() == GridType.CRAFTING) { if (grid.getGridType() == GridType.CRAFTING) {
// If we are connected, try to insert into network. If it fails, stop. // If we are connected, try to insert into network. If it fails, stop.
if (network != null) { if (network != null && grid.isGridActive()) {
if (!network.insertItem(slot, slot.getCount(), Action.SIMULATE).isEmpty()) { if (!network.insertItem(slot, slot.getCount(), Action.SIMULATE).isEmpty()) {
return; return;
} else { } else {
@@ -200,7 +200,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
boolean found = false; boolean found = false;
// If we are connected, first try to get the possibilities from the network // If we are connected, first try to get the possibilities from the network
if (network != null) { if (network != null && grid.isGridActive()) {
for (ItemStack possibility : possibilities) { for (ItemStack possibility : possibilities) {
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM); ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM);

View File

@@ -36,7 +36,7 @@ public class FluidGridHandler implements IFluidGridHandler {
public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) { public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) {
FluidStack stack = network.getFluidStorageCache().getList().get(id); FluidStack stack = network.getFluidStorageCache().getList().get(id);
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) { if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player) || !network.canRun()) {
return; return;
} }
@@ -63,7 +63,7 @@ public class FluidGridHandler implements IFluidGridHandler {
@Override @Override
@Nonnull @Nonnull
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) { public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) { if (!network.getSecurityManager().hasPermission(Permission.INSERT, player) || !network.canRun()) {
return container; return container;
} }

View File

@@ -48,7 +48,7 @@ public class ItemGridHandler implements IItemGridHandler {
public void onExtract(ServerPlayerEntity player, UUID id, int preferredSlot, int flags) { public void onExtract(ServerPlayerEntity player, UUID id, int preferredSlot, int flags) {
ItemStack item = network.getItemStorageCache().getList().get(id); ItemStack item = network.getItemStorageCache().getList().get(id);
if (item == null || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player)) { if (item == null || !network.getSecurityManager().hasPermission(Permission.EXTRACT, player) || !network.canRun()) {
return; return;
} }
@@ -133,7 +133,7 @@ public class ItemGridHandler implements IItemGridHandler {
@Override @Override
@Nonnull @Nonnull
public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack, boolean single) { public ItemStack onInsert(ServerPlayerEntity player, ItemStack stack, boolean single) {
if (!network.getSecurityManager().hasPermission(Permission.INSERT, player)) { if (!network.getSecurityManager().hasPermission(Permission.INSERT, player) || !network.canRun()) {
return stack; return stack;
} }
@@ -157,7 +157,7 @@ public class ItemGridHandler implements IItemGridHandler {
@Override @Override
public void onInsertHeldItem(ServerPlayerEntity player, boolean single) { public void onInsertHeldItem(ServerPlayerEntity player, boolean single) {
if (player.inventory.getItemStack().isEmpty() || !network.getSecurityManager().hasPermission(Permission.INSERT, player)) { if (player.inventory.getItemStack().isEmpty() || !network.getSecurityManager().hasPermission(Permission.INSERT, player) || !network.canRun()) {
return; return;
} }

View File

@@ -28,6 +28,10 @@ public class PortableFluidGridHandler implements IFluidGridHandler {
@Override @Override
public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) { public void onExtract(ServerPlayerEntity player, UUID id, boolean shift) {
if (!portableGrid.isGridActive()) {
return;
}
FluidStack stack = portableGrid.getFluidCache().getList().get(id); FluidStack stack = portableGrid.getFluidCache().getList().get(id);
if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME) { if (stack == null || stack.getAmount() < FluidAttributes.BUCKET_VOLUME) {
@@ -71,6 +75,10 @@ public class PortableFluidGridHandler implements IFluidGridHandler {
@Override @Override
@Nonnull @Nonnull
public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) { public ItemStack onInsert(ServerPlayerEntity player, ItemStack container) {
if (!portableGrid.isGridActive()) {
return container;
}
Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true); Pair<ItemStack, FluidStack> result = StackUtils.getFluid(container, true);
if (!result.getValue().isEmpty() && portableGrid.getFluidStorage().insert(result.getValue(), result.getValue().getAmount(), Action.SIMULATE).isEmpty()) { if (!result.getValue().isEmpty() && portableGrid.getFluidStorage().insert(result.getValue(), result.getValue().getAmount(), Action.SIMULATE).isEmpty()) {

View File

@@ -429,19 +429,32 @@ public class GridNetworkNode extends NetworkNode implements INetworkAwareGrid, I
@Override @Override
public void onClear(PlayerEntity player) { public void onClear(PlayerEntity player) {
if (type == GridType.CRAFTING && network != null && network.getSecurityManager().hasPermission(Permission.INSERT, player)) { if (type == GridType.CRAFTING) {
for (int i = 0; i < matrix.getSizeInventory(); ++i) { if (network != null && network.canRun() && network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
ItemStack slot = matrix.getStackInSlot(i); for (int i = 0; i < matrix.getSizeInventory(); ++i) {
ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) { if (!slot.isEmpty()) {
matrix.setInventorySlotContents(i, network.insertItem(slot, slot.getCount(), Action.PERFORM)); matrix.setInventorySlotContents(i, network.insertItem(slot, slot.getCount(), Action.PERFORM));
network.getItemStorageTracker().changed(player, slot.copy()); network.getItemStorageTracker().changed(player, slot.copy());
}
}
} else {
for (int i = 0; i < matrix.getSizeInventory(); i++) {
ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) {
player.inventory.addItemStackToInventory(matrix.getStackInSlot(i));
}
onCraftingMatrixChanged();
} }
} }
} else if (type == GridType.PATTERN) { } else if (type == GridType.PATTERN) {
clearMatrix(); clearMatrix();
} }
} }
@Override @Override

View File

@@ -102,9 +102,11 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
Collection<IGridStack> gridStacks = ((GridScreen) container.getScreenInfoProvider()).getView().getAllStacks(); Collection<IGridStack> gridStacks = ((GridScreen) container.getScreenInfoProvider()).getView().getAllStacks();
// Check grid // Check grid
for (IGridStack gridStack : gridStacks) { if (container.getGrid().isGridActive()) {
if (gridStack instanceof ItemGridStack) { for (IGridStack gridStack : gridStacks) {
tracker.addAvailableStack(((ItemGridStack) gridStack).getStack(), gridStack); if (gridStack instanceof ItemGridStack) {
tracker.addAvailableStack(((ItemGridStack) gridStack).getStack(), gridStack);
}
} }
} }

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.network.grid; package com.refinedmods.refinedstorage.network.grid;
import com.refinedmods.refinedstorage.container.GridContainer; import com.refinedmods.refinedstorage.container.GridContainer;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@@ -36,8 +37,9 @@ public class GridItemGridScrollMessage {
public static void handle(GridItemGridScrollMessage message, Supplier<NetworkEvent.Context> ctx) { public static void handle(GridItemGridScrollMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> { ctx.get().enqueueWork(() -> {
if (ctx.get().getSender() != null && ctx.get().getSender().openContainer instanceof GridContainer) { ServerPlayerEntity player = ctx.get().getSender();
((GridContainer) ctx.get().getSender().openContainer).getGrid().getItemHandler().onGridScroll(ctx.get().getSender(), message.id, message.shift, message.up); if (player != null && player.openContainer instanceof GridContainer && ((GridContainer) player.openContainer).getGrid().getItemHandler() != null) {
((GridContainer) player.openContainer).getGrid().getItemHandler().onGridScroll(player, message.id, message.shift, message.up);
} }
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.network.grid; package com.refinedmods.refinedstorage.network.grid;
import com.refinedmods.refinedstorage.container.GridContainer; import com.refinedmods.refinedstorage.container.GridContainer;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@@ -29,8 +30,9 @@ public class GridItemInventoryScrollMessage {
public static void handle(GridItemInventoryScrollMessage message, Supplier<NetworkEvent.Context> ctx) { public static void handle(GridItemInventoryScrollMessage message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> { ctx.get().enqueueWork(() -> {
if (ctx.get().getSender() != null && ctx.get().getSender().openContainer instanceof GridContainer) { ServerPlayerEntity player = ctx.get().getSender();
((GridContainer) ctx.get().getSender().openContainer).getGrid().getItemHandler().onInventoryScroll(ctx.get().getSender(), message.slot, message.shift, message.up); if (player != null && player.openContainer instanceof GridContainer && ((GridContainer) player.openContainer).getGrid().getItemHandler() != null) {
((GridContainer) player.openContainer).getGrid().getItemHandler().onInventoryScroll(player, message.slot, message.shift, message.up);
} }
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);

View File

@@ -448,16 +448,14 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
RS.NETWORK_HANDLER.sendToServer(new GridPatternCreateMessage(((GridNetworkNode) grid).getPos())); RS.NETWORK_HANDLER.sendToServer(new GridPatternCreateMessage(((GridNetworkNode) grid).getPos()));
return true;
} else if (clickedClear) {
minecraft.getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
RS.NETWORK_HANDLER.sendToServer(new GridClearMessage());
return true; return true;
} else if (grid.isGridActive()) { } else if (grid.isGridActive()) {
if (clickedClear) {
minecraft.getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
RS.NETWORK_HANDLER.sendToServer(new GridClearMessage());
return true;
}
ItemStack held = container.getPlayer().inventory.getItemStack(); ItemStack held = container.getPlayer().inventory.getItemStack();
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && !held.isEmpty() && (clickedButton == 0 || clickedButton == 1)) { if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && !held.isEmpty() && (clickedButton == 0 || clickedButton == 1)) {