Skip to content

Commit 51f2e62

Browse files
committed
Merge branch 'zb/creative-energy-mui2' into zb/alarm-mui2
2 parents cf8356d + e224379 commit 51f2e62

File tree

9 files changed

+270
-111
lines changed

9 files changed

+270
-111
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.redstudio.alfheim.lighting;
2+
3+
// stub class to appease javac
4+
public class LightingEngine {
5+
}

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ public GTGuiTheme getUITheme() {
491491
return GTGuiTheme.STANDARD;
492492
}
493493

494+
// TODO: once everything has been moved over to MUI2, set this as @NotNull
494495
@Override
495496
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
496497
return null;

src/main/java/gregtech/api/metatileentity/SyncedTileEntityBase.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
1414
import net.minecraft.tileentity.TileEntity;
1515
import net.minecraft.util.EnumFacing;
16+
import net.minecraft.world.WorldServer;
1617
import net.minecraftforge.common.util.Constants;
1718

1819
import io.netty.buffer.ByteBuf;
@@ -57,7 +58,25 @@ public void addPacketsFrom(SyncedTileEntityBase syncedTileEntityBase) {
5758
private void notifyWorld() {
5859
@SuppressWarnings("deprecation")
5960
IBlockState blockState = getBlockType().getStateFromMeta(getBlockMetadata());
60-
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
61+
if (canNotifyWorld()) {
62+
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
63+
}
64+
}
65+
66+
private boolean canNotifyWorld() {
67+
// short circuit with packet size to avoid too many hash lookups and instanceof casts
68+
if (updates.size() > 10 && getWorld() instanceof WorldServer server) {
69+
int x = getPos().getX() >> 4;
70+
int z = getPos().getZ() >> 4;
71+
if (server.getPlayerChunkMap().contains(x, z)) {
72+
return true;
73+
} else {
74+
// cannot send, so clear
75+
updates.clear();
76+
return false;
77+
}
78+
}
79+
return false;
6180
}
6281

6382
@Override

src/main/java/gregtech/api/network/PacketDataList.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import org.jetbrains.annotations.NotNull;
77

8+
import java.util.Arrays;
9+
810
/**
911
* An optimised data structure backed by two arrays.
1012
* This is essentially equivalent to <code>List<Pair<Integer, byte[]>></code>, but more efficient.
@@ -84,9 +86,8 @@ public boolean isEmpty() {
8486
* remove all data packets
8587
*/
8688
public void clear() {
87-
for (int i = 0; i < this.size; i++) {
88-
this.data[i] = null;
89-
}
89+
Arrays.fill(this.discriminators, 0);
90+
Arrays.fill(this.data, null);
9091
this.size = 0;
9192
}
9293

src/main/java/gregtech/api/util/world/DummyWorld.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.minecraftforge.fml.common.Optional.Method;
1616
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
1717

18+
import dev.redstudio.alfheim.lighting.LightingEngine;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021

@@ -116,4 +117,9 @@ public int getLightFromNeighborsFor(EnumSkyBlock type, BlockPos pos) {
116117
public int alfheim$getLight(BlockPos pos, boolean checkNeighbors) {
117118
return 15;
118119
}
120+
121+
@Method(modid = Mods.Names.ALFHEIM)
122+
public LightingEngine getAlfheim$lightingEngine() {
123+
return null;
124+
}
119125
}

src/main/java/gregtech/common/metatileentities/MetaTileEntityRegistration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ private static void miscSingleblocks() {
682682

683683
// creative machines 5650-5659
684684
MetaTileEntities.CREATIVE_ENERGY = MetaTileEntities.registerMetaTileEntity(5650,
685-
new MetaTileEntityCreativeEnergy());
685+
new MetaTileEntityCreativeEnergy(gregtechId("infinite_energy")));
686686
MetaTileEntities.CREATIVE_CHEST = MetaTileEntities.registerMetaTileEntity(5651,
687687
new MetaTileEntityCreativeChest(gregtechId("creative_chest")));
688688
MetaTileEntities.CREATIVE_TANK = MetaTileEntities.registerMetaTileEntity(5652,

src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityDataAccessHatch.java

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import gregtech.api.GTValues;
44
import gregtech.api.capability.IDataAccessHatch;
55
import gregtech.api.capability.impl.NotifiableItemStackHandler;
6-
import gregtech.api.gui.GuiTextures;
7-
import gregtech.api.gui.ModularUI;
8-
import gregtech.api.gui.widgets.SlotWidget;
6+
import gregtech.api.items.itemhandlers.GTItemStackHandler;
97
import gregtech.api.metatileentity.IDataInfoProvider;
108
import gregtech.api.metatileentity.MetaTileEntity;
119
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
1210
import gregtech.api.metatileentity.multiblock.AbilityInstances;
1311
import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart;
1412
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
1513
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
14+
import gregtech.api.mui.GTGuiTextures;
15+
import gregtech.api.mui.GTGuis;
1616
import gregtech.api.recipes.Recipe;
1717
import gregtech.api.recipes.RecipeMaps;
1818
import gregtech.api.recipes.machines.IResearchRecipeMap;
@@ -26,7 +26,6 @@
2626

2727
import net.minecraft.client.resources.I18n;
2828
import net.minecraft.creativetab.CreativeTabs;
29-
import net.minecraft.entity.player.EntityPlayer;
3029
import net.minecraft.item.ItemStack;
3130
import net.minecraft.util.NonNullList;
3231
import net.minecraft.util.ResourceLocation;
@@ -39,6 +38,18 @@
3938
import codechicken.lib.render.CCRenderState;
4039
import codechicken.lib.render.pipeline.IVertexOperation;
4140
import codechicken.lib.vec.Matrix4;
41+
import com.cleanroommc.modularui.api.drawable.IKey;
42+
import com.cleanroommc.modularui.drawable.ItemDrawable;
43+
import com.cleanroommc.modularui.factory.PosGuiData;
44+
import com.cleanroommc.modularui.screen.ModularPanel;
45+
import com.cleanroommc.modularui.utils.Alignment;
46+
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
47+
import com.cleanroommc.modularui.value.sync.SyncHandlers;
48+
import com.cleanroommc.modularui.widget.Widget;
49+
import com.cleanroommc.modularui.widgets.ItemSlot;
50+
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
51+
import com.cleanroommc.modularui.widgets.layout.Flow;
52+
import com.cleanroommc.modularui.widgets.layout.Grid;
4253
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
4354
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
4455
import org.jetbrains.annotations.NotNull;
@@ -56,7 +67,7 @@ public class MetaTileEntityDataAccessHatch extends MetaTileEntityMultiblockNotif
5667
public MetaTileEntityDataAccessHatch(ResourceLocation metaTileEntityId, int tier, boolean isCreative) {
5768
super(metaTileEntityId, tier, false);
5869
this.isCreative = isCreative;
59-
this.recipes = isCreative ? Collections.emptySet() : new ObjectOpenHashSet<>();
70+
this.recipes = isCreative ? Collections.emptySet() : new ObjectOpenHashSet<>(importItems.getSlots());
6071
rebuildData(getController() instanceof MetaTileEntityDataBank);
6172
}
6273

@@ -103,35 +114,77 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
103114
}
104115

105116
@Override
106-
protected ModularUI createUI(EntityPlayer entityPlayer) {
107-
if (isCreative) return null;
108-
int rowSize = (int) Math.sqrt(getInventorySize());
109-
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 18 + 18 * rowSize + 94)
110-
.label(6, 6, getMetaFullName());
111-
112-
for (int y = 0; y < rowSize; y++) {
113-
for (int x = 0; x < rowSize; x++) {
114-
int index = y * rowSize + x;
115-
builder.widget(new SlotWidget(isExportHatch ? exportItems : importItems, index,
116-
88 - rowSize * 9 + x * 18, 18 + y * 18, true, !isExportHatch)
117-
.setBackgroundTexture(GuiTextures.SLOT));
118-
}
119-
}
120-
return builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 18 + 18 * rowSize + 12)
121-
.build(getHolder(), entityPlayer);
117+
protected boolean openGUIOnRightClick() {
118+
return !isCreative;
122119
}
123120

