More SonarQube fixes.
This commit is contained in:
@@ -2,7 +2,6 @@ package com.refinedmods.refinedstorage.integration.jei;
|
||||
|
||||
import com.refinedmods.refinedstorage.RS;
|
||||
import com.refinedmods.refinedstorage.api.network.grid.GridType;
|
||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
|
||||
import com.refinedmods.refinedstorage.container.GridContainer;
|
||||
import com.refinedmods.refinedstorage.network.grid.GridCraftingPreviewRequestMessage;
|
||||
import com.refinedmods.refinedstorage.network.grid.GridProcessingTransferMessage;
|
||||
@@ -28,9 +27,14 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridContainer> {
|
||||
public static final long TRANSFER_SCROLLBAR_DELAY_MS = 200;
|
||||
public static final GridRecipeTransferHandler INSTANCE = new GridRecipeTransferHandler();
|
||||
|
||||
public static long lastTransferTime;
|
||||
private static final long TRANSFER_SCROLLBAR_DELAY_MS = 200;
|
||||
|
||||
private long lastTransferTimeMs;
|
||||
|
||||
private GridRecipeTransferHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<GridContainer> getContainerClass() {
|
||||
@@ -132,48 +136,66 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
|
||||
return tracker;
|
||||
}
|
||||
|
||||
public boolean hasTransferredRecently() {
|
||||
return System.currentTimeMillis() - lastTransferTimeMs <= TRANSFER_SCROLLBAR_DELAY_MS;
|
||||
}
|
||||
|
||||
private void moveItems(GridContainer gridContainer, IRecipeLayout recipeLayout) {
|
||||
IGrid grid = gridContainer.getGrid();
|
||||
this.lastTransferTimeMs = System.currentTimeMillis();
|
||||
|
||||
lastTransferTime = System.currentTimeMillis();
|
||||
|
||||
if (grid.getGridType() == GridType.PATTERN && !recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
||||
List<ItemStack> inputs = new LinkedList<>();
|
||||
List<ItemStack> outputs = new LinkedList<>();
|
||||
|
||||
List<FluidStack> fluidInputs = new LinkedList<>();
|
||||
List<FluidStack> fluidOutputs = new LinkedList<>();
|
||||
|
||||
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||
|
||||
if (guiIngredient.isInput()) {
|
||||
inputs.add(ingredient);
|
||||
} else {
|
||||
outputs.add(ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (IGuiIngredient<FluidStack> guiIngredient : recipeLayout.getFluidStacks().getGuiIngredients().values()) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
FluidStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||
|
||||
if (guiIngredient.isInput()) {
|
||||
fluidInputs.add(ingredient);
|
||||
} else {
|
||||
fluidOutputs.add(ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs));
|
||||
if (gridContainer.getGrid().getGridType() == GridType.PATTERN && !recipeLayout.getRecipeCategory().getUid().equals(VanillaRecipeCategoryUid.CRAFTING)) {
|
||||
moveForProcessing(recipeLayout);
|
||||
} else {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
|
||||
recipeLayout.getItemStacks().getGuiIngredients(),
|
||||
gridContainer.inventorySlots.stream().filter(s -> s.inventory instanceof CraftingInventory).collect(Collectors.toList())
|
||||
));
|
||||
move(gridContainer, recipeLayout);
|
||||
}
|
||||
}
|
||||
|
||||
private void move(GridContainer gridContainer, IRecipeLayout recipeLayout) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
|
||||
recipeLayout.getItemStacks().getGuiIngredients(),
|
||||
gridContainer.inventorySlots.stream().filter(s -> s.inventory instanceof CraftingInventory).collect(Collectors.toList())
|
||||
));
|
||||
}
|
||||
|
||||
private void moveForProcessing(IRecipeLayout recipeLayout) {
|
||||
List<ItemStack> inputs = new LinkedList<>();
|
||||
List<ItemStack> outputs = new LinkedList<>();
|
||||
|
||||
List<FluidStack> fluidInputs = new LinkedList<>();
|
||||
List<FluidStack> fluidOutputs = new LinkedList<>();
|
||||
|
||||
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
handleItemIngredient(inputs, outputs, guiIngredient);
|
||||
}
|
||||
|
||||
for (IGuiIngredient<FluidStack> guiIngredient : recipeLayout.getFluidStacks().getGuiIngredients().values()) {
|
||||
handleFluidIngredient(fluidInputs, fluidOutputs, guiIngredient);
|
||||
}
|
||||
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs));
|
||||
}
|
||||
|
||||
private void handleFluidIngredient(List<FluidStack> fluidInputs, List<FluidStack> fluidOutputs, IGuiIngredient<FluidStack> guiIngredient) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
FluidStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||
|
||||
if (guiIngredient.isInput()) {
|
||||
fluidInputs.add(ingredient);
|
||||
} else {
|
||||
fluidOutputs.add(ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemIngredient(List<ItemStack> inputs, List<ItemStack> outputs, IGuiIngredient<ItemStack> guiIngredient) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||
|
||||
if (guiIngredient.isInput()) {
|
||||
inputs.add(ingredient);
|
||||
} else {
|
||||
outputs.add(ingredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
public class RSJeiPlugin implements IModPlugin {
|
||||
private static final ResourceLocation ID = new ResourceLocation(RS.ID, "plugin");
|
||||
|
||||
public static IJeiRuntime RUNTIME;
|
||||
private static IJeiRuntime runtime;
|
||||
|
||||
@Override
|
||||
public ResourceLocation getPluginUid() {
|
||||
@@ -22,7 +22,7 @@ public class RSJeiPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) {
|
||||
registration.addUniversalRecipeTransferHandler(new GridRecipeTransferHandler());
|
||||
registration.addUniversalRecipeTransferHandler(GridRecipeTransferHandler.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,6 +33,10 @@ public class RSJeiPlugin implements IModPlugin {
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(IJeiRuntime runtime) {
|
||||
RUNTIME = runtime;
|
||||
RSJeiPlugin.runtime = runtime;
|
||||
}
|
||||
|
||||
public static IJeiRuntime getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ public class CrafterManagerScreen extends BaseScreen<CrafterManagerContainer> im
|
||||
public void onPostInit(int x, int y) {
|
||||
addSideButton(new RedstoneModeSideButton(this, CrafterManagerTile.REDSTONE_MODE));
|
||||
addSideButton(new CrafterManagerSearchBoxModeSideButton(this));
|
||||
addSideButton(new GridSizeSideButton(this, () -> crafterManager.getSize(), size -> TileDataManager.setParameter(CrafterManagerTile.SIZE, size)));
|
||||
addSideButton(new GridSizeSideButton(this, crafterManager::getSize, size -> TileDataManager.setParameter(CrafterManagerTile.SIZE, size)));
|
||||
|
||||
this.scrollbar = new ScrollbarWidget(this, 174, getTopHeight(), 12, (getVisibleRows() * 18) - 2);
|
||||
this.scrollbar.addListener((oldOffset, newOffset) -> container.initSlots(null));
|
||||
|
@@ -34,6 +34,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class AlternativesScreen extends BaseScreen<AlternativesContainer> {
|
||||
private static final int VISIBLE_ROWS = 5;
|
||||
|
||||
private final Screen parent;
|
||||
private final ScrollbarWidget scrollbar;
|
||||
|
||||
@@ -126,7 +128,7 @@ public class AlternativesScreen extends BaseScreen<AlternativesContainer> {
|
||||
int yy = 20;
|
||||
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + getVisibleRows();
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + VISIBLE_ROWS;
|
||||
|
||||
if (visible) {
|
||||
lines.get(i).layoutDependantControls(true, guiLeft + xx + 3, guiTop + yy + 3);
|
||||
@@ -141,18 +143,14 @@ public class AlternativesScreen extends BaseScreen<AlternativesContainer> {
|
||||
|
||||
@Override
|
||||
public void tick(int x, int y) {
|
||||
scrollbar.setEnabled(getRows() > getVisibleRows());
|
||||
scrollbar.setMaxOffset(getRows() - getVisibleRows());
|
||||
scrollbar.setEnabled(getRows() > VISIBLE_ROWS);
|
||||
scrollbar.setMaxOffset(getRows() - VISIBLE_ROWS);
|
||||
}
|
||||
|
||||
private int getRows() {
|
||||
return lines.size();
|
||||
}
|
||||
|
||||
private int getVisibleRows() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground(MatrixStack matrixStack, int x, int y, int mouseX, int mouseY) {
|
||||
bindTexture(RS.ID, "gui/alternatives.png");
|
||||
@@ -170,7 +168,7 @@ public class AlternativesScreen extends BaseScreen<AlternativesContainer> {
|
||||
int y = 20;
|
||||
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + getVisibleRows();
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + VISIBLE_ROWS;
|
||||
|
||||
if (visible) {
|
||||
lines.get(i).layoutDependantControls(true, guiLeft + x + 3, guiTop + y + 3);
|
||||
@@ -186,7 +184,7 @@ public class AlternativesScreen extends BaseScreen<AlternativesContainer> {
|
||||
y = 20;
|
||||
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + getVisibleRows();
|
||||
boolean visible = i >= scrollbar.getOffset() && i < scrollbar.getOffset() + VISIBLE_ROWS;
|
||||
|
||||
if (visible) {
|
||||
lines.get(i).renderTooltip(matrixStack, x, y, mouseX, mouseY);
|
||||
|
@@ -132,7 +132,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
addSideButton(new GridSortingDirectionSideButton(this, grid));
|
||||
addSideButton(new GridSortingTypeSideButton(this, grid));
|
||||
addSideButton(new GridSearchBoxModeSideButton(this));
|
||||
addSideButton(new GridSizeSideButton(this, () -> grid.getSize(), size -> grid.onSizeChanged(size)));
|
||||
addSideButton(new GridSizeSideButton(this, grid::getSize, grid::onSizeChanged));
|
||||
|
||||
if (grid.getGridType() == GridType.PATTERN) {
|
||||
processingPattern = addCheckBox(x + 7, y + getTopHeight() + (getVisibleRows() * 18) + 60, new TranslationTextComponent("misc.refinedstorage.processing"), GridTile.PROCESSING_PATTERN.getValue(), btn -> {
|
||||
|
@@ -72,7 +72,7 @@ public class ScrollbarWidget implements IGuiEventListener {
|
||||
|
||||
if (button == 0 && RenderUtils.inBounds(x, y, width, height, mx, my)) {
|
||||
// Prevent accidental scrollbar click after clicking recipe transfer button
|
||||
if (JeiIntegration.isLoaded() && System.currentTimeMillis() - GridRecipeTransferHandler.lastTransferTime <= GridRecipeTransferHandler.TRANSFER_SCROLLBAR_DELAY_MS) {
|
||||
if (JeiIntegration.isLoaded() && GridRecipeTransferHandler.INSTANCE.hasTransferredRecently()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ public class SearchWidget extends TextFieldWidget {
|
||||
|
||||
public void updateJei() {
|
||||
if (JeiIntegration.isLoaded() && (mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED || mode == IGrid.SEARCH_BOX_MODE_JEI_SYNCHRONIZED_AUTOSELECTED)) {
|
||||
RSJeiPlugin.RUNTIME.getIngredientFilter().setFilterText(getText());
|
||||
RSJeiPlugin.getRuntime().getIngredientFilter().setFilterText(getText());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -112,15 +112,12 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
if (disk != null) {
|
||||
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||
|
||||
switch (type) {
|
||||
case ITEM:
|
||||
storage = new PortableItemStorageDisk(disk, PortableGrid.this);
|
||||
cache = new PortableItemStorageCache(PortableGrid.this);
|
||||
break;
|
||||
case FLUID:
|
||||
storage = new PortableFluidStorageDisk(disk, PortableGrid.this);
|
||||
cache = new PortableFluidStorageCache(PortableGrid.this);
|
||||
break;
|
||||
if (type == StorageType.ITEM) {
|
||||
storage = new PortableItemStorageDisk(disk, PortableGrid.this);
|
||||
cache = new PortableItemStorageCache(PortableGrid.this);
|
||||
} else if (type == StorageType.FLUID) {
|
||||
storage = new PortableFluidStorageDisk(disk, PortableGrid.this);
|
||||
cache = new PortableFluidStorageCache(PortableGrid.this);
|
||||
}
|
||||
|
||||
storage.setSettings(null, PortableGrid.this);
|
||||
|
@@ -199,15 +199,12 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
||||
if (disk != null) {
|
||||
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||
|
||||
switch (type) {
|
||||
case ITEM:
|
||||
this.storage = new PortableItemStorageDisk(disk, this);
|
||||
this.cache = new PortableItemStorageCache(this);
|
||||
break;
|
||||
case FLUID:
|
||||
this.storage = new PortableFluidStorageDisk(disk, this);
|
||||
this.cache = new PortableFluidStorageCache(this);
|
||||
break;
|
||||
if (type == StorageType.ITEM) {
|
||||
this.storage = new PortableItemStorageDisk(disk, this);
|
||||
this.cache = new PortableItemStorageCache(this);
|
||||
} else if (type == StorageType.FLUID) {
|
||||
this.storage = new PortableFluidStorageDisk(disk, this);
|
||||
this.cache = new PortableFluidStorageCache(this);
|
||||
}
|
||||
|
||||
this.storage.setSettings(PortableGridTile.this::updateState, PortableGridTile.this);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.refinedmods.refinedstorage.util;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.storage.StorageType;
|
||||
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDisk;
|
||||
import com.refinedmods.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||
import com.refinedmods.refinedstorage.api.storage.tracker.StorageTrackerEntry;
|
||||
@@ -169,15 +170,12 @@ public final class StackUtils {
|
||||
IStorageDisk disk = API.instance().getStorageDiskManager(world).getByStack(diskStack);
|
||||
|
||||
if (disk != null) {
|
||||
switch (((IStorageDiskProvider) diskStack.getItem()).getType()) {
|
||||
case ITEM: {
|
||||
itemDisks[slot] = itemDiskWrapper.apply(disk);
|
||||
break;
|
||||
}
|
||||
case FLUID: {
|
||||
fluidDisks[slot] = fluidDiskWrapper.apply(disk);
|
||||
break;
|
||||
}
|
||||
StorageType type = ((IStorageDiskProvider) diskStack.getItem()).getType();
|
||||
|
||||
if (type == StorageType.ITEM) {
|
||||
itemDisks[slot] = itemDiskWrapper.apply(disk);
|
||||
} else if (type == StorageType.FLUID) {
|
||||
fluidDisks[slot] = fluidDiskWrapper.apply(disk);
|
||||
}
|
||||
} else {
|
||||
itemDisks[slot] = null;
|
||||
|
Reference in New Issue
Block a user