Skip to content

Commit

Permalink
Add more options to WorldFixer
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Mar 10, 2024
1 parent c0eedbf commit edfba17
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 55 deletions.
48 changes: 26 additions & 22 deletions src/main/java/cn/nukkit/block/BlockWall.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,7 @@ public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED) {
int oldMeta = getDamage();

//TODO: post and short wall

if (canConnect(getSide(BlockFace.NORTH), BlockFace.SOUTH)) {
setNorthConnectionType(CONNECTION_TYPE_TALL);
} else {
setNorthConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.SOUTH), BlockFace.NORTH)) {
setSouthConnectionType(CONNECTION_TYPE_TALL);
} else {
setSouthConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.WEST), BlockFace.EAST)) {
setWestConnectionType(CONNECTION_TYPE_TALL);
} else {
setWestConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.EAST), BlockFace.WEST)) {
setEastConnectionType(CONNECTION_TYPE_TALL);
} else {
setEastConnectionType(CONNECTION_TYPE_NONE);
}
recalculateConnections();

if (oldMeta != getDamage()) {
level.setBlock(this, this, true);
Expand All @@ -131,6 +110,31 @@ public int onUpdate(int type) {
return 0;
}

public void recalculateConnections() {
//TODO: post and short wall

if (canConnect(getSide(BlockFace.NORTH), BlockFace.SOUTH)) {
setNorthConnectionType(CONNECTION_TYPE_TALL);
} else {
setNorthConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.SOUTH), BlockFace.NORTH)) {
setSouthConnectionType(CONNECTION_TYPE_TALL);
} else {
setSouthConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.WEST), BlockFace.EAST)) {
setWestConnectionType(CONNECTION_TYPE_TALL);
} else {
setWestConnectionType(CONNECTION_TYPE_NONE);
}
if (canConnect(getSide(BlockFace.EAST), BlockFace.WEST)) {
setEastConnectionType(CONNECTION_TYPE_TALL);
} else {
setEastConnectionType(CONNECTION_TYPE_NONE);
}
}

public boolean isPost() {
return (getDamage() & POST_BIT) == POST_BIT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,4 @@ public void setItem(int index, Item item) {
items.add(NBTIO.putItemHelper(item, index));
}
}

