diff --git a/gradle.properties b/gradle.properties index d53cec7..63ae980 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx4G loader_version=0.11.1 # Mod Properties - mod_version = ALPHA.2 + mod_version = ALPHA.3 maven_group = azzy.ttlg archives_base_name = TTLG libgui_version = 3.3.3+1.16.5 diff --git a/src/main/java/azzy/fabric/lookingglass/LookingGlassClient.java b/src/main/java/azzy/fabric/lookingglass/LookingGlassClient.java index 61cc674..ab2d111 100644 --- a/src/main/java/azzy/fabric/lookingglass/LookingGlassClient.java +++ b/src/main/java/azzy/fabric/lookingglass/LookingGlassClient.java @@ -3,6 +3,7 @@ import azzy.fabric.lookingglass.gui.*; import azzy.fabric.lookingglass.particle.TTLGParticles; import azzy.fabric.lookingglass.render.*; +import azzy.fabric.lookingglass.util.ClientNetworkingUtils; import azzy.fabric.lookingglass.util.client.RenderCache; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; @@ -45,12 +46,9 @@ public void onInitializeClient() { BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutoutMipped(), FISH_BREEDER_BLOCK, BLOCK_TESSERACT_BLOCK); BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), CREATIVE_ENERGY_SOURCE_BLOCK); - //I will update this some day k I promise - ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(MODID, "projector_gui"), (syncID, id, player, buf) -> new ProjectorScreen( new ProjectorGuiDescription(ScreenHandlerType.ANVIL, syncID, player.inventory, ScreenHandlerContext.create(player.world, buf.readBlockPos())), player)); - - TTLGParticles.init(); LookingGlassGUIs.initClient(); + ClientNetworkingUtils.init(); RenderCache.init(); //ClientTickEvents.END_WORLD_TICK.register(clientWorld -> { diff --git a/src/main/java/azzy/fabric/lookingglass/LookingGlassCommon.java b/src/main/java/azzy/fabric/lookingglass/LookingGlassCommon.java index 6963b2b..12254aa 100644 --- a/src/main/java/azzy/fabric/lookingglass/LookingGlassCommon.java +++ b/src/main/java/azzy/fabric/lookingglass/LookingGlassCommon.java @@ -5,8 +5,8 @@ import azzy.fabric.lookingglass.blockentity.ProjectorEntity; import azzy.fabric.lookingglass.feature.TTLGConfiguredFeatures; import azzy.fabric.lookingglass.gui.LookingGlassGUIs; -import azzy.fabric.lookingglass.gui.ProjectorGuiDescription; import azzy.fabric.lookingglass.item.TTLGItems; +import azzy.fabric.lookingglass.util.GeneralNetworking; import azzy.fabric.lookingglass.util.datagen.Metadata; import com.chocohead.mm.api.ClassTinkerers; import net.fabricmc.api.ModInitializer; @@ -38,7 +38,10 @@ public class LookingGlassCommon implements ModInitializer { public static final BlockSoundGroup ELDENMETAL = new BlockSoundGroup(1.0F, 1.0F, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundEvents.BLOCK_SHROOMLIGHT_PLACE, SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, SoundEvents.BLOCK_RESPAWN_ANCHOR_AMBIENT, SoundEvents.BLOCK_BEACON_DEACTIVATE); - public static final Rarity NULL_RARITY = ClassTinkerers.getEnum(Rarity.class, "NULL"); + public static final Rarity FINIS_RARITY = ClassTinkerers.getEnum(Rarity.class, "FINIS"); + public static final Rarity ELDENMETAL_RARITY = ClassTinkerers.getEnum(Rarity.class, "NULL"); + public static final Rarity LUPREVAN_RARITY = ClassTinkerers.getEnum(Rarity.class, "DAWN"); + public static final Rarity WORLDFORGE_RARITY = ClassTinkerers.getEnum(Rarity.class, "TERMINUS"); public static final Logger FFLog = LogManager.getLogger(MODID); public static final SplittableRandom RANDOM = new SplittableRandom(); @@ -61,55 +64,6 @@ public void onInitialize() { TTLGConfiguredFeatures.init(); TTLGConfiguredFeatures.Registrar.init(); LookingGlassGUIs.initCommon(); - - ServerSidePacketRegistry.INSTANCE.register(STRING_TO_SERVER_PACKET, ((packetContext, packetByteBuf) -> { - - String url = packetByteBuf.readString(4096); - BlockPos pos = packetByteBuf.readBlockPos(); - int index = packetByteBuf.readInt(); - World world = packetContext.getPlayer().getEntityWorld(); - - packetContext.getTaskQueue().execute(() -> { - if(world.isChunkLoaded(pos) && world.getBlockState(pos).getBlock() == PROJECTORBLOCK){ - ProjectorEntity projector = (ProjectorEntity) world.getBlockEntity(pos); - assert projector != null; - if(index == 0) - projector.sign = url; - else if(index == 2) - projector.color = url; - else - projector.setUrl(url); - projector.sync(); - } - }); - })); - - ServerSidePacketRegistry.INSTANCE.register(DOUBLES_TO_SERVER_PACKET, ((packetContext, packetByteBuf) -> { - - int index = packetByteBuf.readInt(); - double value = packetByteBuf.readDouble(); - BlockPos pos = packetByteBuf.readBlockPos(); - World world = packetContext.getPlayer().getEntityWorld(); - - packetContext.getTaskQueue().execute(() -> { - if(world.isChunkLoaded(pos) && world.getBlockState(pos).getBlock() == PROJECTORBLOCK){ - ProjectorEntity projector = (ProjectorEntity) world.getBlockEntity(pos); - assert projector != null; - - switch(index){ - case (1): projector.rotX = value; break; - case (2): projector.rotY = value; break; - case (3): projector.rotZ = value; break; - case (4): projector.disX = value; break; - case (5): projector.disY = value; break; - case (6): projector.disZ = value; break; - case (7): projector.scale = value; break; - } - projector.sync(); - } - }); - })); - - ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(MODID, "projector_gui"), (syncID, id, player, buf) -> new ProjectorGuiDescription(ScreenHandlerType.ANVIL, syncID, player.inventory, ScreenHandlerContext.create(player.world, buf.readBlockPos()))); + GeneralNetworking.init(); } } diff --git a/src/main/java/azzy/fabric/lookingglass/LookingGlassEarlyRiser.java b/src/main/java/azzy/fabric/lookingglass/LookingGlassEarlyRiser.java index fb1f577..b7ac9f9 100644 --- a/src/main/java/azzy/fabric/lookingglass/LookingGlassEarlyRiser.java +++ b/src/main/java/azzy/fabric/lookingglass/LookingGlassEarlyRiser.java @@ -14,7 +14,10 @@ public void run() { mappingResolver.mapClassName("intermediary", "net.minecraft.class_1814"), // Rarity "L" + mappingResolver.mapClassName("intermediary", "net.minecraft.class_124") + ";" // Formatting ); + enumAdder.addEnum("FINIS", () -> new Object[]{ Formatting.BLUE }); enumAdder.addEnum("NULL", () -> new Object[]{ Formatting.DARK_PURPLE }); + enumAdder.addEnum("DAWN", () -> new Object[]{ Formatting.GOLD }); + enumAdder.addEnum("TERMINUS", () -> new Object[]{ Formatting.UNDERLINE }); enumAdder.build(); } } diff --git a/src/main/java/azzy/fabric/lookingglass/block/ProjectorBlock.java b/src/main/java/azzy/fabric/lookingglass/block/ProjectorBlock.java index 9601415..78ba374 100644 --- a/src/main/java/azzy/fabric/lookingglass/block/ProjectorBlock.java +++ b/src/main/java/azzy/fabric/lookingglass/block/ProjectorBlock.java @@ -1,7 +1,10 @@ package azzy.fabric.lookingglass.block; import azzy.fabric.lookingglass.blockentity.ProjectorEntity; +import azzy.fabric.lookingglass.util.GeneralNetworking; import net.fabricmc.fabric.api.container.ContainerProviderRegistry; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.BlockState; @@ -11,6 +14,7 @@ import net.minecraft.client.resource.language.I18n; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -37,34 +41,34 @@ public ProjectorBlock(Settings settings) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ProjectorEntity entity = (ProjectorEntity) world.getBlockEntity(pos); if(entity != null) { + if(!player.isInSneakingPose()) + player.openHandledScreen(state.createScreenHandlerFactory(world, pos)); if(!world.isClient) { - if(!player.isInSneakingPose()) { - ContainerProviderRegistry.INSTANCE.openContainer(new Identifier(MODID, "projector_gui"), player, (packetByteBuf -> packetByteBuf.writeBlockPos(pos))); - entity.sync(); - } - } - if(player.isInSneakingPose()){ - if(entity.displayState < 4) - entity.displayState++; - else - entity.displayState = 0; - if(world.isClient()) { - String label = ""; - switch(entity.displayState){ - case(0): label = I18n.translate("label.lookingglass.glass.image_switch", label); break; - case(1): label = I18n.translate("label.lookingglass.glass.item_switch", label); break; - case(2): label = I18n.translate("label.lookingglass.glass.sign_switch");; break; - case(3): label = I18n.translate("label.lookingglass.glass.mob_switch");; break; - case(4): label = I18n.translate("label.lookingglass.glass.player_switch"); break; - } + if(player.isInSneakingPose()) { + if(entity.displayState < 4) + entity.displayState++; + else + entity.displayState = 0; - MinecraftClient.getInstance().player.sendSystemMessage(new LiteralText(label), null); + ServerPlayNetworking.send((ServerPlayerEntity) player, GeneralNetworking.TRANSLATEABLE_PACKET, PacketByteBufs.create().writeString(getClientMessage(entity))); } + entity.sync(); } } return ActionResult.SUCCESS; } + public String getClientMessage(ProjectorEntity entity) { + switch(entity.displayState){ + case(0): return "label.lookingglass.glass.image_switch"; + case(1): return "label.lookingglass.glass.item_switch"; + case(2): return "label.lookingglass.glass.sign_switch"; + case(3): return "label.lookingglass.glass.mob_switch"; + case(4): return "label.lookingglass.glass.player_switch"; + default:return ""; + } + } + @Override public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return shape; diff --git a/src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java b/src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java index 5e5aec9..ab3ff58 100644 --- a/src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java +++ b/src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java @@ -11,14 +11,12 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.*; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.entity.damage.DamageSource; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; @@ -118,7 +116,7 @@ private static FabricBlockSettings eldenMachine() { //Misc public static final Block NEBULOUS_HALITE = registerBlock("nebulous_halite", new NebulousHaliteBlock(FabricBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).emissiveLighting((a, b, c) -> true).requiresTool().breakByTool(FabricToolTags.PICKAXES, 3).nonOpaque().luminance(9).postProcess((a, b, c) -> true).strength(25, 500)), new FabricItemSettings().fireproof().group(LOOKINGGLASS_BLOCKS)); public static final Block NEBULOUS_SALTS = TTLGBlocks.registerBlock("nebulous_salts", new NebulousSaltBlock(FabricBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).emissiveLighting((a, b, c) -> true).requiresTool().breakByTool(FabricToolTags.PICKAXES, 3).nonOpaque().luminance(7).postProcess((a, b, c) -> true).strength(20, 500)), new FabricItemSettings().fireproof().group(LOOKINGGLASS_BLOCKS)); - public static final Block ELDENMETAL_BLOCK = registerBlock("eldenmetal_block", new Block(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).luminance(state -> 3).nonOpaque().sounds(LookingGlassCommon.ELDENMETAL)), basicMachineItem().fireproof().rarity(NULL_RARITY)); + public static final Block ELDENMETAL_BLOCK = registerBlock("eldenmetal_block", new Block(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).luminance(state -> 3).nonOpaque().sounds(LookingGlassCommon.ELDENMETAL)), basicMachineItem().fireproof().rarity(ELDENMETAL_RARITY)); public static final Block SALMON_EGGS = registerBlock("salmon_egg", new SalmonEggBlock(FabricBlockSettings.copyOf(Blocks.TURTLE_EGG).sounds(BlockSoundGroup.HONEY).ticksRandomly()), basicMachineItem()); // BLOCK ENTITIES diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/ProjectorEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/ProjectorEntity.java index f37360b..047cd4d 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/ProjectorEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/ProjectorEntity.java @@ -1,41 +1,40 @@ package azzy.fabric.lookingglass.blockentity; import azzy.fabric.lookingglass.LookingGlassCommon; -import azzy.fabric.lookingglass.util.ExtendedPropertyDelegate; +import azzy.fabric.lookingglass.gui.CrateGuiDescription; +import azzy.fabric.lookingglass.gui.NewProjectorGuiDescription; +import azzy.fabric.lookingglass.util.GeneralNetworking; import azzy.fabric.lookingglass.util.InventoryWrapper; -import com.mojang.authlib.GameProfile; +import azzy.fabric.lookingglass.util.Syncable; import io.github.cottonmc.cotton.gui.PropertyDelegateHolder; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; +import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.OtherClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.EntityType; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventories; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.PropertyDelegate; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.Tickable; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerContext; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; -import java.util.UUID; +import org.jetbrains.annotations.Nullable; import static azzy.fabric.lookingglass.block.TTLGBlocks.PROJECTORENTITY; -public class ProjectorEntity extends BlockEntity implements BlockEntityClientSerializable, InventoryWrapper, PropertyDelegateHolder { +public class ProjectorEntity extends BlockEntity implements BlockEntityClientSerializable, InventoryWrapper, PropertyDelegateHolder, ExtendedScreenHandlerFactory, Syncable { public int displayState; public double rotY, rotX, rotZ, disY, disX, disZ, scale; @@ -142,41 +141,7 @@ public void fromClientTag(CompoundTag compoundTag) { url = compoundTag.getString("image"); } - private final ExtendedPropertyDelegate referenceHolder = new ExtendedPropertyDelegate() { - - @Override - public double getDouble(int index) { - switch(index){ - case (3): return rotX; - case (4): return rotY; - case (5): return rotZ; - case (6): return disX; - case (7): return disY; - case (8): return disZ; - case (9): return scale; - } - return -1; - } - - @Override - public void setDouble(int index, double value) { - if(world.isClient()){ - PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer()); - packet.writeInt(index).writeDouble(value); - packet.writeBlockPos(pos); - ClientSidePacketRegistry.INSTANCE.sendToServer(LookingGlassCommon.DOUBLES_TO_SERVER_PACKET, packet); - } - - switch(index){ - case (1): rotX = value; break; - case (2): rotY = value; break; - case (3): rotZ = value; break; - case (4): disX = value; break; - case (5): disY = value; break; - case (6): disZ = value; break; - case (7): scale = value; break; - } - } + private final PropertyDelegate referenceHolder = new PropertyDelegate() { @Override public int get(int index) { @@ -184,6 +149,9 @@ public int get(int index) { case (0): return displayState; case (1): return Registry.ITEM.getRawId(inventory.get(0).getItem()); case (2): return inventory.get(0).getCount(); + case (3): return pos.getX(); + case (4): return pos.getY(); + case (5): return pos.getZ(); } return -1; } @@ -194,43 +162,9 @@ public void set(int index, int value) { } } - @Override - public String getString(int index) { - switch(index){ - case (0): return sign; - case (1): return url; - case (2): return color; - } - return null; - } - - @Override - public void setString(int index, String value) { - - if(world.isClient()){ - PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer()); - packet.writeString(value).writeBlockPos(pos).writeInt(index); - ClientSidePacketRegistry.INSTANCE.sendToServer(LookingGlassCommon.STRING_TO_SERVER_PACKET, packet); - } - - switch(index){ - case (0): sign = value; break; - case (1): url = value; break; - case (2): color = value; break; - } - - if(!world.isClient) - sync(); - } - - @Override - public BlockPos getPos() { - return pos; - } - @Override public int size() { - return 10; + return 6; } }; @@ -244,4 +178,35 @@ public PropertyDelegate getPropertyDelegate() { return referenceHolder; } + @Override + public Text getDisplayName() { + return new TranslatableText(getCachedState().getBlock().getTranslationKey()); + } + + @Override + public @Nullable ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { + return new NewProjectorGuiDescription(syncId, inv, ScreenHandlerContext.create(world, pos)); + } + + @Override + public void writeScreenOpeningData(ServerPlayerEntity serverPlayerEntity, PacketByteBuf packetByteBuf) { + packetByteBuf.writeBlockPos(pos); + } + + @Override + public void sync(PacketByteBuf packet) { + + + + + + + + + + + + + sync(); + } } \ No newline at end of file diff --git a/src/main/java/azzy/fabric/lookingglass/gui/CrateGuiDescription.java b/src/main/java/azzy/fabric/lookingglass/gui/CrateGuiDescription.java index 6696b7e..af40ebd 100644 --- a/src/main/java/azzy/fabric/lookingglass/gui/CrateGuiDescription.java +++ b/src/main/java/azzy/fabric/lookingglass/gui/CrateGuiDescription.java @@ -19,11 +19,10 @@ public class CrateGuiDescription extends SyncedGuiDescription { - private final WPlainPanel root = new WPlainPanel(); - public CrateGuiDescription(int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) { super(LookingGlassGUIs.CRATE_HANDLER, syncId, playerInventory, getBlockInventory(context, 117), getBlockPropertyDelegate(context)); + WPlainPanel root = new WPlainPanel(); root.setSize(234, 162); setRootPanel(root); WItemSlot itemSlot; diff --git a/src/main/java/azzy/fabric/lookingglass/gui/LookingGlassGUIs.java b/src/main/java/azzy/fabric/lookingglass/gui/LookingGlassGUIs.java index 6b6883c..22a60c9 100644 --- a/src/main/java/azzy/fabric/lookingglass/gui/LookingGlassGUIs.java +++ b/src/main/java/azzy/fabric/lookingglass/gui/LookingGlassGUIs.java @@ -14,6 +14,7 @@ public class LookingGlassGUIs { public static final ScreenHandlerType CRATE_HANDLER = ScreenHandlerRegistry.registerSimple(new Identifier(MODID, "crate_gui"), (syncId, inventory) -> new CrateGuiDescription(syncId, inventory, ScreenHandlerContext.EMPTY)); + public static final ScreenHandlerType PROJECTOR_HANDLER = ScreenHandlerRegistry.registerExtended(new Identifier(MODID, "projector_gui"), (syncId, inventory, packetByteBuf) -> new NewProjectorGuiDescription(syncId, inventory, ScreenHandlerContext.create(inventory.player.world, packetByteBuf.readBlockPos()))); public static void initCommon() {} @@ -21,5 +22,6 @@ public static void initCommon() {} @Environment(EnvType.CLIENT) public static void initClient() { ScreenRegistry.register(CRATE_HANDLER, (gui, inventory, title) -> new CrateScreen(gui, inventory.player, title)); + ScreenRegistry.register(PROJECTOR_HANDLER, (gui, inventory, title) -> new NewProjectorScreen(gui, inventory.player, title)); } } diff --git a/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorGuiDescription.java b/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorGuiDescription.java new file mode 100644 index 0000000..67d5b5b --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorGuiDescription.java @@ -0,0 +1,145 @@ +package azzy.fabric.lookingglass.gui; + +import azzy.fabric.lookingglass.block.TTLGBlocks; +import azzy.fabric.lookingglass.blockentity.ProjectorEntity; +import azzy.fabric.lookingglass.util.GeneralNetworking; +import io.github.cottonmc.cotton.gui.SyncedGuiDescription; +import io.github.cottonmc.cotton.gui.widget.*; +import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandlerContext; +import net.minecraft.text.LiteralText; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.World; + +public class NewProjectorGuiDescription extends SyncedGuiDescription { + + private final WPlainPanel root = new WPlainPanel(); + private final WTextField url = new WTextField().setMaxLength(512); + private final WTextField disX = new WTextField().setMaxLength(4); + private final WTextField disY = new WTextField().setMaxLength(4); + private final WTextField disZ = new WTextField().setMaxLength(4); + private final WTextField sign = new WTextField().setMaxLength(2048); + private final WTextField color = new WTextField().setMaxLength(32); + private final WTextField rotX = new WTextField().setMaxLength(7); + private final WTextField rotY = new WTextField().setMaxLength(7); + private final WTextField rotZ = new WTextField().setMaxLength(7); + private final WTextField scale = new WTextField().setMaxLength(6); + private BlockPos pos = null; + + public NewProjectorGuiDescription(int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) { + super(LookingGlassGUIs.PROJECTOR_HANDLER, syncId, playerInventory, getBlockInventory(context, 1), getBlockPropertyDelegate(context)); + + WPlainPanel root = new WPlainPanel(); + root.setSize(162, 200); + setRootPanel(root); + + root.add(this.createPlayerInventoryPanel(), 1, 212); + + ProjectorEntity entity = (ProjectorEntity) world.getBlockEntity(new BlockPos(propertyDelegate.get(3), propertyDelegate.get(4), propertyDelegate.get(5))); + + if(entity == null) + return; + + pos = entity.getPos(); + + int state = entity.displayState; + + disX.setText(String.valueOf(entity.disX)); + disY.setText(String.valueOf(entity.disY)); + disZ.setText(String.valueOf(entity.disZ)); + sign.setText(entity.sign); + color.setText(entity.color); + rotX.setText(String.valueOf(entity.rotX)); + rotY.setText(String.valueOf(entity.rotY)); + rotZ.setText(String.valueOf(entity.rotZ)); + scale.setText(String.valueOf(entity.scale)); + + root.add(new WText(new LiteralText("X")), 5, 76, 26, 10); + root.add(new WText(new LiteralText("Y")), 5, 106, 26, 10); + root.add(new WText(new LiteralText("Z")), 5, 136, 26, 10); + + root.add(new WText(new LiteralText("Offset")), 20, 55, 55, 10); + root.add(new WText(new LiteralText("Rotation")), 90, 55, 55, 10); + + root.add(rotX, 90, 70, 55, 10); + root.add(rotY, 90, 100, 55, 10); + root.add(rotZ, 90, 130, 55, 10); + root.add(disX, 20, 70, 55, 10); + root.add(disY, 20, 100, 55, 10); + root.add(disZ, 20, 130, 55, 10); + + root.add(scale, 20, state == 2 ? 180 : 160, 125, 40); + + if(state == 1 || state >= 3) + root.add(new WItemSlot(blockInventory, 0, 1, 1, true), 70, 27); + + String label; + + switch(state){ + case(0): label = "label.lookingglass.glass.image"; break; + case(1): label = "label.lookingglass.glass.item"; break; + case(2): label = "label.lookingglass.glass.sign"; break; + case(3): label = "label.lookingglass.glass.mob"; break; + default: label = "label.lookingglass.glass.player"; break; + } + + WDynamicLabel stateLabel = new WDynamicLabel(() -> label); + stateLabel.setSize(100, 20); + stateLabel.setAlignment(HorizontalAlignment.CENTER); + root.add(stateLabel, 72, 10); + + url.setSuggestion("URL"); + url.setSize(160, 5); + url.setText(entity.url); + + sign.setSuggestion("label.lookingglass.glass.signsug"); + sign.setSize(160, 5); + sign.setText(entity.sign); + color.setSuggestion("label.lookingglass.glass.colorsug"); + + if (state == 0) { + root.add(url, 2, 23, 160, 5); + } + + if(state == 2){ + root.add(sign, 2, 23, 160, 5); + root.add(color, 53, 160, 60, 5); + } + root.validate(this); + } + + @Override + public void close(PlayerEntity player) { + World world = player.getEntityWorld(); + + if(pos != null) { + if(world.isClient()) { + try { + PacketByteBuf buf = PacketByteBufs.create(); + buf.writeBlockPos(pos); + buf.writeDouble(Double.parseDouble(rotX.getText())); + buf.writeDouble(Double.parseDouble(rotY.getText())); + buf.writeDouble(Double.parseDouble(rotZ.getText())); + buf.writeDouble(Double.parseDouble(disX.getText())); + buf.writeDouble(Double.parseDouble(disY.getText())); + buf.writeDouble(Double.parseDouble(disZ.getText())); + buf.writeDouble(Double.parseDouble(scale.getText())); + buf.writeString(url.getText()); + buf.writeString(sign.getText()); + buf.writeString(color.getText()); + ClientPlayNetworking.send(GeneralNetworking.PROJECTOR_SYNC_PACKET, buf); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + super.close(player); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorScreen.java b/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorScreen.java new file mode 100644 index 0000000..e7f99b6 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/gui/NewProjectorScreen.java @@ -0,0 +1,12 @@ +package azzy.fabric.lookingglass.gui; + +import io.github.cottonmc.cotton.gui.client.CottonInventoryScreen; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.Text; + +public class NewProjectorScreen extends CottonInventoryScreen { + + public NewProjectorScreen(NewProjectorGuiDescription description, PlayerEntity player, Text title) { + super(description, player, title); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/gui/ProjectorGuiDescription.java b/src/main/java/azzy/fabric/lookingglass/gui/ProjectorGuiDescription.java index 4fbcfe1..db1ad4a 100644 --- a/src/main/java/azzy/fabric/lookingglass/gui/ProjectorGuiDescription.java +++ b/src/main/java/azzy/fabric/lookingglass/gui/ProjectorGuiDescription.java @@ -1,137 +1,136 @@ package azzy.fabric.lookingglass.gui; -import azzy.fabric.lookingglass.util.ExtendedPropertyDelegate; -import io.github.cottonmc.cotton.gui.SyncedGuiDescription; -import io.github.cottonmc.cotton.gui.widget.*; -import io.github.cottonmc.cotton.gui.widget.data.Axis; -import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; - -import javax.swing.*; -import java.awt.*; - - -public class ProjectorGuiDescription extends SyncedGuiDescription { - - private final WPlainPanel root = new WPlainPanel(); - private final ExtendedPropertyDelegate delegate; - private final WTextField url = new WTextField().setMaxLength(512); - private final WTextField disX = new WTextField().setMaxLength(4); - private final WTextField disY = new WTextField().setMaxLength(4); - private final WTextField disZ = new WTextField().setMaxLength(4); - private final WTextField sign = new WTextField().setMaxLength(2048); - private final WTextField color = new WTextField().setMaxLength(32); - private final WSlider rotX = new WSlider(0, 360, Axis.HORIZONTAL); - private final WSlider rotY = new WSlider(0, 360, Axis.HORIZONTAL); - private final WSlider rotZ = new WSlider(0, 360, Axis.HORIZONTAL); - private final WSlider scale = new WSlider(16, 320, Axis.HORIZONTAL); - - private final int state; - private String label; - - public ProjectorGuiDescription(ScreenHandlerType recipeType, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) { - super(recipeType, syncId, playerInventory, getBlockInventory(context), getBlockPropertyDelegate(context)); - delegate = (ExtendedPropertyDelegate) getPropertyDelegate(); - state = delegate.get(0); - - root.setSize(162, 200); - setRootPanel(root); - root.add(this.createPlayerInventoryPanel(), 1, 212); - - disX.setText(String.valueOf(delegate.getDouble(6))); - disY.setText(String.valueOf(delegate.getDouble(7))); - disZ.setText(String.valueOf(delegate.getDouble(8))); - sign.setText(delegate.getString(0)); - color.setText(delegate.getString(2)); - rotX.setValue((int) delegate.getDouble(3)); - rotY.setValue((int) delegate.getDouble(4)); - rotZ.setValue((int) delegate.getDouble(5)); - scale.setValue((int) (delegate.getDouble(9) * 10)); - - root.add(new WText(new LiteralText("X")), 5, 66, 26, 10); - root.add(new WText(new LiteralText("Y")), 5, 96, 26, 10); - root.add(new WText(new LiteralText("Z")), 5, 126, 26, 10); - - root.add(rotX, 55, 65, 90, 10); - root.add(rotY, 55, 95, 90, 10); - root.add(rotZ, 55, 125, 90, 10); - root.add(disX, 20, 60, 26, 10); - root.add(disY, 20, 90, 26, 10); - root.add(disZ, 20, 120, 26, 10); - - root.add(scale, 21, 160, 125, 40); - - switch(state){ - case(0): label = I18n.translate("label.lookingglass.glass.image", label); break; - case(1): label = I18n.translate("label.lookingglass.glass.item", label); break; - case(2): label = I18n.translate("label.lookingglass.glass.sign");; break; - case(3): label = I18n.translate("label.lookingglass.glass.mob");; break; - case(4): label = I18n.translate("label.lookingglass.glass.player"); break; - } - - if(state == 1 || state >= 3) - root.add(new WItemSlot(blockInventory, 0, 1, 1, true), 70, 27); - - - if(world.isClient) { - WDynamicLabel stateLabel = new WDynamicLabel(() -> label); - stateLabel.setSize(100, 20); - stateLabel.setAlignment(HorizontalAlignment.CENTER); - - root.add(stateLabel, 72, 10); - if (state == 0) { - url.setSuggestion("URL"); - url.setSize(160, 5); - url.setText(delegate.getString(1)); - root.add(url, 2, 23, 160, 5); - } - - if(state == 2){ - sign.setSuggestion(I18n.translate("label.lookingglass.glass.signsug")); - sign.setSize(160, 5); - sign.setText(delegate.getString(0)); - color.setSuggestion(I18n.translate("label.lookingglass.glass.colorsug")); - root.add(sign, 2, 23, 160, 5); - root.add(color, 53, 150, 60, 5); - } - } - root.validate(this); - } - - @Override - public void close(PlayerEntity player) { - - if(!world.isClient()) - super.close(player); - - delegate.setDouble(1, rotX.getValue()); - delegate.setDouble(2, rotY.getValue()); - delegate.setDouble(3, rotZ.getValue()); - try{ - delegate.setDouble(4, Double.parseDouble(disX.getText())); - delegate.setDouble(5, Double.parseDouble(disY.getText())); - delegate.setDouble(6, Double.parseDouble(disZ.getText())); - } catch (NumberFormatException e){ - MinecraftClient.getInstance().player.sendSystemMessage(new TranslatableText("label.lookingglass.wrong"), null); - } - delegate.setDouble(7, scale.getValue() / 10.0); - - if(state == 0) - delegate.setString(1, url.getText()); - - else if(state == 2) { - delegate.setString(0, sign.getText()); - delegate.setString(2, color.getText()); - } - - super.close(player); - } - -} +//import azzy.fabric.lookingglass.blockentity.ProjectorEntity; +//import io.github.cottonmc.cotton.gui.SyncedGuiDescription; +//import io.github.cottonmc.cotton.gui.widget.*; +//import io.github.cottonmc.cotton.gui.widget.data.Axis; +//import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; +//import net.minecraft.client.MinecraftClient; +//import net.minecraft.client.resource.language.I18n; +//import net.minecraft.entity.player.PlayerEntity; +//import net.minecraft.entity.player.PlayerInventory; +//import net.minecraft.screen.ScreenHandlerContext; +//import net.minecraft.screen.ScreenHandlerType; +//import net.minecraft.text.LiteralText; +//import net.minecraft.text.TranslatableText; +//import net.minecraft.util.math.BlockPos; +// +// +//public class ProjectorGuiDescription extends SyncedGuiDescription { +// +// private final WPlainPanel root = new WPlainPanel(); +// private final WTextField url = new WTextField().setMaxLength(512); +// private final WTextField disX = new WTextField().setMaxLength(4); +// private final WTextField disY = new WTextField().setMaxLength(4); +// private final WTextField disZ = new WTextField().setMaxLength(4); +// private final WTextField sign = new WTextField().setMaxLength(2048); +// private final WTextField color = new WTextField().setMaxLength(32); +// private final WSlider rotX = new WSlider(0, 360, Axis.HORIZONTAL); +// private final WSlider rotY = new WSlider(0, 360, Axis.HORIZONTAL); +// private final WSlider rotZ = new WSlider(0, 360, Axis.HORIZONTAL); +// private final WSlider scale = new WSlider(16, 320, Axis.HORIZONTAL); +// +// private int state; +// private String label; +// +// public ProjectorGuiDescription(ScreenHandlerType recipeType, int syncId, PlayerInventory playerInventory, ScreenHandlerContext context) { +// super(recipeType, syncId, playerInventory, getBlockInventory(context), getBlockPropertyDelegate(context)); +// +// state = delegate.get(0); +// +// root.setSize(162, 200); +// setRootPanel(root); +// root.add(this.createPlayerInventoryPanel(), 1, 212); +// +// +// +// disX.setText(String.valueOf(delegate.getDouble(6))); +// disY.setText(String.valueOf(delegate.getDouble(7))); +// disZ.setText(String.valueOf(delegate.getDouble(8))); +// sign.setText(delegate.getString(0)); +// color.setText(delegate.getString(2)); +// rotX.setValue((int) delegate.getDouble(3)); +// rotY.setValue((int) delegate.getDouble(4)); +// rotZ.setValue((int) delegate.getDouble(5)); +// scale.setValue((int) (delegate.getDouble(9) * 10)); +// +// root.add(new WText(new LiteralText("X")), 5, 66, 26, 10); +// root.add(new WText(new LiteralText("Y")), 5, 96, 26, 10); +// root.add(new WText(new LiteralText("Z")), 5, 126, 26, 10); +// +// root.add(rotX, 55, 65, 90, 10); +// root.add(rotY, 55, 95, 90, 10); +// root.add(rotZ, 55, 125, 90, 10); +// root.add(disX, 20, 60, 26, 10); +// root.add(disY, 20, 90, 26, 10); +// root.add(disZ, 20, 120, 26, 10); +// +// root.add(scale, 21, 160, 125, 40); +// +// if(state == 1 || state >= 3) +// root.add(new WItemSlot(blockInventory, 0, 1, 1, true), 70, 27); +// +// +// if(world.isClient) { +// switch(state){ +// case(0): label = "label.lookingglass.glass.image"; break; +// case(1): label = "label.lookingglass.glass.item"; break; +// case(2): label = "label.lookingglass.glass.sign"; break; +// case(3): label = "label.lookingglass.glass.mob"; break; +// case(4): label = "label.lookingglass.glass.player"; break; +// } +// +// WDynamicLabel stateLabel = new WDynamicLabel(() -> label); +// stateLabel.setSize(100, 20); +// stateLabel.setAlignment(HorizontalAlignment.CENTER); +// +// root.add(stateLabel, 72, 10); +// if (state == 0) { +// url.setSuggestion("URL"); +// url.setSize(160, 5); +// url.setText(delegate.getString(1)); +// root.add(url, 2, 23, 160, 5); +// } +// +// if(state == 2){ +// sign.setSuggestion(I18n.translate("label.lookingglass.glass.signsug")); +// sign.setSize(160, 5); +// sign.setText(delegate.getString(0)); +// color.setSuggestion(I18n.translate("label.lookingglass.glass.colorsug")); +// root.add(sign, 2, 23, 160, 5); +// root.add(color, 53, 150, 60, 5); +// } +// } +// root.validate(this); +// } +// +// @Override +// public void close(PlayerEntity player) { +// +// if(!world.isClient()) +// super.close(player); +// +// delegate.setDouble(1, rotX.getValue()); +// delegate.setDouble(2, rotY.getValue()); +// delegate.setDouble(3, rotZ.getValue()); +// try{ +// delegate.setDouble(4, Double.parseDouble(disX.getText())); +// delegate.setDouble(5, Double.parseDouble(disY.getText())); +// delegate.setDouble(6, Double.parseDouble(disZ.getText())); +// } catch (NumberFormatException e){ +// MinecraftClient.getInstance().player.sendSystemMessage(new TranslatableText("label.lookingglass.wrong"), null); +// } +// delegate.setDouble(7, scale.getValue() / 10.0); +// +// if(state == 0) +// delegate.setString(1, url.getText()); +// +// else if(state == 2) { +// delegate.setString(0, sign.getText()); +// delegate.setString(2, color.getText()); +// } +// +// super.close(player); +// } +// +//} diff --git a/src/main/java/azzy/fabric/lookingglass/gui/ProjectorScreen.java b/src/main/java/azzy/fabric/lookingglass/gui/ProjectorScreen.java index 0d7ca16..911f152 100644 --- a/src/main/java/azzy/fabric/lookingglass/gui/ProjectorScreen.java +++ b/src/main/java/azzy/fabric/lookingglass/gui/ProjectorScreen.java @@ -1,14 +1,14 @@ package azzy.fabric.lookingglass.gui; -import io.github.cottonmc.cotton.gui.client.CottonInventoryScreen; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.text.Text; - - -public class ProjectorScreen extends CottonInventoryScreen { - - public ProjectorScreen(ProjectorGuiDescription container, PlayerEntity player) { - super(container, player); - } - -} +//import io.github.cottonmc.cotton.gui.client.CottonInventoryScreen; +//import net.minecraft.entity.player.PlayerEntity; +//import net.minecraft.text.Text; +// +// +//public class ProjectorScreen extends CottonInventoryScreen { +// +// public ProjectorScreen(ProjectorGuiDescription container, PlayerEntity player) { +// super(container, player); +// } +// +//} diff --git a/src/main/java/azzy/fabric/lookingglass/gui/screenhandler/PosCarryingScreenHandler.java b/src/main/java/azzy/fabric/lookingglass/gui/screenhandler/PosCarryingScreenHandler.java new file mode 100644 index 0000000..1b3977d --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/gui/screenhandler/PosCarryingScreenHandler.java @@ -0,0 +1,37 @@ +package azzy.fabric.lookingglass.gui.screenhandler; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.SimpleInventory; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +public class PosCarryingScreenHandler extends ScreenHandler { + + private BlockPos pos; + private final Inventory inventory; + + protected PosCarryingScreenHandler(@Nullable ScreenHandlerType type, int syncId, PacketByteBuf buf) { + this(type, syncId, new SimpleInventory(1)); + pos = buf.readBlockPos(); + } + + protected PosCarryingScreenHandler(@Nullable ScreenHandlerType type, int syncId, Inventory inventory) { + super(type, syncId); + this.inventory = inventory; + + pos = BlockPos.ORIGIN; + } + + public BlockPos getPos() { + return pos; + } + + @Override + public boolean canUse(PlayerEntity player) { + return inventory.canPlayerUse(player); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/item/TTLGItems.java b/src/main/java/azzy/fabric/lookingglass/item/TTLGItems.java index 82f6148..057fec2 100644 --- a/src/main/java/azzy/fabric/lookingglass/item/TTLGItems.java +++ b/src/main/java/azzy/fabric/lookingglass/item/TTLGItems.java @@ -1,18 +1,10 @@ package azzy.fabric.lookingglass.item; -import azzy.fabric.lookingglass.block.NebulousSaltBlock; -import azzy.fabric.lookingglass.block.TTLGBlocks; import net.fabricmc.fabric.api.item.v1.FabricItemSettings; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.block.Block; -import net.minecraft.block.Material; -import net.minecraft.block.MaterialColor; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; -import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; import net.minecraft.util.registry.Registry; @@ -34,7 +26,7 @@ private static FabricItemSettings defaultSettings() { } private static FabricItemSettings eldenmetalSettings() { - return new FabricItemSettings().group(LOOKINGGLASS_ITEMS).fireproof().rarity(NULL_RARITY); + return new FabricItemSettings().group(LOOKINGGLASS_ITEMS).fireproof().rarity(ELDENMETAL_RARITY); } //Tools diff --git a/src/main/java/azzy/fabric/lookingglass/render/ProjectorRenderer.java b/src/main/java/azzy/fabric/lookingglass/render/ProjectorRenderer.java index 1094ac2..e520319 100644 --- a/src/main/java/azzy/fabric/lookingglass/render/ProjectorRenderer.java +++ b/src/main/java/azzy/fabric/lookingglass/render/ProjectorRenderer.java @@ -140,7 +140,7 @@ else if(blockEntity.displayState == 1 && !item.isEmpty()){ if(item.getItem() instanceof BlockItem) { BlockState state = ((BlockItem) item.getItem()).getBlock().getDefaultState(); BlockRenderManager manager = MinecraftClient.getInstance().getBlockRenderManager(); - manager.getModelRenderer().render(blockEntity.getWorld(), manager.getModel(state), state, blockEntity.getPos().up(), matrices, vertexConsumers.getBuffer(RenderLayers.getMovingBlockLayer(state)), true, new Random(), state.getRenderingSeed(blockEntity.getPos()), OverlayTexture.DEFAULT_UV); + manager.getModelRenderer().render(blockEntity.getWorld(), manager.getModel(state), state, blockEntity.getPos().up(), matrices, vertexConsumers.getBuffer(RenderLayers.getMovingBlockLayer(state)), false, new Random(), state.getRenderingSeed(blockEntity.getPos()), OverlayTexture.DEFAULT_UV); } else { MinecraftClient.getInstance().getItemRenderer().renderItem(item, ModelTransformation.Mode.NONE, LookingGlassClient.LIGHTMAP_MAX_LUMINANCE, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers); diff --git a/src/main/java/azzy/fabric/lookingglass/util/ClientNetworkingUtils.java b/src/main/java/azzy/fabric/lookingglass/util/ClientNetworkingUtils.java new file mode 100644 index 0000000..2b5a8f1 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/ClientNetworkingUtils.java @@ -0,0 +1,24 @@ +package azzy.fabric.lookingglass.util; + +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; + +public class ClientNetworkingUtils { + + public static void init() { + + ClientPlayNetworking.registerGlobalReceiver(GeneralNetworking.TRANSLATEABLE_PACKET, ((minecraftClient, clientPlayNetworkHandler, packetByteBuf, packetSender) -> { + + String translationKey = packetByteBuf.readString(); + + minecraftClient.execute(() -> { + Text text = new TranslatableText(translationKey); + MinecraftClient.getInstance().player.sendMessage(text, true); + }); + })); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/util/ExtendedPropertyDelegate.java b/src/main/java/azzy/fabric/lookingglass/util/ExtendedPropertyDelegate.java deleted file mode 100644 index 7dd63d1..0000000 --- a/src/main/java/azzy/fabric/lookingglass/util/ExtendedPropertyDelegate.java +++ /dev/null @@ -1,13 +0,0 @@ -package azzy.fabric.lookingglass.util; - -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.util.math.BlockPos; - -public interface ExtendedPropertyDelegate extends PropertyDelegate { - String getString(int index); - void setString(int index, String value); - double getDouble(int index); - void setDouble(int index, double value); - BlockPos getPos(); -} diff --git a/src/main/java/azzy/fabric/lookingglass/util/GeneralNetworking.java b/src/main/java/azzy/fabric/lookingglass/util/GeneralNetworking.java new file mode 100644 index 0000000..2aa2398 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/GeneralNetworking.java @@ -0,0 +1,53 @@ +package azzy.fabric.lookingglass.util; + +import azzy.fabric.lookingglass.blockentity.ProjectorEntity; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; + +import static azzy.fabric.lookingglass.LookingGlassCommon.MODID; + +public class GeneralNetworking { + + public static final Identifier TRANSLATEABLE_PACKET = new Identifier(MODID, "p_translateable"); + public static final Identifier PROJECTOR_SYNC_PACKET = new Identifier(MODID, "p_general"); + + public static void init() { + ServerPlayNetworking.registerGlobalReceiver(PROJECTOR_SYNC_PACKET, ((minecraftServer, serverPlayerEntity, serverPlayNetworkHandler, packet, packetSender) -> { + BlockPos pos = packet.readBlockPos(); + + double rotX = packet.readDouble(); + double rotY = packet.readDouble(); + double rotZ = packet.readDouble(); + double disX = packet.readDouble(); + double disY = packet.readDouble(); + double disZ = packet.readDouble(); + double scale = packet.readDouble(); + String url = packet.readString(2048); + String sign = packet.readString(2048); + String color = packet.readString(256); + + minecraftServer.execute(() -> { + ServerWorld world = (ServerWorld) serverPlayerEntity.world; + BlockEntity entity = world.getBlockEntity(pos); + if(entity instanceof ProjectorEntity) { + ProjectorEntity projector = (ProjectorEntity) entity; + projector.rotX = rotX; + projector.rotY = rotY; + projector.rotZ = rotZ; + projector.disX = disX; + projector.disY = disY; + projector.disZ = disZ; + projector.scale =scale; + projector.url = url; + projector.sign = sign ; + projector.color =color; + projector.sync(); + } + }); + })); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/util/Syncable.java b/src/main/java/azzy/fabric/lookingglass/util/Syncable.java new file mode 100644 index 0000000..9c5f4a5 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/Syncable.java @@ -0,0 +1,8 @@ +package azzy.fabric.lookingglass.util; + +import net.minecraft.network.PacketByteBuf; + +public interface Syncable { + + void sync(PacketByteBuf packet); +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 133d689..5ed3cca 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "lookingglass", - "version": "2.0.0-alpha.1", + "version": "2.0.0-alpha.3", "name": "Through the Looking Glass", "description": "Not a mod about glass working",