Skip to content

Commit

Permalink
complete rewrite of how dmx & artnet work
Browse files Browse the repository at this point in the history
RDM over artnet, now supported!
  • Loading branch information
Rushmead committed May 27, 2024
1 parent 799b052 commit efbc9b0
Show file tree
Hide file tree
Showing 51 changed files with 2,033 additions and 163 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ allprojects {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
}
maven {
name = 'Rushmead'
url = 'https://mvn.imabad.dev/repository/maven-releases/'
}
mavenCentral()
mavenLocal()
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2023-12-11T00:30:48.3049893 Languages: en_us
dba74bb7077ce77df26626ba0432be702cf27329 assets/theatrical/lang/en_us.json
// 1.20.2 2024-05-27T10:52:44.9149037 Languages: en_us
008623f80efad0b7b210bfcdcd1374bc1dd74f63 assets/theatrical/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"block.theatrical.redstone_interface": "Redstone Interface",
"block.theatrical.tank_trap": "Tank Trap",
"block.theatrical.truss": "MT100 Truss",
"button.artnetconfig": "ArtNet Config",
"fixture.dmxStart": "DMX Address",
"fixture.pan": "Pan",
"fixture.tilt": "Tilt",
"itemGroup.theatrical": "Theatrical",
"screen.artnetconfig.enabled": "ArtNet Enabled: %s",
"screen.movinglight": "Moving Light"
}
5 changes: 5 additions & 0 deletions common/src/main/java/dev/imabad/theatrical/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.imabad.theatrical;

public class Constants {
public static final short MANUFACTURER_ID = 0x7FF0;
}
28 changes: 25 additions & 3 deletions common/src/main/java/dev/imabad/theatrical/Theatrical.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.imabad.theatrical;

import dev.architectury.event.events.common.PlayerEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredRegister;
Expand All @@ -8,8 +9,11 @@
import dev.imabad.theatrical.blocks.Blocks;
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.fixtures.Fixtures;
import dev.imabad.theatrical.items.Items;
import dev.imabad.theatrical.net.artnet.ListConsumers;
import dev.imabad.theatrical.net.TheatricalNet;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
Expand All @@ -18,6 +22,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class Theatrical {
public static final String MOD_ID = "theatrical";
// Registering a new creative tab
Expand All @@ -34,15 +41,30 @@ public class Theatrical {
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static void init() {
ConfigHandler configHandler = new ConfigHandler(Platform.getConfigFolder());
ConfigHandler configHandler = ConfigHandler.initialize(Platform.getConfigFolder());
TheatricalConfig.INSTANCE.register(configHandler);
TABS.register();
Fixtures.init();
TheatricalNet.init();
Blocks.BLOCKS.register();
BlockEntities.BLOCK_ENTITIES.register();
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);
}
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);
}
});
PlayerEvent.PLAYER_QUIT.register((event) -> {
DMXNetworkData.getInstance().removeKnownSender(event.connection.player);
});
}


}
46 changes: 45 additions & 1 deletion common/src/main/java/dev/imabad/theatrical/TheatricalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry;
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.blockentities.FresnelRenderer;
import dev.imabad.theatrical.client.blockentities.LEDPanelRenderer;
import dev.imabad.theatrical.client.blockentities.MovingLightRenderer;
import dev.imabad.theatrical.fixtures.Fixtures;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.dmx.DMXDevice;
import dev.imabad.theatrical.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 net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -43,6 +48,14 @@ public static void init() {
BlockEntityRendererRegistry.register(BlockEntities.LED_PANEL.get(), LEDPanelRenderer::new);
// BlockEntityRendererRegistry.register(BlockEntities.CABLE.get(), CableRenderer::new);
artNetManager = new ArtNetManager();
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register((event) -> {
if(TheatricalConfig.INSTANCE.CLIENT.artnetEnabled){
artNetManager.getClient();
}
});
ClientPlayerEvent.CLIENT_PLAYER_QUIT.register((event) -> {
onWorldClose();
});
}

