use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class LootModifierManager method apply.
@Override
protected void apply(Map<ResourceLocation, JsonElement> resourceList, ResourceManager resourceManagerIn, ProfilerFiller profilerIn) {
Builder<ResourceLocation, IGlobalLootModifier> builder = ImmutableMap.builder();
// old way (for reference)
/*Map<IGlobalLootModifier, ResourceLocation> toLocation = new HashMap<IGlobalLootModifier, ResourceLocation>();
resourceList.forEach((location, object) -> {
try {
IGlobalLootModifier modifier = deserializeModifier(location, object);
builder.put(location, modifier);
toLocation.put(modifier, location);
} catch (Exception exception) {
LOGGER.error("Couldn't parse loot modifier {}", location, exception);
}
});
builder.orderEntriesByValue((x,y) -> {
return toLocation.get(x).compareTo(toLocation.get(y));
});*/
// new way
ArrayList<ResourceLocation> finalLocations = new ArrayList<ResourceLocation>();
ResourceLocation resourcelocation = new ResourceLocation("forge", "loot_modifiers/global_loot_modifiers.json");
try {
// read in all data files from forge:loot_modifiers/global_loot_modifiers in order to do layering
for (Resource iresource : resourceManagerIn.getResources(resourcelocation)) {
try (InputStream inputstream = iresource.getInputStream();
Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8))) {
JsonObject jsonobject = GsonHelper.fromJson(GSON_INSTANCE, reader, JsonObject.class);
boolean replace = jsonobject.get("replace").getAsBoolean();
if (replace)
finalLocations.clear();
JsonArray entryList = jsonobject.get("entries").getAsJsonArray();
for (JsonElement entry : entryList) {
String loc = entry.getAsString();
ResourceLocation res = new ResourceLocation(loc);
if (finalLocations.contains(res))
finalLocations.remove(res);
finalLocations.add(res);
}
} catch (RuntimeException | IOException ioexception) {
LOGGER.error("Couldn't read global loot modifier list {} in data pack {}", resourcelocation, iresource.getSourceName(), ioexception);
} finally {
IOUtils.closeQuietly((Closeable) iresource);
}
}
} catch (IOException ioexception1) {
LOGGER.error("Couldn't read global loot modifier list from {}", resourcelocation, ioexception1);
}
// use layered config to fetch modifier data files (modifiers missing from config are disabled)
finalLocations.forEach(location -> {
try {
IGlobalLootModifier modifier = deserializeModifier(location, resourceList.get(location));
if (modifier != null)
builder.put(location, modifier);
} catch (Exception exception) {
LOGGER.error("Couldn't parse loot modifier {}", location, exception);
}
});
ImmutableMap<ResourceLocation, IGlobalLootModifier> immutablemap = builder.build();
this.registeredLootModifiers = immutablemap;
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class LootModifierManager method deserializeModifier.
private IGlobalLootModifier deserializeModifier(ResourceLocation location, JsonElement element) {
if (!element.isJsonObject())
return null;
JsonObject object = element.getAsJsonObject();
LootItemCondition[] lootConditions = GSON_INSTANCE.fromJson(object.get("conditions"), LootItemCondition[].class);
ResourceLocation serializer = new ResourceLocation(GsonHelper.getAsString(object, "type"));
return ForgeRegistries.LOOT_MODIFIER_SERIALIZERS.getValue(serializer).read(location, object, lootConditions);
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method processForgeListPingData.
public static void processForgeListPingData(ServerStatus packet, ServerData target) {
if (packet.getForgeData() != null) {
final Map<String, String> mods = packet.getForgeData().getRemoteModData();
final Map<ResourceLocation, Pair<String, Boolean>> remoteChannels = packet.getForgeData().getRemoteChannels();
final int fmlver = packet.getForgeData().getFMLNetworkVersion();
boolean fmlNetMatches = fmlver == NetworkConstants.FMLNETVERSION;
boolean channelsMatch = NetworkRegistry.checkListPingCompatibilityForClient(remoteChannels);
AtomicBoolean result = new AtomicBoolean(true);
final List<String> extraClientMods = new ArrayList<>();
ModList.get().forEachModContainer((modid, mc) -> mc.getCustomExtension(IExtensionPoint.DisplayTest.class).ifPresent(ext -> {
boolean foundModOnServer = ext.remoteVersionTest().test(mods.get(modid), true);
result.compareAndSet(true, foundModOnServer);
if (!foundModOnServer) {
extraClientMods.add(modid);
}
}));
boolean modsMatch = result.get();
final Map<String, String> extraServerMods = mods.entrySet().stream().filter(e -> !Objects.equals(NetworkConstants.IGNORESERVERONLY, e.getValue())).filter(e -> !ModList.get().isLoaded(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
LOGGER.debug(CLIENTHOOKS, "Received FML ping data from server at {}: FMLNETVER={}, mod list is compatible : {}, channel list is compatible: {}, extra server mods: {}", target.ip, fmlver, modsMatch, channelsMatch, extraServerMods);
String extraReason = null;
if (!extraServerMods.isEmpty()) {
extraReason = "fml.menu.multiplayer.extraservermods";
LOGGER.info(CLIENTHOOKS, ForgeI18n.parseMessage(extraReason) + ": {}", extraServerMods.entrySet().stream().map(e -> e.getKey() + "@" + e.getValue()).collect(Collectors.joining(", ")));
}
if (!modsMatch) {
extraReason = "fml.menu.multiplayer.modsincompatible";
LOGGER.info(CLIENTHOOKS, "Client has mods that are missing on server: {}", extraClientMods);
}
if (!channelsMatch) {
extraReason = "fml.menu.multiplayer.networkincompatible";
}
if (fmlver < NetworkConstants.FMLNETVERSION) {
extraReason = "fml.menu.multiplayer.serveroutdated";
}
if (fmlver > NetworkConstants.FMLNETVERSION) {
extraReason = "fml.menu.multiplayer.clientoutdated";
}
target.forgeData = new ExtendedServerListData("FML", extraServerMods.isEmpty() && fmlNetMatches && channelsMatch && modsMatch, mods.size(), extraReason, packet.getForgeData().isTruncated());
} else {
target.forgeData = new ExtendedServerListData("VANILLA", NetworkRegistry.canConnectToVanillaServer(), 0, null);
}
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class GameTestTest method generateTests.
/**
* An example game test generator.
* <p>
* A <b>game test generator</b> generates a collection of test functions.
* It is called immediately when registered to GameTestRegistry.
* <p><ul>
* <li>Must return {@code Collection<TestFunction>} (or a subclass)</li>
* <li>Must take no parameters</li>
* <li>Can be {@code static} or non-static</li>
* <p>
* WARNING: If made non-static, then it will create an instance of the class every time it is run.</li>
* </ul>
*/
@GameTestGenerator
public static List<TestFunction> generateTests() {
// An example test function, run in the default batch, with the test name "teststone", and the structure name "gametesttest.teststone" under the "gametest_test" namespace.
// No rotation, 100 ticks until the test times out if it does not fail or succeed, 0 ticks for setup time, and the actual code to run.
TestFunction testStone = new TestFunction("defaultBatch", "teststone", new ResourceLocation(MODID, "gametesttest.teststone").toString(), Rotation.NONE, 100, 0, true, helper -> {
BlockPos stonePos = new BlockPos(1, 1, 1);
// This should always assert to true, since we set it then directly check it
helper.setBlock(stonePos, Blocks.STONE);
helper.assertBlockState(stonePos, b -> b.is(Blocks.STONE), () -> "Block was not stone");
helper.succeed();
});
return List.of(testStone);
}
use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.
the class BiomeLoadingEventTest method onBiomeLoading.
public void onBiomeLoading(BiomeLoadingEvent event) {
ResourceLocation biome = event.getName();
LOGGER.info("Biome loaded: {}", biome);
}
Aggregations