Skip to content

Commit 58060b8

Browse files
committed
Add REI support & finishing touches for the beta
1 parent 313c969 commit 58060b8

File tree

22 files changed

+519
-61
lines changed

22 files changed

+519
-61
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
5252
include modImplementation("teamreborn:energy:${project.energy_version}")
5353

54-
modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}") {
54+
modImplementation("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}") {
5555
exclude group: "net.fabricmc.fabric-api"
5656
}
5757
modRuntimeOnly("mcp.mobius.waila:wthit:fabric-${project.wthit_version}") {

src/client/java/dev/technici4n/moderndynamics/client/attachment/SetAttachmentUpgradesPacket.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,16 @@
1818
*/
1919
package dev.technici4n.moderndynamics.client.attachment;
2020

21-
import dev.technici4n.moderndynamics.attachment.upgrade.UpgradeType;
22-
import dev.technici4n.moderndynamics.attachment.upgrade.UpgradeTypes;
23-
import java.util.IdentityHashMap;
24-
import java.util.Map;
21+
import dev.technici4n.moderndynamics.attachment.upgrade.LoadedUpgrades;
2522
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
26-
import net.minecraft.world.item.Item;
2723

2824
public class SetAttachmentUpgradesPacket {
2925
public static final ClientPlayNetworking.PlayChannelHandler HANDLER = (client, handler, buf, responseSender) -> {
30-
int count = buf.readVarInt();
31-
Map<Item, UpgradeType> upgrades = new IdentityHashMap<>();
32-
33-
for (int i = 0; i < count; ++i) {
34-
upgrades.put(Item.byId(buf.readVarInt()), UpgradeType.readPacket(buf));
35-
}
26+
var loadedUpgrades = LoadedUpgrades.fromPacket(buf);
3627

3728
if (!handler.getConnection().isMemoryConnection()) {
3829
client.execute(() -> {
39-
UpgradeTypes.uploadMap(upgrades);
30+
LoadedUpgrades.upload(loadedUpgrades);
4031
});
4132
}
4233
};

src/client/java/dev/technici4n/moderndynamics/client/ber/PipeBlockEntityRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void render(PipeBlockEntity pipe, float tickDelta, PoseStack matrices, Mu
7070
to.y() * ratio + from.y() * (1 - ratio),
7171
to.z() * ratio + from.z() * (1 - ratio));
7272
matrices.scale(0.6f, 0.6f, 0.6f);
73-
matrices.translate(0, -0.1f, 0);
73+
matrices.translate(0, -0.15f, 0);
7474

7575
int seed = item.variant().hashCode() + item.id;
7676
random.setSeed(seed);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Modern Dynamics
3+
* Copyright (C) 2021 shartte & Technici4n
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
package dev.technici4n.moderndynamics.client.compat.rei;
20+
21+
import dev.technici4n.moderndynamics.attachment.upgrade.LoadedUpgrades;
22+
import dev.technici4n.moderndynamics.client.screen.AttachedIoScreen;
23+
import dev.technici4n.moderndynamics.init.MdItems;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import me.shedaniel.math.Rectangle;
27+
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
28+
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
29+
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
30+
import me.shedaniel.rei.api.client.registry.screen.ExclusionZones;
31+
import me.shedaniel.rei.api.common.util.EntryStacks;
32+
33+
public class MdReiPlugin implements REIClientPlugin {
34+
@Override
35+
public void registerCategories(CategoryRegistry registry) {
36+
registry.add(new UpgradeCategory());
37+
38+
for (var workstation : List.of(MdItems.ATTRACTOR, MdItems.EXTRACTOR, MdItems.FILTER)) {
39+
registry.addWorkstations(UpgradeCategory.ID, EntryStacks.of(workstation));
40+
}
41+
42+
registry.removePlusButton(UpgradeCategory.ID);
43+
}
44+
45+
@Override
46+
public void registerExclusionZones(ExclusionZones zones) {
47+
zones.register(AttachedIoScreen.class, s -> {
48+
var screen = (AttachedIoScreen<?>) s;
49+
List<Rectangle> rectangles = new ArrayList<>();
50+
screen.appendExclusionZones(r -> rectangles.add(new Rectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight())));
51+
return rectangles;
52+
});
53+
}
54+
55+
@Override
56+
public void registerDisplays(DisplayRegistry registry) {
57+
for (var upgradeItem : LoadedUpgrades.get().list) {
58+
registry.add(new UpgradeDisplay(upgradeItem, LoadedUpgrades.getType(upgradeItem)));
59+
}
60+
}
61+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Modern Dynamics
3+
* Copyright (C) 2021 shartte & Technici4n
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
package dev.technici4n.moderndynamics.client.compat.rei;
20+
21+
import dev.technici4n.moderndynamics.init.MdItems;
22+
import dev.technici4n.moderndynamics.util.MdId;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import me.shedaniel.math.Point;
26+
import me.shedaniel.math.Rectangle;
27+
import me.shedaniel.rei.api.client.gui.Renderer;
28+
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
29+
import me.shedaniel.rei.api.client.gui.widgets.Widget;
30+
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
31+
import me.shedaniel.rei.api.client.registry.display.DisplayCategory;
32+
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
33+
import me.shedaniel.rei.api.common.util.EntryStacks;
34+
import net.minecraft.ChatFormatting;
35+
import net.minecraft.network.chat.Component;
36+
import net.minecraft.network.chat.Style;
37+
import net.minecraft.network.chat.TextComponent;
38+
import net.minecraft.network.chat.TranslatableComponent;
39+
40+
public class UpgradeCategory implements DisplayCategory<UpgradeDisplay> {
41+
public static final CategoryIdentifier<UpgradeDisplay> ID = CategoryIdentifier.of(MdId.of("upgrades"));
42+
43+
@Override
44+
public Renderer getIcon() {
45+
return EntryStacks.of(MdItems.EXTRACTOR);
46+
}
47+
48+
@Override
49+
public Component getTitle() {
50+
return new TranslatableComponent("gui.moderndynamics.rei.upgrade_category");
51+
}
52+
53+
@Override
54+
public CategoryIdentifier<UpgradeDisplay> getCategoryIdentifier() {
55+
return ID;
56+
}
57+
58+
@Override
59+
public List<Widget> setupDisplay(UpgradeDisplay display, Rectangle bounds) {
60+
List<Widget> widgets = new ArrayList<>();
61+
62+
var type = display.upgradeInfo;
63+
var texture = MdId.of("textures/gui/icons.png");
64+
int baseY = bounds.y + 5 + 36;
65+
int countXOffset = 17;
66+
int countY = bounds.y + 18 + 36;
67+
int effectWidth = 23;
68+
int effectSpacing = 5;
69+
70+
widgets.add(Widgets.createRecipeBase(bounds));
71+
72+
var upgradeSlotPoint = new Point(bounds.x + 7, bounds.y + 7);
73+
widgets.add(Widgets.createSlot(upgradeSlotPoint).entry(EntryStacks.of(display.item)));
74+
75+
widgets.add(Widgets
76+
.createLabel(new Point(bounds.x + 29, bounds.y + 11),
77+
new TranslatableComponent("gui.moderndynamics.tooltip.upgrades_max", type.getSlotLimit()))
78+
.leftAligned().noShadow().color(0xFF404040, 0xFFBBBBBB));
79+
widgets.add(Widgets
80+
.createLabel(new Point(bounds.getCenterX(), bounds.y + 5 + 22),
81+
new TranslatableComponent("gui.moderndynamics.tooltip.upgrades_effects").setStyle(Style.EMPTY.withUnderlined(true)))
82+
.noShadow().color(0xFF404040, 0xFFBBBBBB));
83+
84+
var effects = new ArrayList<UpgradeEffect>();
85+
effects.add(new UpgradeEffect(16, type.getAddFilterSlots(), "addFilterSlots", "+" + type.getAddFilterSlots()));
86+
effects.add(new UpgradeEffect(32, type.getAddItemCount(), "addItemCount", "+" + type.getAddItemCount()));
87+
effects.add(new UpgradeEffect(48, type.getAddItemSpeed(), "addItemSpeed", "+" + type.getAddItemSpeed() * 100 + "%"));
88+
effects.add(new UpgradeEffect(64, type.getAddItemTransferFrequency(), "addItemTransferFrequency",
89+
"+" + type.getAddItemTransferFrequency() * 100 + "%"));
90+
effects.add(new UpgradeEffect(80, type.getAddFluidTransfer(), "addFluidTransfer", "+" + type.getAddFluidTransfer() * 100 + "%"));
91+
effects.add(
92+
new UpgradeEffect(96, type.getMultiplyFluidTransfer(), "multiplyFluidTransfer", "+" + type.getMultiplyFluidTransfer() * 100 + "%"));
93+
94+
effects.removeIf(e -> e.count() == 0);
95+
96+
if (effects.size() > 0) {
97+
int totalWidth = effects.size() * effectWidth + (effects.size() - 1) * effectSpacing;
98+
int baseX = bounds.x + (bounds.getWidth() - totalWidth) / 2;
99+
100+
for (UpgradeEffect e : effects) {
101+
var tooltipRect = new Rectangle(baseX, baseY, 20, 20);
102+
var greenStyle = Style.EMPTY.applyFormat(ChatFormatting.GREEN);
103+
var tooltip = new TranslatableComponent("gui.moderndynamics.tooltip.upgrade_" + e.upgradeName(),
104+
new TextComponent(e.greenText).setStyle(greenStyle));
105+
106+
widgets.add(Widgets.createTexturedWidget(texture, baseX, baseY, e.textureU(), 0, 16, 16));
107+
widgets.add(Widgets.createLabel(new Point(baseX + countXOffset, countY), new TextComponent("" + e.count())).noShadow()
108+
.color(0xFF404040, 0xFFBBBBBB));
109+
widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> {
110+
if (tooltipRect.contains(mouseX, mouseY)) {
111+
Tooltip.create(tooltip).queue();
112+
}
113+
}));
114+
115+
baseX += effectWidth + effectSpacing;
116+
}
117+
}
118+
119+
return widgets;
120+
}
121+
122+
private record UpgradeEffect(int textureU, int count, String upgradeName, String greenText) {
123+
}
124+
125+
@Override
126+
public int getDisplayHeight() {
127+
return 67;
128+
}
129+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Modern Dynamics
3+
* Copyright (C) 2021 shartte & Technici4n
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
package dev.technici4n.moderndynamics.client.compat.rei;
20+
21+
import dev.technici4n.moderndynamics.attachment.upgrade.UpgradeType;
22+
import java.util.List;
23+
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
24+
import me.shedaniel.rei.api.common.display.Display;
25+
import me.shedaniel.rei.api.common.entry.EntryIngredient;
26+
import me.shedaniel.rei.api.common.util.EntryIngredients;
27+
import net.minecraft.world.item.Item;
28+
29+
public class UpgradeDisplay implements Display {
30+
final Item item;
31+
final UpgradeType upgradeInfo;
32+
33+
public UpgradeDisplay(Item item, UpgradeType upgradeInfo) {
34+
this.item = item;
35+
this.upgradeInfo = upgradeInfo;
36+
}
37+
38+
@Override
39+
public List<EntryIngredient> getInputEntries() {
40+
return List.of(EntryIngredients.of(item));
41+
}
42+
43+
@Override
44+
public List<EntryIngredient> getOutputEntries() {
45+
return List.of();
46+
}
47+
48+
@Override
49+
public CategoryIdentifier<?> getCategoryIdentifier() {
50+
return UpgradeCategory.ID;
51+
}
52+
}

src/client/java/dev/technici4n/moderndynamics/client/model/PipeBakedModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, Block
121121

122122
@Override
123123
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
124-
drawPipe(new PipeModelData((byte) 12, (byte) 0, new AttachedAttachment[6]), context);
124+
drawPipe(ITEM_DATA, context);
125125
}
126126

