brainsweeping keeps facing and such

This commit is contained in:
yrsegal@gmail.com 2022-04-30 14:19:30 -04:00
parent 0ff395ca20
commit 123bc988ca
3 changed files with 22 additions and 8 deletions

View file

@ -16,6 +16,7 @@ import net.minecraft.core.BlockPos
import net.minecraft.sounds.SoundEvents
import net.minecraft.sounds.SoundSource
import net.minecraft.world.entity.npc.Villager
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.phys.Vec3
object OpBrainsweep : SpellOperator {
@ -44,15 +45,15 @@ object OpBrainsweep : SpellOperator {
?: throw MishapBadBrainsweep(sacrifice, bpos)
return Triple(
Spell(bpos, sacrifice, recipe),
Spell(bpos, state, sacrifice, recipe),
10 * ManaConstants.CRYSTAL_UNIT,
listOf(ParticleSpray.Cloud(sacrifice.position(), 1.0), ParticleSpray.Burst(Vec3.atCenterOf(bpos), 0.3, 100))
)
}
private data class Spell(val pos: BlockPos, val sacrifice: Villager, val recipe: BrainsweepRecipe) : RenderedSpell {
private data class Spell(val pos: BlockPos, val state: BlockState, val sacrifice: Villager, val recipe: BrainsweepRecipe) : RenderedSpell {
override fun cast(ctx: CastingContext) {
ctx.world.setBlockAndUpdate(pos, recipe.result)
ctx.world.setBlockAndUpdate(pos, BrainsweepRecipe.copyProperties(state, recipe.result))
Brainsweeping.brainsweep(sacrifice)
ctx.world.playSound(null, sacrifice, SoundEvents.VILLAGER_DEATH, SoundSource.AMBIENT, 0.8f, 1f)

View file

@ -16,7 +16,8 @@ import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import net.minecraft.world.level.block.state.properties.Property;
import org.jetbrains.annotations.NotNull;
// God I am a horrible person
public record BrainsweepRecipe(
@ -66,9 +67,22 @@ public record BrainsweepRecipe(
return ItemStack.EMPTY.copy();
}
// Because kotlin doesn't like doing raw, unchecked types
// Can't blame it, but that's what we need to do
@SuppressWarnings({"rawtypes", "unchecked"})
public static BlockState copyProperties(BlockState original, BlockState copyTo) {
for (Property prop : original.getProperties()) {
if (copyTo.hasProperty(prop)) {
copyTo = copyTo.setValue(prop, original.getValue(prop));
}
}
return copyTo;
}
public static class Serializer extends RecipeSerializerBase<BrainsweepRecipe> {
@Override
public BrainsweepRecipe fromJson(ResourceLocation recipeID, JsonObject json) {
public @NotNull BrainsweepRecipe fromJson(ResourceLocation recipeID, JsonObject json) {
var blockIn = StateIngredientHelper.deserialize(GsonHelper.getAsJsonObject(json, "blockIn"));
var villagerIn = VillagerIngredient.deserialize(GsonHelper.getAsJsonObject(json, "villagerIn"));
var result = StateIngredientHelper.readBlockState(GsonHelper.getAsJsonObject(json, "result"));
@ -82,9 +96,8 @@ public record BrainsweepRecipe(
buf.writeVarInt(Block.getId(recipe.result));
}
@Nullable
@Override
public BrainsweepRecipe fromNetwork(ResourceLocation recipeID, FriendlyByteBuf buf) {
public @NotNull BrainsweepRecipe fromNetwork(ResourceLocation recipeID, FriendlyByteBuf buf) {
var blockIn = StateIngredientHelper.read(buf);
var villagerIn = VillagerIngredient.read(buf);
var result = Block.stateById(buf.readVarInt());

View file

@ -8,7 +8,7 @@ import net.minecraft.world.item.crafting.RecipeSerializer;
import javax.annotation.Nullable;
// https://github.com/VazkiiMods/Botania/blob/1.18.x/Xplat/src/main/java/vazkii/botania/common/crafting/RecipeSerializerBase.java
// TL;DR Forge bad so we have to ursed self-mixin
// TL;DR Forge bad, so we have to cursed self-mixin
public abstract class RecipeSerializerBase<T extends Recipe<?>> implements RecipeSerializer<T> {
@Nullable
private ResourceLocation registryName;