mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-15 21:31:05 +00:00
add SignBlockEntityMixin
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package com.dfsek.terra.fabric.mixin.implementations.block.state;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.block.state.SerialState;
|
||||||
|
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||||
|
import net.minecraft.block.entity.SignBlockEntity;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
@Mixin(SignBlockEntity.class)
|
||||||
|
@Implements(@Interface(iface = Sign.class, prefix = "terra$"))
|
||||||
|
public abstract class SignBlockEntityMixin {
|
||||||
|
@Shadow
|
||||||
|
public abstract void setTextOnRow(int row, Text text);
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract Text getTextOnRow(int row);
|
||||||
|
|
||||||
|
public @NotNull String[] terra$getLines() {
|
||||||
|
return new String[] {
|
||||||
|
getTextOnRow(0).asString(),
|
||||||
|
getTextOnRow(1).asString(),
|
||||||
|
getTextOnRow(2).asString(),
|
||||||
|
getTextOnRow(3).asString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String terra$getLine(int index) throws IndexOutOfBoundsException {
|
||||||
|
return getTextOnRow(index).asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void terra$setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||||
|
setTextOnRow(index, new LiteralText(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void terra$applyState(String state) {
|
||||||
|
SerialState.parse(state).forEach((k, v) -> {
|
||||||
|
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
|
||||||
|
terra$setLine(Integer.parseInt(k.substring(4)), v);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.Block;
|
|||||||
import com.dfsek.terra.api.platform.block.BlockData;
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.platform.block.state.Container;
|
import com.dfsek.terra.api.platform.block.state.Container;
|
||||||
|
import com.dfsek.terra.api.platform.block.state.Sign;
|
||||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
@@ -26,7 +27,7 @@ public class FabricBlockState implements BlockState {
|
|||||||
|
|
||||||
BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
||||||
if(entity instanceof SignBlockEntity) {
|
if(entity instanceof SignBlockEntity) {
|
||||||
return new FabricSign((SignBlockEntity) entity, worldAccess);
|
return (Sign) entity;
|
||||||
} else if(entity instanceof MobSpawnerBlockEntity) {
|
} else if(entity instanceof MobSpawnerBlockEntity) {
|
||||||
return new FabricMobSpawner((MobSpawnerBlockEntity) entity, worldAccess);
|
return new FabricMobSpawner((MobSpawnerBlockEntity) entity, worldAccess);
|
||||||
} else if(entity instanceof LootableContainerBlockEntity) {
|
} else if(entity instanceof LootableContainerBlockEntity) {
|
||||||
|
|||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
package com.dfsek.terra.fabric.world.block.state;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.platform.block.state.SerialState;
|
|
||||||
import com.dfsek.terra.api.platform.block.state.Sign;
|
|
||||||
import net.minecraft.block.entity.SignBlockEntity;
|
|
||||||
import net.minecraft.text.LiteralText;
|
|
||||||
import net.minecraft.world.WorldAccess;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class FabricSign extends FabricBlockState implements Sign {
|
|
||||||
public FabricSign(SignBlockEntity blockEntity, WorldAccess worldAccess) {
|
|
||||||
super(blockEntity, worldAccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull String[] getLines() {
|
|
||||||
SignBlockEntity sign = (SignBlockEntity) blockEntity;
|
|
||||||
|
|
||||||
return new String[] {
|
|
||||||
sign.getTextOnRow(0).asString(),
|
|
||||||
sign.getTextOnRow(1).asString(),
|
|
||||||
sign.getTextOnRow(2).asString(),
|
|
||||||
sign.getTextOnRow(3).asString()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull String getLine(int index) throws IndexOutOfBoundsException {
|
|
||||||
return ((SignBlockEntity) blockEntity).getTextOnRow(index).asString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
|
||||||
((SignBlockEntity) blockEntity).setTextOnRow(index, new LiteralText(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyState(String state) {
|
|
||||||
SerialState.parse(state).forEach((k, v) -> {
|
|
||||||
if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k);
|
|
||||||
setLine(Integer.parseInt(k.substring(4)), v);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,24 +5,25 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"GeneratorOptionsMixin",
|
"GeneratorOptionsMixin",
|
||||||
|
"implementations.BiomeMixin",
|
||||||
|
"implementations.ChunkGeneratorMixin",
|
||||||
"implementations.block.BlockEntityMixin",
|
"implementations.block.BlockEntityMixin",
|
||||||
"implementations.block.state.LootableContainerBlockEntityMixin",
|
"implementations.block.state.LootableContainerBlockEntityMixin",
|
||||||
|
"implementations.block.state.SignBlockEntityMixin",
|
||||||
|
"implementations.chunk.ChunkRegionMixin",
|
||||||
|
"implementations.chunk.WorldChunkMixin",
|
||||||
|
"implementations.chunk.data.ProtoChunkMixin",
|
||||||
"implementations.entity.EntityMixin",
|
"implementations.entity.EntityMixin",
|
||||||
"implementations.entity.EntityTypeMixin",
|
"implementations.entity.EntityTypeMixin",
|
||||||
"implementations.entity.PlayerEntityMixin",
|
"implementations.entity.PlayerEntityMixin",
|
||||||
"implementations.entity.ServerCommandSourceMixin",
|
"implementations.entity.ServerCommandSourceMixin",
|
||||||
"implementations.inventory.meta.EnchantmentMixin",
|
|
||||||
"implementations.inventory.item.ItemMixin",
|
"implementations.inventory.item.ItemMixin",
|
||||||
|
"implementations.inventory.item.ItemStackMixin",
|
||||||
|
"implementations.inventory.meta.EnchantmentMixin",
|
||||||
"implementations.inventory.meta.ItemStackDamageableMixin",
|
"implementations.inventory.meta.ItemStackDamageableMixin",
|
||||||
"implementations.inventory.meta.ItemStackMetaMixin",
|
"implementations.inventory.meta.ItemStackMetaMixin",
|
||||||
"implementations.inventory.item.ItemStackMixin",
|
|
||||||
"implementations.BiomeMixin",
|
|
||||||
"implementations.ChunkGeneratorMixin",
|
|
||||||
"implementations.chunk.ChunkRegionMixin",
|
|
||||||
"implementations.world.ChunkRegionMixin",
|
"implementations.world.ChunkRegionMixin",
|
||||||
"implementations.chunk.data.ProtoChunkMixin",
|
"implementations.world.ServerWorldMixin"
|
||||||
"implementations.world.ServerWorldMixin",
|
|
||||||
"implementations.chunk.WorldChunkMixin"
|
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"GeneratorTypeAccessor"
|
"GeneratorTypeAccessor"
|
||||||
|
|||||||
Reference in New Issue
Block a user