Skip to content

Commit

Permalink
Merge pull request #9 from theatricalmod/feat/networks
Browse files Browse the repository at this point in the history
Feature: Networks
  • Loading branch information
Rushmead authored Jul 30, 2024
2 parents 24358b7 + 00085fa commit 601749a
Show file tree
Hide file tree
Showing 67 changed files with 2,450 additions and 370 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1.20.2 2024-07-20T12:53:36.9724263 Item Models: theatrical
// 1.20.2 2024-07-30T19:12:09.649396 Item Models: theatrical
b61dea162dac1064778fccd83e00b34aeea3d2b7 assets/theatrical/models/item/artnet_interface.json
b8f0135bf11be0f31f5d16d76a8c50f28900ee04 assets/theatrical/models/item/basic_lighting_desk.json
545f9e738bfe2c1e7b2236f46042b2504b81373b assets/theatrical/models/item/configuration_card.json
0dc3e30a7627a40ada8a4b8e20249c809067a337 assets/theatrical/models/item/led_fresnel.json
81307d2abd44e288e5e8c9b7824de5a0e895e0be assets/theatrical/models/item/led_panel.json
e6b312509e9a1cfcd5730624d5cbd9f04781d7f7 assets/theatrical/models/item/moving_light.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2024-07-20T12:53:36.9764242 Languages: en_us
e3979f69d6f26453fdf1227dc1d640cc4143c3ff assets/theatrical/lang/en_us.json
// 1.20.2 2024-07-30T20:12:14.177896 Languages: en_us
dd27ac82d3d3f2c79ab7c9dcfc8cbd0ad314670e assets/theatrical/lang/en_us.json
19 changes: 19 additions & 0 deletions common/src/generated/resources/assets/theatrical/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@
"block.theatrical.redstone_interface": "Redstone Interface",
"block.theatrical.tank_trap": "Tank Trap",
"block.theatrical.truss": "MT100 Truss",
"button.artnetconfig": "ArtNet Config",
"commands.network": "%s (%s) has %s member(s)",
"commands.network.created": "Network created",
"commands.network.deleted": "Network deleted",
"commands.network.invalid": "Unknown network mode: %s",
"commands.network.members": "There are %s network member(s): %s.",
"commands.network.members.add.failed": "Player already member of network.",
"commands.network.members.add.success": "Added %s to the network.",
"commands.network.members.remove.success": "Removed %s from the network.",
"commands.network.notfound": "Network not found.",
"commands.network.role.invalid": "Unknown member role: %s",
"commands.network.updated": "Network updated",
"commands.networks": "There are %s network(s): %s.",
"fixture.dmxStart": "DMX Address",
"fixture.pan": "Pan",
"fixture.tilt": "Tilt",
"item.configurationcard.success": "Configured device to %s network, %s universe, %s address - next address is %s.",
"item.theatrical.configuration_card": "Configuration Card",
"itemGroup.theatrical": "Theatrical",
"screen.artnetconfig.enabled": "ArtNet Enabled: %s",
"screen.artnetconfig.network": "Network",
"screen.configurationcard": "Configuration Card",
"screen.configurationcard.autoincrement": "Address Auto Increment",
"screen.movinglight": "Moving Light",
"ui.control.cue": "Cue - %s",
"ui.control.cues": "Cues",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "theatrical:item/configuration_card"
}
}
55 changes: 41 additions & 14 deletions common/src/main/java/dev/imabad/theatrical/Theatrical.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
package dev.imabad.theatrical;

