mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
implement BlockState with mixin on Fabric
This commit is contained in:
@@ -85,22 +85,23 @@ public class TerraFlora implements Structure {
|
||||
int size = layers.size();
|
||||
int c = ceiling ? -1 : 1;
|
||||
|
||||
EnumSet<Direction> faces = doRotation ? getFaces(location.mutable().add(0, c, 0).immutable(), world) : EnumSet.noneOf(Direction.class);
|
||||
EnumSet<Direction> faces = doRotation ? getFaces(location.mutable().add(0, c, 0).immutable(), world) : EnumSet.noneOf(
|
||||
Direction.class);
|
||||
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
|
||||
|
||||
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (FastMath.abs(i));
|
||||
BlockState data = getStateCollection((ceiling ? lvl : size - lvl - 1)).get(distribution, location.getX(), location.getY(),
|
||||
location.getZ(), world.getSeed()).clone();
|
||||
location.getZ(), world.getSeed());
|
||||
if(doRotation) {
|
||||
Direction oneFace = new ArrayList<>(faces).get(
|
||||
new Random(location.getX() ^ location.getZ()).nextInt(faces.size())); // Get random face.
|
||||
|
||||
data.setIfPresent(Properties.DIRECTION, oneFace.opposite())
|
||||
.setIfPresent(Properties.NORTH, faces.contains(Direction.NORTH))
|
||||
.setIfPresent(Properties.SOUTH, faces.contains(Direction.SOUTH))
|
||||
.setIfPresent(Properties.EAST, faces.contains(Direction.EAST))
|
||||
.setIfPresent(Properties.WEST, faces.contains(Direction.WEST));
|
||||
data = data.setIfPresent(Properties.DIRECTION, oneFace.opposite())
|
||||
.setIfPresent(Properties.NORTH, faces.contains(Direction.NORTH))
|
||||
.setIfPresent(Properties.SOUTH, faces.contains(Direction.SOUTH))
|
||||
.setIfPresent(Properties.EAST, faces.contains(Direction.EAST))
|
||||
.setIfPresent(Properties.WEST, faces.contains(Direction.WEST));
|
||||
}
|
||||
world.setBlockState(location.mutable().add(0, i + c, 0).immutable(), data, physics);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class BlockFunction implements Function<Void> {
|
||||
@Override
|
||||
public Void apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
BlockState rot = getBlockState(implementationArguments, variableMap).clone();
|
||||
BlockState rot = getBlockState(implementationArguments, variableMap);
|
||||
setBlock(implementationArguments, variableMap, arguments, rot);
|
||||
return null;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class BlockFunction implements Function<Void> {
|
||||
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
|
||||
|
||||
|
||||
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
rot = RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
try {
|
||||
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
y.apply(implementationArguments, variableMap).doubleValue(),
|
||||
|
||||
@@ -48,8 +48,7 @@ public class PullFunction implements Function<Void> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
|
||||
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
|
||||
|
||||
BlockState rot = data.clone();
|
||||
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
BlockState rot = RotationUtil.rotateBlockData(data, arguments.getRotation().inverse());
|
||||
|
||||
Vector3.Mutable mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
|
||||
@@ -14,31 +14,33 @@ import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
|
||||
public interface BlockState extends Cloneable, Handle {
|
||||
public interface BlockState extends Handle {
|
||||
|
||||
boolean matches(BlockState other);
|
||||
|
||||
BlockState clone();
|
||||
<T extends Comparable<T>> boolean has(Property<T> property);
|
||||
|
||||
<T> boolean has(Property<T> property);
|
||||
<T extends Comparable<T>> T get(Property<T> property);
|
||||
|
||||
<T> T get(Property<T> property);
|
||||
<T extends Comparable<T>> BlockState set(Property<T> property, T value);
|
||||
|
||||
<T> BlockState set(Property<T> property, T value);
|
||||
|
||||
default <T> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
|
||||
default <T extends Comparable<T>> BlockState ifProperty(Property<T> property, Consumer<BlockState> action) {
|
||||
if(has(property)) action.accept(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
default <T> BlockState setIfPresent(Property<T> property, T value) {
|
||||
default <T extends Comparable<T>> BlockState setIfPresent(Property<T> property, T value) {
|
||||
if(has(property)) set(property, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BlockType getBlockType();
|
||||
|
||||
String getAsString();
|
||||
default String getAsString() {
|
||||
return getAsString(true);
|
||||
}
|
||||
|
||||
String getAsString(boolean properties);
|
||||
|
||||
boolean isAir();
|
||||
}
|
||||
|
||||
@@ -104,8 +104,8 @@ public final class RotationUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static void rotateBlockData(BlockState data, Rotation r) {
|
||||
data
|
||||
public static BlockState rotateBlockData(BlockState data, Rotation r) {
|
||||
return data
|
||||
.ifProperty(Properties.NORTH, state -> state.set(rotateCardinal(Properties.NORTH, r), state.get(Properties.NORTH)))
|
||||
.ifProperty(Properties.SOUTH, state -> state.set(rotateCardinal(Properties.SOUTH, r), state.get(Properties.SOUTH)))
|
||||
.ifProperty(Properties.EAST, state -> state.set(rotateCardinal(Properties.EAST, r), state.get(Properties.EAST)))
|
||||
|
||||
@@ -46,17 +46,17 @@ public class BukkitBlockState implements BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean has(Property<T> property) {
|
||||
public <T extends Comparable<T>> boolean has(Property<T> property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T get(Property<T> property) {
|
||||
public <T extends Comparable<T>> T get(Property<T> property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> BlockState set(Property<T> property, T value) {
|
||||
public <T extends Comparable<T>> BlockState set(Property<T> property, T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -66,23 +66,12 @@ public class BukkitBlockState implements BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
return delegate.getAsString(false);
|
||||
public String getAsString(boolean properties) {
|
||||
return delegate.getAsString(!properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return delegate.getMaterial().isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitBlockState clone() {
|
||||
try {
|
||||
BukkitBlockState n = (BukkitBlockState) super.clone();
|
||||
n.delegate = delegate.clone();
|
||||
return n;
|
||||
} catch(CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.block;
|
||||
|
||||
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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||
import com.dfsek.terra.api.util.generic.Construct;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.fabric.mixin.access.StateAccessor;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
|
||||
|
||||
public class FabricBlockState implements BlockState {
|
||||
private static final Map<Property<?>, Pair<net.minecraft.state.property.Property<?>, Function<Object, Object>>>
|
||||
PROPERTY_DELEGATES_T2M = Construct.construct(() -> {
|
||||
Map<Property<?>, Pair<net.minecraft.state.property.Property<?>, Function<Object, Object>>> map = new HashMap<>();
|
||||
map.put(Properties.AXIS, Pair.of(net.minecraft.state.property.Properties.AXIS,
|
||||
a -> FabricAdapter.adapt((net.minecraft.util.math.Direction.Axis) a)));
|
||||
|
||||
map.put(Properties.NORTH, Pair.of(net.minecraft.state.property.Properties.NORTH, Function.identity()));
|
||||
map.put(Properties.SOUTH, Pair.of(net.minecraft.state.property.Properties.SOUTH, Function.identity()));
|
||||
map.put(Properties.EAST, Pair.of(net.minecraft.state.property.Properties.EAST, Function.identity()));
|
||||
map.put(Properties.WEST, Pair.of(net.minecraft.state.property.Properties.WEST, Function.identity()));
|
||||
|
||||
map.put(Properties.NORTH_CONNECTION, Pair.of(net.minecraft.state.property.Properties.NORTH_WIRE_CONNECTION,
|
||||
c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.SOUTH_CONNECTION, Pair.of(net.minecraft.state.property.Properties.SOUTH_WIRE_CONNECTION,
|
||||
c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.EAST_CONNECTION, Pair.of(net.minecraft.state.property.Properties.EAST_WIRE_CONNECTION,
|
||||
c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
map.put(Properties.WEST_CONNECTION, Pair.of(net.minecraft.state.property.Properties.WEST_WIRE_CONNECTION,
|
||||
c -> FabricAdapter.adapt((WireConnection) c)));
|
||||
|
||||
|
||||
map.put(Properties.NORTH_HEIGHT,
|
||||
Pair.of(net.minecraft.state.property.Properties.NORTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.SOUTH_HEIGHT,
|
||||
Pair.of(net.minecraft.state.property.Properties.SOUTH_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.EAST_HEIGHT,
|
||||
Pair.of(net.minecraft.state.property.Properties.EAST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
map.put(Properties.WEST_HEIGHT,
|
||||
Pair.of(net.minecraft.state.property.Properties.WEST_WALL_SHAPE, h -> FabricAdapter.adapt((WallShape) h)));
|
||||
|
||||
map.put(Properties.DIRECTION,
|
||||
Pair.of(net.minecraft.state.property.Properties.FACING, d -> FabricAdapter.adapt((Direction) d)));
|
||||
|
||||
map.put(Properties.WATERLOGGED, Pair.of(net.minecraft.state.property.Properties.WATERLOGGED, Function.identity()));
|
||||
|
||||
map.put(Properties.RAIL_SHAPE,
|
||||
Pair.of(net.minecraft.state.property.Properties.RAIL_SHAPE, s -> FabricAdapter.adapt((RailShape) s)));
|
||||
|
||||
map.put(Properties.HALF,
|
||||
Pair.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) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState other) {
|
||||
return delegate.getBlock() == ((FabricBlockState) other).delegate.getBlock();
|
||||
}
|
||||
|
||||
@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) {
|
||||
Pair<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 BlockType getBlockType() {
|
||||
return (BlockType) delegate.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
StringBuilder data = new StringBuilder(Registry.BLOCK.getId(delegate.getBlock()).toString());
|
||||
if(!delegate.getEntries().isEmpty()) {
|
||||
data.append('[');
|
||||
data.append(
|
||||
delegate.getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
|
||||
data.append(']');
|
||||
}
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return delegate.isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState clone() {
|
||||
try {
|
||||
return (FabricBlockState) super.clone();
|
||||
} catch(CloneNotSupportedException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.block.BlockState getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.Chunkified;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.FabricEntryPoint;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
import com.dfsek.terra.fabric.mixin.access.StructureAccessorAccessor;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
@@ -207,7 +206,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView heightmapType) {
|
||||
int height = ((ServerWorld) world).getMaxHeight();
|
||||
while(height >= ((ServerWorld) world).getMinHeight() && !heightmap.getBlockPredicate().test(
|
||||
((FabricBlockState) ((ServerWorld) world).getGenerator().getBlock((ServerWorld) world, x, height - 1, z)).getHandle())) {
|
||||
(BlockState) ((ServerWorld) world).getGenerator().getBlock((ServerWorld) world, x, height - 1, z))) {
|
||||
height--;
|
||||
}
|
||||
return height;
|
||||
@@ -217,8 +216,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
|
||||
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView view) {
|
||||
BlockState[] array = new BlockState[view.getHeight()];
|
||||
for(int y = view.getTopY() - 1; y >= view.getBottomY(); y--) {
|
||||
array[y - view.getBottomY()] = ((FabricBlockState) ((ServerWorld) world).getGenerator().getBlock((ServerWorld) world, x, y,
|
||||
z)).getHandle();
|
||||
array[y - view.getBottomY()] = (BlockState) ((ServerWorld) world).getGenerator().getBlock((ServerWorld) world, x, y, z);
|
||||
}
|
||||
return new VerticalBlockSample(view.getBottomY(), array);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
|
||||
package com.dfsek.terra.fabric.handle;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.command.argument.BlockArgumentParser;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -28,28 +30,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
|
||||
|
||||
public class FabricWorldHandle implements WorldHandle {
|
||||
|
||||
private static final com.dfsek.terra.api.block.state.BlockState AIR = FabricAdapter.adapt(Blocks.AIR.getDefaultState());
|
||||
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();
|
||||
|
||||
@Override
|
||||
public @NotNull FabricBlockState createBlockState(@NotNull String data) {
|
||||
public @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
BlockArgumentParser parser = new BlockArgumentParser(new StringReader(data), true);
|
||||
try {
|
||||
BlockState state = parser.parse(true).getBlockState();
|
||||
net.minecraft.block.BlockState state = parser.parse(true).getBlockState();
|
||||
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
|
||||
return FabricAdapter.adapt(state);
|
||||
return (BlockState) state;
|
||||
} catch(CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.block.state.@NotNull BlockState air() {
|
||||
public @NotNull BlockState air() {
|
||||
return AIR;
|
||||
}
|
||||
|
||||
@@ -59,5 +60,4 @@ public class FabricWorldHandle implements WorldHandle {
|
||||
if(identifier == null) identifier = Identifier.tryParse(id);
|
||||
return (EntityType) Registry.ENTITY_TYPE.get(identifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
||||
import com.dfsek.terra.api.Handle;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
@@ -31,6 +32,7 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
ChunkRegion.class,
|
||||
|
||||
Block.class,
|
||||
BlockState.class,
|
||||
|
||||
BlockEntity.class,
|
||||
LootableContainerBlockEntity.class,
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
@Implements(@Interface(iface = BlockType.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BlockMixin {
|
||||
public com.dfsek.terra.api.block.state.BlockState terra$getDefaultState() {
|
||||
return FabricAdapter.adapt(((Block) (Object) this).getDefaultState());
|
||||
return (com.dfsek.terra.api.block.state.BlockState) ((Block) (Object) this).getDefaultState();
|
||||
}
|
||||
|
||||
public boolean terra$isSolid() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.entity;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -54,6 +54,6 @@ public abstract class BlockEntityMixin {
|
||||
}
|
||||
|
||||
public BlockState terra$getBlockState() {
|
||||
return FabricAdapter.adapt(((net.minecraft.block.entity.BlockEntity) (Object) this).getCachedState());
|
||||
return (BlockState) ((net.minecraft.block.entity.BlockEntity) (Object) this).getCachedState();
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,15 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.entity;
|
||||
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.fabric.mixin.implementations.block.BlockEntityMixin;
|
||||
|
||||
|
||||
@Mixin(LootableContainerBlockEntity.class)
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.entity;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.entity;
|
||||
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||
|
||||
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
import com.dfsek.terra.fabric.mixin.access.StateAccessor;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.block.AbstractBlock.AbstractBlockState;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.State;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Mixin(AbstractBlockState.class)
|
||||
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BlockStateMixin extends State<Block, net.minecraft.block.BlockState> {
|
||||
private BlockStateMixin(Block owner, ImmutableMap<net.minecraft.state.property.Property<?>, Comparable<?>> entries,
|
||||
MapCodec<net.minecraft.block.BlockState> codec) {
|
||||
super(owner, entries, codec);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract Block getBlock();
|
||||
|
||||
@Shadow
|
||||
public abstract boolean isAir();
|
||||
|
||||
@Shadow
|
||||
public abstract void randomTick(ServerWorld world, BlockPos pos, Random random);
|
||||
|
||||
public boolean terra$matches(BlockState other) {
|
||||
return getBlock() == ((net.minecraft.block.BlockState) other).getBlock();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> boolean terra$has(Property<T> property) {
|
||||
if(property instanceof net.minecraft.state.property.Property<?> minecraftProperty) {
|
||||
return contains(minecraftProperty);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> T terra$get(Property<T> property) {
|
||||
return get((net.minecraft.state.property.Property<T>) property);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Intrinsic
|
||||
public <T extends Comparable<T>> BlockState terra$set(Property<T> property, T value) {
|
||||
return (BlockState) with((net.minecraft.state.property.Property<T>) property, value);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public BlockType terra$getBlockType() {
|
||||
return (BlockType) getBlock();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public String terra$getAsString(boolean properties) {
|
||||
StringBuilder data = new StringBuilder(Registry.BLOCK.getId(getBlock()).toString());
|
||||
if(properties && !getEntries().isEmpty()) {
|
||||
data.append('[');
|
||||
data.append(
|
||||
getEntries().entrySet().stream().map(StateAccessor.getPropertyMapPrinter()).collect(Collectors.joining(",")));
|
||||
data.append(']');
|
||||
}
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public boolean terra$isAir() {
|
||||
return isAir();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.state.property.Property.class)
|
||||
public abstract class PropertyMixin<T> implements Property<T> {
|
||||
@Shadow
|
||||
@Final
|
||||
private Class<T> type;
|
||||
|
||||
@Shadow
|
||||
public abstract Collection<T> getValues();
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public Collection<T> values() {
|
||||
return getValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
|
||||
|
||||
@Mixin(ChunkRegion.class)
|
||||
@@ -41,13 +40,12 @@ public abstract class ChunkRegionMixin {
|
||||
|
||||
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockState blockState, boolean physics) {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)),
|
||||
((FabricBlockState) blockState).getHandle(), 0);
|
||||
(net.minecraft.block.BlockState) blockState, 0);
|
||||
}
|
||||
|
||||
public @NotNull BlockState terraChunk$getBlock(int x, int y, int z) {
|
||||
return new FabricBlockState(
|
||||
((ChunkRegion) (Object) this).getBlockState(
|
||||
new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4))));
|
||||
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(
|
||||
new BlockPos(x + (centerPos.getPos().x << 4), y, z + (centerPos.getPos().z << 4)));
|
||||
}
|
||||
|
||||
public int terraChunk$getX() {
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
|
||||
|
||||
@Mixin(WorldChunk.class)
|
||||
@@ -49,16 +48,17 @@ public abstract class WorldChunkMixin {
|
||||
public abstract net.minecraft.block.BlockState setBlockState(BlockPos pos, net.minecraft.block.BlockState state, boolean moved);
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||
setBlockState(new BlockPos(x, y, z), ((FabricBlockState) data).getHandle(), false);
|
||||
setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) data, false);
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockState) blockState).getHandle(),
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
|
||||
false);
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
|
||||
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
|
||||
return (BlockState) getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terra$getX() {
|
||||
|
||||
@@ -21,13 +21,11 @@ import net.minecraft.util.math.BlockPos;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
|
||||
|
||||
@Mixin(net.minecraft.world.chunk.ProtoChunk.class)
|
||||
@@ -37,12 +35,12 @@ public abstract class ProtoChunkMixin {
|
||||
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockState) blockState).getHandle(),
|
||||
((net.minecraft.world.chunk.Chunk) (Object) this).setBlockState(new BlockPos(x, y, z), (net.minecraft.block.BlockState) blockState,
|
||||
false);
|
||||
}
|
||||
|
||||
public @NotNull BlockState terra$getBlock(int x, int y, int z) {
|
||||
return new FabricBlockState(getBlockState(new BlockPos(x, y, z)));
|
||||
return (BlockState) getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
@@ -49,7 +48,6 @@ import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
@@ -94,11 +92,11 @@ public abstract class ChunkRegionMixin {
|
||||
@Intrinsic(displace = true)
|
||||
public void terraWorld$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
((ChunkRegion) (Object) this).setBlockState(pos, ((FabricBlockState) data).getHandle(), physics ? 3 : 1042);
|
||||
if(physics && ((FabricBlockState) data).getHandle().getBlock() instanceof FluidBlock) {
|
||||
((ChunkRegion) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data, physics ? 3 : 1042);
|
||||
if(physics && ((net.minecraft.block.BlockState) data).getBlock() instanceof FluidBlock) {
|
||||
getFluidTickScheduler().scheduleTick(
|
||||
OrderedTick.create(((FluidBlock) ((FabricBlockState) data).getHandle().getBlock()).getFluidState(
|
||||
((FabricBlockState) data).getHandle()).getFluid(), pos));
|
||||
OrderedTick.create(((FluidBlock) ((net.minecraft.block.BlockState) data).getBlock()).getFluidState(
|
||||
(net.minecraft.block.BlockState) data).getFluid(), pos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +112,7 @@ public abstract class ChunkRegionMixin {
|
||||
@Intrinsic(displace = true)
|
||||
public BlockState terraWorld$getBlockState(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlockState(((ChunkRegion) (Object) this).getBlockState(pos));
|
||||
return (BlockState) ((ChunkRegion) (Object) this).getBlockState(pos);
|
||||
}
|
||||
|
||||
public BlockEntity terraWorld$getBlockEntity(int x, int y, int z) {
|
||||
|
||||
@@ -22,7 +22,6 @@ import net.minecraft.server.WorldGenerationProgressListener;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.Spawner;
|
||||
@@ -51,7 +50,6 @@ import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
@@ -94,7 +92,7 @@ public abstract class ServerWorldMixin {
|
||||
|
||||
public void terra$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
((net.minecraft.server.world.ServerWorld) (Object) this).setBlockState(pos, ((FabricBlockState) data).getHandle(),
|
||||
((net.minecraft.server.world.ServerWorld) (Object) this).setBlockState(pos, (net.minecraft.block.BlockState) data,
|
||||
physics ? 3 : 1042);
|
||||
}
|
||||
|
||||
@@ -113,7 +111,7 @@ public abstract class ServerWorldMixin {
|
||||
}
|
||||
|
||||
public BlockState terra$getBlockState(int x, int y, int z) {
|
||||
return new FabricBlockState(((net.minecraft.server.world.ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z)));
|
||||
return (BlockState) ((net.minecraft.server.world.ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public BlockEntity terra$getBlockEntity(int x, int y, int z) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.WallShape;
|
||||
import net.minecraft.block.enums.WireConnection;
|
||||
@@ -30,7 +29,6 @@ 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.util.vector.Vector3;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockState;
|
||||
|
||||
|
||||
public final class FabricAdapter {
|
||||
@@ -42,10 +40,6 @@ public final class FabricAdapter {
|
||||
return Vector3.of(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static FabricBlockState adapt(BlockState state) {
|
||||
return new FabricBlockState(state);
|
||||
}
|
||||
|
||||
public static Direction adapt(com.dfsek.terra.api.block.state.properties.enums.Direction direction) {
|
||||
return switch(direction) {
|
||||
case SOUTH -> Direction.SOUTH;
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
"access.StructureAccessorAccessor",
|
||||
"implementations.BiomeMixin",
|
||||
"implementations.HandleImplementationMixin",
|
||||
"implementations.block.BlockEntityMixin",
|
||||
"implementations.block.BlockMixin",
|
||||
"implementations.block.state.LootableContainerBlockEntityMixin",
|
||||
"implementations.block.state.MobSpawnerBlockEntityMixin",
|
||||
"implementations.block.state.SignBlockEntityMixin",
|
||||
"implementations.block.entity.BlockEntityMixin",
|
||||
"implementations.block.entity.LootableContainerBlockEntityMixin",
|
||||
"implementations.block.entity.MobSpawnerBlockEntityMixin",
|
||||
"implementations.block.entity.SignBlockEntityMixin",
|
||||
"implementations.block.state.BlockStateMixin",
|
||||
"implementations.block.state.PropertyMixin",
|
||||
"implementations.chunk.ChunkRegionMixin",
|
||||
"implementations.chunk.WorldChunkMixin",
|
||||
"implementations.chunk.data.ProtoChunkMixin",
|
||||
|
||||
@@ -42,17 +42,17 @@ public class SpongeBlockState implements BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean has(Property<T> property) {
|
||||
public <T extends Comparable<T>> boolean has(Property<T> property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T get(Property<T> property) {
|
||||
public <T extends Comparable<T>> T get(Property<T> property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> BlockState set(Property<T> property, T value) {
|
||||
public <T extends Comparable<T>> BlockState set(Property<T> property, T value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SpongeBlockState implements BlockState {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString() {
|
||||
public String getAsString(boolean verbose) {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user