|
|
|
@ -11,20 +11,30 @@ import net.fabricmc.api.ModInitializer;
|
|
|
|
|
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
|
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
|
|
|
|
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
|
|
|
|
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
|
import net.minecraft.registry.Registry;
|
|
|
|
|
import net.minecraft.registry.Registries;
|
|
|
|
|
import net.minecraft.resource.Resource;
|
|
|
|
|
import net.minecraft.resource.ResourceManager;
|
|
|
|
|
import net.minecraft.resource.ResourceType;
|
|
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class RedControl implements ModInitializer {
|
|
|
|
|
// This logger is used to write text to the console and the log file.
|
|
|
|
|
// It is considered best practice to use your mod id as the logger's name.
|
|
|
|
|
// That way, it's clear which mod wrote info, warnings, and errors.
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger("redcontrol");
|
|
|
|
|
public static final HashMap<String,byte[]> images = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
//Blocks
|
|
|
|
|
public static final CpuBlock CPU = new CpuBlock(FabricBlockSettings.create().strength(4.0f));
|
|
|
|
@ -43,6 +53,29 @@ public class RedControl implements ModInitializer {
|
|
|
|
|
// However, some things (like resources) may still be uninitialized.
|
|
|
|
|
// Proceed with mild caution.
|
|
|
|
|
|
|
|
|
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public Identifier getFabricId() {
|
|
|
|
|
return Identifier.of("redcontrol","image");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void reload(ResourceManager manager) {
|
|
|
|
|
images.clear(); //remove all previous images
|
|
|
|
|
for(Map.Entry<Identifier,Resource> entry : manager.findResources("image", path -> true).entrySet()) {
|
|
|
|
|
try(InputStream stream = entry.getValue().getInputStream();) {
|
|
|
|
|
String[] split = entry.getKey().getPath().split("/");
|
|
|
|
|
String file = split[split.length-1];
|
|
|
|
|
LOGGER.info("Found image {}",file);
|
|
|
|
|
images.put(file,stream.readAllBytes());
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
LOGGER.error("Error occurred while loading resource json {}", entry.getKey().toString(), e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LOGGER.info("Initializing RedControl!");
|
|
|
|
|
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU);
|
|
|
|
|
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "monitor"), MONITOR);
|
|
|
|
|