-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
5d61704
commit 88ffa07
Showing
14 changed files
with
220 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package ua.mei.mgui.api.gui; | ||
|
||
import eu.pb4.sgui.api.gui.SimpleGui; | ||
import eu.pb4.sgui.virtual.SguiScreenHandlerFactory; | ||
import eu.pb4.sgui.virtual.inventory.VirtualScreenHandler; | ||
import net.minecraft.screen.GenericContainerScreenHandler; | ||
import net.minecraft.screen.NamedScreenHandlerFactory; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import ua.mei.mgui.impl.packet.MGuiOpenScreenPacket; | ||
import ua.mei.mgui.mixin.SimpleGuiAccessor; | ||
|
||
import java.util.OptionalInt; | ||
|
||
public class TexturedGui extends SimpleGui { | ||
public boolean showVanillaBackground = false; | ||
|
||
public TexturedGui(ScreenHandlerType<GenericContainerScreenHandler> type, ServerPlayerEntity player, boolean manipulatePlayerSlots) { | ||
super(type, player, manipulatePlayerSlots); | ||
} | ||
|
||
@Override | ||
public void setTitle(Text title) { | ||
((SimpleGuiAccessor) this).setTitle(title); | ||
|
||
if (this.isOpen()) { | ||
this.player.networkHandler.connection.send(new MGuiOpenScreenPacket(this.syncId, this.type, title)); | ||
this.screenHandler.syncState(); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean sendGui() { | ||
this.reOpen = true; | ||
|
||
if (this.player.currentScreenHandler != this.player.playerScreenHandler) { | ||
this.player.closeHandledScreen(); | ||
} | ||
this.player.incrementScreenHandlerSyncId(); | ||
|
||
OptionalInt temp = OptionalInt.empty(); | ||
|
||
if (this.player.currentScreenHandler == this.player.playerScreenHandler) { | ||
NamedScreenHandlerFactory factory = SguiScreenHandlerFactory.ofDefault(this); | ||
ScreenHandler screenHandler = factory.createMenu(this.player.screenHandlerSyncId, this.player.getInventory(), this.player); | ||
|
||
if (screenHandler == null) { | ||
if (this.player.isSpectator()) { | ||
this.player.sendMessage(Text.translatable("container.spectatorCantOpen").formatted(Formatting.RED), true); | ||
} | ||
} else { | ||
this.player.networkHandler.connection.send(new MGuiOpenScreenPacket(screenHandler.syncId, screenHandler.getType(), factory.getDisplayName())); | ||
this.player.onScreenHandlerOpened(screenHandler); | ||
this.player.currentScreenHandler = screenHandler; | ||
|
||
temp = OptionalInt.of(this.player.screenHandlerSyncId); | ||
} | ||
} | ||
this.reOpen = false; | ||
|
||
if (temp.isPresent()) { | ||
this.syncId = temp.getAsInt(); | ||
|
||
if (this.player.currentScreenHandler instanceof VirtualScreenHandler) { | ||
this.screenHandler = (VirtualScreenHandler) this.player.currentScreenHandler; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/ua/mei/mgui/impl/packet/MGuiOpenScreenPacket.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,20 @@ | ||
package ua.mei.mgui.impl.packet; | ||
|
||
import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.text.Text; | ||
|
||
public class MGuiOpenScreenPacket extends OpenScreenS2CPacket { | ||
private final Text finalName; | ||
|
||
public MGuiOpenScreenPacket(int syncId, ScreenHandlerType<?> screenHandlerId, Text name) { | ||
super(syncId, screenHandlerId, name); | ||
|
||
this.finalName = name; | ||
} | ||
|
||
@Override | ||
public Text getName() { | ||
return this.finalName; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/ua/mei/mgui/mixin/OpenScreenS2CPacketMixin.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,35 @@ | ||
package ua.mei.mgui.mixin; | ||
|
||
import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import ua.mei.mgui.impl.MGuiImpl; | ||
import ua.mei.mgui.impl.VanillaTextures; | ||
import ua.mei.pfu.api.util.TextBuilder; | ||
|
||
@Mixin(OpenScreenS2CPacket.class) | ||
public abstract class OpenScreenS2CPacketMixin { | ||
@Shadow @Final private Text name; | ||
|
||
@Shadow @Final private ScreenHandlerType<?> screenHandlerId; | ||
|
||
@Inject(method = "getName", at = @At("HEAD"), cancellable = true) | ||
public void mgui$replaceName(CallbackInfoReturnable<Text> cir) { | ||
if (MGuiImpl.genericScreenHandlers.contains(this.screenHandlerId)) { | ||
cir.setReturnValue( | ||
new TextBuilder() | ||
.text(VanillaTextures.fromScreenHandler(this.screenHandlerId).formatted(Formatting.WHITE)) | ||
.text((MutableText) this.name) | ||
.build() | ||
); | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/main/java/ua/mei/mgui/mixin/ServerPlayerEntityMixin.java
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
package ua.mei.mgui.mixin; | ||
|
||
import eu.pb4.sgui.api.gui.SimpleGui; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(SimpleGui.class) | ||
public interface SimpleGuiAccessor { | ||
@Accessor | ||
Text getTitle(); | ||
|
||
@Accessor | ||
void setTitle(Text title); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
accessWidener v2 named | ||
|
||
accessible method net/minecraft/server/network/ServerPlayerEntity incrementScreenHandlerSyncId ()V | ||
|
||
accessible field net/minecraft/server/network/ServerPlayerEntity screenHandlerSyncId I | ||
|
||
accessible field net/minecraft/server/network/ServerCommonNetworkHandler connection Lnet/minecraft/network/ClientConnection; | ||
|
||
accessible method net/minecraft/server/network/ServerPlayerEntity onScreenHandlerOpened (Lnet/minecraft/screen/ScreenHandler;)V |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ua.mei.mgui.test.gui; | ||
|
||
import eu.pb4.sgui.api.GuiHelpers; | ||
import eu.pb4.sgui.api.elements.GuiElementBuilder; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.text.Text; | ||
import ua.mei.mgui.api.gui.TexturedGui; | ||
|
||
public class TestGui extends TexturedGui { | ||
public TestGui(ServerPlayerEntity player) { | ||
super(ScreenHandlerType.GENERIC_9X3, player, false); | ||
|
||
setSlot(13, new GuiElementBuilder() | ||
.setItem(Items.DIAMOND) | ||
.setCallback(() -> player.sendMessage(Text.literal("Hello world!"))) | ||
.build() | ||
); | ||
} | ||
} |