Skip to content

Commit

Permalink
Merge pull request #88 from Ultreon/XyperCode/fix-my-mess
Browse files Browse the repository at this point in the history
Fix the mess I accidentally created
  • Loading branch information
XyperCode authored Nov 26, 2023
2 parents a947512 + 7747b42 commit e32ad84
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"replace": false,
"values": [
"devices:laptop",
"devices:printer",
"devices:mac_max_x"
]
}
32 changes: 16 additions & 16 deletions common/src/main/java/com/ultreon/devices/BuiltinApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

public class BuiltinApps {
public static void registerBuiltinApps() {
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "diagnostics"), () -> DiagnosticsApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "settings"), () -> SettingsApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "file_browser"), () -> FileBrowserApp::new, true);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "gitweb"), () -> GitWebApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "note_stash"), () -> NoteStashApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "pixel_painter"), () -> PixelPainterApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "ender_mail"), () -> EmailApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "app_store"), () -> AppStore::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "diagnostics"), () -> DiagnosticsApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "settings"), () -> SettingsApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "file_browser"), () -> FileBrowserApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "gitweb"), () -> GitWebApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "note_stash"), () -> NoteStashApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "pixel_painter"), () -> PixelPainterApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "ender_mail"), () -> EmailApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "app_store"), () -> AppStore::new, true);

// if (Platform.isDevelopmentEnvironment()) {
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "bank"), () -> BankApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "boat_racers"), () -> BoatRacersApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "mine_bay"), () -> MineBayApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "snake"), () -> SnakeApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "themes"), () -> ThemesApp::new, false);
// }
if (Platform.isDevelopmentEnvironment()) {
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "bank"), () -> BankApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "boat_racers"), () -> BoatRacersApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "mine_bay"), () -> MineBayApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "snake"), () -> SnakeApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "themes"), () -> ThemesApp::new, false);
}

// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "vulnerability"), () -> VulnerabilityApp::new, true);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "vulnerability"), () -> VulnerabilityApp::new, true);
}
}
42 changes: 21 additions & 21 deletions common/src/main/java/com/ultreon/devices/Devices.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,29 @@ private void registerApplications() {
TaskManager.registerTask(TaskInstallApp::new);

// Ender Mail
// TaskManager.registerTask(TaskUpdateInbox::new);
// TaskManager.registerTask(TaskSendEmail::new);
// TaskManager.registerTask(TaskCheckEmailAccount::new);
// TaskManager.registerTask(TaskRegisterEmailAccount::new);
// TaskManager.registerTask(TaskDeleteEmail::new);
// TaskManager.registerTask(TaskViewEmail::new);
TaskManager.registerTask(TaskUpdateInbox::new);
TaskManager.registerTask(TaskSendEmail::new);
TaskManager.registerTask(TaskCheckEmailAccount::new);
TaskManager.registerTask(TaskRegisterEmailAccount::new);
TaskManager.registerTask(TaskDeleteEmail::new);
TaskManager.registerTask(TaskViewEmail::new);

// Auction
// TaskManager.registerTask(TaskAddAuction::new);
// TaskManager.registerTask(TaskGetAuctions::new);
// TaskManager.registerTask(TaskBuyItem::new);

// if (DEVELOPER_MODE) {
// // Applications (Developers)
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "example"), () -> ExampleApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "icons"), () -> IconsApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "text_area"), () -> TextAreaApp::new, false);
// ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "test"), () -> TestApp::new, false);
//
// TaskManager.registerTask(TaskNotificationTest::new);
// }
//
// EnvExecutor.runInEnv(Env.CLIENT, () -> () -> PrintingManager.registerPrint(new ResourceLocation(Reference.MOD_ID, "picture"), PixelPainterApp.PicturePrint.class));
TaskManager.registerTask(TaskAddAuction::new);
TaskManager.registerTask(TaskGetAuctions::new);
TaskManager.registerTask(TaskBuyItem::new);

if (DEVELOPER_MODE) {
// Applications (Developers)
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "example"), () -> ExampleApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "icons"), () -> IconsApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "text_area"), () -> TextAreaApp::new, false);
ApplicationManager.registerApplication(new ResourceLocation(Reference.MOD_ID, "test"), () -> TestApp::new, false);

TaskManager.registerTask(TaskNotificationTest::new);
}

EnvExecutor.runInEnv(Env.CLIENT, () -> () -> PrintingManager.registerPrint(new ResourceLocation(Reference.MOD_ID, "picture"), PixelPainterApp.PicturePrint.class));
}

public abstract int getBurnTime(ItemStack stack, RecipeType<?> type);
Expand Down
24 changes: 20 additions & 4 deletions common/src/main/java/com/ultreon/devices/core/network/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.ultreon.devices.DeviceConfig;
import com.ultreon.devices.block.entity.NetworkDeviceBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
Expand Down Expand Up @@ -80,18 +83,31 @@ public Collection<NetworkDevice> getConnectedDevices(Level level) {
return NETWORK_DEVICES.values().stream().filter(device -> device.getPos() != null).toList();
}

