mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
start work on state mixins
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package com.dfsek.terra.fabric.mixin.block;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.block.Block;
|
||||||
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
|
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||||
|
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||||
|
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
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(BlockEntity.class)
|
||||||
|
@Implements(@Interface(iface = BlockState.class, prefix = "terra$"))
|
||||||
|
public abstract class BlockEntityMixin {
|
||||||
|
@Shadow
|
||||||
|
protected BlockPos pos;
|
||||||
|
@Shadow
|
||||||
|
@Nullable
|
||||||
|
protected World world;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract net.minecraft.block.BlockState getCachedState();
|
||||||
|
|
||||||
|
public Object terra$getHandle() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block terra$getBlock() {
|
||||||
|
return new FabricBlock(pos, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int terra$getX() {
|
||||||
|
return pos.getX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int terra$getY() {
|
||||||
|
return pos.getY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int terra$getZ() {
|
||||||
|
return pos.getZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockData terra$getBlockData() {
|
||||||
|
return FabricAdapter.adapt(getCachedState());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean terra$update(boolean applyPhysics) {
|
||||||
|
world.getChunk(pos).setBlockEntity(pos, (BlockEntity) (Object) this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.dfsek.terra.fabric.mixin.block;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.platform.block.state.Container;
|
||||||
|
import com.dfsek.terra.api.platform.inventory.Inventory;
|
||||||
|
import com.dfsek.terra.fabric.inventory.FabricInventory;
|
||||||
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
|
@Mixin(LootableContainerBlockEntity.class)
|
||||||
|
@Implements(@Interface(iface = Container.class, prefix = "terra$"))
|
||||||
|
public abstract class LootableContainerBlockEntityMixin extends BlockEntityMixin {
|
||||||
|
public Inventory terra$getInventory() {
|
||||||
|
return new FabricInventory(((LootableContainerBlockEntity) (Object) this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object terra$getHandle() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -3,6 +3,7 @@ package com.dfsek.terra.fabric.world.block.state;
|
|||||||
import com.dfsek.terra.api.platform.block.Block;
|
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.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;
|
||||||
@@ -20,7 +21,7 @@ public class FabricBlockState implements BlockState {
|
|||||||
this.worldAccess = worldAccess;
|
this.worldAccess = worldAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FabricBlockState newInstance(Block block) {
|
public static BlockState newInstance(Block block) {
|
||||||
WorldAccess worldAccess = (WorldAccess) block.getLocation().getWorld();
|
WorldAccess worldAccess = (WorldAccess) block.getLocation().getWorld();
|
||||||
|
|
||||||
BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
||||||
@@ -29,7 +30,7 @@ public class FabricBlockState implements BlockState {
|
|||||||
} 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) {
|
||||||
return new FabricContainer((LootableContainerBlockEntity) entity, worldAccess);
|
return (Container) entity;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package com.dfsek.terra.fabric.world.block.state;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.platform.block.state.Container;
|
|
||||||
import com.dfsek.terra.api.platform.inventory.Inventory;
|
|
||||||
import com.dfsek.terra.fabric.inventory.FabricInventory;
|
|
||||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
|
||||||
import net.minecraft.world.WorldAccess;
|
|
||||||
|
|
||||||
public class FabricContainer extends FabricBlockState implements Container {
|
|
||||||
public FabricContainer(LootableContainerBlockEntity blockEntity, WorldAccess worldAccess) {
|
|
||||||
super(blockEntity, worldAccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
return new FabricInventory(((LootableContainerBlockEntity) blockEntity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinGeneratorOptions",
|
"MixinGeneratorOptions",
|
||||||
|
"block.BlockEntityMixin",
|
||||||
|
"block.LootableContainerBlockEntityMixin",
|
||||||
"entity.EntityMixin",
|
"entity.EntityMixin",
|
||||||
"entity.EntityTypeMixin",
|
"entity.EntityTypeMixin",
|
||||||
"entity.PlayerEntityMixin",
|
"entity.PlayerEntityMixin",
|
||||||
|
|||||||
Reference in New Issue
Block a user