Improve crafting preview system a bit.
This commit is contained in:
@@ -150,7 +150,7 @@ public interface IRSAPI {
|
||||
* @param type the type
|
||||
* @return a set of external storage providers
|
||||
*/
|
||||
Set<IExternalStorageProvider<?>> getExternalStorageProviders(StorageType type);
|
||||
<T> Set<IExternalStorageProvider<T>> getExternalStorageProviders(StorageType type);
|
||||
|
||||
/**
|
||||
* @param world the world
|
||||
|
@@ -10,12 +10,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
/**
|
||||
* Represents a crafting preview element.
|
||||
*/
|
||||
public interface ICraftingPreviewElement<T> {
|
||||
/**
|
||||
* @return the underlying element to display
|
||||
*/
|
||||
T getElement();
|
||||
|
||||
public interface ICraftingPreviewElement {
|
||||
/**
|
||||
* @param matrixStack the matrix stack
|
||||
* @param x position on the x axis to render
|
||||
@@ -26,21 +21,9 @@ public interface ICraftingPreviewElement<T> {
|
||||
void draw(MatrixStack matrixStack, int x, int y, IElementDrawers drawers);
|
||||
|
||||
/**
|
||||
* @return available amount of the {@link #getElement()}
|
||||
* @return true when this crafting preview elements signifies an error that disables starting a task
|
||||
*/
|
||||
int getAvailable();
|
||||
|
||||
/**
|
||||
* @return the amount to craft or missing (depends on {@link #hasMissing()} amount of the {@link #getElement()}
|
||||
*/
|
||||
int getToCraft();
|
||||
|
||||
/**
|
||||
* When this is true {@link #getToCraft()} will be the missing items.
|
||||
*
|
||||
* @return true when items are missing, false otherwise
|
||||
*/
|
||||
boolean hasMissing();
|
||||
boolean doesDisableTaskStarting();
|
||||
|
||||
/**
|
||||
* @param buf buffer to write to
|
||||
|
@@ -16,7 +16,7 @@ public interface ICraftingPreviewElementRegistry {
|
||||
* @param id the id, as specified in {@link ICraftingPreviewElement#getId()}
|
||||
* @param factory the factory
|
||||
*/
|
||||
void add(ResourceLocation id, Function<PacketBuffer, ICraftingPreviewElement<?>> factory);
|
||||
void add(ResourceLocation id, Function<PacketBuffer, ICraftingPreviewElement> factory);
|
||||
|
||||
/**
|
||||
* Returns a factory from the registry.
|
||||
@@ -25,5 +25,5 @@ public interface ICraftingPreviewElementRegistry {
|
||||
* @return the factory, or null if no factory was found
|
||||
*/
|
||||
@Nullable
|
||||
Function<PacketBuffer, ICraftingPreviewElement<?>> get(ResourceLocation id);
|
||||
Function<PacketBuffer, ICraftingPreviewElement> get(ResourceLocation id);
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@ public interface ICalculationResult {
|
||||
CalculationResultType getType();
|
||||
|
||||
/**
|
||||
* @return get a list of {@link ICraftingPreviewElement}s
|
||||
* @return get a list of preview elements
|
||||
*/
|
||||
List<ICraftingPreviewElement<?>> getPreviewElements();
|
||||
List<ICraftingPreviewElement> getPreviewElements();
|
||||
|
||||
/**
|
||||
* @return the task if the calculation {@link #isOk()}, otherwise null
|
||||
|
@@ -11,16 +11,16 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CraftingPreviewElementRegistry implements ICraftingPreviewElementRegistry {
|
||||
private final Map<ResourceLocation, Function<PacketBuffer, ICraftingPreviewElement<?>>> registry = new HashMap<>();
|
||||
private final Map<ResourceLocation, Function<PacketBuffer, ICraftingPreviewElement>> registry = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void add(ResourceLocation id, Function<PacketBuffer, ICraftingPreviewElement<?>> factory) {
|
||||
public void add(ResourceLocation id, Function<PacketBuffer, ICraftingPreviewElement> factory) {
|
||||
registry.put(id, factory);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Function<PacketBuffer, ICraftingPreviewElement<?>> get(ResourceLocation id) {
|
||||
public Function<PacketBuffer, ICraftingPreviewElement> get(ResourceLocation id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
||||
|
@@ -9,20 +9,19 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ErrorCraftingPreviewElement implements ICraftingPreviewElement<ItemStack> {
|
||||
public class ErrorCraftingPreviewElement implements ICraftingPreviewElement {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "error");
|
||||
|
||||
private final CalculationResultType type;
|
||||
private final ItemStack stack;
|
||||
private final ItemStack recursedPattern;
|
||||
|
||||
public ErrorCraftingPreviewElement(CalculationResultType type, ItemStack stack) {
|
||||
public ErrorCraftingPreviewElement(CalculationResultType type, ItemStack recursedPattern) {
|
||||
this.type = type;
|
||||
this.stack = stack;
|
||||
this.recursedPattern = recursedPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getElement() {
|
||||
return stack;
|
||||
public ItemStack getRecursedPattern() {
|
||||
return recursedPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,24 +30,14 @@ public class ErrorCraftingPreviewElement implements ICraftingPreviewElement<Item
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
return false;
|
||||
public boolean doesDisableTaskStarting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buf) {
|
||||
buf.writeInt(type.ordinal());
|
||||
buf.writeItemStack(stack);
|
||||
buf.writeItemStack(recursedPattern);
|
||||
}
|
||||
|
||||
public CalculationResultType getType() {
|
||||
|
@@ -14,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FluidCraftingPreviewElement implements ICraftingPreviewElement<FluidStack> {
|
||||
public class FluidCraftingPreviewElement implements ICraftingPreviewElement {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "fluid");
|
||||
|
||||
private final FluidStack stack;
|
||||
@@ -51,8 +51,7 @@ public class FluidCraftingPreviewElement implements ICraftingPreviewElement<Flui
|
||||
return new FluidCraftingPreviewElement(stack, available, missing, toCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getElement() {
|
||||
public FluidStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ public class FluidCraftingPreviewElement implements ICraftingPreviewElement<Flui
|
||||
x += 5;
|
||||
y += 7;
|
||||
|
||||
drawers.getFluidDrawer().draw(matrixStack, x, y, getElement());
|
||||
drawers.getFluidDrawer().draw(matrixStack, x, y, getStack());
|
||||
|
||||
float scale = Minecraft.getInstance().getForceUnicodeFont() ? 1F : 0.5F;
|
||||
|
||||
@@ -75,15 +74,15 @@ public class FluidCraftingPreviewElement implements ICraftingPreviewElement<Flui
|
||||
matrixStack.push();
|
||||
matrixStack.scale(scale, scale, 1);
|
||||
|
||||
if (getToCraft() > 0) {
|
||||
String format = hasMissing() ? "gui.refinedstorage.crafting_preview.missing" : "gui.refinedstorage.crafting_preview.to_craft";
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format(format, API.instance().getQuantityFormatter().formatInBucketForm(getToCraft())));
|
||||
if (toCraft > 0) {
|
||||
String format = doesDisableTaskStarting() ? "gui.refinedstorage.crafting_preview.missing" : "gui.refinedstorage.crafting_preview.to_craft";
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format(format, API.instance().getQuantityFormatter().formatInBucketForm(toCraft)));
|
||||
|
||||
y += 7;
|
||||
}
|
||||
|
||||
if (getAvailable() > 0) {
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format("gui.refinedstorage.crafting_preview.available", API.instance().getQuantityFormatter().formatInBucketForm(getAvailable())));
|
||||
if (available > 0) {
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format("gui.refinedstorage.crafting_preview.available", API.instance().getQuantityFormatter().formatInBucketForm(available)));
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
@@ -93,26 +92,16 @@ public class FluidCraftingPreviewElement implements ICraftingPreviewElement<Flui
|
||||
this.available += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void addToCraft(int amount) {
|
||||
this.toCraft += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return this.toCraft;
|
||||
}
|
||||
|
||||
public void setMissing(boolean missing) {
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
public boolean doesDisableTaskStarting() {
|
||||
return missing;
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemStack> {
|
||||
public class ItemCraftingPreviewElement implements ICraftingPreviewElement {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "item");
|
||||
|
||||
private final ItemStack stack;
|
||||
@@ -34,6 +34,10 @@ public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemS
|
||||
this.toCraft = toCraft;
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buf) {
|
||||
buf.writeItemStack(stack);
|
||||
@@ -51,11 +55,6 @@ public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemS
|
||||
return new ItemCraftingPreviewElement(stack, available, missing, toCraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getElement() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void draw(MatrixStack matrixStack, int x, int y, IElementDrawers drawers) {
|
||||
@@ -66,7 +65,7 @@ public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemS
|
||||
x += 5;
|
||||
y += 7;
|
||||
|
||||
drawers.getItemDrawer().draw(matrixStack, x, y, getElement());
|
||||
drawers.getItemDrawer().draw(matrixStack, x, y, stack);
|
||||
|
||||
float scale = Minecraft.getInstance().getForceUnicodeFont() ? 1F : 0.5F;
|
||||
|
||||
@@ -75,15 +74,15 @@ public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemS
|
||||
matrixStack.push();
|
||||
matrixStack.scale(scale, scale, 1);
|
||||
|
||||
if (getToCraft() > 0) {
|
||||
String format = hasMissing() ? "gui.refinedstorage.crafting_preview.missing" : "gui.refinedstorage.crafting_preview.to_craft";
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format(format, getToCraft()));
|
||||
if (toCraft > 0) {
|
||||
String format = doesDisableTaskStarting() ? "gui.refinedstorage.crafting_preview.missing" : "gui.refinedstorage.crafting_preview.to_craft";
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format(format, toCraft));
|
||||
|
||||
y += 7;
|
||||
}
|
||||
|
||||
if (getAvailable() > 0) {
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format("gui.refinedstorage.crafting_preview.available", getAvailable()));
|
||||
if (available > 0) {
|
||||
drawers.getStringDrawer().draw(matrixStack, RenderUtils.getOffsetOnScale(x + 23, scale), RenderUtils.getOffsetOnScale(y, scale), I18n.format("gui.refinedstorage.crafting_preview.available", available));
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
@@ -93,26 +92,16 @@ public class ItemCraftingPreviewElement implements ICraftingPreviewElement<ItemS
|
||||
this.available += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void addToCraft(int amount) {
|
||||
this.toCraft += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToCraft() {
|
||||
return this.toCraft;
|
||||
}
|
||||
|
||||
public void setMissing(boolean missing) {
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMissing() {
|
||||
public boolean doesDisableTaskStarting() {
|
||||
return missing;
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
public class CalculationResult implements ICalculationResult {
|
||||
private final CalculationResultType type;
|
||||
private final ICraftingPattern recursedPattern;
|
||||
private final List<ICraftingPreviewElement<?>> previewElements;
|
||||
private final List<ICraftingPreviewElement> previewElements;
|
||||
private final ICraftingTask craftingTask;
|
||||
|
||||
public CalculationResult(CalculationResultType type) {
|
||||
@@ -30,7 +30,7 @@ public class CalculationResult implements ICalculationResult {
|
||||
this.craftingTask = null;
|
||||
}
|
||||
|
||||
public CalculationResult(CalculationResultType type, List<ICraftingPreviewElement<?>> previewElements, @Nullable ICraftingTask craftingTask) {
|
||||
public CalculationResult(CalculationResultType type, List<ICraftingPreviewElement> previewElements, @Nullable ICraftingTask craftingTask) {
|
||||
this.type = type;
|
||||
this.recursedPattern = null;
|
||||
this.previewElements = previewElements;
|
||||
@@ -43,7 +43,7 @@ public class CalculationResult implements ICalculationResult {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ICraftingPreviewElement<?>> getPreviewElements() {
|
||||
public List<ICraftingPreviewElement> getPreviewElements() {
|
||||
return previewElements;
|
||||
}
|
||||
|
||||
|
@@ -76,7 +76,7 @@ public class CraftingCalculator {
|
||||
craftingPreviewInfo.getToCraftFluids().add(StackUtils.copy(requested.getFluid(), qty * qtyPerCraft));
|
||||
}
|
||||
|
||||
List<ICraftingPreviewElement<?>> previewElements = new CraftingPreviewElementFactory().getElements(craftingPreviewInfo);
|
||||
List<ICraftingPreviewElement> previewElements = new CraftingPreviewElementFactory().getElements(craftingPreviewInfo);
|
||||
|
||||
if (craftingPreviewInfo.hasMissing()) {
|
||||
return new CalculationResult(CalculationResultType.MISSING, previewElements, null);
|
||||
|
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CraftingPreviewElementFactory {
|
||||
public List<ICraftingPreviewElement<?>> getElements(CraftingPreviewInfo info) {
|
||||
public List<ICraftingPreviewElement> getElements(CraftingPreviewInfo info) {
|
||||
Map<Integer, ItemCraftingPreviewElement> map = new LinkedHashMap<>();
|
||||
Map<Integer, FluidCraftingPreviewElement> mapFluids = new LinkedHashMap<>();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class CraftingPreviewElementFactory {
|
||||
previewStack.addAvailable(stack.getStack().getAmount());
|
||||
}
|
||||
|
||||
List<ICraftingPreviewElement<?>> elements = new ArrayList<>();
|
||||
List<ICraftingPreviewElement> elements = new ArrayList<>();
|
||||
|
||||
elements.addAll(map.values());
|
||||
elements.addAll(mapFluids.values());
|
||||
|
@@ -212,17 +212,17 @@ public class ExternalStorageNetworkNode extends NetworkNode implements IStorageP
|
||||
|
||||
if (facing != null) {
|
||||
if (type == IType.ITEMS) {
|
||||
for (IExternalStorageProvider<?> provider : API.instance().getExternalStorageProviders(StorageType.ITEM)) {
|
||||
for (IExternalStorageProvider<ItemStack> provider : API.instance().<ItemStack>getExternalStorageProviders(StorageType.ITEM)) {
|
||||
if (provider.canProvide(facing, getDirection())) {
|
||||
itemStorages.add((IExternalStorage<ItemStack>) provider.provide(this, getFacingTile(), getDirection()));
|
||||
itemStorages.add(provider.provide(this, getFacingTile(), getDirection()));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (type == IType.FLUIDS) {
|
||||
for (IExternalStorageProvider<?> provider : API.instance().getExternalStorageProviders(StorageType.FLUID)) {
|
||||
for (IExternalStorageProvider<FluidStack> provider : API.instance().<FluidStack>getExternalStorageProviders(StorageType.FLUID)) {
|
||||
if (provider.canProvide(facing, getDirection())) {
|
||||
fluidStorages.add((IExternalStorage<FluidStack>) provider.provide(this, getFacingTile(), getDirection()));
|
||||
fluidStorages.add(provider.provide(this, getFacingTile(), getDirection()));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@@ -13,19 +13,19 @@ import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridCraftingPreviewResponseMessage {
|
||||
private final List<ICraftingPreviewElement<?>> elements;
|
||||
private final List<ICraftingPreviewElement> elements;
|
||||
private final UUID id;
|
||||
private final int quantity;
|
||||
private final boolean fluids;
|
||||
|
||||
public GridCraftingPreviewResponseMessage(List<ICraftingPreviewElement<?>> elements, UUID id, int quantity, boolean fluids) {
|
||||
public GridCraftingPreviewResponseMessage(List<ICraftingPreviewElement> elements, UUID id, int quantity, boolean fluids) {
|
||||
this.elements = elements;
|
||||
this.id = id;
|
||||
this.quantity = quantity;
|
||||
this.fluids = fluids;
|
||||
}
|
||||
|
||||
public List<ICraftingPreviewElement<?>> getElements() {
|
||||
public List<ICraftingPreviewElement> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@@ -46,16 +46,16 @@ public class GridCraftingPreviewResponseMessage {
|
||||
int quantity = buf.readInt();
|
||||
boolean fluids = buf.readBoolean();
|
||||
|
||||
List<ICraftingPreviewElement<?>> stacks = new LinkedList<>();
|
||||
List<ICraftingPreviewElement> elements = new LinkedList<>();
|
||||
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
ResourceLocation type = buf.readResourceLocation();
|
||||
stacks.add(API.instance().getCraftingPreviewElementRegistry().get(type).apply(buf));
|
||||
elements.add(API.instance().getCraftingPreviewElementRegistry().get(type).apply(buf));
|
||||
}
|
||||
|
||||
return new GridCraftingPreviewResponseMessage(stacks, id, quantity, fluids);
|
||||
return new GridCraftingPreviewResponseMessage(elements, id, quantity, fluids);
|
||||
}
|
||||
|
||||
public static void encode(GridCraftingPreviewResponseMessage message, PacketBuffer buf) {
|
||||
@@ -64,9 +64,9 @@ public class GridCraftingPreviewResponseMessage {
|
||||
buf.writeBoolean(message.fluids);
|
||||
buf.writeInt(message.elements.size());
|
||||
|
||||
for (ICraftingPreviewElement<?> stack : message.elements) {
|
||||
buf.writeResourceLocation(stack.getId());
|
||||
stack.write(buf);
|
||||
for (ICraftingPreviewElement element : message.elements) {
|
||||
buf.writeResourceLocation(element.getId());
|
||||
element.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,4 +74,4 @@ public class GridCraftingPreviewResponseMessage {
|
||||
ctx.get().enqueueWork(() -> ClientProxy.onReceivedCraftingPreviewResponseMessage(message));
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.refinedmods.refinedstorage.RS;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
|
||||
import com.refinedmods.refinedstorage.api.autocrafting.task.CalculationResultType;
|
||||
import com.refinedmods.refinedstorage.api.render.IElementDrawers;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.preview.ErrorCraftingPreviewElement;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.preview.FluidCraftingPreviewElement;
|
||||
@@ -39,7 +38,7 @@ import java.util.UUID;
|
||||
public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
private static final int VISIBLE_ROWS = 5;
|
||||
|
||||
private final List<ICraftingPreviewElement<?>> stacks;
|
||||
private final List<ICraftingPreviewElement> elements;
|
||||
private final Screen parent;
|
||||
|
||||
private final ScrollbarWidget scrollbar;
|
||||
@@ -53,7 +52,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
|
||||
private final IElementDrawers drawers = new CraftingPreviewElementDrawers(this, font);
|
||||
|
||||
public CraftingPreviewScreen(Screen parent, List<ICraftingPreviewElement<?>> stacks, UUID id, int quantity, boolean fluids, ITextComponent title) {
|
||||
public CraftingPreviewScreen(Screen parent, List<ICraftingPreviewElement> elements, UUID id, int quantity, boolean fluids, ITextComponent title) {
|
||||
super(new Container(null, 0) {
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull PlayerEntity player) {
|
||||
@@ -61,7 +60,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
}
|
||||
}, 254, 201, null, title);
|
||||
|
||||
this.stacks = new ArrayList<>(stacks);
|
||||
this.elements = new ArrayList<>(elements);
|
||||
this.parent = parent;
|
||||
|
||||
this.id = id;
|
||||
@@ -76,7 +75,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
addButton(x + 55, y + 201 - 20 - 7, 50, 20, new TranslationTextComponent("gui.cancel"), true, true, btn -> close());
|
||||
|
||||
Button startButton = addButton(x + 129, y + 201 - 20 - 7, 50, 20, new TranslationTextComponent("misc.refinedstorage.start"), true, true, btn -> startRequest());
|
||||
startButton.active = stacks.stream().noneMatch(ICraftingPreviewElement::hasMissing) && getErrorType() == null;
|
||||
startButton.active = elements.stream().noneMatch(ICraftingPreviewElement::doesDisableTaskStarting);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,9 +85,9 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CalculationResultType getErrorType() {
|
||||
if (stacks.size() == 1 && stacks.get(0) instanceof ErrorCraftingPreviewElement) {
|
||||
return ((ErrorCraftingPreviewElement) stacks.get(0)).getType();
|
||||
private ErrorCraftingPreviewElement getError() {
|
||||
if (elements.size() == 1 && elements.get(0) instanceof ErrorCraftingPreviewElement) {
|
||||
return (ErrorCraftingPreviewElement) elements.get(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -100,7 +99,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
|
||||
blit(matrixStack, x, y, 0, 0, xSize, ySize);
|
||||
|
||||
if (getErrorType() != null) {
|
||||
if (getError() != null) {
|
||||
fill(matrixStack, x + 7, y + 20, x + 228, y + 169, 0xFFDBDBDB);
|
||||
}
|
||||
|
||||
@@ -116,9 +115,9 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
|
||||
float scale = Minecraft.getInstance().getForceUnicodeFont() ? 1F : 0.5F;
|
||||
|
||||
CalculationResultType errorType = getErrorType();
|
||||
if (errorType != null) {
|
||||
renderError(matrixStack, x, y, scale, errorType);
|
||||
ErrorCraftingPreviewElement error = getError();
|
||||
if (error != null) {
|
||||
renderError(matrixStack, x, y, scale, error);
|
||||
} else {
|
||||
renderPreview(matrixStack, mouseX, mouseY, x, y);
|
||||
}
|
||||
@@ -134,8 +133,8 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
this.hoveringFluid = null;
|
||||
|
||||
for (int i = 0; i < 3 * 5; ++i) {
|
||||
if (slot < stacks.size()) {
|
||||
renderElement(matrixStack, mouseX, mouseY, x, y, stacks.get(slot));
|
||||
if (slot < elements.size()) {
|
||||
renderElement(matrixStack, mouseX, mouseY, x, y, elements.get(slot));
|
||||
}
|
||||
|
||||
if ((i + 1) % 3 == 0) {
|
||||
@@ -149,35 +148,33 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderElement(MatrixStack matrixStack, int mouseX, int mouseY, int x, int y, ICraftingPreviewElement<?> element) {
|
||||
private void renderElement(MatrixStack matrixStack, int mouseX, int mouseY, int x, int y, ICraftingPreviewElement element) {
|
||||
element.draw(matrixStack, x, y + 5, drawers);
|
||||
|
||||
if (RenderUtils.inBounds(x + 5, y + 7, 16, 16, mouseX, mouseY)) {
|
||||
this.hoveringStack = element.getId().equals(ItemCraftingPreviewElement.ID) ? (ItemStack) element.getElement() : null;
|
||||
this.hoveringStack = element instanceof ItemCraftingPreviewElement ? ((ItemCraftingPreviewElement) element).getStack() : null;
|
||||
|
||||
if (this.hoveringStack == null) {
|
||||
this.hoveringFluid = element.getId().equals(FluidCraftingPreviewElement.ID) ? (FluidStack) element.getElement() : null;
|
||||
this.hoveringFluid = element instanceof FluidCraftingPreviewElement ? ((FluidCraftingPreviewElement) element).getStack() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderError(MatrixStack matrixStack, int x, int y, float scale, CalculationResultType errorType) {
|
||||
private void renderError(MatrixStack matrixStack, int x, int y, float scale, ErrorCraftingPreviewElement errorElement) {
|
||||
matrixStack.push();
|
||||
matrixStack.scale(scale, scale, 1);
|
||||
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 11, scale), I18n.format("gui.refinedstorage.crafting_preview.error"));
|
||||
|
||||
switch (errorType) {
|
||||
switch (errorElement.getType()) {
|
||||
case RECURSIVE:
|
||||
renderRecursiveError(matrixStack, x, y, scale);
|
||||
break;
|
||||
case OK:
|
||||
case MISSING:
|
||||
case NO_PATTERN:
|
||||
renderRecursiveError(matrixStack, x, y, scale, errorElement.getRecursedPattern());
|
||||
break;
|
||||
case TOO_COMPLEX:
|
||||
renderTooComplexError(matrixStack, x, y, scale);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
@@ -188,7 +185,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 31, scale), I18n.format("gui.refinedstorage.crafting_preview.error.too_complex.1"));
|
||||
}
|
||||
|
||||
private void renderRecursiveError(MatrixStack matrixStack, int x, int y, float scale) {
|
||||
private void renderRecursiveError(MatrixStack matrixStack, int x, int y, float scale, ItemStack recursedPattern) {
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 21, scale), I18n.format("gui.refinedstorage.crafting_preview.error.recursive.0"));
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 31, scale), I18n.format("gui.refinedstorage.crafting_preview.error.recursive.1"));
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 41, scale), I18n.format("gui.refinedstorage.crafting_preview.error.recursive.2"));
|
||||
@@ -196,15 +193,12 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 5, scale), RenderUtils.getOffsetOnScale(y + 61, scale), I18n.format("gui.refinedstorage.crafting_preview.error.recursive.4"));
|
||||
|
||||
ICraftingPattern pattern = PatternItem.fromCache(parent.getMinecraft().world, (ItemStack) stacks.get(0).getElement());
|
||||
ICraftingPattern pattern = PatternItem.fromCache(parent.getMinecraft().world, recursedPattern);
|
||||
|
||||
int yy = 83;
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (output != null) {
|
||||
matrixStack.push();
|
||||
matrixStack.scale(scale, scale, 1);
|
||||
renderString(matrixStack, RenderUtils.getOffsetOnScale(x + 25, scale), RenderUtils.getOffsetOnScale(yy + 6, scale), output.getDisplayName().getString());
|
||||
matrixStack.pop();
|
||||
|
||||
RenderHelper.setupGui3DDiffuseLighting();
|
||||
RenderSystem.enableDepthTest();
|
||||
@@ -282,7 +276,7 @@ public class CraftingPreviewScreen extends BaseScreen<Container> {
|
||||
}
|
||||
|
||||
private int getRows() {
|
||||
return Math.max(0, (int) Math.ceil((float) stacks.size() / 3F));
|
||||
return Math.max(0, (int) Math.ceil((float) elements.size() / 3F));
|
||||
}
|
||||
|
||||
private void close() {
|
||||
|
Reference in New Issue
Block a user