keep properties of decayed blocks

This commit is contained in:
CreepyCre 2021-10-11 15:01:26 +02:00
parent d12c069ae6
commit bcf5e45d01

View file

@ -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<Property<?>> 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 <T extends Comparable<T>> BlockState transferProperty(BlockState from, BlockState to, Property<T> property) {
return to.with(property, from.get(property));
}
public static SimpleDecayProcesor.Builder builder() {
return new SimpleDecayProcesor.Builder();
}