Skip to content

Commit

Permalink
Implement a stone/cobblestone generator upgrade for the digital miner…
Browse files Browse the repository at this point in the history
… for use in replacing blocks mekanism/Mekanism-Feature-Requests#219. Also make the miner's auto eject mimic machines by shuffling the order of items it ejects to hopefully make it less likely to get stuck just ejecting the last item over and over again when there are stacks of other things filling up the miner mekanism/Mekanism-Feature-Requests#253
  • Loading branch information
pupnewfster committed Jun 8, 2021
1 parent 7c8ca96 commit 492fc0f
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 64 deletions.
5 changes: 3 additions & 2 deletions src/api/java/mekanism/api/Upgrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public enum Upgrade implements IHasTranslationKey {
ENERGY("energy", APILang.UPGRADE_ENERGY, APILang.UPGRADE_ENERGY_DESCRIPTION, 8, EnumColor.BRIGHT_GREEN),
FILTER("filter", APILang.UPGRADE_FILTER, APILang.UPGRADE_FILTER_DESCRIPTION, 1, EnumColor.DARK_AQUA),
GAS("gas", APILang.UPGRADE_GAS, APILang.UPGRADE_GAS_DESCRIPTION, 8, EnumColor.YELLOW),
MUFFLING("muffling", APILang.UPGRADE_MUFFLING, APILang.UPGRADE_MUFFLING_DESCRIPTION, 4, EnumColor.DARK_GRAY),
ANCHOR("anchor", APILang.UPGRADE_ANCHOR, APILang.UPGRADE_ANCHOR_DESCRIPTION, 1, EnumColor.DARK_GREEN);
MUFFLING("muffling", APILang.UPGRADE_MUFFLING, APILang.UPGRADE_MUFFLING_DESCRIPTION, 4, EnumColor.INDIGO),
ANCHOR("anchor", APILang.UPGRADE_ANCHOR, APILang.UPGRADE_ANCHOR_DESCRIPTION, 1, EnumColor.DARK_GREEN),
STONE_GENERATOR("stone_generator", APILang.UPGRADE_STONE_GENERATOR, APILang.UPGRADE_STONE_GENERATOR_DESCRIPTION, 1, EnumColor.ORANGE);

private static final Upgrade[] UPGRADES = values();

Expand Down
2 changes: 2 additions & 0 deletions src/api/java/mekanism/api/text/APILang.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum APILang implements ILangEntry {
UPGRADE_MUFFLING_DESCRIPTION("upgrade", "muffling.description"),
UPGRADE_ANCHOR("upgrade", "anchor"),
UPGRADE_ANCHOR_DESCRIPTION("upgrade", "anchor.description"),
UPGRADE_STONE_GENERATOR("upgrade", "stone_generator"),
UPGRADE_STONE_GENERATOR_DESCRIPTION("upgrade", "stone_generator.description"),
//Generic
@Deprecated//TODO - 1.17: Remove this generic lang entry in favor of just having string text components be used
GENERIC("generic", "format"),
Expand Down
5 changes: 3 additions & 2 deletions src/datagen/generated/mekanism/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ d5bd6c407c9250a90e22e1f2c8805738b3830abf assets/mekanism/blockstates/lithium.jso
c1be0ed56a542f711719367cf1e508f10063c695 assets/mekanism/blockstates/sulfuric_acid.json
f5e3eb6799a15d0b72969547614dfc51dac53419 assets/mekanism/blockstates/tin_ore.json
246c1904e7699b01a3a20f2a2b79b35b5d99aec9 assets/mekanism/blockstates/uranium_ore.json
183575a0e4372c97be5f7080f7abb7dad7e06cf5 assets/mekanism/lang/en_ud.json
e500cb7a71dd2d125911a2c0ea3a178c036146ea assets/mekanism/lang/en_us.json
bff13d66c2c444808054fd714fbdde4e460d5914 assets/mekanism/lang/en_ud.json
242e66bbac245cdc2d755c9afd2b8b94f4e742c7 assets/mekanism/lang/en_us.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/brine.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/chlorine.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/ethene.json
Expand Down Expand Up @@ -2524,6 +2524,7 @@ d6a3d17c57dc72808dfb89a41618769c68c85567 data/mekanism/recipes/upgrade/filter.js
c6194b01656da10ae68e9a54003fb87ef8ad1ec2 data/mekanism/recipes/upgrade/gas.json
22e23669d3edb40656d3976533d595bacf98dc46 data/mekanism/recipes/upgrade/muffling.json
87545c2a7c6a9197ced562127d8988ca3a65ab02 data/mekanism/recipes/upgrade/speed.json
5bea5a02d8d74afeea042cdc1e2daa628ba9e354 data/mekanism/recipes/upgrade/stone_generator.json
0e943f7510e2277c6c4c3d1701ac02564333690c data/mekanism/scripts/mekanism_activating.zs
fa3f1814bb1395a68d17db354d6edc5ab72aea82 data/mekanism/scripts/mekanism_centrifuging.zs
241ccddef25bfa1a622338ee91e0f1368c99d3a1 data/mekanism/scripts/mekanism_chemical_infusing.zs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
"item.mekanism.upgrade_gas": "\u01DDp\u0250\u0279\u1D77d\u2229 s\u0250\u2141",
"item.mekanism.upgrade_muffling": "\u01DDp\u0250\u0279\u1D77d\u2229 \u1D77u\u1D09\uA781\u025F\u025FnW",
"item.mekanism.upgrade_speed": "\u01DDp\u0250\u0279\u1D77d\u2229 p\u01DD\u01DDdS",
"item.mekanism.upgrade_stone_generator": "\u01DDp\u0250\u0279\u1D77d\u2229 \u0279o\u0287\u0250\u0279\u01DDu\u01DD\u2141 \u01DDuo\u0287S",
"item.mekanism.yellow_cake_uranium": "\u026Fn\u1D09u\u0250\u0279\u2229 \u01DD\u029E\u0250\u0186 \u028Do\uA781\uA781\u01DD\u2144",
"jetpack.mekanism.disabled": "p\u01DD\uA781q\u0250s\u1D09\u15E1",
"jetpack.mekanism.hover": "\u0279\u01DD\u028CoH",
Expand Down Expand Up @@ -1372,6 +1373,8 @@
"upgrade.mekanism.muffling.description": "\u02D9\u028E\u0279\u01DDu\u1D09\u0265\u0254\u0250\u026F \u028Eq p\u01DD\u0287\u0250\u0279\u01DDu\u01DD\u1D77 \u01DDs\u1D09ou s\u01DD\u0254np\u01DD\u1D1A",
"upgrade.mekanism.speed": "p\u01DD\u01DDdS",
"upgrade.mekanism.speed.description": "\u02D9\u028E\u0279\u01DDu\u1D09\u0265\u0254\u0250\u026F \u025Fo p\u01DD\u01DDds s\u01DDs\u0250\u01DD\u0279\u0254uI",
"upgrade.mekanism.stone_generator": "\u0279o\u0287\u0250\u0279\u01DDu\u01DD\u2141 \u01DDuo\u0287S",
"upgrade.mekanism.stone_generator.description": "\u02D9p\u01DDp\u01DD\u01DDu s\u0250 \u01DDuo\u0287s\u01DD\uA781qqo\u0254 \u0279o \u01DDuo\u0287s s\u01DD\u0287\u0250\u0279\u01DDu\u01DD\u2141",
"waste_barrel.mekanism.decay_rate": "\u0287/\u15FA\u026F %s :\u01DD\u0287\u0250\u1D1A \u028E\u0250\u0254\u01DD\u15E1",
"waste_barrel.mekanism.decay_rate.actual": "s\u029E\u0254\u1D09\u0287 %2$s / \u15FA\u026F %1$s :\u01DD\u0287\u0250\u1D1A \u028E\u0250\u0254\u01DD\u15E1 \uA781\u0250n\u0287\u0254\u2C6F"
}
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
"item.mekanism.upgrade_gas": "Gas Upgrade",
"item.mekanism.upgrade_muffling": "Muffling Upgrade",
"item.mekanism.upgrade_speed": "Speed Upgrade",
"item.mekanism.upgrade_stone_generator": "Stone Generator Upgrade",
"item.mekanism.yellow_cake_uranium": "Yellow Cake Uranium",
"jetpack.mekanism.disabled": "Disabled",
"jetpack.mekanism.hover": "Hover",
Expand Down Expand Up @@ -1372,6 +1373,8 @@
"upgrade.mekanism.muffling.description": "Reduces noise generated by machinery.",
"upgrade.mekanism.speed": "Speed",
"upgrade.mekanism.speed.description": "Increases speed of machinery.",
"upgrade.mekanism.stone_generator": "Stone Generator",
"upgrade.mekanism.stone_generator.description": "Generates stone or cobblestone as needed.",
"waste_barrel.mekanism.decay_rate": "Decay Rate: %s mB/t",
"waste_barrel.mekanism.decay_rate.actual": "Actual Decay Rate: %s mB / %s ticks"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "minecraft:crafting_shaped",
"result": {
"item": "mekanism:upgrade_stone_generator"
},
"pattern": [
" G ",
"#AB",
" G "
],
"key": {
"G": {
"tag": "forge:glass"
},
"#": {
"item": "minecraft:water_bucket"
},
"B": {
"item": "minecraft:lava_bucket"
},
"A": {
"tag": "mekanism:alloys/infused"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private void addItems() {
add(MekanismItems.MUFFLING_UPGRADE, "Muffling Upgrade");
add(MekanismItems.GAS_UPGRADE, "Gas Upgrade");
add(MekanismItems.ANCHOR_UPGRADE, "Anchor Upgrade");
add(MekanismItems.STONE_GENERATOR_UPGRADE, "Stone Generator Upgrade");
//Alloys
add(MekanismItems.INFUSED_ALLOY, "Infused Alloy");
add(MekanismItems.REINFORCED_ALLOY, "Reinforced Alloy");
Expand Down Expand Up @@ -468,6 +469,8 @@ private void addMisc() {
add(APILang.UPGRADE_MUFFLING_DESCRIPTION, "Reduces noise generated by machinery.");
add(APILang.UPGRADE_ANCHOR, "Anchor");
add(APILang.UPGRADE_ANCHOR_DESCRIPTION, "Keeps a machine's chunk loaded.");
add(APILang.UPGRADE_STONE_GENERATOR, "Stone Generator");
add(APILang.UPGRADE_STONE_GENERATOR_DESCRIPTION, "Generates stone or cobblestone as needed.");
//Transmission types
add(MekanismLang.TRANSMISSION_TYPE_ENERGY, "Energy");
add(MekanismLang.TRANSMISSION_TYPE_FLUID, "Fluids");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mekanism.common.tags.MekanismTags;
import net.minecraft.data.IFinishedRecipe;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.tags.ITag;
import net.minecraftforge.common.Tags;

Expand All @@ -34,6 +35,16 @@ public void addRecipes(Consumer<IFinishedRecipe> consumer) {
addUpgradeRecipe(consumer, MekanismItems.GAS_UPGRADE, MekanismTags.Items.PROCESSED_RESOURCES.get(ResourceType.DUST, PrimaryResource.IRON), basePath);
addUpgradeRecipe(consumer, MekanismItems.MUFFLING_UPGRADE, MekanismTags.Items.DUSTS_STEEL, basePath);
addUpgradeRecipe(consumer, MekanismItems.SPEED_UPGRADE, MekanismTags.Items.PROCESSED_RESOURCES.get(ResourceType.DUST, PrimaryResource.OSMIUM), basePath);
ExtendedShapedRecipeBuilder.shapedRecipe(MekanismItems.STONE_GENERATOR_UPGRADE)
.pattern(RecipePattern.createPattern(
TripleLine.of(Pattern.EMPTY, MekanismRecipeProvider.GLASS_CHAR, Pattern.EMPTY),
TripleLine.of(Pattern.CONSTANT, Pattern.ALLOY, Pattern.BUCKET),
TripleLine.of(Pattern.EMPTY, MekanismRecipeProvider.GLASS_CHAR, Pattern.EMPTY))
).key(MekanismRecipeProvider.GLASS_CHAR, Tags.Items.GLASS)
.key(Pattern.CONSTANT, Items.WATER_BUCKET)
.key(Pattern.BUCKET, Items.LAVA_BUCKET)
.key(Pattern.ALLOY, MekanismTags.Items.ALLOYS_INFUSED)
.build(consumer, Mekanism.rl(basePath + getSaveName(MekanismItems.STONE_GENERATOR_UPGRADE)));
}

private void addUpgradeRecipe(Consumer<IFinishedRecipe> consumer, ItemRegistryObject<ItemUpgrade> upgrade, ITag<Item> dustTag, String basePath) {
Expand All @@ -42,6 +53,10 @@ private void addUpgradeRecipe(Consumer<IFinishedRecipe> consumer, ItemRegistryOb
.key(MekanismRecipeProvider.GLASS_CHAR, Tags.Items.GLASS)
.key(Pattern.CONSTANT, dustTag)
.key(Pattern.ALLOY, MekanismTags.Items.ALLOYS_INFUSED)
.build(consumer, Mekanism.rl(basePath + upgrade.getItem().getUpgradeType(upgrade.getItemStack()).getRawName()));
.build(consumer, Mekanism.rl(basePath + getSaveName(upgrade)));
}

private String getSaveName(ItemRegistryObject<ItemUpgrade> upgrade) {
return upgrade.getItem().getUpgradeType(upgrade.getItemStack()).getRawName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void clearSelection() {
@Override
public void renderForeground(MatrixStack matrix, int mouseX, int mouseY) {
super.renderForeground(matrix, mouseX, mouseY);
forEachUpgrade((upgrade, multipliedElement) -> drawString(matrix, TextComponentUtil.build(upgrade), relativeX + 13, relativeY + 3 + multipliedElement,
titleTextColor()));
forEachUpgrade((upgrade, multipliedElement) -> drawTextScaledBound(matrix, TextComponentUtil.build(upgrade), relativeX + 13, relativeY + 3 + multipliedElement,
titleTextColor(), 44));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import mekanism.client.gui.GuiMekanism;
import mekanism.client.gui.IGuiWrapper;
import mekanism.client.gui.element.GuiInnerScreen;
import mekanism.client.gui.element.button.MekanismButton;
import mekanism.client.gui.element.button.DigitalButton;
import mekanism.client.gui.element.button.MekanismButton;
import mekanism.client.gui.element.custom.GuiSupportedUpgrades;
import mekanism.client.gui.element.progress.GuiProgress;
import mekanism.client.gui.element.progress.ProgressType;
Expand Down Expand Up @@ -74,11 +74,14 @@ public void renderForeground(MatrixStack matrix, int mouseX, int mouseY) {
if (scrollList.hasSelection()) {
Upgrade selectedType = scrollList.getSelection();
int amount = tile.getComponent().getUpgrades(selectedType);
drawTextWithScale(matrix, MekanismLang.UPGRADE_TYPE.translate(selectedType), relativeX + 74, relativeY + 20, screenTextColor(), 0.6F);
drawTextWithScale(matrix, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), relativeX + 74, relativeY + 28, screenTextColor(), 0.6F);
int text = 0;
int textY = relativeY + 20;
int lines = drawWrappedTextWithScale(matrix, MekanismLang.UPGRADE_TYPE.translate(selectedType), relativeX + 74, textY, screenTextColor(), 56, 0.6F);
textY += 6 * lines + 2;
drawTextWithScale(matrix, MekanismLang.UPGRADE_COUNT.translate(amount, selectedType.getMax()), relativeX + 74, textY, screenTextColor(), 0.6F);
for (ITextComponent component : UpgradeUtils.getInfo(tile, selectedType)) {
drawTextWithScale(matrix, component, relativeX + 74, relativeY + 34 + (6 * text++), screenTextColor(), 0.6F);
//Note: We add the six here instead of after to account for the line above this for loop that draws the upgrade count
textY += 6;
drawTextWithScale(matrix, component, relativeX + 74, textY, screenTextColor(), 0.6F);
}
} else {
drawTextWithScale(matrix, MekanismLang.UPGRADE_NO_SELECTION.translate(), relativeX + 74, relativeY + 20, screenTextColor(), 0.8F);
Expand Down
45 changes: 33 additions & 12 deletions src/main/java/mekanism/client/render/IFancyFontRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,51 @@ default void prepTextScale(MatrixStack matrix, Consumer<MatrixStack> runnable, f
MekanismRenderer.resetColor();
}

default int drawWrappedTextWithScale(MatrixStack matrix, ITextComponent text, float x, float y, int color, float maxLength, float scale) {
return new WrappedTextRenderer(this).renderWithScale(matrix, text.getString(), x, y, color, maxLength, scale);
}

default void drawWrappedCenteredText(MatrixStack matrix, ITextComponent text, float x, float y, int color, float maxLength) {
new WrappedTextRenderer(this).render(matrix, text.getString(), x, y, color, maxLength);
new WrappedTextRenderer(this).renderCentered(matrix, text.getString(), x, y, color, maxLength);
}

// efficient tool to draw word-by-word wrapped text based on a horizontal bound. looks intimidating but runs in O(n)
class WrappedTextRenderer {

final IFancyFontRenderer font;
final List<Pair<ITextComponent, Float>> linesToDraw = new ArrayList<>();
StringBuilder lineBuilder = new StringBuilder(), wordBuilder = new StringBuilder();
float lineLength = 0, wordLength = 0;
final float SPACE_LENGTH;
private final IFancyFontRenderer font;
private final List<Pair<ITextComponent, Float>> linesToDraw = new ArrayList<>();
private StringBuilder lineBuilder = new StringBuilder(), wordBuilder = new StringBuilder();
private float lineLength = 0, wordLength = 0;
private final float SPACE_LENGTH;

WrappedTextRenderer(IFancyFontRenderer font) {
this.font = font;
SPACE_LENGTH = font.getFont().width(" ");
}

void render(MatrixStack matrix, String text, float x, float y, int color, float maxLength) {
void renderCentered(MatrixStack matrix, String text, float x, float y, int color, float maxLength) {
calculateLines(text, maxLength);
float startY = y;
for (Pair<ITextComponent, Float> p : linesToDraw) {
font.drawTextExact(matrix, p.getLeft(), x - p.getRight() / 2, startY, color);
startY += 9;
}
}

int renderWithScale(MatrixStack matrix, String text, float x, float y, int color, float maxLength, float scale) {
//Divide by scale for calculating actual max length so that when the text is scaled it has the proper total space available
calculateLines(text, maxLength / scale);
font.prepTextScale(matrix, m -> {
int startY = 0;
for (Pair<ITextComponent, Float> p : linesToDraw) {
font.drawString(m, p.getLeft(), 0, startY, color);
startY += 9;
}
}, x, y, scale);
return linesToDraw.size();
}

void calculateLines(String text, float maxLength) {
for (char c : text.toCharArray()) {
if (c == ' ') {
addWord(maxLength);
Expand All @@ -150,11 +176,6 @@ void render(MatrixStack matrix, String text, float x, float y, int color, float
if (lineBuilder.length() > 0) {
linesToDraw.add(Pair.of(TextComponentUtil.getString(lineBuilder.toString()), lineLength));
}
float startY = y;
for (Pair<ITextComponent, Float> p : linesToDraw) {
font.drawTextExact(matrix, p.getLeft(), x - p.getRight() / 2, startY, color);
startY += 9;
}
}

void addWord(float maxLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ protected void addSlots() {
//Don't include the inventory slots
return;
}
if (tile.supportsUpgrades()) {
//Add the virtual slot for the upgrade (add them before the main inventory to make sure they take priority in targeting)
//TODO - 10.1: Test this and test how it handles
addSlot(upgradeSlot = tile.getComponent().getUpgradeSlot().createContainerSlot());
addSlot(upgradeOutputSlot = tile.getComponent().getUpgradeOutputSlot().createContainerSlot());
}
if (tile.hasInventory()) {
//Get all the inventory slots the tile has
List<IInventorySlot> inventorySlots = tile.getInventorySlots(null);
Expand All @@ -83,11 +89,6 @@ protected void addSlots() {
}
}
}
if (tile.supportsUpgrades()) {
//Add the virtual slot for the upgrade
addSlot(upgradeSlot = tile.getComponent().getUpgradeSlot().createContainerSlot());
addSlot(upgradeOutputSlot = tile.getComponent().getUpgradeOutputSlot().createContainerSlot());
}
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private MekanismBlockTypes() {
.createMachine(() -> MekanismTileEntityTypes.DIGITAL_MINER, MekanismLang.DESCRIPTION_DIGITAL_MINER)
.withGui(() -> MekanismContainerTypes.DIGITAL_MINER)
.withEnergyConfig(MekanismConfig.usage.digitalMiner, MekanismConfig.storage.digitalMiner)
.withSupportedUpgrades(EnumSet.of(Upgrade.SPEED, Upgrade.ENERGY, Upgrade.ANCHOR))
.withSupportedUpgrades(EnumSet.of(Upgrade.SPEED, Upgrade.ENERGY, Upgrade.ANCHOR, Upgrade.STONE_GENERATOR))
.withCustomShape(BlockShapes.DIGITAL_MINER)
.with(AttributeCustomSelectionBox.JSON)
.withComputerSupport("digitalMiner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private MekanismItems() {
public static final ItemRegistryObject<ItemUpgrade> MUFFLING_UPGRADE = registerUpgrade(Upgrade.MUFFLING);
public static final ItemRegistryObject<ItemUpgrade> GAS_UPGRADE = registerUpgrade(Upgrade.GAS);
public static final ItemRegistryObject<ItemUpgrade> ANCHOR_UPGRADE = registerUpgrade(Upgrade.ANCHOR);
public static final ItemRegistryObject<ItemUpgrade> STONE_GENERATOR_UPGRADE = registerUpgrade(Upgrade.STONE_GENERATOR);

public static final ItemRegistryObject<ItemTierInstaller> BASIC_TIER_INSTALLER = registerInstaller(null, BaseTier.BASIC);
public static final ItemRegistryObject<ItemTierInstaller> ADVANCED_TIER_INSTALLER = registerInstaller(BaseTier.BASIC, BaseTier.ADVANCED);
Expand Down
Loading

0 comments on commit 492fc0f

Please sign in to comment.