124121
@Override
125-
protected boolean openGUIOnRightClick() {
126-
return !this.isCreative;
122+
public boolean usesMui2() {
123+
return true;
124+
}
125+
126+
@Override
127+
public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManager) {
128+
int rowSize = (int) Math.sqrt(getInventorySize());
129+
panelSyncManager.registerSlotGroup("slots", rowSize);
130+
131+
Widget<?> recipeLogo = GTGuiTextures.getLogo(getUITheme())
132+
.asWidget()
133+
.align(Alignment.BottomRight)
134+
.tooltipBuilder(tooltip -> {
135+
if (recipes.isEmpty()) {
136+
tooltip.addLine(IKey.lang("gregtech.machine.data_access_hatch.no_recipes"));
137+
} else {
138+
tooltip.addLine(IKey.lang("gregtech.machine.data_access_hatch.recipes"));
139+
tooltip.spaceLine(2);
140+
}
141+
142+
Set<ItemStack> itemsAdded = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAll());
143+
for (Recipe recipe : recipes) {
144+
ItemStack output = recipe.getOutputs().get(0);
145+
if (itemsAdded.add(output)) {
146+
tooltip.add(new ItemDrawable(output));
147+
tooltip.space();
148+
tooltip.addLine(IKey.str(output.getDisplayName()));
149+
}
150+
}
151+
});
152+
153+
return GTGuis.createPanel(this, 176, 18 + 18 * rowSize + 94)
154+
.child(IKey.lang(getMetaFullName())
155+
.asWidget()
156+
.pos(5, 5))
157+
.child(Flow.row()
158+
.top(18)
159+
.margin(7, 0)
160+
.coverChildrenHeight()
161+
.child(new Grid()
162+
.height(rowSize * 18)
163+
.minElementMargin(0, 0)
164+
.minColWidth(18).minRowHeight(18)
165+
.alignX(0.5f)
166+
.mapTo(rowSize, rowSize * rowSize, index -> new ItemSlot()
167+
.slot(SyncHandlers.itemSlot(importItems, index)
168+
.slotGroup("slots")
169+
.changeListener((newItem, onlyAmountChanged, client, init) -> {
170+
recipeLogo.markTooltipDirty();
171+
if (onlyAmountChanged &&
172+
importItems instanceof GTItemStackHandler gtHandler) {
173+
gtHandler.onContentsChanged(index);
174+
}
175+
}))))
176+
.child(recipeLogo))
177+
.child(SlotGroupWidget.playerInventory()
178+
.left(7)
179+
.bottom(7));
127180
}
128181

129182
protected int getInventorySize() {
130183
return getTier() == GTValues.LuV ? 16 : 9;
131184
}
132185

133186
private void rebuildData(boolean isDataBank) {
134-
if (isCreative || getWorld() == null || getWorld().isRemote) return;
187+
if (isCreative || getWorld() == null) return;
135188
recipes.clear();
136189
for (int i = 0; i < this.importItems.getSlots(); i++) {
137190
ItemStack stack = this.importItems.getStackInSlot(i);

0 commit comments

Comments
 (0)