mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
sort of working fabric impl
This commit is contained in:
@@ -21,7 +21,7 @@ public final class Types {
|
||||
public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP;
|
||||
|
||||
static {
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection");
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockStateProbabilityCollection");
|
||||
FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection");
|
||||
TREE_PROBABILITY_COLLECTION_TYPE = getType("treeProbabilityCollection");
|
||||
TERRA_BIOME_PROBABILITY_COLLECTION_TYPE = getType("terraBiomeProbabilityCollection");
|
||||
@@ -38,8 +38,7 @@ public final class Types {
|
||||
try {
|
||||
return Types.class.getDeclaredField(dummyFieldName).getGenericType();
|
||||
} catch(NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
throw new Error("this should never happen. i dont know what you did to make this happen but something is very wrong.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
@@ -2,13 +2,68 @@ package com.dfsek.terra.fabric.block;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Axis;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Half;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
import com.dfsek.terra.api.util.generic.pair.ImmutablePair;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.mixin.access.StateAccessor;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.RailShape;
|
||||
import net.minecraft.block.enums.WallShape;
|
||||
import net.minecraft.block.enums.WireConnection;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import scala.collection.immutable.Stream;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FabricBlockState implements BlockState {
|
||||
private static final Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> PROPERTY_DELEGATES_T2M = Construct.construct(() -> {
|
||||
Map<Property<?>, ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> map = new HashMap<>();
|
||||
map.put(Properties.AXIS, ImmutablePair.of(net.minecraft.state.property.Properties.AXIS, a -> FabricAdapter.adapt((net.minecraft.util.math.Direction.Axis) a)));
|
||||
|
||||
map.put(Properties.NORTH, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH, Function.identity()));
|
||||
map.put(Properties.SOUTH, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH, Function.identity()));
|
||||
map.put(Properties.EAST, ImmutablePair.of(net.minecraft.state.property.Properties.EAST, Function.identity()));
|
||||
map.put(Properties.WEST, ImmutablePair.of(net.minecraft.state.property.Properties.WEST, Function.identity()));
|
||||
|
||||
map.put(Properties.NORTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.SOUTH_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.EAST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.WEST_CONNECTION, ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WIRE_CONNECTION, c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
|
||||
|
||||
map.put(Properties.NORTH_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.NORTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.SOUTH_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.SOUTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.EAST_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.EAST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.WEST_HEIGHT, ImmutablePair.of(net.minecraft.state.property.Properties.WEST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
|
||||
map.put(Properties.DIRECTION, ImmutablePair.of(net.minecraft.state.property.Properties.FACING, d -> FabricAdapter.adapt((Direction) d)));
|
||||
|
||||
map.put(Properties.WATERLOGGED, ImmutablePair.of(net.minecraft.state.property.Properties.WATERLOGGED, Function.identity()));
|
||||
|
||||
map.put(Properties.RAIL_SHAPE, ImmutablePair.of(net.minecraft.state.property.Properties.RAIL_SHAPE, s -> FabricAdapter.adapt((RailShape) s)));
|
||||
|
||||
map.put(Properties.HALF, ImmutablePair.of(net.minecraft.state.property.Properties.BLOCK_HALF, h -> FabricAdapter.adapt((BlockHalf) h)));
|
||||
|
||||
return map;
|
||||
});
|
||||
|
||||
private static final Map<net.minecraft.state.property.Property<?>, Property<?>> PROPERTY_DELEGATES_M2T = Construct.construct(() -> {
|
||||
Map<net.minecraft.state.property.Property<?>, Property<?>> map = new HashMap<>();
|
||||
PROPERTY_DELEGATES_T2M.forEach((p, p2) -> map.put(p2.getLeft(), p));
|
||||
return map;
|
||||
});
|
||||
|
||||
protected net.minecraft.block.BlockState delegate;
|
||||
|
||||
public FabricBlockState(net.minecraft.block.BlockState delegate) {
|
||||
@@ -55,6 +110,24 @@ public class FabricBlockState implements BlockState {
|
||||
return delegate.getBlock() == Blocks.STRUCTURE_VOID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean has(Property<T> property) {
|
||||
return delegate.getProperties().contains(PROPERTY_DELEGATES_T2M.get(property).getLeft());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T get(Property<T> property) {
|
||||
ImmutablePair<net.minecraft.state.property.Property<?>, Function<Object, Object>> pair = PROPERTY_DELEGATES_T2M.get(property);
|
||||
return (T) pair.getRight().apply(delegate.get(pair.getLeft()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> BlockState set(Property<T> property, T value) {
|
||||
//return delegate = delegate.with(PROPERTY_DELEGATES_T2M.get(property), v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.block.BlockState getHandle() {
|
||||
return delegate;
|
||||
|
||||
@@ -2,11 +2,16 @@ package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Half;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.Axis;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.RailShape;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.RedstoneConnection;
|
||||
import com.dfsek.terra.api.block.state.properties.enums.WallHeight;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
import com.dfsek.terra.vector.Vector3Impl;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.WallShape;
|
||||
import net.minecraft.block.enums.WireConnection;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
@@ -23,6 +28,89 @@ public final class FabricAdapter {
|
||||
return new FabricBlockState(state);
|
||||
}
|
||||
|
||||
public static Direction adapt(com.dfsek.terra.api.block.state.properties.enums.Direction direction) {
|
||||
switch(direction) {
|
||||
case SOUTH:
|
||||
return Direction.SOUTH;
|
||||
case NORTH:
|
||||
return Direction.NORTH;
|
||||
case WEST:
|
||||
return Direction.WEST;
|
||||
case EAST:
|
||||
return Direction.EAST;
|
||||
case UP:
|
||||
return Direction.UP;
|
||||
case DOWN:
|
||||
return Direction.DOWN;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public static com.dfsek.terra.api.block.state.properties.enums.Direction adapt(Direction direction) {
|
||||
switch(direction) {
|
||||
case SOUTH:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.SOUTH;
|
||||
case NORTH:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.NORTH;
|
||||
case WEST:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.WEST;
|
||||
case EAST:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.EAST;
|
||||
case UP:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.UP;
|
||||
case DOWN:
|
||||
return com.dfsek.terra.api.block.state.properties.enums.Direction.DOWN;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public static WallHeight adapt(WallShape shape) {
|
||||
switch(shape) {
|
||||
case LOW:
|
||||
return WallHeight.LOW;
|
||||
case NONE:
|
||||
return WallHeight.NONE;
|
||||
case TALL:
|
||||
return WallHeight.TALL;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public static WallShape adapt(WallHeight shape) {
|
||||
switch(shape) {
|
||||
case LOW:
|
||||
return WallShape.LOW;
|
||||
case NONE:
|
||||
return WallShape.NONE;
|
||||
case TALL:
|
||||
return WallShape.TALL;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public static RedstoneConnection adapt(WireConnection connection) {
|
||||
switch(connection) {
|
||||
case NONE:
|
||||
return RedstoneConnection.NONE;
|
||||
case UP:
|
||||
return RedstoneConnection.UP;
|
||||
case SIDE:
|
||||
return RedstoneConnection.SIDE;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public static WireConnection adapt(RedstoneConnection connection) {
|
||||
switch(connection) {
|
||||
case NONE:
|
||||
return WireConnection.NONE;
|
||||
case UP:
|
||||
return WireConnection.UP;
|
||||
case SIDE:
|
||||
return WireConnection.SIDE;
|
||||
}
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
|
||||
public static Half adapt(BlockHalf half) {
|
||||
@@ -47,6 +135,57 @@ public final class FabricAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public static RailShape adapt(net.minecraft.block.enums.RailShape railShape) {
|
||||
switch(railShape) {
|
||||
case EAST_WEST:
|
||||
return RailShape.EAST_WEST;
|
||||
case NORTH_EAST:
|
||||
return RailShape.NORTH_EAST;
|
||||
case NORTH_WEST:
|
||||
return RailShape.NORTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return RailShape.SOUTH_EAST;
|
||||
case SOUTH_WEST:
|
||||
return RailShape.SOUTH_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return RailShape.NORTH_SOUTH;
|
||||
case ASCENDING_EAST:
|
||||
return RailShape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH:
|
||||
return RailShape.ASCENDING_NORTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return RailShape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return RailShape.ASCENDING_WEST;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
public static net.minecraft.block.enums.RailShape adapt(RailShape railShape) {
|
||||
switch(railShape) {
|
||||
case EAST_WEST:
|
||||
return net.minecraft.block.enums.RailShape.EAST_WEST;
|
||||
case NORTH_EAST:
|
||||
return net.minecraft.block.enums.RailShape.NORTH_EAST;
|
||||
case NORTH_WEST:
|
||||
return net.minecraft.block.enums.RailShape.NORTH_WEST;
|
||||
case SOUTH_EAST:
|
||||
return net.minecraft.block.enums.RailShape.SOUTH_EAST;
|
||||
case SOUTH_WEST:
|
||||
return net.minecraft.block.enums.RailShape.SOUTH_WEST;
|
||||
case NORTH_SOUTH:
|
||||
return net.minecraft.block.enums.RailShape.NORTH_SOUTH;
|
||||
case ASCENDING_EAST:
|
||||
return net.minecraft.block.enums.RailShape.ASCENDING_EAST;
|
||||
case ASCENDING_NORTH:
|
||||
return net.minecraft.block.enums.RailShape.ASCENDING_NORTH;
|
||||
case ASCENDING_SOUTH:
|
||||
return net.minecraft.block.enums.RailShape.ASCENDING_SOUTH;
|
||||
case ASCENDING_WEST:
|
||||
return net.minecraft.block.enums.RailShape.ASCENDING_WEST;
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
public static Axis adapt(Direction.Axis axis) {
|
||||
|
||||
Reference in New Issue
Block a user