mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 18:39:20 +00:00
方块实体3
This commit is contained in:
@@ -6,7 +6,9 @@ import net.momirealms.craftengine.core.block.entity.BlockEntityType;
|
||||
import net.momirealms.craftengine.core.block.entity.tick.BlockEntityTicker;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface EntityBlockBehavior {
|
||||
|
||||
<T extends BlockEntity> BlockEntityType<T> blockEntityType();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.momirealms.craftengine.core.block.entity;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public final class BlockEntityTypeKeys {
|
||||
private BlockEntityTypeKeys() {}
|
||||
|
||||
public static final Key SIMPLE_STORAGE = Key.of("craftengine:simple_storage");
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
package net.momirealms.craftengine.core.block.entity;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public class BlockEntityTypes {
|
||||
|
||||
public static <T extends BlockEntity> BlockEntityType<T> register(Key id, BlockEntity.Factory<T> factory) {
|
||||
BlockEntityType<T> type = new BlockEntityType<>(id, factory);
|
||||
((WritableRegistry<BlockEntityType<?>>) BuiltInRegistries.BLOCK_ENTITY_TYPE)
|
||||
.register(ResourceKey.create(Registries.BLOCK_ENTITY_TYPE.location(), id), type);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,6 +426,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/safe_block_bottom.png");
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/safe_block_side.png");
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/safe_block_front.png");
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/safe_block_front_open.png");
|
||||
// items
|
||||
plugin.saveResource("resources/default/configuration/items.yml");
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/item/custom/topaz_rod.png");
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package net.momirealms.craftengine.core.plugin.dependency;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class Dependencies {
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ public class MCUtils {
|
||||
return value < (double) truncated ? truncated - 1 : truncated;
|
||||
}
|
||||
|
||||
public static int lerpDiscrete(float delta, int start, int end) {
|
||||
int i = end - start;
|
||||
return start + fastFloor(delta * (float) (i - 1)) + (delta > 0.0F ? 1 : 0);
|
||||
}
|
||||
|
||||
public static int murmurHash3Mixer(int value) {
|
||||
value ^= value >>> 16;
|
||||
value *= -2048144789;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.core.world;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
@@ -15,6 +16,8 @@ import java.util.UUID;
|
||||
|
||||
public interface World {
|
||||
|
||||
CEWorld storageWorld();
|
||||
|
||||
Object platformWorld();
|
||||
|
||||
Object serverWorld();
|
||||
@@ -29,6 +32,10 @@ public interface World {
|
||||
|
||||
void setBlockAt(int x, int y, int z, BlockStateWrapper blockState, int flags);
|
||||
|
||||
default void setBlockAt(int x, int y, int z, ImmutableBlockState blockState, int flags) {
|
||||
this.setBlockAt(x, y, z, blockState.customBlockState(), flags);
|
||||
}
|
||||
|
||||
String name();
|
||||
|
||||
Path directory();
|
||||
|
||||
@@ -65,11 +65,18 @@ public class CEChunk {
|
||||
if (removedBlockEntity != null) {
|
||||
removedBlockEntity.setValid(false);
|
||||
}
|
||||
this.removeBlockEntityTicker(blockPos);
|
||||
}
|
||||
|
||||
public void clearAllBlockEntities() {
|
||||
public void activateAllBlockEntities() {
|
||||
for (BlockEntity blockEntity : this.blockEntities.values()) {
|
||||
blockEntity.setValid(true);
|
||||
replaceOrCreateTickingBlockEntity(blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivateAllBlockEntities() {
|
||||
this.blockEntities.values().forEach(e -> e.setValid(false));
|
||||
this.blockEntities.clear();
|
||||
this.tickingBlockEntitiesByPos.values().forEach((ticker) -> ticker.setTicker(DummyTickingBlockEntity.INSTANCE));
|
||||
this.tickingBlockEntitiesByPos.clear();
|
||||
}
|
||||
@@ -247,13 +254,14 @@ public class CEChunk {
|
||||
public void load() {
|
||||
if (this.loaded) return;
|
||||
this.world.addLoadedChunk(this);
|
||||
this.activateAllBlockEntities();
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
if (!this.loaded) return;
|
||||
this.world.removeLoadedChunk(this);
|
||||
this.clearAllBlockEntities();
|
||||
this.deactivateAllBlockEntities();
|
||||
this.loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.momirealms.craftengine.core.world.collision;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Direction;
|
||||
import net.momirealms.craftengine.core.util.MCUtils;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.EntityHitResult;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -34,6 +36,17 @@ public class AABB {
|
||||
this.maxZ = Math.max(pos1.z, pos2.z);
|
||||
}
|
||||
|
||||
public AABB(BlockPos pos) {
|
||||
this(pos.x(), pos.y(), pos.z(), pos.x() + 1, pos.y() + 1, pos.z() + 1);
|
||||
}
|
||||
|
||||
public double distanceToSqr(Vec3d vec) {
|
||||
double x = Math.max(Math.max(this.minX - vec.x, vec.x - this.maxX), 0.0F);
|
||||
double y = Math.max(Math.max(this.minY - vec.y, vec.y - this.maxY), 0.0F);
|
||||
double z = Math.max(Math.max(this.minZ - vec.z, vec.z - this.maxZ), 0.0F);
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public static AABB fromInteraction(Vec3d pos, double width, double height) {
|
||||
return new AABB(
|
||||
pos.x - width / 2,
|
||||
|
||||
Reference in New Issue
Block a user