More SonarQube fixes.
This commit is contained in:
@@ -3,7 +3,7 @@ package com.refinedmods.refinedstorage.apiimpl.autocrafting;
|
|||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
public class CraftingPatternFactoryException extends Exception {
|
public class CraftingPatternFactoryException extends Exception {
|
||||||
private final ITextComponent errorMessage;
|
private final transient ITextComponent errorMessage;
|
||||||
|
|
||||||
public CraftingPatternFactoryException(ITextComponent errorMessage) {
|
public CraftingPatternFactoryException(ITextComponent errorMessage) {
|
||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
|
@@ -104,14 +104,12 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!took.isEmpty()) {
|
if (!took.isEmpty() && ItemHandlerHelper.insertItemStacked(playerInventory, took, true).isEmpty()) {
|
||||||
if (ItemHandlerHelper.insertItemStacked(playerInventory, took, true).isEmpty()) {
|
|
||||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||||
|
|
||||||
ItemHandlerHelper.insertItemStacked(playerInventory, took, false);
|
ItemHandlerHelper.insertItemStacked(playerInventory, took, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||||
|
|
||||||
|
@@ -198,13 +198,11 @@ public class StorageMonitorNetworkNode extends NetworkNode implements IComparabl
|
|||||||
if (!filter.isEmpty()) {
|
if (!filter.isEmpty()) {
|
||||||
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
|
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
|
||||||
|
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty() && !player.inventory.addItemStackToInventory(result.copy())) {
|
||||||
if (!player.inventory.addItemStackToInventory(result.copy())) {
|
|
||||||
InventoryHelper.spawnItemStack(world, player.getPosX(), player.getPosY(), player.getPosZ(), result);
|
InventoryHelper.spawnItemStack(world, player.getPosX(), player.getPosY(), player.getPosZ(), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void extractFluids(PlayerEntity player) {
|
private void extractFluids(PlayerEntity player) {
|
||||||
FluidStack filter = fluidFilter.getFluid(0);
|
FluidStack filter = fluidFilter.getFluid(0);
|
||||||
|
@@ -17,17 +17,13 @@ public class Comparer implements IComparer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
if ((flags & COMPARE_NBT) == COMPARE_NBT && !ItemStack.areItemStackTagsEqual(left, right)) {
|
||||||
if (!ItemStack.areItemStackTagsEqual(left, right)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY && left.getCount() != right.getCount()) {
|
||||||
if (left.getCount() != right.getCount()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -42,17 +38,13 @@ public class Comparer implements IComparer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
if ((flags & COMPARE_NBT) == COMPARE_NBT && !FluidStack.areFluidStackTagsEqual(left, right)) {
|
||||||
if (!FluidStack.areFluidStackTagsEqual(left, right)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY && left.getAmount() != right.getAmount()) {
|
||||||
if (left.getAmount() != right.getAmount()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ public class ServerConfig {
|
|||||||
private final Relay relay;
|
private final Relay relay;
|
||||||
private final Detector detector;
|
private final Detector detector;
|
||||||
private final SecurityManager securityManager;
|
private final SecurityManager securityManager;
|
||||||
private final Interface _interface;
|
private final Interface iface;
|
||||||
private final FluidInterface fluidInterface;
|
private final FluidInterface fluidInterface;
|
||||||
private final WirelessTransmitter wirelessTransmitter;
|
private final WirelessTransmitter wirelessTransmitter;
|
||||||
private final StorageMonitor storageMonitor;
|
private final StorageMonitor storageMonitor;
|
||||||
@@ -53,7 +53,7 @@ public class ServerConfig {
|
|||||||
relay = new Relay();
|
relay = new Relay();
|
||||||
detector = new Detector();
|
detector = new Detector();
|
||||||
securityManager = new SecurityManager();
|
securityManager = new SecurityManager();
|
||||||
_interface = new Interface();
|
iface = new Interface();
|
||||||
fluidInterface = new FluidInterface();
|
fluidInterface = new FluidInterface();
|
||||||
wirelessTransmitter = new WirelessTransmitter();
|
wirelessTransmitter = new WirelessTransmitter();
|
||||||
storageMonitor = new StorageMonitor();
|
storageMonitor = new StorageMonitor();
|
||||||
@@ -137,7 +137,7 @@ public class ServerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Interface getInterface() {
|
public Interface getInterface() {
|
||||||
return _interface;
|
return iface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FluidInterface getFluidInterface() {
|
public FluidInterface getFluidInterface() {
|
||||||
|
@@ -76,11 +76,10 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
|
|||||||
transferManager.setNotFoundHandler(slotIndex -> {
|
transferManager.setNotFoundHandler(slotIndex -> {
|
||||||
if (!getPlayer().getEntityWorld().isRemote) {
|
if (!getPlayer().getEntityWorld().isRemote) {
|
||||||
Slot slot = inventorySlots.get(slotIndex);
|
Slot slot = inventorySlots.get(slotIndex);
|
||||||
if (grid instanceof IPortableGrid && slot instanceof SlotItemHandler) {
|
if (grid instanceof IPortableGrid && slot instanceof SlotItemHandler && ((SlotItemHandler) slot).getItemHandler().equals(((IPortableGrid) grid).getDiskInventory())) {
|
||||||
if (((SlotItemHandler) slot).getItemHandler().equals(((IPortableGrid) grid).getDisk())) {
|
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (slot.getHasStack()) {
|
if (slot.getHasStack()) {
|
||||||
if (slot == craftingResultSlot) {
|
if (slot == craftingResultSlot) {
|
||||||
grid.onCraftedShift(getPlayer());
|
grid.onCraftedShift(getPlayer());
|
||||||
@@ -122,9 +121,9 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addPortableGridSlots() {
|
private void addPortableGridSlots() {
|
||||||
addSlot(new SlotItemHandler(((IPortableGrid) grid).getDisk(), 0, 204, 6));
|
addSlot(new SlotItemHandler(((IPortableGrid) grid).getDiskInventory(), 0, 204, 6));
|
||||||
|
|
||||||
transferManager.addBiTransfer(getPlayer().inventory, ((IPortableGrid) grid).getDisk());
|
transferManager.addBiTransfer(getPlayer().inventory, ((IPortableGrid) grid).getDiskInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFilterSlots() {
|
private void addFilterSlots() {
|
||||||
|
@@ -30,8 +30,7 @@ public class GhostIngredientHandler implements IGhostIngredientHandler<BaseScree
|
|||||||
|
|
||||||
Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.xPos, gui.getGuiTop() + slot.yPos, 17, 17);
|
Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.xPos, gui.getGuiTop() + slot.yPos, 17, 17);
|
||||||
|
|
||||||
if (ingredient instanceof ItemStack) {
|
if (ingredient instanceof ItemStack && (slot instanceof LegacyFilterSlot || slot instanceof FilterSlot)) {
|
||||||
if (slot instanceof LegacyFilterSlot || slot instanceof FilterSlot) {
|
|
||||||
targets.add(new Target<I>() {
|
targets.add(new Target<I>() {
|
||||||
@Override
|
@Override
|
||||||
public Rectangle2d getArea() {
|
public Rectangle2d getArea() {
|
||||||
@@ -45,9 +44,7 @@ public class GhostIngredientHandler implements IGhostIngredientHandler<BaseScree
|
|||||||
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(slot.slotNumber, (ItemStack) ingredient));
|
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(slot.slotNumber, (ItemStack) ingredient));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else if (ingredient instanceof FluidStack && slot instanceof FluidFilterSlot) {
|
||||||
} else if (ingredient instanceof FluidStack) {
|
|
||||||
if (slot instanceof FluidFilterSlot) {
|
|
||||||
targets.add(new Target<I>() {
|
targets.add(new Target<I>() {
|
||||||
@Override
|
@Override
|
||||||
public Rectangle2d getArea() {
|
public Rectangle2d getArea() {
|
||||||
@@ -61,7 +58,6 @@ public class GhostIngredientHandler implements IGhostIngredientHandler<BaseScree
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
@@ -79,8 +79,8 @@ public class PortableGridBlockItem extends EnergyBlockItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||||
if (oldStack.getItem() == newStack.getItem()) {
|
if (oldStack.getItem() == newStack.getItem() &&
|
||||||
if (WirelessGridItem.getSortingDirection(oldStack) == WirelessGridItem.getSortingDirection(newStack) &&
|
WirelessGridItem.getSortingDirection(oldStack) == WirelessGridItem.getSortingDirection(newStack) &&
|
||||||
WirelessGridItem.getSortingType(oldStack) == WirelessGridItem.getSortingType(newStack) &&
|
WirelessGridItem.getSortingType(oldStack) == WirelessGridItem.getSortingType(newStack) &&
|
||||||
WirelessGridItem.getSearchBoxMode(oldStack) == WirelessGridItem.getSearchBoxMode(newStack) &&
|
WirelessGridItem.getSearchBoxMode(oldStack) == WirelessGridItem.getSearchBoxMode(newStack) &&
|
||||||
WirelessGridItem.getTabSelected(oldStack) == WirelessGridItem.getTabSelected(newStack) &&
|
WirelessGridItem.getTabSelected(oldStack) == WirelessGridItem.getTabSelected(newStack) &&
|
||||||
@@ -88,7 +88,6 @@ public class PortableGridBlockItem extends EnergyBlockItem {
|
|||||||
WirelessGridItem.getSize(oldStack) == WirelessGridItem.getSize(newStack)) {
|
WirelessGridItem.getSize(oldStack) == WirelessGridItem.getSize(newStack)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
|
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,17 @@ public class SetFilterSlotMessage {
|
|||||||
ctx.get().enqueueWork(() -> {
|
ctx.get().enqueueWork(() -> {
|
||||||
Container container = player.openContainer;
|
Container container = player.openContainer;
|
||||||
|
|
||||||
if (container != null) {
|
if (container != null && message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
||||||
if (message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
handle(message, container);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handle(SetFilterSlotMessage message, Container container) {
|
||||||
Slot slot = container.getSlot(message.containerSlot);
|
Slot slot = container.getSlot(message.containerSlot);
|
||||||
|
|
||||||
if (slot instanceof FilterSlot || slot instanceof LegacyFilterSlot) {
|
if (slot instanceof FilterSlot || slot instanceof LegacyFilterSlot) {
|
||||||
@@ -64,10 +73,3 @@ public class SetFilterSlotMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -31,14 +31,24 @@ public class SetFluidFilterSlotMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void handle(SetFluidFilterSlotMessage message, Supplier<NetworkEvent.Context> ctx) {
|
public static void handle(SetFluidFilterSlotMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
if (!message.stack.isEmpty()) {
|
||||||
PlayerEntity player = ctx.get().getSender();
|
PlayerEntity player = ctx.get().getSender();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ctx.get().enqueueWork(() -> {
|
ctx.get().enqueueWork(() -> {
|
||||||
Container container = player.openContainer;
|
Container container = player.openContainer;
|
||||||
|
|
||||||
if (container != null) {
|
if (container != null && message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
||||||
if (message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
handle(message, container);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handle(SetFluidFilterSlotMessage message, Container container) {
|
||||||
Slot slot = container.getSlot(message.containerSlot);
|
Slot slot = container.getSlot(message.containerSlot);
|
||||||
|
|
||||||
if (slot instanceof FluidFilterSlot) {
|
if (slot instanceof FluidFilterSlot) {
|
||||||
@@ -54,9 +64,3 @@ public class SetFluidFilterSlotMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.get().setPacketHandled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -356,13 +356,7 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
|
|||||||
public abstract void renderForeground(MatrixStack matrixStack, int mouseX, int mouseY);
|
public abstract void renderForeground(MatrixStack matrixStack, int mouseX, int mouseY);
|
||||||
|
|
||||||
public static <T> void executeLater(Class<T> clazz, Consumer<T> callback) {
|
public static <T> void executeLater(Class<T> clazz, Consumer<T> callback) {
|
||||||
Queue<Consumer> queue = ACTIONS.get(clazz);
|
ACTIONS.computeIfAbsent(clazz, eky -> new ArrayDeque<>()).add(callback);
|
||||||
|
|
||||||
if (queue == null) {
|
|
||||||
ACTIONS.put(clazz, queue = new ArrayDeque<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
queue.add(callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeLater(Consumer<ContainerScreen> callback) {
|
public static void executeLater(Consumer<ContainerScreen> callback) {
|
||||||
|
@@ -72,7 +72,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IFilter> getFilters() {
|
public List<IFilter> getFilters() {
|
||||||
return null;
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -203,7 +203,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cancelAllButton != null) {
|
if (cancelAllButton != null) {
|
||||||
cancelAllButton.active = tasks.size() > 0;
|
cancelAllButton.active = !tasks.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ public class CraftingSettingsScreen extends AmountSpecifyingScreen<CraftingSetti
|
|||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onOkButtonPressed(boolean shiftDown) {
|
protected void onOkButtonPressed(boolean shiftDown) {
|
||||||
try {
|
try {
|
||||||
int quantity = Integer.parseInt(amountField.getText());
|
int quantity = Integer.parseInt(amountField.getText());
|
||||||
|
@@ -526,12 +526,10 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
|||||||
doSort = !isOverSlotArea(x - guiLeft, y - guiTop) && !isOverCraftingOutputArea(x - guiLeft, y - guiTop);
|
doSort = !isOverSlotArea(x - guiLeft, y - guiTop) && !isOverCraftingOutputArea(x - guiLeft, y - guiTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOverInventory(x - guiLeft, y - guiTop)) {
|
|
||||||
if (grid.getGridType() != GridType.FLUID && hoveredSlot != null && hoveredSlot.getHasStack()) {
|
|
||||||
RS.NETWORK_HANDLER.sendToServer(new GridItemInventoryScrollMessage(hoveredSlot.getSlotIndex(), hasShiftDown(), delta > 0));
|
|
||||||
}
|
|
||||||
} else if (isOverSlotArea(x - guiLeft, y - guiTop)) {
|
|
||||||
if (grid.getGridType() != GridType.FLUID) {
|
if (grid.getGridType() != GridType.FLUID) {
|
||||||
|
if (isOverInventory(x - guiLeft, y - guiTop) && hoveredSlot != null && hoveredSlot.getHasStack()) {
|
||||||
|
RS.NETWORK_HANDLER.sendToServer(new GridItemInventoryScrollMessage(hoveredSlot.getSlotIndex(), hasShiftDown(), delta > 0));
|
||||||
|
} else if (isOverSlotArea(x - guiLeft, y - guiTop)) {
|
||||||
RS.NETWORK_HANDLER.sendToServer(new GridItemGridScrollMessage(isOverSlotWithStack() ? view.getStacks().get(slotNumber).getId() : null, hasShiftDown(), delta > 0));
|
RS.NETWORK_HANDLER.sendToServer(new GridItemGridScrollMessage(isOverSlotWithStack() ? view.getStacks().get(slotNumber).getId() : null, hasShiftDown(), delta > 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ public class CheckboxWidget extends CheckboxButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
super.drawString(matrixStack, fontrenderer, this.getMessage(), this.x + 13, this.y + (this.height - 8) / 2, color);
|
drawString(matrixStack, fontrenderer, this.getMessage(), this.x + 13, this.y + (this.height - 8) / 2, color);
|
||||||
} else {
|
} else {
|
||||||
fontrenderer.drawString(matrixStack, this.getMessage().getString(), this.x + 13, this.y + (this.height - 8) / 2F, color);
|
fontrenderer.drawString(matrixStack, this.getMessage().getString(), this.x + 13, this.y + (this.height - 8) / 2F, color);
|
||||||
}
|
}
|
||||||
|
@@ -38,11 +38,9 @@ public class CrafterTile extends NetworkNodeTile<CrafterNetworkNode> {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction direction) {
|
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction direction) {
|
||||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && direction != null && !direction.equals(this.getNode().getDirection())) {
|
||||||
if (direction != null && !direction.equals(this.getNode().getDirection())) {
|
|
||||||
return patternsCapability.cast();
|
return patternsCapability.cast();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return super.getCapability(cap, direction);
|
return super.getCapability(cap, direction);
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ public interface IPortableGrid {
|
|||||||
|
|
||||||
int getEnergy();
|
int getEnergy();
|
||||||
|
|
||||||
BaseItemHandler getDisk();
|
BaseItemHandler getDiskInventory();
|
||||||
|
|
||||||
IItemHandlerModifiable getFilter();
|
IItemHandlerModifiable getFilter();
|
||||||
|
|
||||||
|
@@ -107,10 +107,10 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
|||||||
storage = null;
|
storage = null;
|
||||||
cache = null;
|
cache = null;
|
||||||
} else {
|
} else {
|
||||||
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) player.world).getByStack(getDisk().getStackInSlot(0));
|
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) player.world).getByStack(getDiskInventory().getStackInSlot(0));
|
||||||
|
|
||||||
if (disk != null) {
|
if (disk != null) {
|
||||||
StorageType type = ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType();
|
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ITEM:
|
case ITEM:
|
||||||
@@ -209,7 +209,7 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemHandler getDisk() {
|
public BaseItemHandler getDiskInventory() {
|
||||||
return disk;
|
return disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GridType getGridType() {
|
public GridType getGridType() {
|
||||||
return (getDisk().getStackInSlot(0).isEmpty() || ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType() == StorageType.ITEM) ? GridType.NORMAL : GridType.FLUID;
|
return (getDiskInventory().getStackInSlot(0).isEmpty() || ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType() == StorageType.ITEM) ? GridType.NORMAL : GridType.FLUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@@ -188,16 +188,16 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadStorage() {
|
private void loadStorage() {
|
||||||
ItemStack diskStack = getDisk().getStackInSlot(0);
|
ItemStack diskStack = getDiskInventory().getStackInSlot(0);
|
||||||
|
|
||||||
if (diskStack.isEmpty()) {
|
if (diskStack.isEmpty()) {
|
||||||
this.storage = null;
|
this.storage = null;
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
} else {
|
} else {
|
||||||
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).getByStack(getDisk().getStackInSlot(0));
|
IStorageDisk disk = API.instance().getStorageDiskManager((ServerWorld) world).getByStack(getDiskInventory().getStackInSlot(0));
|
||||||
|
|
||||||
if (disk != null) {
|
if (disk != null) {
|
||||||
StorageType type = ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType();
|
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ITEM:
|
case ITEM:
|
||||||
@@ -311,7 +311,7 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GridType getServerGridType() {
|
private GridType getServerGridType() {
|
||||||
return (getDisk().getStackInSlot(0).isEmpty() || ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType() == StorageType.ITEM) ? GridType.NORMAL : GridType.FLUID;
|
return (getDiskInventory().getStackInSlot(0).isEmpty() || ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType() == StorageType.ITEM) ? GridType.NORMAL : GridType.FLUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -625,7 +625,7 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseItemHandler getDisk() {
|
public BaseItemHandler getDiskInventory() {
|
||||||
return disk;
|
return disk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import net.minecraftforge.registries.DeferredRegister;
|
|||||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -34,7 +34,7 @@ import java.util.function.Supplier;
|
|||||||
public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
||||||
public static final DyeColor DEFAULT_COLOR = DyeColor.LIGHT_BLUE;
|
public static final DyeColor DEFAULT_COLOR = DyeColor.LIGHT_BLUE;
|
||||||
|
|
||||||
private final Map<DyeColor, RegistryObject<T>> colorMap = new HashMap<>();
|
private final Map<DyeColor, RegistryObject<T>> map = new EnumMap<>(DyeColor.class);
|
||||||
|
|
||||||
private DeferredRegister<Item> itemRegister;
|
private DeferredRegister<Item> itemRegister;
|
||||||
private DeferredRegister<Block> blockRegister;
|
private DeferredRegister<Block> blockRegister;
|
||||||
@@ -50,40 +50,40 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RegistryObject<T> get(DyeColor color) {
|
public RegistryObject<T> get(DyeColor color) {
|
||||||
return colorMap.get(color);
|
return map.get(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<RegistryObject<T>> values() {
|
public Collection<RegistryObject<T>> values() {
|
||||||
return colorMap.values();
|
return map.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(DyeColor color, RegistryObject<T> object) {
|
public void put(DyeColor color, RegistryObject<T> object) {
|
||||||
colorMap.put(color, object);
|
map.put(color, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forEach(BiConsumer<DyeColor, RegistryObject<T>> consumer) {
|
public void forEach(BiConsumer<DyeColor, RegistryObject<T>> consumer) {
|
||||||
colorMap.forEach(consumer);
|
map.forEach(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block[] getBlocks() {
|
public Block[] getBlocks() {
|
||||||
return colorMap.values().stream().map(RegistryObject::get).toArray(Block[]::new);
|
return map.values().stream().map(RegistryObject::get).toArray(Block[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <S extends Block> void registerBlocks(String name, Supplier<S> blockFactory) {
|
public <S extends Block> void registerBlocks(String name, Supplier<S> blockFactory) {
|
||||||
for (DyeColor color : DyeColor.values()) {
|
for (DyeColor color : DyeColor.values()) {
|
||||||
String prefix = color != DEFAULT_COLOR ? color + "_" : "";
|
String prefix = color != DEFAULT_COLOR ? color + "_" : "";
|
||||||
RegistryObject<S> block = blockRegister.register(prefix + name, blockFactory);
|
RegistryObject<S> block = blockRegister.register(prefix + name, blockFactory);
|
||||||
colorMap.put(color, (RegistryObject<T>) block);
|
map.put(color, (RegistryObject<T>) block);
|
||||||
RSBlocks.COLORED_BLOCKS.add(block);
|
RSBlocks.COLORED_BLOCKS.add(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <S extends BaseBlock> void registerItemsFromBlocks(ColorMap<S> blockMap) {
|
public <S extends BaseBlock> void registerItemsFromBlocks(ColorMap<S> blockMap) {
|
||||||
RegistryObject<S> originalBlock = blockMap.get(DEFAULT_COLOR);
|
RegistryObject<S> originalBlock = blockMap.get(DEFAULT_COLOR);
|
||||||
colorMap.put(DEFAULT_COLOR, registerBlockItemFor(originalBlock, DEFAULT_COLOR, originalBlock));
|
map.put(DEFAULT_COLOR, registerBlockItemFor(originalBlock, DEFAULT_COLOR, originalBlock));
|
||||||
lateRegistration.add(() -> blockMap.forEach((color, block) -> {
|
lateRegistration.add(() -> blockMap.forEach((color, block) -> {
|
||||||
if (color != DEFAULT_COLOR) {
|
if (color != DEFAULT_COLOR) {
|
||||||
colorMap.put(color, registerBlockItemFor(block, color, originalBlock));
|
map.put(color, registerBlockItemFor(block, color, originalBlock));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
RSItems.COLORED_ITEM_TAGS.put(ItemTags.createOptional(new ResourceLocation(RS.ID, blockMap.get(DEFAULT_COLOR).getId().getPath())), (ColorMap<BlockItem>) this);
|
RSItems.COLORED_ITEM_TAGS.put(ItemTags.createOptional(new ResourceLocation(RS.ID, blockMap.get(DEFAULT_COLOR).getId().getPath())), (ColorMap<BlockItem>) this);
|
||||||
@@ -103,11 +103,11 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
|||||||
|
|
||||||
public <S extends BaseBlock> ActionResultType changeBlockColor(BlockState state, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {
|
public <S extends BaseBlock> ActionResultType changeBlockColor(BlockState state, ItemStack heldItem, World world, BlockPos pos, PlayerEntity player) {
|
||||||
DyeColor color = DyeColor.getColor(heldItem);
|
DyeColor color = DyeColor.getColor(heldItem);
|
||||||
if (color == null || state.getBlock().equals(colorMap.get(color).get())) {
|
if (color == null || state.getBlock().equals(map.get(color).get())) {
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setBlockState(getNewState((RegistryObject<S>) colorMap.get(color), state), heldItem, world, pos, player);
|
return setBlockState(getNewState((RegistryObject<S>) map.get(color), state), heldItem, world, pos, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <S extends BaseBlock> BlockState getNewState(RegistryObject<S> block, BlockState state) {
|
private <S extends BaseBlock> BlockState getNewState(RegistryObject<S> block, BlockState state) {
|
||||||
|
Reference in New Issue
Block a user