More SonarQube fixes.
This commit is contained in:
@@ -3,7 +3,7 @@ package com.refinedmods.refinedstorage.apiimpl.autocrafting;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class CraftingPatternFactoryException extends Exception {
|
||||
private final ITextComponent errorMessage;
|
||||
private final transient ITextComponent errorMessage;
|
||||
|
||||
public CraftingPatternFactoryException(ITextComponent errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
|
@@ -104,12 +104,10 @@ public class PortableItemGridHandler implements IItemGridHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!took.isEmpty()) {
|
||||
if (ItemHandlerHelper.insertItemStacked(playerInventory, took, true).isEmpty()) {
|
||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
if (!took.isEmpty() && ItemHandlerHelper.insertItemStacked(playerInventory, took, true).isEmpty()) {
|
||||
took = portableGrid.getItemStorage().extract(item, size, IComparer.COMPARE_NBT, Action.PERFORM);
|
||||
|
||||
ItemHandlerHelper.insertItemStacked(playerInventory, took, false);
|
||||
}
|
||||
ItemHandlerHelper.insertItemStacked(playerInventory, took, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@@ -198,10 +198,8 @@ public class StorageMonitorNetworkNode extends NetworkNode implements IComparabl
|
||||
if (!filter.isEmpty()) {
|
||||
ItemStack result = network.extractItem(filter, toExtract, compare, Action.PERFORM);
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
if (!player.inventory.addItemStackToInventory(result.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosX(), player.getPosY(), player.getPosZ(), result);
|
||||
}
|
||||
if (!result.isEmpty() && !player.inventory.addItemStackToInventory(result.copy())) {
|
||||
InventoryHelper.spawnItemStack(world, player.getPosX(), player.getPosY(), player.getPosZ(), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,16 +17,12 @@ public class Comparer implements IComparer {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
||||
if (!ItemStack.areItemStackTagsEqual(left, right)) {
|
||||
return false;
|
||||
}
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT && !ItemStack.areItemStackTagsEqual(left, right)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
||||
if (left.getCount() != right.getCount()) {
|
||||
return false;
|
||||
}
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY && left.getCount() != right.getCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -42,16 +38,12 @@ public class Comparer implements IComparer {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
||||
if (!FluidStack.areFluidStackTagsEqual(left, right)) {
|
||||
return false;
|
||||
}
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT && !FluidStack.areFluidStackTagsEqual(left, right)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
||||
if (left.getAmount() != right.getAmount()) {
|
||||
return false;
|
||||
}
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY && left.getAmount() != right.getAmount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -21,7 +21,7 @@ public class ServerConfig {
|
||||
private final Relay relay;
|
||||
private final Detector detector;
|
||||
private final SecurityManager securityManager;
|
||||
private final Interface _interface;
|
||||
private final Interface iface;
|
||||
private final FluidInterface fluidInterface;
|
||||
private final WirelessTransmitter wirelessTransmitter;
|
||||
private final StorageMonitor storageMonitor;
|
||||
@@ -53,7 +53,7 @@ public class ServerConfig {
|
||||
relay = new Relay();
|
||||
detector = new Detector();
|
||||
securityManager = new SecurityManager();
|
||||
_interface = new Interface();
|
||||
iface = new Interface();
|
||||
fluidInterface = new FluidInterface();
|
||||
wirelessTransmitter = new WirelessTransmitter();
|
||||
storageMonitor = new StorageMonitor();
|
||||
@@ -137,7 +137,7 @@ public class ServerConfig {
|
||||
}
|
||||
|
||||
public Interface getInterface() {
|
||||
return _interface;
|
||||
return iface;
|
||||
}
|
||||
|
||||
public FluidInterface getFluidInterface() {
|
||||
|
@@ -76,11 +76,10 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
|
||||
transferManager.setNotFoundHandler(slotIndex -> {
|
||||
if (!getPlayer().getEntityWorld().isRemote) {
|
||||
Slot slot = inventorySlots.get(slotIndex);
|
||||
if (grid instanceof IPortableGrid && slot instanceof SlotItemHandler) {
|
||||
if (((SlotItemHandler) slot).getItemHandler().equals(((IPortableGrid) grid).getDisk())) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (grid instanceof IPortableGrid && slot instanceof SlotItemHandler && ((SlotItemHandler) slot).getItemHandler().equals(((IPortableGrid) grid).getDiskInventory())) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (slot.getHasStack()) {
|
||||
if (slot == craftingResultSlot) {
|
||||
grid.onCraftedShift(getPlayer());
|
||||
@@ -122,9 +121,9 @@ public class GridContainer extends BaseContainer implements ICraftingGridListene
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@@ -30,36 +30,32 @@ public class GhostIngredientHandler implements IGhostIngredientHandler<BaseScree
|
||||
|
||||
Rectangle2d bounds = new Rectangle2d(gui.getGuiLeft() + slot.xPos, gui.getGuiTop() + slot.yPos, 17, 17);
|
||||
|
||||
if (ingredient instanceof ItemStack) {
|
||||
if (slot instanceof LegacyFilterSlot || slot instanceof FilterSlot) {
|
||||
targets.add(new Target<I>() {
|
||||
@Override
|
||||
public Rectangle2d getArea() {
|
||||
return bounds;
|
||||
}
|
||||
if (ingredient instanceof ItemStack && (slot instanceof LegacyFilterSlot || slot instanceof FilterSlot)) {
|
||||
targets.add(new Target<I>() {
|
||||
@Override
|
||||
public Rectangle2d getArea() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(I ingredient) {
|
||||
slot.putStack((ItemStack) ingredient);
|
||||
@Override
|
||||
public void accept(I ingredient) {
|
||||
slot.putStack((ItemStack) ingredient);
|
||||
|
||||
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(slot.slotNumber, (ItemStack) ingredient));
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (ingredient instanceof FluidStack) {
|
||||
if (slot instanceof FluidFilterSlot) {
|
||||
targets.add(new Target<I>() {
|
||||
@Override
|
||||
public Rectangle2d getArea() {
|
||||
return bounds;
|
||||
}
|
||||
RS.NETWORK_HANDLER.sendToServer(new SetFilterSlotMessage(slot.slotNumber, (ItemStack) ingredient));
|
||||
}
|
||||
});
|
||||
} else if (ingredient instanceof FluidStack && slot instanceof FluidFilterSlot) {
|
||||
targets.add(new Target<I>() {
|
||||
@Override
|
||||
public Rectangle2d getArea() {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(I ingredient) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new SetFluidFilterSlotMessage(slot.slotNumber, StackUtils.copy((FluidStack) ingredient, FluidAttributes.BUCKET_VOLUME)));
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void accept(I ingredient) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new SetFluidFilterSlotMessage(slot.slotNumber, StackUtils.copy((FluidStack) ingredient, FluidAttributes.BUCKET_VOLUME)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -79,15 +79,14 @@ public class PortableGridBlockItem extends EnergyBlockItem {
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||
if (oldStack.getItem() == newStack.getItem()) {
|
||||
if (WirelessGridItem.getSortingDirection(oldStack) == WirelessGridItem.getSortingDirection(newStack) &&
|
||||
WirelessGridItem.getSortingType(oldStack) == WirelessGridItem.getSortingType(newStack) &&
|
||||
WirelessGridItem.getSearchBoxMode(oldStack) == WirelessGridItem.getSearchBoxMode(newStack) &&
|
||||
WirelessGridItem.getTabSelected(oldStack) == WirelessGridItem.getTabSelected(newStack) &&
|
||||
WirelessGridItem.getTabPage(oldStack) == WirelessGridItem.getTabPage(newStack) &&
|
||||
WirelessGridItem.getSize(oldStack) == WirelessGridItem.getSize(newStack)) {
|
||||
return false;
|
||||
}
|
||||
if (oldStack.getItem() == newStack.getItem() &&
|
||||
WirelessGridItem.getSortingDirection(oldStack) == WirelessGridItem.getSortingDirection(newStack) &&
|
||||
WirelessGridItem.getSortingType(oldStack) == WirelessGridItem.getSortingType(newStack) &&
|
||||
WirelessGridItem.getSearchBoxMode(oldStack) == WirelessGridItem.getSearchBoxMode(newStack) &&
|
||||
WirelessGridItem.getTabSelected(oldStack) == WirelessGridItem.getTabSelected(newStack) &&
|
||||
WirelessGridItem.getTabPage(oldStack) == WirelessGridItem.getTabPage(newStack) &&
|
||||
WirelessGridItem.getSize(oldStack) == WirelessGridItem.getSize(newStack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
|
||||
|
@@ -40,29 +40,8 @@ public class SetFilterSlotMessage {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container != null) {
|
||||
if (message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
||||
Slot slot = container.getSlot(message.containerSlot);
|
||||
|
||||
if (slot instanceof FilterSlot || slot instanceof LegacyFilterSlot) {
|
||||
// Avoid resetting allowed tag list in the pattern grid.
|
||||
if (API.instance().getComparer().isEqualNoQuantity(slot.getStack(), message.stack)) {
|
||||
slot.getStack().setCount(message.stack.getCount());
|
||||
|
||||
if (slot instanceof FilterSlot) {
|
||||
IItemHandler itemHandler = ((FilterSlot) slot).getItemHandler();
|
||||
|
||||
if (itemHandler instanceof BaseItemHandler) {
|
||||
((BaseItemHandler) itemHandler).onChanged(slot.getSlotIndex());
|
||||
}
|
||||
} else {
|
||||
slot.inventory.markDirty();
|
||||
}
|
||||
} else {
|
||||
slot.putStack(message.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (container != null && message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
||||
handle(message, container);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -70,4 +49,27 @@ public class SetFilterSlotMessage {
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
private static void handle(SetFilterSlotMessage message, Container container) {
|
||||
Slot slot = container.getSlot(message.containerSlot);
|
||||
|
||||
if (slot instanceof FilterSlot || slot instanceof LegacyFilterSlot) {
|
||||
// Avoid resetting allowed tag list in the pattern grid.
|
||||
if (API.instance().getComparer().isEqualNoQuantity(slot.getStack(), message.stack)) {
|
||||
slot.getStack().setCount(message.stack.getCount());
|
||||
|
||||
if (slot instanceof FilterSlot) {
|
||||
IItemHandler itemHandler = ((FilterSlot) slot).getItemHandler();
|
||||
|
||||
if (itemHandler instanceof BaseItemHandler) {
|
||||
((BaseItemHandler) itemHandler).onChanged(slot.getSlotIndex());
|
||||
}
|
||||
} else {
|
||||
slot.inventory.markDirty();
|
||||
}
|
||||
} else {
|
||||
slot.putStack(message.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,32 +31,36 @@ public class SetFluidFilterSlotMessage {
|
||||
}
|
||||
|
||||
public static void handle(SetFluidFilterSlotMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
if (!message.stack.isEmpty()) {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container != null) {
|
||||
if (message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
|
||||
Slot slot = container.getSlot(message.containerSlot);
|
||||
|
||||
if (slot instanceof FluidFilterSlot) {
|
||||
FluidFilterSlot fluidFilterSlot = (FluidFilterSlot) slot;
|
||||
|
||||
// Avoid resetting allowed tag list in the pattern grid.
|
||||
if (API.instance().getComparer().isEqual(fluidFilterSlot.getFluidInventory().getFluid(slot.getSlotIndex()), message.stack, IComparer.COMPARE_NBT)) {
|
||||
fluidFilterSlot.getFluidInventory().getFluid(slot.getSlotIndex()).setAmount(message.stack.getAmount());
|
||||
fluidFilterSlot.getFluidInventory().onChanged(slot.getSlotIndex());
|
||||
} else {
|
||||
fluidFilterSlot.getFluidInventory().setFluid(slot.getSlotIndex(), message.stack);
|
||||
}
|
||||
}
|
||||
if (container != null && 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);
|
||||
|
||||
if (slot instanceof FluidFilterSlot) {
|
||||
FluidFilterSlot fluidFilterSlot = (FluidFilterSlot) slot;
|
||||
|
||||
// Avoid resetting allowed tag list in the pattern grid.
|
||||
if (API.instance().getComparer().isEqual(fluidFilterSlot.getFluidInventory().getFluid(slot.getSlotIndex()), message.stack, IComparer.COMPARE_NBT)) {
|
||||
fluidFilterSlot.getFluidInventory().getFluid(slot.getSlotIndex()).setAmount(message.stack.getAmount());
|
||||
fluidFilterSlot.getFluidInventory().onChanged(slot.getSlotIndex());
|
||||
} else {
|
||||
fluidFilterSlot.getFluidInventory().setFluid(slot.getSlotIndex(), message.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 static <T> void executeLater(Class<T> clazz, Consumer<T> callback) {
|
||||
Queue<Consumer> queue = ACTIONS.get(clazz);
|
||||
|
||||
if (queue == null) {
|
||||
ACTIONS.put(clazz, queue = new ArrayDeque<>());
|
||||
}
|
||||
|
||||
queue.add(callback);
|
||||
ACTIONS.computeIfAbsent(clazz, eky -> new ArrayDeque<>()).add(callback);
|
||||
}
|
||||
|
||||
public static void executeLater(Consumer<ContainerScreen> callback) {
|
||||
|
@@ -72,7 +72,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
|
||||
|
||||
@Override
|
||||
public List<IFilter> getFilters() {
|
||||
return null;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,7 +203,7 @@ public class CraftingMonitorScreen extends BaseScreen<CraftingMonitorContainer>
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onOkButtonPressed(boolean shiftDown) {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
|
||||
if (isOverInventory(x - guiLeft, y - guiTop)) {
|
||||
if (grid.getGridType() != GridType.FLUID && hoveredSlot != null && hoveredSlot.getHasStack()) {
|
||||
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)) {
|
||||
if (grid.getGridType() != GridType.FLUID) {
|
||||
} else if (isOverSlotArea(x - guiLeft, y - guiTop)) {
|
||||
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) {
|
||||
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 {
|
||||
fontrenderer.drawString(matrixStack, this.getMessage().getString(), this.x + 13, this.y + (this.height - 8) / 2F, color);
|
||||
}
|
||||
|
@@ -38,10 +38,8 @@ public class CrafterTile extends NetworkNodeTile<CrafterNetworkNode> {
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction direction) {
|
||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
if (direction != null && !direction.equals(this.getNode().getDirection())) {
|
||||
return patternsCapability.cast();
|
||||
}
|
||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && direction != null && !direction.equals(this.getNode().getDirection())) {
|
||||
return patternsCapability.cast();
|
||||
}
|
||||
|
||||
return super.getCapability(cap, direction);
|
||||
|
@@ -37,7 +37,7 @@ public interface IPortableGrid {
|
||||
|
||||
int getEnergy();
|
||||
|
||||
BaseItemHandler getDisk();
|
||||
BaseItemHandler getDiskInventory();
|
||||
|
||||
IItemHandlerModifiable getFilter();
|
||||
|
||||
|
@@ -107,10 +107,10 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
storage = null;
|
||||
cache = null;
|
||||
} 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) {
|
||||
StorageType type = ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType();
|
||||
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||
|
||||
switch (type) {
|
||||
case ITEM:
|
||||
@@ -209,7 +209,7 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseItemHandler getDisk() {
|
||||
public BaseItemHandler getDiskInventory() {
|
||||
return disk;
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@@ -188,16 +188,16 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
||||
}
|
||||
|
||||
private void loadStorage() {
|
||||
ItemStack diskStack = getDisk().getStackInSlot(0);
|
||||
ItemStack diskStack = getDiskInventory().getStackInSlot(0);
|
||||
|
||||
if (diskStack.isEmpty()) {
|
||||
this.storage = null;
|
||||
this.cache = null;
|
||||
} 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) {
|
||||
StorageType type = ((IStorageDiskProvider) getDisk().getStackInSlot(0).getItem()).getType();
|
||||
StorageType type = ((IStorageDiskProvider) getDiskInventory().getStackInSlot(0).getItem()).getType();
|
||||
|
||||
switch (type) {
|
||||
case ITEM:
|
||||
@@ -311,7 +311,7 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
||||
}
|
||||
|
||||
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
|
||||
@@ -625,7 +625,7 @@ public class PortableGridTile extends BaseTile implements ITickableTileEntity, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseItemHandler getDisk() {
|
||||
public BaseItemHandler getDiskInventory() {
|
||||
return disk;
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -34,7 +34,7 @@ import java.util.function.Supplier;
|
||||
public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
||||
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<Block> blockRegister;
|
||||
@@ -50,40 +50,40 @@ public class ColorMap<T extends IForgeRegistryEntry<? super T>> {
|
||||
}
|
||||
|
||||
public RegistryObject<T> get(DyeColor color) {
|
||||
return colorMap.get(color);
|
||||
return map.get(color);
|
||||
}
|
||||
|
||||
public Collection<RegistryObject<T>> values() {
|
||||
return colorMap.values();
|
||||
return map.values();
|
||||
}
|
||||
|
||||
public void put(DyeColor color, RegistryObject<T> object) {
|
||||
colorMap.put(color, object);
|
||||
map.put(color, object);
|
||||
}
|
||||
|
||||
public void forEach(BiConsumer<DyeColor, RegistryObject<T>> consumer) {
|
||||
colorMap.forEach(consumer);
|
||||
map.forEach(consumer);
|
||||
}
|
||||
|
||||
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) {
|
||||
for (DyeColor color : DyeColor.values()) {
|
||||
String prefix = color != DEFAULT_COLOR ? color + "_" : "";
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public <S extends BaseBlock> void registerItemsFromBlocks(ColorMap<S> blockMap) {
|
||||
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) -> {
|
||||
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);
|
||||
@@ -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) {
|
||||
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 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) {
|
||||
|
Reference in New Issue
Block a user