use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation 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.crafting.recipe.BlockTransmutation 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.crafting.recipe.BlockTransmutation 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.crafting.recipe.BlockTransmutation 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)));
}
use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation in project AstralSorcery by HellFirePvP.
the class BlockTransmutationHandler method receiveStarlight.
@Override
public void receiveStarlight(World world, Random rand, BlockPos pos, BlockState state, IWeakConstellation starlightType, double amount) {
BlockTransmutation recipe = RecipeTypesAS.TYPE_BLOCK_TRANSMUTATION.findRecipe(new BlockTransmutationContext(world, pos, state, starlightType));
if (recipe == null) {
// Wait what
return;
}
WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
ActiveTransmutation activeRecipe = runningTransmutations.get(at);
if (activeRecipe == null || !activeRecipe.recipe.equals(recipe)) {
activeRecipe = new ActiveTransmutation(recipe);
runningTransmutations.put(at, activeRecipe);
}
activeRecipe.acceptStarlight(amount);
PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.BLOCK_TRANSMUTATION_TICK).addData(buf -> ByteBufUtils.writePos(buf, pos));
PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 24));
if (activeRecipe.isFinished() && activeRecipe.finish(world, pos)) {
runningTransmutations.remove(at);
}
}
Aggregations