use of com.mcmoddev.orespawn.impl.os3.ReplacementEntry in project OreSpawn by MinecraftModDevelopmentMods.
the class ReplacementsRegistry method addBlock.
public void addBlock(String name, IBlockState state) {
ResourceLocation regName = new ResourceLocation(name);
if (registry.containsKey(regName)) {
IReplacementEntry old = registry.getValue(regName);
IReplacementEntry newRE;
List<IBlockState> oldList = old.getEntries();
oldList.add(state);
newRE = new ReplacementEntry(name, oldList);
registry.remove(regName);
newRE.setRegistryName(regName);
registry.register(newRE);
return;
}
IReplacementEntry r = new ReplacementEntry(name, state);
registry.register(r);
}
use of com.mcmoddev.orespawn.impl.os3.ReplacementEntry in project OreSpawn by MinecraftModDevelopmentMods.
the class ReplacementsRegistry method loadFile.
@SuppressWarnings("deprecation")
public void loadFile(Path file) {
JsonParser parser = new JsonParser();
JsonObject elements;
String rawJson;
try {
rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset());
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getFileName());
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
OreSpawn.LOGGER.info(report.getCompleteReport());
return;
}
elements = parser.parse(rawJson).getAsJsonObject();
elements.entrySet().stream().forEach(elem -> {
String entName = elem.getKey();
JsonArray entries = elem.getValue().getAsJsonArray();
List<IBlockState> blocks = new LinkedList<>();
for (JsonElement e : entries) {
JsonObject asObj = e.getAsJsonObject();
String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString().toLowerCase();
// is this an OreDictionary entry ?
if (blockName.startsWith("ore:")) {
// yes, it is
String oreDictName = blockName.split(":")[1];
OreDictionary.getOres(oreDictName).forEach(iS -> {
if (iS.getMetadata() != 0) {
blocks.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata()));
} else {
blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState());
}
});
} else {
String state = null;
ResourceLocation blockRL = new ResourceLocation(blockName);
Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL);
if (asObj.has(Constants.ConfigNames.METADATA)) {
// has metadata
int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt();
blocks.add(theBlock.getStateFromMeta(meta));
} else if (asObj.has(Constants.ConfigNames.STATE)) {
// has a state
state = asObj.get(Constants.ConfigNames.STATE).getAsString();
blocks.add(StateUtil.deserializeState(theBlock, state));
} else {
// use the default state
blocks.add(theBlock.getDefaultState());
}
}
}
IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks);
registry.register(replacer);
});
}
Aggregations