Skip to content

Commit

Permalink
further network refactor and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Jul 28, 2024
1 parent d4c8529 commit 4af5243
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 258 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ issues=https://github.com/modfest/glowcase/issues
sources=https://github.com/modfest/glowcase
license=CC0-1.0
# Mod Version
baseVersion=1.3.3
baseVersion=1.4.0
branch=1.21
5 changes: 1 addition & 4 deletions src/main/java/dev/hephaestus/glowcase/Glowcase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import dev.hephaestus.glowcase.block.entity.MailboxBlockEntity;
import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
import dev.hephaestus.glowcase.compat.PolydexCompatibility;
import dev.hephaestus.glowcase.networking.NetworkPayloads;
import dev.hephaestus.glowcase.networking.RegisterC2SNetworking;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
Expand Down Expand Up @@ -97,8 +95,7 @@ public static <T extends BlockEntity> Supplier<BlockEntityType<T>> registerBlock

@Override
public void onInitialize() {
NetworkPayloads.initialize();
RegisterC2SNetworking.initialize();
GlowcaseNetworking.init();

CommandRegistrationCallback.EVENT.register((dispatcher, access, environment) -> {
dispatcher.register(
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/dev/hephaestus/glowcase/GlowcaseNetworking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.hephaestus.glowcase;

import dev.hephaestus.glowcase.packet.C2SEditHyperlinkBlock;
import dev.hephaestus.glowcase.packet.C2SEditItemDisplayBlock;
import dev.hephaestus.glowcase.packet.C2SEditTextBlock;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;

public class GlowcaseNetworking {
public static void init() {
PayloadTypeRegistry.playC2S().register(C2SEditHyperlinkBlock.ID, C2SEditHyperlinkBlock.PACKET_CODEC);
PayloadTypeRegistry.playC2S().register(C2SEditItemDisplayBlock.ID, C2SEditItemDisplayBlock.PACKET_CODEC);
PayloadTypeRegistry.playC2S().register(C2SEditTextBlock.ID, C2SEditTextBlock.PACKET_CODEC);

ServerPlayNetworking.registerGlobalReceiver(C2SEditHyperlinkBlock.ID, C2SEditHyperlinkBlock::receive);
ServerPlayNetworking.registerGlobalReceiver(C2SEditItemDisplayBlock.ID, C2SEditItemDisplayBlock::receive);
ServerPlayNetworking.registerGlobalReceiver(C2SEditTextBlock.ID, C2SEditTextBlock::receive);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.hephaestus.glowcase.block.entity;

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.networking.packet.EditHyperlinkBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -61,10 +60,6 @@ public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLooku
this.url = tag.getString("url");
}

public EditHyperlinkBlock createEditPacket() {
return new EditHyperlinkBlock(pos, url);
}

// standard blockentity boilerplate

public void dispatch() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.hephaestus.glowcase.block.entity;

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.networking.packet.EditItemDisplayBlockSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -113,12 +112,6 @@ public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLooku
}
}

public EditItemDisplayBlockSettings createEditPacket() {
var itemValues = new EditItemDisplayBlockSettings.ItemDisplayBlockValues(
getCachedState().get(Properties.ROTATION), showName, pitch, yaw);
return new EditItemDisplayBlockSettings(pos, rotationType, givesItem, offset, itemValues);
}

public boolean hasItem() {
return this.stack != null && !this.stack.isEmpty();
}
Expand Down Expand Up @@ -261,4 +254,4 @@ public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryL
public Packet<ClientPlayPacketListener> toUpdatePacket() {
return BlockEntityUpdateS2CPacket.create(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer;
import dev.hephaestus.glowcase.networking.packet.EditTextBlock;
import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.TagParser;
Expand Down Expand Up @@ -81,11 +80,6 @@ protected void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLo
this.renderDirty = true;
}

public EditTextBlock createEditPacket() {
var textValues = new EditTextBlock.TextBlockValues(scale, color, lines);
return new EditTextBlock(pos, textAlignment, zOffset, shadowType, textValues);
}

public String getRawLine(int i) {
var line = this.lines.get(i);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dev.hephaestus.glowcase;
package dev.hephaestus.glowcase.client;

import dev.hephaestus.glowcase.Glowcase;
import dev.hephaestus.glowcase.block.entity.MailboxBlockEntity;
import dev.hephaestus.glowcase.client.GlowcaseClientProxy;
import dev.hephaestus.glowcase.client.render.block.entity.BakedBlockEntityRenderer;
import dev.hephaestus.glowcase.client.render.block.entity.HyperlinkBlockEntityRenderer;
import dev.hephaestus.glowcase.client.render.block.entity.ItemDisplayBlockEntityRenderer;
import dev.hephaestus.glowcase.client.render.block.entity.TextBlockEntityRenderer;
import dev.hephaestus.glowcase.networking.RegisterS2CNetworking;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.client.rendering.v1.InvalidateRenderStateCallback;
Expand Down Expand Up @@ -34,8 +33,6 @@ public void onInitializeClient() {
WorldRenderEvents.AFTER_TRANSLUCENT.register(BakedBlockEntityRenderer.Manager::render);
InvalidateRenderStateCallback.EVENT.register(BakedBlockEntityRenderer.Manager::reset);

RegisterS2CNetworking.initialize();

HudRenderCallback.EVENT.register((context, tickDelta) -> {
MinecraftClient client = MinecraftClient.getInstance();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.hephaestus.glowcase.client.gui.screen.ingame;

import dev.hephaestus.glowcase.block.entity.HyperlinkBlockEntity;
import dev.hephaestus.glowcase.packet.C2SEditHyperlinkBlock;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -53,7 +54,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
public void close() {
hyperlinkBlockEntity.setUrl(urlEntryWidget.getText());
hyperlinkBlockEntity.setTitle(titleEntryWidget.getText());
hyperlinkBlockEntity.createEditPacket().send();
C2SEditHyperlinkBlock.of(hyperlinkBlockEntity).send();
super.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.hephaestus.glowcase.client.gui.screen.ingame;

import dev.hephaestus.glowcase.block.entity.ItemDisplayBlockEntity;
import dev.hephaestus.glowcase.packet.C2SEditItemDisplayBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
Expand All @@ -9,7 +10,7 @@
public class ItemDisplayBlockEditScreen extends GlowcaseScreen {
private final ItemDisplayBlockEntity displayBlock;

private ButtonWidget givesItemButtom;
private ButtonWidget givesItemButton;
private ButtonWidget rotationTypeButton;
private ButtonWidget showNameButton;
private ButtonWidget offsetButton;
Expand All @@ -28,9 +29,9 @@ public void init() {
int centerW = width / 2;
int centerH = height / 2;

this.givesItemButtom = ButtonWidget.builder(Text.stringifiedTranslatable("gui.glowcase.gives_item", this.displayBlock.givesItem), (action) -> {
this.givesItemButton = ButtonWidget.builder(Text.stringifiedTranslatable("gui.glowcase.gives_item", this.displayBlock.givesItem), (action) -> {
this.displayBlock.cycleGiveType();
this.givesItemButtom.setMessage(Text.stringifiedTranslatable("gui.glowcase.gives_item", this.displayBlock.givesItem));
this.givesItemButton.setMessage(Text.stringifiedTranslatable("gui.glowcase.gives_item", this.displayBlock.givesItem));
editItemDisplayBlock(true);
}).dimensions(centerW - 75, centerH - 40 - individualPadding, 150, 20).build();

Expand All @@ -52,7 +53,7 @@ public void init() {
editItemDisplayBlock(true);
}).dimensions(centerW - 75, centerH + 20 + padding, 150, 20).build();

this.addDrawableChild(this.givesItemButtom);
this.addDrawableChild(this.givesItemButton);
this.addDrawableChild(this.rotationTypeButton);
this.addDrawableChild(this.showNameButton);
this.addDrawableChild(this.offsetButton);
Expand All @@ -65,6 +66,6 @@ private void editItemDisplayBlock(boolean updatePitchAndYaw) {
displayBlock.pitch = pitchAndYaw.x;
displayBlock.yaw = pitchAndYaw.y;
}
displayBlock.createEditPacket().send();
C2SEditItemDisplayBlock.of(displayBlock).send();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
import dev.hephaestus.glowcase.packet.C2SEditTextBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void tick() {

@Override
public void close() {
textBlockEntity.createEditPacket().send();
C2SEditTextBlock.of(textBlockEntity).send();
super.close();
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4af5243

Please sign in to comment.