keep properties of decayed blocks
This commit is contained in:
parent
d12c069ae6
commit
bcf5e45d01
1 changed files with 14 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
package org.dimdev.dimdoors.world.decay.processors;
|
package org.dimdev.dimdoors.world.decay.processors;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.minecraft.state.property.Property;
|
||||||
import org.dimdev.dimdoors.world.decay.DecayProcessor;
|
import org.dimdev.dimdoors.world.decay.DecayProcessor;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -12,6 +13,9 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SimpleDecayProcesor implements DecayProcessor {
|
public class SimpleDecayProcesor implements DecayProcessor {
|
||||||
public static final String KEY = "simple";
|
public static final String KEY = "simple";
|
||||||
|
|
||||||
|
@ -53,10 +57,19 @@ public class SimpleDecayProcesor implements DecayProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int process(World world, BlockPos pos, BlockState origin, BlockState target) {
|
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;
|
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() {
|
public static SimpleDecayProcesor.Builder builder() {
|
||||||
return new SimpleDecayProcesor.Builder();
|
return new SimpleDecayProcesor.Builder();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue