mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
implement FabricDirectional
This commit is contained in:
parent
7c177d568b
commit
7f988dcf26
@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.fabric.world;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
|
||||
@ -9,6 +10,7 @@ import com.dfsek.terra.fabric.inventory.FabricItem;
|
||||
import com.dfsek.terra.fabric.inventory.FabricItemStack;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockType;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricDirectional;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricOrientable;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricRotatable;
|
||||
@ -24,6 +26,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -42,22 +45,42 @@ public final class FabricAdapter {
|
||||
|
||||
if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state);
|
||||
|
||||
if(state.contains(Properties.AXIS)) return new FabricOrientable(state);
|
||||
if(state.contains(Properties.AXIS)) return new FabricOrientable(state, Properties.AXIS);
|
||||
if(state.contains(Properties.HORIZONTAL_AXIS)) return new FabricOrientable(state, Properties.HORIZONTAL_AXIS);
|
||||
|
||||
if(state.contains(Properties.ROTATION)) return new FabricRotatable(state);
|
||||
|
||||
if(state.contains(Properties.FACING)) return new FabricDirectional(state, Properties.FACING);
|
||||
if(state.contains(Properties.HOPPER_FACING)) return new FabricDirectional(state, Properties.HOPPER_FACING);
|
||||
if(state.contains(Properties.HORIZONTAL_FACING)) return new FabricDirectional(state, Properties.HORIZONTAL_FACING);
|
||||
|
||||
if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST)))
|
||||
return new FabricMultipleFacing(state);
|
||||
if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state);
|
||||
return new FabricBlockData(state);
|
||||
}
|
||||
|
||||
public static BlockType adapt(Block block) {
|
||||
return new FabricBlockType(block);
|
||||
public static Direction adapt(BlockFace face) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal direction: " + face);
|
||||
}
|
||||
}
|
||||
|
||||
public WorldAccess adapt(FabricWorldHandle worldHandle) {
|
||||
return worldHandle.getWorld();
|
||||
public static BlockType adapt(Block block) {
|
||||
return new FabricBlockType(block);
|
||||
}
|
||||
|
||||
public static EntityType adapt(net.minecraft.entity.EntityType<?> entityType) {
|
||||
@ -87,4 +110,8 @@ public final class FabricAdapter {
|
||||
public static net.minecraft.enchantment.Enchantment adapt(Enchantment enchantment) {
|
||||
return ((FabricEnchantment) enchantment).getHandle();
|
||||
}
|
||||
|
||||
public WorldAccess adapt(FabricWorldHandle worldHandle) {
|
||||
return worldHandle.getWorld();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.data.Directional;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
|
||||
public class FabricDirectional extends FabricBlockData implements Directional {
|
||||
private final DirectionProperty property;
|
||||
|
||||
public FabricDirectional(BlockState delegate, DirectionProperty property) {
|
||||
super(delegate);
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
switch(delegate.get(property)) {
|
||||
case SOUTH:
|
||||
return BlockFace.SOUTH;
|
||||
case DOWN:
|
||||
return BlockFace.DOWN;
|
||||
case UP:
|
||||
return BlockFace.UP;
|
||||
case EAST:
|
||||
return BlockFace.EAST;
|
||||
case WEST:
|
||||
return BlockFace.WEST;
|
||||
case NORTH:
|
||||
return BlockFace.NORTH;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFacing(BlockFace facing) {
|
||||
delegate = delegate.with(property, FabricAdapter.adapt(facing));
|
||||
}
|
||||
}
|
@ -4,15 +4,19 @@ import com.dfsek.terra.api.platform.block.Axis;
|
||||
import com.dfsek.terra.api.platform.block.data.Orientable;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FabricOrientable extends FabricBlockData implements Orientable {
|
||||
public FabricOrientable(BlockState delegate) {
|
||||
private final EnumProperty<Direction.Axis> property;
|
||||
|
||||
public FabricOrientable(BlockState delegate, EnumProperty<Direction.Axis> property) {
|
||||
super(delegate);
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,11 +26,11 @@ public class FabricOrientable extends FabricBlockData implements Orientable {
|
||||
|
||||
@Override
|
||||
public Axis getAxis() {
|
||||
return FabricEnumAdapter.adapt(getHandle().get(Properties.AXIS));
|
||||
return FabricEnumAdapter.adapt(getHandle().get(property));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAxis(Axis axis) {
|
||||
delegate = delegate.with(Properties.AXIS, FabricEnumAdapter.adapt(axis));
|
||||
delegate = delegate.with(property, FabricEnumAdapter.adapt(axis));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user