More SonarQube fixes.

This commit is contained in:
raoulvdberge
2020-10-18 13:59:17 +02:00
parent 3e33c13518
commit 340897fc76
18 changed files with 216 additions and 91 deletions

View File

@@ -9,18 +9,34 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
public final class RSLootFunctions {
public static LootFunctionType STORAGE_BLOCK;
public static LootFunctionType PORTABLE_GRID;
public static LootFunctionType CRAFTER;
public static LootFunctionType CONTROLLER;
private static LootFunctionType storageBlock;
private static LootFunctionType portableGrid;
private static LootFunctionType crafter;
private static LootFunctionType controller;
private RSLootFunctions() {
}
public static void register() {
STORAGE_BLOCK = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "storage_block"), new LootFunctionType(new StorageBlockLootFunction.Serializer()));
PORTABLE_GRID = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "portable_grid"), new LootFunctionType(new PortableGridBlockLootFunction.Serializer()));
CRAFTER = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "crafter"), new LootFunctionType(new CrafterLootFunction.Serializer()));
CONTROLLER = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "controller"), new LootFunctionType(new ControllerLootFunction.Serializer()));
storageBlock = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "storage_block"), new LootFunctionType(new StorageBlockLootFunction.Serializer()));
portableGrid = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "portable_grid"), new LootFunctionType(new PortableGridBlockLootFunction.Serializer()));
crafter = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "crafter"), new LootFunctionType(new CrafterLootFunction.Serializer()));
controller = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "controller"), new LootFunctionType(new ControllerLootFunction.Serializer()));
}
public static LootFunctionType getStorageBlock() {
return storageBlock;
}
public static LootFunctionType getPortableGrid() {
return portableGrid;
}
public static LootFunctionType getCrafter() {
return crafter;
}
public static LootFunctionType getController() {
return controller;
}
}

View File

