mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
fabric slabs & MultipleFacing
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
package com.dfsek.terra.bukkit.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.data.Slab;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Waterlogged;
|
||||
import com.dfsek.terra.bukkit.world.block.BukkitBlockData;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class BukkitSlab extends BukkitBlockData implements Slab {
|
||||
public BukkitSlab(BlockData delegate) {
|
||||
public class BukkitSlab extends BukkitWaterlogged implements Slab {
|
||||
public BukkitSlab(org.bukkit.block.data.type.Slab delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWaterlogged() {
|
||||
return ((Waterlogged) getHandle()).isWaterlogged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWaterlogged(boolean waterlogged) {
|
||||
((Waterlogged) getHandle()).setWaterlogged(waterlogged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return BukkitEnumAdapter.fromBukkitSlabType(((org.bukkit.block.data.type.Slab) getHandle()).getType());
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.dfsek.terra.api.generic.world.block.BlockData;
|
||||
import com.dfsek.terra.api.generic.world.block.MaterialData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricMaterialData;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricSlab;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
@@ -15,6 +17,8 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.argument.BlockArgumentParser;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricWorldHandle implements WorldHandle {
|
||||
@Override
|
||||
public void setBlockData(Block block, BlockData data, boolean physics) {
|
||||
@@ -38,6 +42,9 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
BlockState state = parser.parse(true).getBlockState();
|
||||
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
|
||||
if(state.contains(Properties.STAIR_SHAPE)) return new FabricStairs(state);
|
||||
if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state);
|
||||
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);
|
||||
} catch(CommandSyntaxException e) {
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.BlockFace;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Bisected;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Slab;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Stairs;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.SlabType;
|
||||
import net.minecraft.block.enums.StairShape;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
@@ -54,4 +56,17 @@ public final class FabricEnumAdapter {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
public static Slab.Type fromFabricSlabType(SlabType type) {
|
||||
switch(type) {
|
||||
case BOTTOM:
|
||||
return Slab.Type.BOTTOM;
|
||||
case TOP:
|
||||
return Slab.Type.TOP;
|
||||
case DOUBLE:
|
||||
return Slab.Type.DOUBLE;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.BlockFace;
|
||||
import com.dfsek.terra.api.generic.world.block.data.MultipleFacing;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FabricMultipleFacing extends FabricBlockData implements MultipleFacing {
|
||||
public FabricMultipleFacing(BlockState delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<BlockFace> getFaces() {
|
||||
Set<BlockFace> set = new HashSet<>();
|
||||
if(delegate.get(Properties.NORTH)) set.add(BlockFace.NORTH);
|
||||
if(delegate.get(Properties.SOUTH)) set.add(BlockFace.SOUTH);
|
||||
if(delegate.get(Properties.EAST)) set.add(BlockFace.EAST);
|
||||
if(delegate.get(Properties.WEST)) set.add(BlockFace.WEST);
|
||||
if(delegate.contains(Properties.UP) && delegate.get(Properties.UP)) set.add(BlockFace.UP);
|
||||
if(delegate.contains(Properties.DOWN) && delegate.get(Properties.DOWN)) set.add(BlockFace.DOWN);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFace(BlockFace face, boolean facing) {
|
||||
switch(face) {
|
||||
case NORTH:
|
||||
delegate = delegate.with(Properties.NORTH, facing);
|
||||
break;
|
||||
case SOUTH:
|
||||
delegate = delegate.with(Properties.SOUTH, facing);
|
||||
break;
|
||||
case EAST:
|
||||
delegate = delegate.with(Properties.EAST, facing);
|
||||
break;
|
||||
case WEST:
|
||||
delegate = delegate.with(Properties.WEST, facing);
|
||||
break;
|
||||
case UP:
|
||||
delegate = delegate.with(Properties.UP, facing);
|
||||
break;
|
||||
case DOWN:
|
||||
delegate = delegate.with(Properties.DOWN, facing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<BlockFace> getAllowedFaces() {
|
||||
Set<BlockFace> set = new HashSet<>();
|
||||
if(delegate.contains(Properties.NORTH)) set.add(BlockFace.NORTH);
|
||||
if(delegate.contains(Properties.SOUTH)) set.add(BlockFace.SOUTH);
|
||||
if(delegate.contains(Properties.EAST)) set.add(BlockFace.EAST);
|
||||
if(delegate.contains(Properties.WEST)) set.add(BlockFace.WEST);
|
||||
if(delegate.contains(Properties.UP)) set.add(BlockFace.UP);
|
||||
if(delegate.contains(Properties.DOWN)) set.add(BlockFace.DOWN);
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFace(BlockFace f) {
|
||||
return getFaces().contains(f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.data.Slab;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.property.Properties;
|
||||
|
||||
public class FabricSlab extends FabricWaterlogged implements Slab {
|
||||
public FabricSlab(BlockState delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return FabricEnumAdapter.fromFabricSlabType(delegate.get(Properties.SLAB_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(Type type) {
|
||||
delegate = delegate.with(Properties.SLAB_TYPE, TerraEnumAdapter.fromTerraSlabType(type));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package com.dfsek.terra.fabric.world.block.data;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.block.BlockFace;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Bisected;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Slab;
|
||||
import com.dfsek.terra.api.generic.world.block.data.Stairs;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.SlabType;
|
||||
import net.minecraft.block.enums.StairShape;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
@@ -54,4 +56,17 @@ public final class TerraEnumAdapter {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public static SlabType fromTerraSlabType(Slab.Type type) {
|
||||
switch(type) {
|
||||
case DOUBLE:
|
||||
return SlabType.DOUBLE;
|
||||
case TOP:
|
||||
return SlabType.TOP;
|
||||
case BOTTOM:
|
||||
return SlabType.BOTTOM;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user