public Collection<NetworkDevice> getConnectedDevices(final Level level, Class<? extends NetworkDeviceBlockEntity> type) {
final Predicate<NetworkDevice> DEVICE_TYPE = networkDevice -> {
public Collection<NetworkDevice> getConnectedDevices(final Level level, BlockEntityType<?> targetType) {
final Predicate<NetworkDevice> deviceType = networkDevice -> {
if (networkDevice.getPos() == null)
return false;

BlockEntity blockEntity = level.getBlockEntity(networkDevice.getPos());
return blockEntity instanceof NetworkDeviceBlockEntity device && targetType.equals(device.getType());

};
return getConnectedDevices(level).stream().filter(deviceType).toList();
}

public Collection<NetworkDevice> getConnectedDevices(final Level level, TagKey<BlockEntityType<?>> targetType) {
final Predicate<NetworkDevice> deviceType = networkDevice -> {
if (networkDevice.getPos() == null)
return false;

BlockEntity blockEntity = level.getBlockEntity(networkDevice.getPos());

if (blockEntity instanceof NetworkDeviceBlockEntity device) {
return type.isAssignableFrom(device.getClass());
return BuiltInRegistries.BLOCK_ENTITY_TYPE.wrapAsHolder(blockEntity.getType()).is(targetType);
}
return false;
};
return getConnectedDevices(level).stream().filter(DEVICE_TYPE).toList();
return getConnectedDevices(level).stream().filter(deviceType).toList();
}

private void sendBeacon(Level level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import com.ultreon.devices.core.network.NetworkDevice;
import com.ultreon.devices.core.network.Router;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.chunk.LevelChunk;

import java.util.Collection;
Expand All @@ -19,7 +21,7 @@
*/
public class TaskGetDevices extends Task {
private BlockPos devicePos;
private Class<? extends NetworkDeviceBlockEntity> targetDeviceClass;
private BlockEntityType<?> targetType;

private Collection<NetworkDevice> foundDevices;
private String reason;
Expand All @@ -33,39 +35,45 @@ public TaskGetDevices(BlockPos devicePos) {
this.devicePos = devicePos;
}

public TaskGetDevices(BlockPos devicePos, Class<? extends NetworkDeviceBlockEntity> targetDeviceClass) {
public TaskGetDevices(BlockPos devicePos, BlockEntityType<?> targetType) {
this();
this.devicePos = devicePos;
this.targetType = targetType;
}

/**
* @deprecated Use {@link #TaskGetDevices(BlockPos, BlockEntityType)} instead.
*/
@Deprecated(forRemoval = true)
public TaskGetDevices(BlockPos devicePos, Class<? extends NetworkDeviceBlockEntity> ignoredTargetDeviceClass) {
this();
this.devicePos = devicePos;
this.targetDeviceClass = targetDeviceClass;
}

@Override
public void prepareRequest(CompoundTag tag) {
tag.putLong("devicePos", devicePos.asLong());
if (targetDeviceClass != null) {
tag.putString("targetClass", targetDeviceClass.getName());
if (targetType != null) {
tag.putInt("targetType", BuiltInRegistries.BLOCK_ENTITY_TYPE.getId(targetType));
}
}

@Override
@SuppressWarnings("unchecked")
public void processRequest(CompoundTag tag, Level level, Player player) {
BlockPos devicePos = BlockPos.of(tag.getLong("devicePos"));
Class<? extends NetworkDeviceBlockEntity> targetDeviceClass = null;
try {
Class<?> targetClass = Class.forName(tag.getString("targetClass"));
if (NetworkDeviceBlockEntity.class.isAssignableFrom(targetClass)) {
targetDeviceClass = (Class<? extends NetworkDeviceBlockEntity>) targetClass;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
BlockEntityType<?> targetType;
int typeId = tag.getInt("targetType");
if (typeId < 0) {
this.reason = "Invalid target ID received: " + typeId;
return;
}

targetType = BuiltInRegistries.BLOCK_ENTITY_TYPE.byId(typeId);

BlockEntity tileEntity = level.getChunkAt(devicePos).getBlockEntity(devicePos, LevelChunk.EntityCreationType.IMMEDIATE);

if (!(tileEntity instanceof NetworkDeviceBlockEntity tileEntityNetworkDevice)) {
this.reason = "No network driver found";
this.reason = "Not a network device";
return;
}

Expand All @@ -80,11 +88,7 @@ public void processRequest(CompoundTag tag, Level level, Player player) {
return;
}

if (targetDeviceClass != null) {
this.foundDevices = router.getConnectedDevices(level, targetDeviceClass);
} else {
this.foundDevices = router.getConnectedDevices(level);
}
this.foundDevices = targetType != null ? router.getConnectedDevices(level) : router.getConnectedDevices(level, targetType);
this.setSuccessful();
}

Expand All @@ -101,6 +105,6 @@ public void prepareResponse(CompoundTag tag) {

@Override
public void processResponse(CompoundTag tag) {

// Does not need response processing
}
}
11 changes: 10 additions & 1 deletion common/src/main/java/com/ultreon/devices/init/ModTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;

/**
* @author Qboi
* @author XyperCode
*/
public final class ModTags {
public static final class Items {
Expand All @@ -30,4 +31,12 @@ private static TagKey<Block> createTag(String name) {
return TagKey.create(Registries.BLOCK, Devices.id(name));
}
}

public static final class BlockEntityTypes {
public static final TagKey<BlockEntityType<?>> NETWORK_DEVICES = createTag("network_devices");

private static TagKey<BlockEntityType<?>> createTag(String name) {
return TagKey.create(Registries.BLOCK_ENTITY_TYPE, Devices.id(name));
}
}
}

0 comments on commit e32ad84

Please sign in to comment.