generated from EpimorphicPioneers/ArchLoom-TemplateMod
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
2,720 additions
and
783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/com/epimorphismmc/gregiceng/api/gui/wight/AESlotWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.epimorphismmc.gregiceng.api.gui.wight; | ||
|
||
import appeng.api.stacks.AEKey; | ||
import com.epimorphismmc.gregiceng.api.misc.IConfigurableAESlot; | ||
import com.lowdragmc.lowdraglib.gui.widget.Widget; | ||
import com.lowdragmc.lowdraglib.utils.Position; | ||
import com.lowdragmc.lowdraglib.utils.Size; | ||
import lombok.Setter; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
|
||
public abstract class AESlotWidget<T extends AEKey> extends Widget { | ||
@Setter | ||
protected BiConsumer<AESlotWidget<T>, List<Component>> onAddedTooltips; | ||
protected IConfigurableAESlot<T> aeSlot; | ||
protected T key; | ||
protected long amount; | ||
|
||
public AESlotWidget(IConfigurableAESlot<T> aeSlot, Position selfPosition) { | ||
super(selfPosition, new Size(18, 18)); | ||
this.aeSlot = aeSlot; | ||
} | ||
|
||
public AESlotWidget(IConfigurableAESlot<T> aeSlot, int x, int y) { | ||
this(aeSlot, new Position(x, y)); | ||
} | ||
|
||
@Override | ||
public final void setSize(Size size) { | ||
// you cant modify size. | ||
} | ||
|
||
protected abstract void fromPacket(@Nullable FriendlyByteBuf buf); | ||
|
||
@Override | ||
public void writeInitialData(FriendlyByteBuf buffer) { | ||
super.writeInitialData(buffer); | ||
this.key = aeSlot.getConfig(); | ||
this.amount = aeSlot.getAmount(); | ||
if (key != null && amount > 0){ | ||
buffer.writeBoolean(true); | ||
key.writeToPacket(buffer); | ||
buffer.writeVarLong(amount); | ||
} else { | ||
buffer.writeBoolean(false); | ||
} | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
public void readInitialData(FriendlyByteBuf buffer) { | ||
super.readInitialData(buffer); | ||
if (buffer.readBoolean()) { | ||
fromPacket(buffer); | ||
this.amount = buffer.readVarLong(); | ||
} else { | ||
fromPacket(null); | ||
this.amount = 0; | ||
} | ||
} | ||
|
||
@Override | ||
public void detectAndSendChanges() { | ||
super.detectAndSendChanges(); | ||
var newKey = aeSlot.getConfig(); | ||
var newAmount = aeSlot.getAmount(); | ||
// TODO 是否用equal | ||
if (newKey != key || amount != newAmount) { | ||
this.key = newKey; | ||
this.amount = newAmount; | ||
writeUpdateInfo(1, buffer -> { | ||
if (key != null && amount > 0) { | ||
buffer.writeBoolean(true); | ||
key.writeToPacket(buffer); | ||
buffer.writeVarLong(amount); | ||
} else { | ||
buffer.writeBoolean(false); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
public void readUpdateInfo(int id, FriendlyByteBuf buffer) { | ||
super.readUpdateInfo(id, buffer); | ||
if (id == 1) { | ||
if (buffer.readBoolean()) { | ||
fromPacket(buffer); | ||
this.amount = buffer.readVarLong(); | ||
} else { | ||
fromPacket(null); | ||
this.amount = 0; | ||
} | ||
} | ||
} | ||
|
||
protected List<Component> getToolTips(List<Component> list) { | ||
if (this.onAddedTooltips != null) { | ||
this.onAddedTooltips.accept(this, list); | ||
} | ||
return list; | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
src/main/java/com/epimorphismmc/gregiceng/api/gui/wight/ConfigSlotWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.epimorphismmc.gregiceng.api.gui.wight; | ||
|
||
import appeng.api.stacks.AEKey; | ||
import com.epimorphismmc.gregiceng.api.misc.IConfigurableAESlotList; | ||
import com.lowdragmc.lowdraglib.gui.ingredient.IGhostIngredientTarget; | ||
import com.lowdragmc.lowdraglib.gui.ingredient.Target; | ||
import com.lowdragmc.lowdraglib.gui.widget.Widget; | ||
import com.lowdragmc.lowdraglib.utils.Position; | ||
import com.lowdragmc.lowdraglib.utils.Size; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.BooleanSupplier; | ||
import java.util.function.Predicate; | ||
|
||
import static com.lowdragmc.lowdraglib.gui.util.DrawerHelper.drawSolidRect; | ||
|
||
public abstract class ConfigSlotWidget<T extends AEKey> extends Widget implements IGhostIngredientTarget { | ||
protected final static int REMOVE_ID = 1000; | ||
protected final static int UPDATE_ID = 1001; | ||
protected static final int BLOCKED_OVERLAY_COLOR = 0x80404040; | ||
protected static final int SELECTION_OVERLAY_COLOR = -0x7f000001; | ||
protected final int index; | ||
protected final IConfigurableAESlotList<T> slotList; | ||
protected final Predicate<T> validator; | ||
protected T latestConfig; | ||
protected BooleanSupplier isBlocked = () -> false; | ||
|
||
public ConfigSlotWidget(IConfigurableAESlotList<T> slotList, int index, Position pos, Predicate<T> validator) { | ||
super(pos, new Size(18, 18)); | ||
this.slotList = slotList; | ||
this.index = index; | ||
this.validator = validator; | ||
} | ||
|
||
public ConfigSlotWidget(IConfigurableAESlotList<T> slotList, int index, int x, int y, Predicate<T> validator) { | ||
this(slotList, index, new Position(x, y), validator); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
public void drawInForeground(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { | ||
if (isMouseOverElement(mouseX, mouseY) | ||
&& getHoverElement(mouseX, mouseY) == this | ||
&& gui != null | ||
&& gui.getModularUIGui() != null) { | ||
drawTooltipTexts(mouseX, mouseY); | ||
} | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
@Override | ||
protected void drawTooltipTexts(int mouseX, int mouseY) { | ||
gui.getModularUIGui().setHoverTooltip(getHoverTexts(new ArrayList<>()), ItemStack.EMPTY, null, null); | ||
} | ||
|
||
public ConfigSlotWidget<T> setIsBlocked(BooleanSupplier isBlocked) { | ||
this.isBlocked = isBlocked; | ||
return this; | ||
} | ||
|
||
protected @Nullable T getConfig() { | ||
return slotList.getAESlot(index).getConfig(); | ||
} | ||
|
||
protected void setConfig(@Nullable T config) { | ||
slotList.getAESlot(index).setConfig(config); | ||
} | ||
|
||
protected List<Component> getHoverTexts(List<Component> hoverTexts) { | ||
if (getConfig() == null) { | ||
if (isBlocked.getAsBoolean()) { | ||
|
||
} else { | ||
hoverTexts.add(Component.translatable("gtceu.gui.config_slot")); | ||
hoverTexts.add(Component.translatable("gtceu.gui.config_slot.set")); | ||
hoverTexts.add(Component.translatable("gtceu.gui.config_slot.remove")); | ||
} | ||
hoverTexts.addAll(tooltipTexts); | ||
} | ||
return hoverTexts; | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
protected static void drawBlockedOverlay(GuiGraphics graphics, int x, int y, int width, int height) { | ||
RenderSystem.disableDepthTest(); | ||
RenderSystem.colorMask(true, true, true, false); | ||
drawSolidRect(graphics, x, y, width, height, BLOCKED_OVERLAY_COLOR); | ||
RenderSystem.colorMask(true, true, true, true); | ||
RenderSystem.enableDepthTest(); | ||
RenderSystem.enableBlend(); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
protected static void drawSelectionOverlay(GuiGraphics graphics, int x, int y, int width, int height) { | ||
RenderSystem.disableDepthTest(); | ||
RenderSystem.colorMask(true, true, true, false); | ||
drawSolidRect(graphics, x, y, width, height, SELECTION_OVERLAY_COLOR); | ||
RenderSystem.colorMask(true, true, true, true); | ||
RenderSystem.enableDepthTest(); | ||
RenderSystem.enableBlend(); | ||
} | ||
|
||
@Override | ||
public List<Target> getPhantomTargets(Object ingredient) { | ||
return Collections.emptyList(); | ||
} | ||
} |
Oops, something went wrong.