brainsweeping keeps facing and such

This commit is contained in:
yrsegal@gmail.com 2022-04-30 14:19:30 -04:00
parent 0abb9b3ecc
commit 4155f90f30
2 changed files with 18 additions and 3 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,6 +16,7 @@ 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 net.minecraft.world.level.block.state.properties.Property;
import net.minecraftforge.registries.ForgeRegistryEntry;
import org.jetbrains.annotations.Nullable;
@ -69,6 +70,19 @@ 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 ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<BrainsweepRecipe> {
@Override
public BrainsweepRecipe fromJson(ResourceLocation recipeID, JsonObject json) {