@@ -125,7 +125,7 @@ public class CraftingCalculator {
} else if (node instanceof ProcessingNode) {
ProcessingNode processing = (ProcessingNode) node;
calculateForFluids(qty, storageSource, fluidStorageSource, results, fluidResults, pattern, inputs, fluidsToExtract, processing);
calculateForFluids(qty, storageSource, fluidStorageSource, results, fluidResults, inputs, fluidsToExtract, processing);
for (ItemStack output : pattern.getOutputs()) {
results.add(output, output.getCount() * qty);
@@ -241,7 +241,6 @@ public class CraftingCalculator {
IStackList<FluidStack> fluidStorageSource,
IStackList<ItemStack> results,
IStackList<FluidStack> fluidResults,
ICraftingPattern pattern,
CraftingPatternInputs inputs,
IStackList<FluidStack> fluidsToExtract,
ProcessingNode node) throws CraftingCalculatorException {
@@ -335,9 +334,30 @@ public class CraftingCalculator {
}
private int getQuantityPerCraft(@Nullable ItemStack item, @Nullable FluidStack fluid, ICraftingPattern pattern) {
if (item != null) {
return getQuantityPerCraftForItem(item, pattern);
} else if (fluid != null) {
return getQuantityPerCraftForFluid(fluid, pattern);
} else {
return 0;
}
}
private int getQuantityPerCraftForFluid(FluidStack fluid, ICraftingPattern pattern) {
int qty = 0;
for (FluidStack output : pattern.getFluidOutputs()) {
if (API.instance().getComparer().isEqual(output, fluid, IComparer.COMPARE_NBT)) {
qty += output.getAmount();
}
}
return qty;
}
private int getQuantityPerCraftForItem(ItemStack item, ICraftingPattern pattern) {
int qty = 0;
if (item != null) {
for (ItemStack output : pattern.getOutputs()) {
if (API.instance().getComparer().isEqualNoQuantity(output, item)) {
qty += output.getCount();
@@ -347,13 +367,6 @@ public class CraftingCalculator {
}
}
}
} else if (fluid != null) {
for (FluidStack output : pattern.getFluidOutputs()) {
if (API.instance().getComparer().isEqual(output, fluid, IComparer.COMPARE_NBT)) {
qty += output.getAmount();
}
}
}
return qty;
}

View File

@@ -287,7 +287,11 @@ public class GridNetworkNode extends NetworkNode implements INetworkAwareGrid, I
@Nullable
@Override
public IStorageCache getStorageCache() {
return network != null ? (type == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache()) : null;
if (network != null) {
return type == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache();
}
return null;
}
@Nullable

View File

@@ -27,9 +27,18 @@ public class BlockModels {
generator.getVariantBuilder(block)
.forAllStates(state -> {
Direction dir = state.get(BlockDirection.ANY.getProperty());
int xRotation = 0;
if (dir == Direction.DOWN) {
xRotation = 180;
}
if (dir.getAxis().isHorizontal()) {
xRotation = 90;
}
return ConfiguredModel.builder()
.modelFile(modelFunc.apply(state))
.rotationX(dir == Direction.DOWN ? 180 : dir.getAxis().isHorizontal() ? 90 : 0)
.rotationX(xRotation)
.rotationY(dir.getAxis().isVertical() ? 0 : (((int) dir.getHorizontalAngle()) + angleOffset) % 360)
.build();
});
@@ -39,9 +48,17 @@ public class BlockModels {
generator.getVariantBuilder(block)
.forAllStates(state -> {
Direction dir = state.get(BlockDirection.ANY.getProperty());
int xRotation;
if (dir.getAxis() == Direction.Axis.Y) {
xRotation = dir == Direction.UP ? 180 : 0;
} else {
xRotation = dir.getAxis().isHorizontal() ? 90 : 0;
}
return ConfiguredModel.builder()
.modelFile(modelFunc.apply(state))
.rotationX(dir.getAxis() == Direction.Axis.Y ? (dir == Direction.UP ? 180 : 0) : dir.getAxis().isHorizontal() ? 90 : 0)
.rotationX(xRotation)
.rotationY(dir.getAxis().isVertical() ? 0 : (((int) dir.getHorizontalAngle()) + angleOffset) % 360)
.build();
});

View File

@@ -34,7 +34,7 @@ public class ControllerLootFunction extends LootFunction {
@Override
public LootFunctionType func_230425_b_() {
return RSLootFunctions.CONTROLLER;
return RSLootFunctions.getController();
}
public static LootFunction.Builder<?> builder() {

View File

@@ -36,7 +36,7 @@ public class CrafterLootFunction extends LootFunction {
@Override
public LootFunctionType func_230425_b_() {
return RSLootFunctions.CRAFTER;
return RSLootFunctions.getCrafter();
}
public static LootFunction.Builder<?> builder() {

View File

@@ -30,7 +30,7 @@ public class PortableGridBlockLootFunction extends LootFunction {
@Override
public LootFunctionType func_230425_b_() {
return RSLootFunctions.PORTABLE_GRID;
return RSLootFunctions.getPortableGrid();
}
public static class Serializer extends LootFunction.Serializer<PortableGridBlockLootFunction> {

View File

@@ -51,7 +51,7 @@ public class StorageBlockLootFunction extends LootFunction {
@Override
public LootFunctionType func_230425_b_() {
return RSLootFunctions.STORAGE_BLOCK;
return RSLootFunctions.getStorageBlock();
}
public static class Serializer extends LootFunction.Serializer<StorageBlockLootFunction> {

View File

@@ -356,7 +356,7 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
public abstract void renderForeground(MatrixStack matrixStack, int mouseX, int mouseY);
public static <T> void executeLater(Class<T> clazz, Consumer<T> callback) {
ACTIONS.computeIfAbsent(clazz, eky -> new ArrayDeque<>()).add(callback);
ACTIONS.computeIfAbsent(clazz, key -> new ArrayDeque<>()).add(callback);
}
public static void executeLater(Consumer<ContainerScreen> callback) {

View File

@@ -91,7 +91,16 @@ public class CrafterManagerScreen extends BaseScreen<CrafterManagerContainer> im
for (int i = 0; i < rows; ++i) {
yy += 18;
blit(matrixStack, x, yy, 0, getTopHeight() + (i > 0 ? (i == rows - 1 ? 18 * 2 : 18) : 0), xSize, 18);
int yTextureStart = getTopHeight();
if (i > 0) {
if (i == rows - 1) {
yTextureStart += 18 * 2;
} else {
yTextureStart += 18;
}
}
blit(matrixStack, x, yy, 0, yTextureStart, xSize, 18);
}
yy += 18;

View File

@@ -15,12 +15,14 @@ public class DiskDriveScreen extends StorageScreen<DiskDriveContainer> {
inventory,
title,
"gui/disk_drive.png",
new StorageScreenTileDataParameters(
DiskDriveTile.TYPE,
NetworkNodeTile.REDSTONE_MODE,
DiskDriveTile.COMPARE,
DiskDriveTile.WHITELIST_BLACKLIST,
DiskDriveTile.PRIORITY,
DiskDriveTile.ACCESS_TYPE,
DiskDriveTile.ACCESS_TYPE
),
DiskDriveTile.STORED::getValue,
DiskDriveTile.CAPACITY::getValue
);

View File

@@ -13,12 +13,14 @@ public class ExternalStorageScreen extends StorageScreen<ExternalStorageContaine
inventory,
title,
"gui/storage.png",
new StorageScreenTileDataParameters(
ExternalStorageTile.TYPE,
NetworkNodeTile.REDSTONE_MODE,
ExternalStorageTile.COMPARE,
ExternalStorageTile.WHITELIST_BLACKLIST,
ExternalStorageTile.PRIORITY,
ExternalStorageTile.ACCESS_TYPE,
ExternalStorageTile.ACCESS_TYPE
),
ExternalStorageTile.STORED::getValue,
ExternalStorageTile.CAPACITY::getValue
);

View File

@@ -13,12 +13,14 @@ public class FluidStorageBlockScreen extends StorageScreen<FluidStorageContainer
inventory,
title,
"gui/storage.png",
new StorageScreenTileDataParameters(
null,
NetworkNodeTile.REDSTONE_MODE,
FluidStorageTile.COMPARE,
FluidStorageTile.WHITELIST_BLACKLIST,
FluidStorageTile.PRIORITY,
FluidStorageTile.ACCESS_TYPE,
FluidStorageTile.ACCESS_TYPE
),
FluidStorageTile.STORED::getValue,
() -> (long) ((FluidStorageTile) container.getTile()).getFluidStorageType().getCapacity()
);

View File

@@ -13,12 +13,14 @@ public class StorageBlockScreen extends StorageScreen<StorageContainer> {
inventory,
title,
"gui/storage.png",
new StorageScreenTileDataParameters(
null,
NetworkNodeTile.REDSTONE_MODE,
StorageTile.COMPARE,
StorageTile.WHITELIST_BLACKLIST,
StorageTile.PRIORITY,
StorageTile.ACCESS_TYPE,
StorageTile.ACCESS_TYPE
),
StorageTile.STORED::getValue,
() -> (long) ((StorageTile) container.getTile()).getItemStorageType().getCapacity()
);

View File

@@ -2,10 +2,8 @@ package com.refinedmods.refinedstorage.screen;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.storage.AccessType;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.screen.widget.sidebutton.*;
import com.refinedmods.refinedstorage.tile.data.TileDataParameter;
import com.refinedmods.refinedstorage.util.RenderUtils;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
@@ -14,7 +12,6 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import javax.annotation.Nullable;
import java.util.function.Supplier;
public class StorageScreen<T extends Container> extends BaseScreen<T> {
@@ -24,12 +21,7 @@ public class StorageScreen<T extends Container> extends BaseScreen<T> {
private static final int BAR_HEIGHT = 70;
private final String texture;
private final TileDataParameter<Integer, ?> typeParameter;
private final TileDataParameter<Integer, ?> redstoneModeParameter;
private final TileDataParameter<Integer, ?> exactModeParameter;
private final TileDataParameter<Integer, ?> whitelistBlacklistParameter;
private final TileDataParameter<Integer, ?> priorityParameter;
private final TileDataParameter<AccessType, ?> accessTypeParameter;
private final StorageScreenTileDataParameters dataParameters;
private final Supplier<Long> storedSupplier;
private final Supplier<Long> capacitySupplier;
@@ -37,51 +29,50 @@ public class StorageScreen<T extends Container> extends BaseScreen<T> {
PlayerInventory inventory,
ITextComponent title,
String texture,
@Nullable TileDataParameter<Integer, ?> typeParameter,
@Nullable TileDataParameter<Integer, ?> redstoneModeParameter,
@Nullable TileDataParameter<Integer, ?> exactModeParameter,
@Nullable TileDataParameter<Integer, ?> whitelistBlacklistParameter,
TileDataParameter<Integer, ?> priorityParameter,
@Nullable TileDataParameter<AccessType, ?> accessTypeParameter,
Supplier<Long> storedSupplier, Supplier<Long> capacitySupplier) {
StorageScreenTileDataParameters dataParameters,
Supplier<Long> storedSupplier,
Supplier<Long> capacitySupplier) {
super(container, 176, 223, inventory, title);
this.texture = texture;
this.typeParameter = typeParameter;
this.redstoneModeParameter = redstoneModeParameter;
this.exactModeParameter = exactModeParameter;
this.whitelistBlacklistParameter = whitelistBlacklistParameter;
this.priorityParameter = priorityParameter;
this.accessTypeParameter = accessTypeParameter;
this.dataParameters = dataParameters;
this.storedSupplier = storedSupplier;
this.capacitySupplier = capacitySupplier;
}
@Override
public void onPostInit(int x, int y) {
if (redstoneModeParameter != null) {
addSideButton(new RedstoneModeSideButton(this, redstoneModeParameter));
if (dataParameters.getRedstoneModeParameter() != null) {
addSideButton(new RedstoneModeSideButton(this, dataParameters.getRedstoneModeParameter()));
}
if (typeParameter != null) {
addSideButton(new TypeSideButton(this, typeParameter));
if (dataParameters.getTypeParameter() != null) {
addSideButton(new TypeSideButton(this, dataParameters.getTypeParameter()));
}
if (whitelistBlacklistParameter != null) {
addSideButton(new WhitelistBlacklistSideButton(this, whitelistBlacklistParameter));
if (dataParameters.getWhitelistBlacklistParameter() != null) {
addSideButton(new WhitelistBlacklistSideButton(this, dataParameters.getWhitelistBlacklistParameter()));
}
if (exactModeParameter != null) {
addSideButton(new ExactModeSideButton(this, exactModeParameter));
if (dataParameters.getExactModeParameter() != null) {
addSideButton(new ExactModeSideButton(this, dataParameters.getExactModeParameter()));
}
if (accessTypeParameter != null) {
addSideButton(new AccessTypeSideButton(this, accessTypeParameter));
if (dataParameters.getAccessTypeParameter() != null) {
addSideButton(new AccessTypeSideButton(this, dataParameters.getAccessTypeParameter()));
}
int buttonWidth = 10 + font.getStringWidth(I18n.format("misc.refinedstorage.priority"));
addButton(x + 169 - buttonWidth, y + 41, buttonWidth, 20, new TranslationTextComponent("misc.refinedstorage.priority"), true, true, btn -> minecraft.displayGuiScreen(new PriorityScreen(this, priorityParameter, playerInventory)));
addButton(
x + 169 - buttonWidth,
y + 41, buttonWidth,
20,
new TranslationTextComponent("misc.refinedstorage.priority"),
true,
true,
btn -> minecraft.displayGuiScreen(new PriorityScreen(this, dataParameters.getPriorityParameter(), playerInventory))
);
}
@Override

View File

@@ -0,0 +1,58 @@
package com.refinedmods.refinedstorage.screen;
import com.refinedmods.refinedstorage.api.storage.AccessType;
import com.refinedmods.refinedstorage.tile.data.TileDataParameter;
import javax.annotation.Nullable;
public class StorageScreenTileDataParameters {
@Nullable
private final TileDataParameter<Integer, ?> typeParameter;
@Nullable
private final TileDataParameter<Integer, ?> redstoneModeParameter;
@Nullable
private final TileDataParameter<Integer, ?> exactModeParameter;
@Nullable
private final TileDataParameter<Integer, ?> whitelistBlacklistParameter;
private final TileDataParameter<Integer, ?> priorityParameter;
@Nullable
private final TileDataParameter<AccessType, ?> accessTypeParameter;
public StorageScreenTileDataParameters(@Nullable TileDataParameter<Integer, ?> typeParameter, @Nullable TileDataParameter<Integer, ?> redstoneModeParameter, @Nullable TileDataParameter<Integer, ?> exactModeParameter, @Nullable TileDataParameter<Integer, ?> whitelistBlacklistParameter, TileDataParameter<Integer, ?> priorityParameter, @Nullable TileDataParameter<AccessType, ?> accessTypeParameter) {
this.typeParameter = typeParameter;
this.redstoneModeParameter = redstoneModeParameter;
this.exactModeParameter = exactModeParameter;
this.whitelistBlacklistParameter = whitelistBlacklistParameter;
this.priorityParameter = priorityParameter;
this.accessTypeParameter = accessTypeParameter;
}
@Nullable
public TileDataParameter<Integer, ?> getTypeParameter() {
return typeParameter;
}
@Nullable
public TileDataParameter<Integer, ?> getRedstoneModeParameter() {
return redstoneModeParameter;
}
@Nullable
public TileDataParameter<Integer, ?> getExactModeParameter() {
return exactModeParameter;
}
@Nullable
public TileDataParameter<Integer, ?> getWhitelistBlacklistParameter() {
return whitelistBlacklistParameter;
}
public TileDataParameter<Integer, ?> getPriorityParameter() {
return priorityParameter;
}
@Nullable
public TileDataParameter<AccessType, ?> getAccessTypeParameter() {
return accessTypeParameter;
}
}

View File

@@ -315,7 +315,16 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
for (int i = 0; i < rows; ++i) {
yy += 18;
blit(matrixStack, x, yy, 0, getTopHeight() + (i > 0 ? (i == rows - 1 ? 18 * 2 : 18) : 0), xSize - 34, 18);
int yTextureStart = getTopHeight();
if (i > 0) {
if (i == rows - 1) {
yTextureStart += 18 * 2;
} else {
yTextureStart += 18;
}
}
blit(matrixStack, x, yy, 0, yTextureStart, xSize - 34, 18);
}
yy += 18;

View File

@@ -25,7 +25,7 @@ public abstract class SearchBoxModeSideButton extends SideButton {
return MODE_ROTATION.get(MODE_ROTATION.indexOf(oldMode) + 1);
}
public SearchBoxModeSideButton(BaseScreen<?> screen) {
protected SearchBoxModeSideButton(BaseScreen<?> screen) {
super(screen);
}