Properly implement piglin/hoglin dimension safety

Whether they shake or not is now controlled by the server, as implemented in Java Edition.
This commit is contained in:
Camotoy 2021-12-20 22:54:34 -05:00
parent fd955a66af
commit 4c409f98f3
4 changed files with 12 additions and 5 deletions

View file

@ -29,9 +29,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanE
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.util.DimensionUtils;
import org.geysermc.geyser.session.GeyserSession;
import java.util.UUID;
@ -50,7 +49,7 @@ public class HoglinEntity extends AnimalEntity {
@Override
protected boolean isShaking() {
return (!isImmuneToZombification && !session.getDimension().equals(DimensionUtils.NETHER)) || super.isShaking();
return (!isImmuneToZombification && !session.isDimensionPiglinSafe()) || super.isShaking();
}
@Override

View file

@ -30,7 +30,6 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.DimensionUtils;
import java.util.UUID;
@ -49,6 +48,6 @@ public class BasePiglinEntity extends MonsterEntity {
@Override
protected boolean isShaking() {
return (!isImmuneToZombification && !session.getDimension().equals(DimensionUtils.NETHER)) || super.isShaking();
return (!isImmuneToZombification && !session.isDimensionPiglinSafe()) || super.isShaking();
}
}

View file

@ -302,6 +302,12 @@ public class GeyserSession implements GeyserConnection, CommandSender {
*/
@Setter
private String dimension = DimensionUtils.OVERWORLD;
/**
* Whether piglins and hoglins are safe from conversion in this dimension.
* This controls if they have the shaking effect applied in the dimension.
*/
@Setter
private boolean dimensionPiglinSafe;
@Setter
private int breakingBlock;

View file

@ -265,5 +265,8 @@ public class ChunkUtils {
// Load world coordinate scale for the world border
double coordinateScale = ((Number) dimensionTag.get("coordinate_scale").getValue()).doubleValue();
session.getWorldBorder().setWorldCoordinateScale(coordinateScale);
// Set if piglins/hoglins should shake
session.setDimensionPiglinSafe(((Number) dimensionTag.get("piglin_safe").getValue()).byteValue() != (byte) 0);
}
}