use of pl.asie.charset.lib.network.PacketRegistry in project Charset by CharsetMC.
the class ModCharsetGates method init.
@EventHandler
public void init(FMLInitializationEvent event) {
packet = new PacketRegistry(ModCharsetGates.MODID);
registerGateStack(ItemGate.getStack(new PartGateNOR().setInvertedSides(0b0001)), "scs", "scs", "sss");
registerGateStack(ItemGate.getStack(new PartGateNAND().setInvertedSides(0b0001)), "wcw", "ccc", "sws");
registerGateStack(ItemGate.getStack(new PartGateXOR()), "wsw", "cwc", "scs");
registerGateStack(ItemGate.getStack(new PartGateNOR()), "sws", "scs", "sss");
registerGateStack(ItemGate.getStack(new PartGateNAND()), "www", "ccc", "sws");
registerGateStack(ItemGate.getStack(new PartGateXOR().setInvertedSides(0b0001)), "wcw", "cwc", "scs");
registerGateStack(ItemGate.getStack(new PartGatePulseFormer()), "wcw", "cwc", "wws");
registerGateStack(ItemGate.getStack(new PartGateMultiplexer()), "wcw", "csc", "wcw");
registerGateStack(ItemGate.getStack(new PartGateRSLatch()), "scs", "wsw", "scs");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(itemScrewdriver), " i", "si ", "ws ", 'i', "ingotIron", 's', "stickWood", 'w', new ItemStack(Blocks.wool, 1, EnumDyeColor.PINK.getMetadata())));
}
use of pl.asie.charset.lib.network.PacketRegistry in project Charset by CharsetMC.
the class ModCharsetStorage method init.
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
GameRegistry.registerTileEntity(TileBackpack.class, "charset:backpack");
proxy.init();
packet = new PacketRegistry(ModCharsetStorage.MODID);
packet.registerPacket(0x01, PacketBackpackOpen.class);
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerStorage());
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(backpackBlock), "lgl", "scs", "lwl", 'l', Items.leather, 'c', "chestWood", 's', "stickWood", 'g', "ingotGold", 'w', Blocks.wool));
}
use of pl.asie.charset.lib.network.PacketRegistry in project Charset by CharsetMC.
the class ModuleLoader method readDataTable.
@SuppressWarnings("unchecked")
private void readDataTable(ASMDataTable table) {
Multimap<String, String> unmetDependencies = HashMultimap.create();
Set<String> enabledModules = new HashSet<>();
Set<String> compatModules = new HashSet<>();
Map<String, ASMDataTable.ASMData> moduleData = new HashMap<>();
Property baseProfileProp = ModCharset.configGeneral.get("general", "profile", "DEFAULT");
baseProfileProp.setValidValues(new String[] { "DEFAULT", "STABLE", "TESTING", "EXPERIMENTAL" });
baseProfileProp.setLanguageKey("config.charset.profile.name");
baseProfileProp.setRequiresMcRestart(true);
ModuleProfile profile, defaultProfile;
if (ModCharset.INDEV) {
defaultProfile = ModuleProfile.INDEV;
} else if (ModCharset.defaultOptions.containsKey("profile")) {
defaultProfile = getProfileFromString(ModCharset.defaultOptions.get("profile"));
} else {
defaultProfile = ModuleProfile.STABLE;
}
baseProfileProp.setComment("Set the base profile for Charset.\nThis will give you a default set of modules based on stability.\nAllowed values: DEFAULT, STABLE, TESTING, EXPERIMENTAL (DEFAULT means " + defaultProfile.name() + ")\nFor fine-grained configuration, check modules.cfg!");
if ("DEFAULT".equals(baseProfileProp.getString().toUpperCase())) {
profile = defaultProfile;
} else {
profile = getProfileFromString(baseProfileProp.getString());
}
ModCharset.profile = profile;
ModCharset.logger.info("Charset profile is " + ModCharset.profile);
ConfigCategory category = ModCharset.configModules.getCategory("overrides");
category.setComment("Overrides can have one of three values: DEFAULT, ENABLE, DISABLE\nDEFAULT will enable the module based on your profile settings and dependency availability.");
category = ModCharset.configModules.getCategory("categories");
category.setComment("This section allows you to disable certain categories of content, based on a tag system.");
boolean configDirty = false;
Map<String, Boolean> categoryMap = new HashMap<>();
// Initialize categories
for (ASMDataTable.ASMData data : table.getAll(CharsetModule.class.getName())) {
Map<String, Object> info = data.getAnnotationInfo();
List<String> tags = (List<String>) info.getOrDefault("categories", Collections.emptyList());
for (String s : tags) {
if (!categoryMap.containsKey(s)) {
Property prop = ModCharset.configModules.get("categories", s, !CATEGORIES_OFF_BY_DEFAULT.contains(s));
prop.setRequiresMcRestart(true);
categoryMap.put(s, prop.getBoolean());
}
}
}
for (ASMDataTable.ASMData data : table.getAll(CharsetModule.class.getName())) {
Map<String, Object> info = data.getAnnotationInfo();
String name = (String) info.get("name");
String desc = (String) info.get("description");
if (desc == null)
desc = "";
ModuleProfile modProfile = ModuleProfile.valueOf(((ModAnnotation.EnumHolder) info.get("profile")).getValue());
Boolean isDefault = (Boolean) info.getOrDefault("isDefault", true);
Boolean compat = modProfile == ModuleProfile.COMPAT;
Boolean clientOnly = (Boolean) info.getOrDefault("isClientOnly", false);
Boolean serverOnly = (Boolean) info.getOrDefault("isServerOnly", false);
List<String> tags = (List<String>) info.getOrDefault("categories", Collections.emptyList());
String moduleGuiClass = (String) info.getOrDefault("moduleConfigGui", "");
if (moduleGuiClass.length() > 0) {
moduleGuiClasses.put(name, moduleGuiClass);
}
moduleData.put(name, data);
ThreeState override = ThreeState.MAYBE;
if ((Boolean) info.getOrDefault("isVisible", true)) {
if (modProfile == ModuleProfile.INDEV && profile != ModuleProfile.INDEV) {
override = ThreeState.NO;
} else {
if (compat) {
Property prop = ModCharset.configModules.get("compat", name, isDefault);
prop.setRequiresMcRestart(true);
if (!prop.getBoolean())
override = ThreeState.NO;
} else {
Property prop = ModCharset.configModules.get("overrides", name, "DEFAULT");
prop.setValidValues(new String[] { "DEFAULT", "ENABLE", "DISABLE" });
prop.setRequiresMcRestart(true);
if (desc.length() > 0)
desc += " ";
desc += "[Profile: " + modProfile.name().toUpperCase() + "";
if (!isDefault) {
desc += ", off by default!";
}
desc += "]";
if (!desc.equals(prop.getComment())) {
prop.setComment(desc);
configDirty = true;
}
if (prop.getString().toUpperCase().startsWith("ENABLE")) {
override = ThreeState.YES;
} else if (prop.getString().toUpperCase().startsWith("DISABLE")) {
override = ThreeState.NO;
} else if (!"DEFAULT".equals(prop.getString().toUpperCase())) {
ModCharset.logger.warn("Invalid value for '" + name + "' override: '" + prop.getString() + ";");
}
}
}
}
if (clientOnly && !FMLCommonHandler.instance().getSide().isClient()) {
continue;
}
if (serverOnly && !FMLCommonHandler.instance().getSide().isServer()) {
continue;
}
if (compat) {
compatModules.add(name);
}
if (override == ThreeState.MAYBE && isDefault) {
List<String> antideps = (List<String>) info.get("antidependencies");
if (antideps != null) {
for (String dep : antideps) {
if (isDepPresent(dep, enabledModules)) {
ModCharset.logger.info("Antidependency " + dep + " is present - disabling otherwise not forced module " + name + ".");
isDefault = false;
break;
}
}
}
for (String s : tags) {
if (!categoryMap.get(s)) {
ModCharset.logger.info("Category " + s + " is disabled - disabling otherwise not forced module " + name + ".");
isDefault = false;
}
}
}
if (!compat && modProfile != ModuleProfile.FORCED && modProfile.ordinal() > profile.ordinal()) {
isDefault = false;
}
EnableInformation enableInfo = new EnableInformation(isDefault, override);
if (enableInfo.isEnabled()) {
enabledModules.add(name);
enableInfoMap.put(name, enableInfo);
if (!"lib".equals(name))
dependencies.put(name, "lib");
List<String> deps = (List<String>) info.get("dependencies");
if (deps != null) {
dependencies.putAll(name, deps);
}
}
}
if (ModCharset.configGeneral.hasChanged()) {
ModCharset.configGeneral.save();
}
if (ModCharset.configModules.hasChanged() || configDirty) {
ModCharset.configModules.save();
configDirty = false;
}
int removedCount = 1;
while (removedCount > 0) {
removedCount = 0;
for (String name : enabledModules) {
if (dependencies.containsKey(name)) {
for (String dep : dependencies.get(name)) {
boolean optional = false;
if (dep.startsWith("optional:")) {
optional = true;
dep = dep.substring("optional:".length());
}
boolean met = optional || isDepPresent(dep, enabledModules);
if (!met) {
enableInfoMap.get(name).dependenciesMet = false;
unmetDependencies.put(name, dep);
break;
}
}
}
}
Iterator<String> unmetDepKey = unmetDependencies.keySet().iterator();
while (unmetDepKey.hasNext()) {
String depMod = unmetDepKey.next();
EnableInformation enableInfo = enableInfoMap.get(depMod);
if (!enableInfo.isEnabled()) {
if (!compatModules.contains(depMod)) {
ModCharset.logger.info("Module " + depMod + " requires " + joinerComma.join(unmetDependencies.get(depMod)) + ", but is not force-enabled. You can ignore this - it is not an error, just information.");
}
removedCount++;
enabledModules.remove(depMod);
unmetDepKey.remove();
}
}
}
for (String name : enabledModules) {
if (ModCharset.INDEV) {
ModCharset.logger.info("Instantiating module " + name);
}
ASMDataTable.ASMData data = moduleData.get(name);
try {
Object o = getClass(data).newInstance();
loadedModules.put(name, o);
loadedModulesByClass.put(data.getClassName(), o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
if (unmetDependencies.size() > 0) {
List<String> depStrings = new ArrayList<>(unmetDependencies.size());
for (String depMod : unmetDependencies.keys()) {
depStrings.add(depMod + "<-[" + joinerComma.join(unmetDependencies.get(depMod)) + "]");
}
throw new RuntimeException("The following mandatory dependencies were not met: " + joinerComma.join(depStrings));
}
iterateModules(table, Mod.EventHandler.class.getName(), (data, instance) -> {
String methodName = data.getObjectName().substring(0, data.getObjectName().indexOf('('));
String methodDesc = data.getObjectName().substring(methodName.length());
MethodType methodType = MethodType.fromMethodDescriptorString(methodDesc, classLoader);
if (ModCharset.INDEV) {
if (methodType.parameterCount() != 1) {
throw new RuntimeException("Invalid parameter count " + methodType.parameterCount() + " for EventHandler in " + instance.getClass() + "!");
}
}
try {
MethodHandle methodHandle = MethodHandles.lookup().findVirtual(getClass(data), methodName, methodType);
List<Pair<String, MethodHandle>> list = loaderHandles.computeIfAbsent(methodType.parameterType(0), k -> new ArrayList<>());
list.sort(Comparator.comparing(Pair::getLeft));
list.add(Pair.of(loadedModules.inverse().get(instance), methodHandle));
} catch (NoSuchMethodException e) {
// method has been annotated away, ignore
} catch (Exception e) {
throw new RuntimeException(e);
}
});
iterateModules(table, CharsetModule.Instance.class.getName(), (data, instance) -> {
try {
String instString = (String) data.getAnnotationInfo().get("value");
if (instString == null || instString.equals("")) {
getField(data).set(instance, instance);
} else {
Object inst2 = loadedModules.get(instString);
getField(data).set(instance, inst2);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
iterateModules(table, CharsetModule.PacketRegistry.class.getName(), (data, instance) -> {
String id = (String) data.getAnnotationInfo().get("value");
if (id == null)
id = loadedModules.inverse().get(instance);
try {
String channelName = "chrs:" + id.substring(id.lastIndexOf('.') + 1);
getField(data).set(instance, new PacketRegistry(channelName));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
iterateModules(table, CharsetModule.Configuration.class.getName(), (data, instance) -> {
String id = (String) data.getAnnotationInfo().get("value");
if (id == null)
id = loadedModules.inverse().get(instance);
try {
Configuration config = new Configuration(ModCharset.getModuleConfigFile(id));
getField(data).set(instance, config);
moduleConfigs.put(id, config);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
Side side = FMLCommonHandler.instance().getSide();
for (ASMDataTable.ASMData data : table.getAll(CharsetModule.SidedProxy.class.getName())) {
String clientSide = (String) data.getAnnotationInfo().get("clientSide");
String serverSide = (String) data.getAnnotationInfo().get("serverSide");
try {
Field f = getField(data);
f.set(null, Class.forName(side == Side.CLIENT ? clientSide : serverSide).newInstance());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
List<String> sortedModules = new ArrayList<>();
Set<String> remainingModules = Sets.newHashSet(enabledModules);
while (!remainingModules.isEmpty()) {
Iterator<String> remainingIterator = remainingModules.iterator();
boolean added = false;
while (remainingIterator.hasNext()) {
String s = remainingIterator.next();
boolean canAdd = true;
for (String dep : dependencies.get(s)) {
if (!dep.startsWith("mod:") && !dep.startsWith("optional:") && !sortedModules.contains(dep)) {
canAdd = false;
break;
}
}
if (canAdd) {
added = true;
sortedModules.add(s);
remainingIterator.remove();
}
}
if (!added) {
throw new RuntimeException("Cyclic dependency within Charset modules! Report!");
}
}
for (List<Pair<String, MethodHandle>> list : loaderHandles.values()) {
list.sort(Comparator.comparingInt(a -> sortedModules.indexOf(a.getKey())));
}
for (String s : sortedModules) {
MinecraftForge.EVENT_BUS.register(loadedModules.get(s));
}
for (ASMDataTable.ASMData data : table.getAll(CharsetCompatAnnotation.class.getName())) {
String id = (String) data.getAnnotationInfo().get("value");
try {
addClassNames(table, Class.forName(data.getClassName()), id);
} catch (Exception e) {
e.printStackTrace();
}
}
passEvent(new CharsetLoadConfigEvent(true));
if (ModCharset.configModules.hasChanged() || configDirty) {
ModCharset.configModules.save();
configDirty = false;
}
}
use of pl.asie.charset.lib.network.PacketRegistry in project Charset by CharsetMC.
the class ModCharsetAudio method init.
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
packet = new PacketRegistry(ModCharsetAudio.MODID);
packet.registerPacket(0x01, PacketNoteParticle.class);
packet.registerPacket(0x10, PacketDriveState.class);
packet.registerPacket(0x11, PacketDriveAudio.class);
packet.registerPacket(0x12, PacketDriveStop.class);
packet.registerPacket(0x13, PacketDriveRecord.class);
packet.registerPacket(0x14, PacketDriveCounter.class);
GameRegistry.registerTileEntity(TileIronNote.class, "charset:ironnoteblock");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ironNoteBlock), "iii", "iNi", "iii", 'i', "ingotIron", 'N', Blocks.noteblock));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(tapeReelItem), " i ", "ipi", " i ", 'i', "ingotIron", 'p', Items.paper));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(magneticTapeItem, 32), "ddd", "rir", "ddd", 'd', "dyeBlack", 'r', Items.redstone, 'i', "ingotIron"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(partTapeDriveItem), "igi", "rRr", "ipi", 'g', "blockGlass", 'p', Blocks.piston, 'R', new ItemStack(tapeReelItem, 1, 0), 'r', Items.redstone, 'i', "ingotIron"));
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerAudio());
GameRegistry.addRecipe(new RecipeTapeReel());
RecipeSorter.register("charsetaudio:tapeReel", RecipeTapeReel.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
GameRegistry.addRecipe(new RecipeTape());
RecipeSorter.register("charsetaudio:tape", RecipeTape.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped");
proxy.init();
}
use of pl.asie.charset.lib.network.PacketRegistry in project Charset by CharsetMC.
the class ModCharsetWires method init.
@EventHandler
public void init(FMLInitializationEvent event) {
packet = new PacketRegistry(ModCharsetWires.MODID);
// Temporary recipes
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(wire, 16, 0), "r r", "rir", "r r", 'r', "dustRedstone", 'i', "ingotIron"));
for (int i = 0; i < 16; i++) {
OreDictionary.registerOre("charsetWireInsulated", new ItemStack(wire, 1, (i + 1) << 1));
OreDictionary.registerOre("charsetWireInsulatedFreestanding", new ItemStack(wire, 1, (i + 1) << 1));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(wire, 8, 2 + (i << 1)), "ddd", "dwd", "ddd", 'd', new ItemStack(wire, 1, 0), 'w', new ItemStack(Blocks.wool, 1, i)));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(wire, 8, 3 + (i << 1)), "ddd", "dwd", "ddd", 'd', new ItemStack(wire, 1, 1), 'w', new ItemStack(Blocks.wool, 1, i)));
}
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(wire, 1, 34), "sws", "www", "sws", 'w', "charsetWireInsulated", 's', Items.string));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(wire, 1, 35), "sws", "www", "sws", 'w', "charsetWireInsulatedFreestanding", 's', Items.string));
for (int i = 0; i < 18; i++) {
GameRegistry.addShapelessRecipe(new ItemStack(wire, 1, 0 + (i << 1)), new ItemStack(wire, 1, 1 + (i << 1)));
GameRegistry.addShapelessRecipe(new ItemStack(wire, 1, 1 + (i << 1)), new ItemStack(wire, 1, 0 + (i << 1)));
}
}
Aggregations