mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 09:46:24 +00:00
BlockState -> BlockEntity
This commit is contained in:
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
public interface BlockState extends Handle {
|
||||
public interface BlockEntity extends Handle {
|
||||
Vector3 getPosition();
|
||||
|
||||
int getX();
|
||||
@@ -2,5 +2,5 @@ package com.dfsek.terra.api.block.state;
|
||||
|
||||
import com.dfsek.terra.api.inventory.BlockInventoryHolder;
|
||||
|
||||
public interface Container extends BlockState, BlockInventoryHolder {
|
||||
public interface Container extends BlockEntity, BlockInventoryHolder {
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.api.block.state;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MobSpawner extends BlockState {
|
||||
public interface MobSpawner extends BlockEntity {
|
||||
EntityType getSpawnedType();
|
||||
|
||||
void setSpawnedType(@NotNull EntityType creatureType);
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.api.block.state;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface Sign extends BlockState {
|
||||
public interface Sign extends BlockEntity {
|
||||
@NotNull String[] getLines();
|
||||
|
||||
@NotNull String getLine(int index) throws IndexOutOfBoundsException;
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.api.world;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -43,9 +43,9 @@ public interface World extends Handle {
|
||||
setBlockData(position.getBlockX(), position.getBlockY(), position.getBlockZ(), data, physics);
|
||||
}
|
||||
|
||||
BlockState getBlockState(int x, int y, int z);
|
||||
BlockEntity getBlockState(int x, int y, int z);
|
||||
|
||||
default BlockState getBlockState(Vector3 position) {
|
||||
default BlockEntity getBlockState(Vector3 position) {
|
||||
return getBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.Container;
|
||||
import com.dfsek.terra.api.event.events.world.generation.LootPopulateEvent;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
@@ -25,7 +25,7 @@ public class BufferedLootApplication implements BufferedItem {
|
||||
@Override
|
||||
public void paste(Vector3 origin, World world) {
|
||||
try {
|
||||
BlockState data = world.getBlockState(origin);
|
||||
BlockEntity data = world.getBlockState(origin);
|
||||
if(!(data instanceof Container)) {
|
||||
main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container.");
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
@@ -18,7 +18,7 @@ public class BufferedStateManipulator implements BufferedItem {
|
||||
@Override
|
||||
public void paste(Vector3 origin, World world) {
|
||||
try {
|
||||
BlockState state = world.getBlockState(origin);
|
||||
BlockEntity state = world.getBlockState(origin);
|
||||
state.applyState(data);
|
||||
state.update(false);
|
||||
} catch(Exception e) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.commands.structure;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.Sign;
|
||||
import com.dfsek.terra.api.command.CommandTemplate;
|
||||
import com.dfsek.terra.api.command.annotation.Argument;
|
||||
@@ -58,7 +58,7 @@ public class StructureExportCommand implements CommandTemplate {
|
||||
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
|
||||
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
|
||||
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
|
||||
BlockState state = player.world().getBlockState(x, y, z);
|
||||
BlockEntity state = player.world().getBlockState(x, y, z);
|
||||
if(state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) {
|
||||
@@ -77,7 +77,7 @@ public class StructureExportCommand implements CommandTemplate {
|
||||
|
||||
BlockData data = player.world().getBlockData(x, y, z);
|
||||
if(data.isStructureVoid()) continue;
|
||||
BlockState state = player.world().getBlockState(x, y, z);
|
||||
BlockEntity state = player.world().getBlockState(x, y, z);
|
||||
if(state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if(sign.getLine(0).equals("[TERRA]")) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.config.dummy;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -47,7 +47,7 @@ public class DummyWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
public BlockEntity getBlockState(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException("Cannot get block in DummyWorld");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -10,7 +10,7 @@ import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.bukkit.BukkitEntity;
|
||||
import com.dfsek.terra.bukkit.generator.BukkitChunkGenerator;
|
||||
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.block.state.BukkitBlockEntity;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
import java.io.File;
|
||||
@@ -66,8 +66,8 @@ public class BukkitWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
return BukkitBlockState.newInstance(delegate.getBlockAt(x, y, z).getState());
|
||||
public BlockEntity getBlockState(int x, int y, int z) {
|
||||
return BukkitBlockEntity.newInstance(delegate.getBlockAt(x, y, z).getState());
|
||||
}
|
||||
|
||||
public File getWorldFolder() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.bukkit.world.block.state;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
|
||||
@@ -9,18 +9,18 @@ import org.bukkit.block.Container;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
public class BukkitBlockState implements BlockState {
|
||||
public class BukkitBlockEntity implements BlockEntity {
|
||||
private final org.bukkit.block.BlockState delegate;
|
||||
|
||||
protected BukkitBlockState(org.bukkit.block.BlockState block) {
|
||||
protected BukkitBlockEntity(org.bukkit.block.BlockState block) {
|
||||
this.delegate = block;
|
||||
}
|
||||
|
||||
public static BukkitBlockState newInstance(org.bukkit.block.BlockState block) {
|
||||
public static BukkitBlockEntity newInstance(org.bukkit.block.BlockState block) {
|
||||
if(block instanceof Container) return new BukkitContainer((Container) block);
|
||||
if(block instanceof Sign) return new BukkitSign((Sign) block);
|
||||
if(block instanceof CreatureSpawner) return new BukkitMobSpawner((CreatureSpawner) block);
|
||||
return new BukkitBlockState(block);
|
||||
return new BukkitBlockEntity(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -4,7 +4,7 @@ import com.dfsek.terra.api.block.state.Container;
|
||||
import com.dfsek.terra.api.inventory.Inventory;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitInventory;
|
||||
|
||||
public class BukkitContainer extends BukkitBlockState implements Container {
|
||||
public class BukkitContainer extends BukkitBlockEntity implements Container {
|
||||
|
||||
protected BukkitContainer(org.bukkit.block.Container block) {
|
||||
super(block);
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BukkitMobSpawner extends BukkitBlockState implements MobSpawner {
|
||||
public class BukkitMobSpawner extends BukkitBlockEntity implements MobSpawner {
|
||||
protected BukkitMobSpawner(CreatureSpawner block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.api.block.state.Sign;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BukkitSign extends BukkitBlockState implements Sign {
|
||||
public class BukkitSign extends BukkitBlockEntity implements Sign {
|
||||
protected BukkitSign(org.bukkit.block.Sign block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -14,8 +13,8 @@ import org.spongepowered.asm.mixin.Intrinsic;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(BlockEntity.class)
|
||||
@Implements(@Interface(iface = BlockState.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
@Mixin(net.minecraft.block.entity.BlockEntity.class)
|
||||
@Implements(@Interface(iface = BlockEntity.class, prefix = "terra$", remap = Interface.Remap.NONE))
|
||||
public abstract class BlockEntityMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
@@ -52,7 +51,7 @@ public abstract class BlockEntityMixin {
|
||||
}
|
||||
|
||||
public boolean terra$update(boolean applyPhysics) {
|
||||
if(hasWorld()) world.getChunk(pos).setBlockEntity((BlockEntity) (Object) this);
|
||||
if(hasWorld()) world.getChunk(pos).setBlockEntity((net.minecraft.block.entity.BlockEntity) (Object) this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.world;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -58,7 +59,7 @@ public abstract class ChunkRegionMixin {
|
||||
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public com.dfsek.terra.api.block.state.BlockState terraWorld$getBlockState(int x, int y, int z) {
|
||||
public BlockEntity terraWorld$getBlockState(int x, int y, int z) {
|
||||
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.world;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -40,7 +41,7 @@ public abstract class ServerWorldMixin {
|
||||
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public com.dfsek.terra.api.block.state.BlockState terra$getBlockState(int x, int y, int z) {
|
||||
public BlockEntity terra$getBlockState(int x, int y, int z) {
|
||||
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.Container;
|
||||
import com.dfsek.terra.api.block.state.MobSpawner;
|
||||
import com.dfsek.terra.api.block.state.Sign;
|
||||
@@ -13,7 +13,6 @@ import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
@@ -141,8 +140,8 @@ public final class FabricUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockState createState(WorldAccess worldAccess, BlockPos pos) {
|
||||
BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
|
||||
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerBlockEntity) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.platform;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
|
||||
public class DirectBlockState implements BlockState {
|
||||
public class DirectBlockEntity implements BlockEntity {
|
||||
@Override
|
||||
public Vector3 getPosition() {
|
||||
return null;
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.platform;
|
||||
|
||||
import com.dfsek.terra.DirectUtils;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockEntity;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
@@ -67,7 +67,7 @@ public class DirectWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
public BlockEntity getBlockState(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user