import dev.architectury.event.events.common.CommandRegistrationEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.event.events.common.PlayerEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrySupplier;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blocks.Blocks;
import dev.imabad.theatrical.commands.CommandArguments;
import dev.imabad.theatrical.commands.DMXNetworkModeArgument;
import dev.imabad.theatrical.commands.MemberRoleArgument;
import dev.imabad.theatrical.commands.NetworkCommand;
import dev.imabad.theatrical.config.ConfigHandler;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.dmx.DMXDevice;
import dev.imabad.theatrical.dmx.DMXNetworkData;
import dev.imabad.theatrical.dmx.*;
import dev.imabad.theatrical.fixtures.Fixtures;
import dev.imabad.theatrical.items.Items;
import dev.imabad.theatrical.mixin.ArgumentTypeInfosAccessor;
import dev.imabad.theatrical.net.artnet.ListConsumers;
import dev.imabad.theatrical.net.TheatricalNet;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -48,23 +59,39 @@ public static void init() {
TheatricalNet.init();
Blocks.BLOCKS.register();
BlockEntities.BLOCK_ENTITIES.register();

DeferredRegister<ArgumentTypeInfo<?, ?>> argTypes = TheatricalRegistry.get(Registries.COMMAND_ARGUMENT_TYPE);
registerArgument(argTypes, SingletonArgumentInfo.contextFree(DMXNetworkModeArgument::networkMode), "network_mode", DMXNetworkModeArgument.class);
registerArgument(argTypes, SingletonArgumentInfo.contextFree(MemberRoleArgument::memberRole), "member_role", MemberRoleArgument.class);

dev.imabad.theatrical.items.Items.ITEMS.register();
PlayerEvent.PLAYER_JOIN.register((event) -> {
if(event.connection.player.hasPermissions(event.getServer().getOperatorUserPermissionLevel())){
DMXNetworkData.getInstance().addKnownSender(event.connection.player);
DMXNetworkData instance = DMXNetworkData.getInstance(event.server.overworld());
for (DMXNetwork network : instance.getNetworksForPlayer(event.connection.player.getUUID())) {
for (Integer universe : network.getUniverses()) {
List<DMXDevice> devices = new ArrayList<>();
network.getConsumers(universe).forEach(consumer -> {
devices.add(new DMXDevice(consumer.getDeviceId(), consumer.getChannelStart(),
consumer.getChannelCount(), consumer.getDeviceTypeId(), consumer.getActivePersonality(), consumer.getModelName(),
consumer.getFixtureId()));
});
new ListConsumers(universe, devices).sendTo(event.connection.player);
}
}
for (Integer universe : DMXNetworkData.getInstance().getUniverses()) {
List<DMXDevice> devices = new ArrayList<>();
DMXNetworkData.getInstance().getConsumers(universe).forEach(consumer -> {
devices.add(new DMXDevice(consumer.getDeviceId(), consumer.getChannelStart(),
consumer.getChannelCount(), consumer.getDeviceTypeId(), consumer.getActivePersonality(), consumer.getModelName(),
consumer.getFixtureId()));
});
new ListConsumers(universe, devices).sendTo(event.connection.player);
});
LifecycleEvent.SERVER_LEVEL_UNLOAD.register(world -> {
if(world.dimension().equals(Level.OVERWORLD)){
DMXNetworkData.unloadLevel();
}
});
PlayerEvent.PLAYER_QUIT.register((event) -> {
DMXNetworkData.getInstance().removeKnownSender(event.connection.player);
CommandRegistrationEvent.EVENT.register((dispatcher, registry, selection) -> {
NetworkCommand.register(dispatcher);
});
}

private static void registerArgument(DeferredRegister<ArgumentTypeInfo<?, ?>> argTypes,
ArgumentTypeInfo<?, ?> serializer, String id, Class<?> clazz) {
argTypes.register(new ResourceLocation(Theatrical.MOD_ID, id), () -> serializer);
ArgumentTypeInfosAccessor.classMap().put(clazz, serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
import com.mojang.math.Axis;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry;
import dev.architectury.registry.client.rendering.RenderTypeRegistry;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.client.LazyRenderers;
import dev.imabad.theatrical.client.blockentities.BasicLightingConsoleRenderer;
import dev.imabad.theatrical.client.blockentities.FresnelRenderer;
import dev.imabad.theatrical.client.blockentities.LEDPanelRenderer;
import dev.imabad.theatrical.client.blockentities.MovingLightRenderer;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.dmx.DMXDevice;
import dev.imabad.theatrical.dmx.TheatricalArtNetClient;
import dev.imabad.theatrical.client.dmx.TheatricalArtNetClient;
import dev.imabad.theatrical.lighting.LightManager;
import dev.imabad.theatrical.net.artnet.ListConsumers;
import dev.imabad.theatrical.net.artnet.NotifyConsumerChange;
import dev.imabad.theatrical.protocols.artnet.ArtNetManager;
import dev.imabad.theatrical.client.dmx.ArtNetManager;
import dev.imabad.theatrical.net.artnet.RequestNetworks;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
Expand Down Expand Up @@ -52,6 +53,7 @@ public static void init() {
// BlockEntityRendererRegistry.register(BlockEntities.CABLE.get(), CableRenderer::new);
artNetManager = new ArtNetManager();
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register((event) -> {
new RequestNetworks().sendToServer();
if(TheatricalConfig.INSTANCE.CLIENT.artnetEnabled){
artNetManager.getClient();
}
Expand Down Expand Up @@ -87,6 +89,7 @@ public static void renderWorldLastAfterTripwire(LevelRenderer levelRenderer){

public static void renderWorldLast(PoseStack poseStack, Matrix4f projectionMatrix, Camera camera, float tickDelta){
Minecraft mc = Minecraft.getInstance();
LazyRenderers.doRender(camera,poseStack, mc.renderBuffers().bufferSource(), tickDelta);
if(mc.getDebugOverlay().showDebugScreen()){
Vec3 cameraPos = camera.getPosition();
//#region translateToCamera
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.imabad.theatrical.api.dmx;

import java.util.UUID;

public interface BelongsToNetwork {

UUID getNetworkId();

void setNetworkId(UUID newNetworkId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import ch.bildspur.artnet.rdm.RDMDeviceId;
import net.minecraft.resources.ResourceLocation;

public interface DMXConsumer {
import java.util.UUID;

public interface DMXConsumer extends BelongsToNetwork {

int getChannelCount();

Expand All @@ -23,4 +25,5 @@ public interface DMXConsumer {

int getActivePersonality();

UUID getNetworkId();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.imabad.theatrical.blockentities.control;

import dev.imabad.theatrical.api.dmx.BelongsToNetwork;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.ClientSyncBlockEntity;
import dev.imabad.theatrical.blocks.control.BasicLightingDeskBlock;
Expand All @@ -13,12 +14,9 @@
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Optional;
import java.util.*;

public class BasicLightingDeskBlockEntity extends ClientSyncBlockEntity {
public class BasicLightingDeskBlockEntity extends ClientSyncBlockEntity implements BelongsToNetwork {
public static class StoredCue {
private byte[] faders;
private int fadeInTicks;
Expand Down Expand Up @@ -75,9 +73,11 @@ public int getFadeOutTicks() {
private int fadeOutTicksRemaining = 0;
private byte[] perTickOut, perTickIn;
private boolean isFadingOut = false;

private byte grandMaster = -1;

private UUID networkId;
private int universe = 0;

public BasicLightingDeskBlockEntity(BlockPos blockPos, BlockState blockState) {
super(BlockEntities.BASIC_LIGHTING_DESK.get(), blockPos, blockState);
}
Expand Down Expand Up @@ -119,9 +119,9 @@ public void tick(){

public void update(byte[] data) {
if(level != null && level.getServer() != null) {
var dmxData = DMXNetworkData.getInstance();
var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId);
if(dmxData != null) {
dmxData.getConsumersInRange(getBlockPos(), TheatricalConfig.INSTANCE.COMMON.wirelessDMXRadius).forEach(dmxConsumer -> dmxConsumer.consume(data));
dmxData.getConsumers(universe).forEach(consumer -> consumer.consume(data));
}
}
}
Expand Down Expand Up @@ -151,6 +151,10 @@ public void write(CompoundTag compoundTag) {
compoundTag.putBoolean("isRunMode", isRunMode);
compoundTag.putInt("fadeInTicks", fadeInTicks);
compoundTag.putInt("fadeOutTicks", fadeOutTicks);
if(networkId != null){
compoundTag.putUUID("network", networkId);
}
compoundTag.putInt("universe", universe);
}

@Override
Expand Down Expand Up @@ -181,10 +185,17 @@ public void read(CompoundTag compoundTag) {
if(compoundTag.contains("fadeOutTicks")){
fadeOutTicks = compoundTag.getInt("fadeOutTicks");
}
if(compoundTag.contains("network")){
networkId = compoundTag.getUUID("network");
}
if(compoundTag.contains("universe")){
universe = compoundTag.getInt("universe");
}
}

public void setFaders(byte[] faders){
this.faders = Arrays.copyOf(faders, faders.length);
setChanged();
}

public void setFader(int fader, int value){
Expand All @@ -193,6 +204,7 @@ public void setFader(int fader, int value){
} else {
this.grandMaster = (byte) value;
}
setChanged();
}

public int getCurrentStep() {
Expand Down Expand Up @@ -345,4 +357,17 @@ public void setFadeOutTicks(int fadeOutTicks) {
this.fadeOutTicks = fadeOutTicks;
}

public UUID getNetworkId() {
return networkId;
}

@Override
public void setNetworkId(UUID newNetworkId) {
if(newNetworkId == this.networkId){
return;
}
this.networkId = newNetworkId;
setChanged();
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static <T extends BlockEntity> void tick(Level level, BlockPos pos, Block

private int subnet, universe, tickTimer = 0;
private String ip = "127.0.0.1";
private UUID ownerUUID;
private UUID networkId;

public ArtNetInterfaceBlockEntity(BlockPos blockPos, BlockState blockState) {
super(BlockEntities.ART_NET_INTERFACE.get(), blockPos, blockState);
Expand All @@ -42,8 +42,8 @@ public void write(CompoundTag compoundTag) {
compoundTag.putString("ip", ip);
compoundTag.putInt("subnet", subnet);
compoundTag.putInt("universe", universe);
if(ownerUUID != null) {
compoundTag.putUUID("ownerUUID", ownerUUID);
if(networkId != null) {
compoundTag.putUUID("networkId", networkId);
}
}

Expand All @@ -52,30 +52,19 @@ public void read(CompoundTag compoundTag) {
this.ip = compoundTag.getString("ip");
this.subnet = compoundTag.getInt("subnet");
this.universe = compoundTag.getInt("universe");
if(compoundTag.contains("ownerUUID")) {
this.ownerUUID = compoundTag.getUUID("ownerUUID");
if(compoundTag.contains("networkId")) {
this.networkId = compoundTag.getUUID("networkId");
}
}

public void update(byte[] data) {
if(level != null && level.getServer() != null) {
var dmxData = DMXNetworkData.getInstance();
var dmxData = DMXNetworkData.getInstance(level.getServer().overworld()).getNetwork(networkId);
if(dmxData != null) {
dmxData.getConsumersInRange(universe, getBlockPos(), TheatricalConfig.INSTANCE.COMMON.wirelessDMXRadius).forEach(dmxConsumer -> dmxConsumer.consume(data));
}
}
}

public boolean isOwnedByCurrentClient(){
if(!TheatricalConfig.INSTANCE.CLIENT.doOwnerCheck){
return true;
}
if(level != null && level.isClientSide){
return ownerUUID != null && ownerUUID.equals(Minecraft.getInstance().getUser().getProfileId());
}
return false;
}

public boolean hasReceivedPacket(){
// if(level != null && level.isClientSide){
// return TheatricalClient.getArtNetManager().getClient(this.ip).hasReceivedPacket();
Expand All @@ -98,9 +87,9 @@ public String getIp() {
return ip;
}

public UUID getOwnerUUID() {
return ownerUUID;
}
// public UUID getOwnerUUID() {
// return ownerUUID;
// }

public void updateConfig(String ipAddress, int dmxUniverse){
this.ip = ipAddress;
Expand All @@ -109,9 +98,9 @@ public void updateConfig(String ipAddress, int dmxUniverse){
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}

public void setOwnerUUID(UUID ownerUUID) {
this.ownerUUID = ownerUUID;
setChanged();
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
// public void setOwnerUUID(UUID ownerUUID) {
// this.ownerUUID = ownerUUID;
// setChanged();
// level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
// }
}
Loading

0 comments on commit 601749a

Please sign in to comment.