127127
private void drawPipe(PipeModelData data, RenderContext context) {

src/client/java/dev/technici4n/moderndynamics/client/screen/AttachedIoScreen.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import dev.technici4n.moderndynamics.util.MdId;
3131
import java.util.ArrayList;
3232
import java.util.List;
33+
import java.util.function.Consumer;
3334
import net.minecraft.ChatFormatting;
3435
import net.minecraft.client.gui.components.AbstractWidget;
3536
import net.minecraft.client.gui.components.Widget;
@@ -58,7 +59,7 @@ public class AttachedIoScreen<T extends AttachedIoMenu<?>> extends AbstractConta
5859
*/
5960
private static final int TAB_BORDER = 4;
6061

61-
private static final float TAB_OPEN_PER_TICK = 0.35f;
62+
private static final float TAB_OPEN_PER_TICK = 0.20f;
6263

6364
public static final ResourceLocation TEXTURE = MdId.of("textures/gui/attachment.png");
6465
public static final ResourceLocation TAB_RIGHT_TEXTURE = MdId.of("textures/gui/tab_right.png");
@@ -266,6 +267,13 @@ private void renderRedstoneTabBg(PoseStack matrices, float partialTicks) {
266267
RenderSystem.disableScissor();
267268
}
268269

270+
public void appendExclusionZones(Consumer<Rect2i> consumer) {
271+
// Upgrades
272+
consumer.accept(new Rect2i(leftPos + UpgradePanel.START_LEFT, topPos + UpgradePanel.START_TOP, UpgradePanel.WIDTH, UpgradePanel.HEIGHT));
273+
// Redstone tab
274+
consumer.accept(redstoneTabRect);
275+
}
276+
269277
private void updateRedstoneTabRect(float partialTicks) {
270278
var tabX = leftPos + imageWidth;
271279
var tabY = topPos + 4;

src/main/java/dev/technici4n/moderndynamics/attachment/attached/UpgradeContainer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package dev.technici4n.moderndynamics.attachment.attached;
2020

2121
import dev.technici4n.moderndynamics.Constants;
22+
import dev.technici4n.moderndynamics.attachment.upgrade.LoadedUpgrades;
2223
import dev.technici4n.moderndynamics.attachment.upgrade.UpgradeType;
23-
import dev.technici4n.moderndynamics.attachment.upgrade.UpgradeTypes;
2424
import java.util.function.ToIntFunction;
2525
import net.minecraft.core.NonNullList;
2626
import net.minecraft.nbt.CompoundTag;
@@ -48,13 +48,13 @@ public boolean mayPlaceUpgrade(int slot, Item upgrade) {
4848
}
4949
}
5050

51-
return UpgradeTypes.getSlotLimit(upgrade) > 0;
51+
return LoadedUpgrades.getType(upgrade).getSlotLimit() > 0;
5252
}
5353

5454
private int reduce(ToIntFunction<UpgradeType> valueExtractor) {
5555
int tot = 0;
5656
for (var stack : upgrades) {
57-
tot += stack.getCount() * valueExtractor.applyAsInt(UpgradeTypes.getType(stack.getItem()));
57+
tot += stack.getCount() * valueExtractor.applyAsInt(LoadedUpgrades.getType(stack.getItem()));
5858
}
5959
return tot;
6060
}

0 commit comments

Comments
 (0)