mirror of
https://codeberg.org/moonleay/Gimbal.git
synced 2024-11-25 22:22:10 +00:00
fix: Made replace mode more dynamic to copy properties for all blocks
This commit is contained in:
parent
6002af93a5
commit
31bab51603
1 changed files with 13 additions and 17 deletions
|
@ -18,12 +18,11 @@
|
|||
|
||||
package net.moonleay.gimbal.mixin;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.StairsBlock;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.moonleay.gimbal.editor.ServerEditorManager;
|
||||
import net.moonleay.gimbal.editor.state.mode.Capability;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -34,8 +33,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.minecraft.block.StairsBlock.*;
|
||||
|
||||
@Mixin(BlockItem.class)
|
||||
public abstract class ReplaceStateUpdaterMixin extends Item {
|
||||
|
||||
|
@ -54,21 +51,20 @@ public abstract class ReplaceStateUpdaterMixin extends Item {
|
|||
if (!ServerEditorManager.INSTANCE.shouldPlayer(id, Capability.REPLACE))
|
||||
return this.place(context, state);
|
||||
BlockState oldState = context.getWorld().getBlockState(context.getBlockPos());
|
||||
Block targetBl = oldState.getBlock();
|
||||
if (state.getBlock() instanceof StairsBlock && targetBl instanceof StairsBlock targetStair) {
|
||||
// Block and item is stairs, parse Stairs data
|
||||
return this.place(context, copyStairState(oldState, instance));
|
||||
}
|
||||
return this.place(context, state);
|
||||
return this.place(context, getTargetBlockState(oldState, instance.getBlock().getDefaultState()));
|
||||
}
|
||||
|
||||
|
||||
@Unique
|
||||
public BlockState copyStairState(BlockState targetState, BlockItem item) {
|
||||
BlockState blockState = item.getBlock().getDefaultState()
|
||||
.with(FACING, targetState.get(FACING))
|
||||
.with(HALF, targetState.get(HALF))
|
||||
.with(WATERLOGGED, targetState.get(WATERLOGGED));
|
||||
return blockState.with(SHAPE, targetState.get(SHAPE));
|
||||
public BlockState getTargetBlockState(BlockState oldState, BlockState newBlock) {
|
||||
var oldManager = oldState.getBlock().getStateManager();
|
||||
var newManager = newBlock.getBlock().getStateManager();
|
||||
for (var prop : oldManager.getProperties()) {
|
||||
var matchingProp = newManager.getProperty(prop.getName());
|
||||
if (matchingProp != null) {
|
||||
//noinspection rawtypes,unchecked
|
||||
newBlock = newBlock.with((Property) matchingProp, oldState.get(matchingProp));
|
||||
}
|
||||
}
|
||||
return newBlock;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue