From bcf5e45d01019d833906a518c478583b580d2315 Mon Sep 17 00:00:00 2001 From: CreepyCre Date: Mon, 11 Oct 2021 15:01:26 +0200 Subject: [PATCH] keep properties of decayed blocks --- .../decay/processors/SimpleDecayProcesor.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dimdev/dimdoors/world/decay/processors/SimpleDecayProcesor.java b/src/main/java/org/dimdev/dimdoors/world/decay/processors/SimpleDecayProcesor.java index c14f5247..75d09e0b 100644 --- a/src/main/java/org/dimdev/dimdoors/world/decay/processors/SimpleDecayProcesor.java +++ b/src/main/java/org/dimdev/dimdoors/world/decay/processors/SimpleDecayProcesor.java @@ -1,6 +1,7 @@ package org.dimdev.dimdoors.world.decay.processors; import com.google.gson.JsonObject; +import net.minecraft.state.property.Property; import org.dimdev.dimdoors.world.decay.DecayProcessor; import net.minecraft.block.Block; @@ -12,6 +13,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; +import java.util.Set; +import java.util.stream.Collectors; + public class SimpleDecayProcesor implements DecayProcessor { public static final String KEY = "simple"; @@ -53,10 +57,19 @@ public class SimpleDecayProcesor implements DecayProcessor { @Override public int process(World world, BlockPos pos, BlockState origin, BlockState target) { - world.setBlockState(pos, block.getDefaultState()); + BlockState newState = block.getDefaultState(); + Set> commonProperties = target.getProperties().stream().filter(newState.getProperties()::contains).collect(Collectors.toSet()); + for(Property property : commonProperties) { + newState = transferProperty(target, newState, property); + } + world.setBlockState(pos, newState); return entropy; } + private static > BlockState transferProperty(BlockState from, BlockState to, Property property) { + return to.with(property, from.get(property)); + } + public static SimpleDecayProcesor.Builder builder() { return new SimpleDecayProcesor.Builder(); }