public static ArtNetManager getArtNetManager(){
Expand All @@ -61,6 +74,10 @@ public static float[] renderThings(BlockPos MY_BLOCK, VertexConsumer consumer, P
return new float[]{be.getTilt(), be.getPan()};
}

public static void onWorldClose(){
artNetManager.shutdownAll();
}

public static void renderWorldLastAfterTripwire(LevelRenderer levelRenderer){
LightManager.updateAll(levelRenderer);
}
Expand Down Expand Up @@ -128,4 +145,31 @@ public static byte[] UUID2Bytes(UUID uuid) {
long lo = uuid.getLeastSignificantBits();
return ByteBuffer.allocate(16).putLong(hi).putLong(lo).array();
}

public static void handleConsumerChange(NotifyConsumerChange notifyConsumerChange){
if(TheatricalConfig.INSTANCE.CLIENT.artnetEnabled){
TheatricalArtNetClient artNetClient = getArtNetManager().getClient();
if(artNetClient.isSubscribedTo(notifyConsumerChange.getUniverse())){
DMXDevice dmxDevice = notifyConsumerChange.getDmxDevice();
if(notifyConsumerChange.getChangeType() == NotifyConsumerChange.ChangeType.ADD){
artNetClient.addDevice(notifyConsumerChange.getUniverse(), dmxDevice.getDeviceId(), dmxDevice);
} else if(notifyConsumerChange.getChangeType() == NotifyConsumerChange.ChangeType.UPDATE) {
artNetClient.updateDevice(notifyConsumerChange.getUniverse(), dmxDevice.getDeviceId(), dmxDevice);
} else {
artNetClient.removeDevice(notifyConsumerChange.getUniverse(), dmxDevice.getDeviceId());
}
}
}
}

public static void handleListConsumers(ListConsumers listConsumers){
if(TheatricalConfig.INSTANCE.CLIENT.artnetEnabled) {
TheatricalArtNetClient artNetClient = getArtNetManager().getClient();
if (artNetClient.isSubscribedTo(listConsumers.getUniverse())) {
for (DMXDevice dmxDevice : listConsumers.getDmxDevices()) {
artNetClient.addDevice(listConsumers.getUniverse(), dmxDevice.getDeviceId(), dmxDevice);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ public static Path getConfigDirectory() {
public static BakedModel getBakedModel(ResourceLocation modelLocation){
throw new AssertionError();
}
@ExpectPlatform
public static String getModVersion() {
throw new AssertionError();
}

}
4 changes: 4 additions & 0 deletions common/src/main/java/dev/imabad/theatrical/api/Fixture.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package dev.imabad.theatrical.api;

import dev.imabad.theatrical.api.dmx.DMXPersonality;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;

import java.util.List;

public abstract class Fixture {
public abstract ResourceLocation getTiltModel();

Expand Down Expand Up @@ -36,4 +39,5 @@ public boolean hasBeam(){
return true;
}
public abstract float[] getTransforms(BlockState fixtureBlockState, BlockState supportBlockState);
public abstract List<DMXPersonality> getDMXPersonalities();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package dev.imabad.theatrical.api.dmx;

import ch.bildspur.artnet.rdm.RDMDeviceId;
import net.minecraft.resources.ResourceLocation;

public interface DMXConsumer {

int getChannelCount();

int getChannelStart();

int getUniverse();

void consume(byte[] dmxValues);

RDMDeviceId getDeviceId();

int getDeviceTypeId();

String getModelName();

ResourceLocation getFixtureId();

int getActivePersonality();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.imabad.theatrical.api.dmx;

import java.util.ArrayList;
import java.util.List;

public class DMXPersonality {
private final int channelCount;
private final String description;
private final List<DMXSlot> slots;

public DMXPersonality(int channelCount, String description){
this.channelCount = channelCount;
this.description = description;
this.slots = new ArrayList<>();
}

public DMXPersonality addSlot(DMXSlot slot){
slots.add(slot);
return this;
}

public DMXPersonality addSlot(int position, DMXSlot slot){
slots.add(position, slot);
return this;
}

public int getChannelCount() {
return channelCount;
}

public String getDescription() {
return description;
}

public List<DMXSlot> getSlots() {
return slots;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.imabad.theatrical.api.dmx;

import ch.bildspur.artnet.rdm.RDMSlotID;
import ch.bildspur.artnet.rdm.RDMSlotType;

public record DMXSlot(String label, RDMSlotType slotType, RDMSlotID slotID) {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package dev.imabad.theatrical.blockentities.interfaces;

import dev.imabad.theatrical.TheatricalClient;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.ClientSyncBlockEntity;
import dev.imabad.theatrical.config.TheatricalConfig;
import dev.imabad.theatrical.dmx.DMXNetworkData;
import dev.imabad.theatrical.net.SendArtNetData;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -19,12 +17,16 @@
public class ArtNetInterfaceBlockEntity extends ClientSyncBlockEntity {
public static <T extends BlockEntity> void tick(Level level, BlockPos pos, BlockState state, T be) {
ArtNetInterfaceBlockEntity tile = (ArtNetInterfaceBlockEntity) be;
if(level.isClientSide){
if(tile.isOwnedByCurrentClient()){
byte[] data = TheatricalClient.getArtNetManager().getClient(tile.ip).readDmxData(tile.subnet, tile.universe);
new SendArtNetData(pos, data).sendToServer();
}
}
// if(level.isClientSide){
// if(tile.isOwnedByCurrentClient()){
// TheatricalArtNetClient client = TheatricalClient.getArtNetManager().getClient(tile.ip);
// if(!client.isSubscribedTo(tile.universe)){
// client.subscribeToUniverse(tile.universe);
// }
// byte[] data = client.readDmxData(tile.subnet, tile.universe);
// new SendArtNetData(pos, data).sendToServer();
// }
// }
}

private int subnet, universe, tickTimer = 0;
Expand All @@ -40,22 +42,26 @@ public void write(CompoundTag compoundTag) {
compoundTag.putString("ip", ip);
compoundTag.putInt("subnet", subnet);
compoundTag.putInt("universe", universe);
compoundTag.putUUID("ownerUUID", ownerUUID);
if(ownerUUID != null) {
compoundTag.putUUID("ownerUUID", ownerUUID);
}
}

@Override
public void read(CompoundTag compoundTag) {
this.ip = compoundTag.getString("ip");
this.subnet = compoundTag.getInt("subnet");
this.universe = compoundTag.getInt("universe");
this.ownerUUID = compoundTag.getUUID("ownerUUID");
if(compoundTag.contains("ownerUUID")) {
this.ownerUUID = compoundTag.getUUID("ownerUUID");
}
}

public void update(byte[] data) {
if(level != null && level.getServer() != null) {
var dmxData = DMXNetworkData.getInstance();
if(dmxData != null) {
dmxData.getConsumersInRange(getBlockPos(), TheatricalConfig.INSTANCE.COMMON.wirelessDMXRadius).forEach(dmxConsumer -> dmxConsumer.consume(data));
dmxData.getConsumersInRange(universe, getBlockPos(), TheatricalConfig.INSTANCE.COMMON.wirelessDMXRadius).forEach(dmxConsumer -> dmxConsumer.consume(data));
}
}
}
Expand All @@ -71,16 +77,16 @@ public boolean isOwnedByCurrentClient(){
}

public boolean hasReceivedPacket(){
if(level != null && level.isClientSide){
return TheatricalClient.getArtNetManager().getClient(this.ip).hasReceivedPacket();
}
// if(level != null && level.isClientSide){
// return TheatricalClient.getArtNetManager().getClient(this.ip).hasReceivedPacket();
// }
return false;
}

public long getLastReceivedPacket(){
if(level != null && level.isClientSide){
return TheatricalClient.getArtNetManager().getClient(this.ip).getLastPacketMS();
}
// if(level != null && level.isClientSide){
// return TheatricalClient.getArtNetManager().getClient(this.ip).getLastPacketMS();
// }
return 0;
}

Expand Down
Loading

0 comments on commit efbc9b0

Please sign in to comment.