public Inventory getRealInventory() {
return getInventory();
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/Entities.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static Class<? extends Entity> registerEntity(int typeId, String identif
}

private static Class<? extends Entity> registerEntity(int typeId, String identifier, String name, Class<? extends Entity> clazz, EntityFactory factory, boolean force) {
if (!Entity.registerEntity(identifier, name, clazz, factory, force)) {
if (!Entity.registerEntity("minecraft:" + identifier, identifier, name, clazz, factory, force)) {
return null;
}
TYPE_TO_IDENTIFIER[typeId] = identifier;
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import cn.nukkit.network.protocol.*;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.potion.Effect;
import cn.nukkit.potion.EffectID;
import cn.nukkit.utils.ChunkException;
import com.google.common.collect.Iterables;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand Down Expand Up @@ -843,6 +842,10 @@ public static boolean registerEntity(String name, Class<? extends Entity> clazz,
}

public static boolean registerEntity(String identifier, String name, Class<? extends Entity> clazz, EntityFactory factory, boolean force) {
return registerEntity(identifier, identifier, name, clazz, factory, force);
}

static boolean registerEntity(String identifier, String shortName, String name, Class<? extends Entity> clazz, EntityFactory factory, boolean force) {
if (clazz == null) {
return false;
}
Expand All @@ -859,8 +862,9 @@ public static boolean registerEntity(String identifier, String name, Class<? ext
entityType = -1;
}

EntityEntry entry = new EntityEntry(clazz, entityType, identifier, name, factory);
EntityEntry entry = new EntityEntry(clazz, entityType, identifier, shortName, name, factory);
BY_NAME.put(name, entry);
BY_NAME.put(shortName, entry);
BY_NAME.put(identifier, entry);
BY_CLASS.put(clazz, entry);
if (entityType != -1) {
Expand Down Expand Up @@ -1034,6 +1038,14 @@ public String getIdentifier() {
return entry.identifier;
}

public String getShortIdentifier() {
EntityEntry entry = BY_CLASS.get(this.getClass());
if (entry == null) {
return ":";
}
return entry.shortName;
}

public final String getSaveId() {
EntityEntry entry = BY_CLASS.get(this.getClass());
if (entry == null) {
Expand Down Expand Up @@ -2665,6 +2677,7 @@ private static class EntityEntry {
Class<? extends Entity> clazz;
int type;
String identifier;
String shortName;
String name;
EntityFactory factory;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/nukkit/entity/item/EntityPainting.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockPlanks;
import cn.nukkit.blockentity.BlockEntityPistonArm;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityHanging;
import cn.nukkit.entity.EntityID;
import cn.nukkit.item.Item;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.GlobalBlockPalette;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockVector3;
Expand Down Expand Up @@ -229,11 +229,11 @@ public void recalculateBoundingBox(boolean send) {
sizeY *= 0.5f;
sizeZ *= 0.5f;

this.boundingBox.setBounds(this.x - sizeX, this.y - sizeY, this.z - sizeZ, this.x + sizeX, this.y + sizeY, this.z + sizeZ);
this.boundingBox.setBounds(this.x - sizeX + (1f / 16 * 0.5 * 0.5), this.y - sizeY + (1f / 16 * 0.5 * 0.5), this.z - sizeZ + (1f / 16 * 0.5 * 0.5), this.x + sizeX - (1f / 16 * 0.5 * 0.5), this.y + sizeY - (1f / 16 * 0.5 * 0.5), this.z + sizeZ - (1f / 16 * 0.5 * 0.5));
}

@Override
protected boolean isSurfaceValid() {
public boolean isSurfaceValid() {
int minX = Mth.floor(this.boundingBox.getMinX());
int minY = Mth.floor(this.boundingBox.getMinY());
int minZ = Mth.floor(this.boundingBox.getMinZ());
Expand Down Expand Up @@ -299,7 +299,7 @@ protected boolean isSurfaceValid() {
@Override
protected void dropItem(Entity entity) {
this.level.addLevelEvent(this, LevelEventPacket.EVENT_SOUND_ITEM_FRAME_REMOVED);
this.level.addLevelEvent(this, LevelEventPacket.EVENT_PARTICLE_DESTROY_BLOCK_NO_SOUND, GlobalBlockPalette.getOrCreateRuntimeId(Block.PLANKS, 0));
this.level.addLevelEvent(this, LevelEventPacket.EVENT_PARTICLE_DESTROY_BLOCK_NO_SOUND, Block.getFullId(Block.PLANKS, BlockPlanks.OAK));

if (!this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cn/nukkit/inventory/InventoryHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public interface InventoryHolder {

Inventory getInventory();

default Inventory getRealInventory() {
return getInventory();
}

default void openInventory(Player player) {
player.addWindow(getInventory());
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cn/nukkit/level/format/ChunkSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ default boolean setBlock(int layer, int x, int y, int z, int blockId) {

boolean isEmpty();

default boolean isEmpty(boolean fast) {
return isEmpty();
}

boolean hasLayer(int layer);

@Deprecated
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/cn/nukkit/level/format/FullChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,36 @@ default boolean isEmpty() {

HeightRange getHeightRange();

/**
* Upgrade wall states to 1.16+ (connected walls)
*/
default void fixWalls() {
fixBlocks(true, false, false);
}

/**
* Remove invalid extra blocks.
*/
default void fixBlockLayers() {
fixBlocks(false, true, false);
}

/**
* Remove invalid block entities and create missing block entities.
*/
default void fixCorruptedBlockEntities() {
fixBlocks(false, false, true);
}

default void fixBlocks() {
fixBlocks(true, true, true);
}

default void fixBlocks(boolean fixWalls, boolean fixBlockLayers, boolean fixBlockEntities) {
fixBlocks(fixWalls, fixBlockLayers, fixBlockEntities, false);
}

default void fixBlocks(boolean fixWalls, boolean fixBlockLayers, boolean fixBlockEntities, boolean emptyContainers) {
}

default boolean fixInvalidBiome() {
Expand Down
Loading

0 comments on commit edfba17

Please sign in to comment.