use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationBuilder method validateAndGet.
@Nonnull
@Override
protected BlockTransmutation validateAndGet() {
if (this.stateCheck.isEmpty()) {
throw new IllegalArgumentException("No block input checks!");
}
for (BlockMatchInformation inputMatch : this.stateCheck) {
if (!inputMatch.isValid()) {
throw new IllegalArgumentException("A block transmutation must not convert 'air' into something!");
}
}
BlockTransmutation tr = new BlockTransmutation(this.id, this.outputState, this.starlight, this.constellation);
this.stateCheck.forEach(tr::addInputOption);
tr.setOutputDisplay(this.outputDisplay);
return tr;
}
use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationSerializer method read.
@Nullable
@Override
public BlockTransmutation read(ResourceLocation recipeId, PacketBuffer buffer) {
List<BlockMatchInformation> matchInformation = ByteBufUtils.readList(buffer, BlockMatchInformation::read);
BlockState output = ByteBufUtils.readBlockState(buffer);
ItemStack display = ByteBufUtils.readItemStack(buffer);
double starlight = buffer.readDouble();
IWeakConstellation cst = ByteBufUtils.readOptional(buffer, ByteBufUtils::readRegistryEntry);
BlockTransmutation tr = new BlockTransmutation(recipeId, output, starlight, cst);
matchInformation.forEach(tr::addInputOption);
tr.setOutputDisplay(display);
return tr;
}
use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationSerializer method read.
@Override
public BlockTransmutation read(ResourceLocation recipeId, JsonObject json) {
List<BlockMatchInformation> matchInformation = new ArrayList<>();
JsonHelper.parseMultipleJsonObjects(json, "input", object -> matchInformation.add(BlockMatchInformation.read(object)));
if (matchInformation.isEmpty()) {
throw new IllegalArgumentException("A block transmutation has to have at least 1 input!");
}
for (BlockMatchInformation info : matchInformation) {
if (!info.isValid()) {
throw new JsonSyntaxException("Block transmutation must not convert an air-block into something!");
}
}
BlockState output = BlockStateHelper.deserializeObject(JSONUtils.getJsonObject(json, "output"));
ItemStack outputDisplay = new ItemStack(output.getBlock());
if (JSONUtils.hasField(json, "display")) {
outputDisplay = JsonHelper.getItemStack(json, "display");
}
float starlight = JSONUtils.getFloat(json, "starlight");
IWeakConstellation matchConstellation = null;
if (json.has("constellation")) {
ResourceLocation cstKey = new ResourceLocation(JSONUtils.getString(json, "constellation"));
IConstellation cst = RegistriesAS.REGISTRY_CONSTELLATIONS.getValue(cstKey);
if (cst == null) {
throw new JsonSyntaxException(String.format("Unknown constellation %s!", cstKey.toString()));
}
if (!(cst instanceof IWeakConstellation)) {
throw new JsonSyntaxException(String.format("Constellation %s has to be either a major or dim constellation!", cstKey.toString()));
}
matchConstellation = (IWeakConstellation) cst;
}
BlockTransmutation tr = new BlockTransmutation(recipeId, output, starlight, matchConstellation);
matchInformation.forEach(tr::addInputOption);
tr.setOutputDisplay(outputDisplay);
return tr;
}
use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationSerializer method write.
@Override
public void write(JsonObject object, BlockTransmutation recipe) {
JsonArray inputs = new JsonArray();
for (BlockMatchInformation info : recipe.getInputOptions()) {
inputs.add(info.serializeJson());
}
object.add("input", inputs);
object.add("output", BlockStateHelper.serializeObject(recipe.getOutput(), true));
object.add("display", JsonHelper.serializeItemStack(recipe.getOutputDisplay()));
object.addProperty("starlight", recipe.getStarlightRequired());
if (recipe.getRequiredConstellation() != null) {
object.addProperty("constellation", recipe.getRequiredConstellation().getRegistryName().toString());
}
}
use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationManager method removeRecipe.
@ZenCodeType.Method
public void removeRecipe(BlockState outputState, boolean exact) {
BlockMatchInformation matcher = new BlockMatchInformation(outputState, exact);
CraftTweakerAPI.apply(new ActionRemoveRecipe(this, iRecipe -> {
if (iRecipe instanceof BlockTransmutation) {
BlockTransmutation recipe = (BlockTransmutation) iRecipe;
return matcher.test(recipe.getOutput());
}
return false;
}, action -> "Removing Block Transmutation recipes that output " + ExpandBlockState.getCommandString(outputState)));
}
Aggregations