Skip to content

Commit

Permalink
Boats can now sink or float on bubble columns
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed May 5, 2024
1 parent 687b0bd commit 86803c9
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBubbleColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected AxisAlignedBB recalculateBoundingBox() {
return null;
}

@Override
protected AxisAlignedBB recalculateCollisionBoundingBox() {
return this;
}

@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/cn/nukkit/block/BlockVine.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ public BlockColor getColor() {
return BlockColor.PLANT_BLOCK_COLOR;
}

@Override
public boolean canSilkTouch() {
return true;
}

@Override
public int getBurnChance() {
return 15;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cn/nukkit/entity/data/Skin.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public String getSkinColor() {
}

public void setSkinColor(String skinColor) {
Objects.requireNonNull(skinColor, "skinColor");
this.skinColor = skinColor;
}

Expand All @@ -411,6 +412,7 @@ public String getArmSize() {
}

public void setArmSize(String armSize) {
Objects.requireNonNull(armSize, "armSize");
this.armSize = armSize;
}

Expand Down
112 changes: 102 additions & 10 deletions src/main/java/cn/nukkit/entity/item/EntityBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockWater;
import cn.nukkit.block.BlockBubbleColumn;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityHuman;
import cn.nukkit.entity.EntityID;
import cn.nukkit.entity.EntityLiving;
import cn.nukkit.entity.data.ByteEntityData;
import cn.nukkit.entity.data.FloatEntityData;
import cn.nukkit.entity.data.StringEntityData;
import cn.nukkit.entity.passive.EntityWaterAnimal;
import cn.nukkit.event.entity.EntityDamageByEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
Expand All @@ -23,9 +25,11 @@
import cn.nukkit.math.Vector3f;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.network.protocol.AnimatePacket;
import cn.nukkit.network.protocol.LevelSoundEventPacket;
import cn.nukkit.network.protocol.SetEntityLinkPacket;

import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;

/**
* Created by yescallop on 2016/2/13.
Expand All @@ -35,6 +39,7 @@ public class EntityBoat extends EntityVehicle {
public static final int NETWORK_ID = EntityID.BOAT;

public static final String BUOYANCY_DATA = "{\"apply_gravity\":true,\"base_buoyancy\":1.0,\"big_wave_probability\":0.02999999932944775,\"big_wave_speed\":10.0,\"drag_down_on_buoyancy_removed\":0.0,\"liquid_blocks\":[\"minecraft:water\",\"minecraft:flowing_water\"],\"simulate_waves\":true}";
public static final String BUBBLE_COLUMN_BUOYANCY_DATA = "{\"apply_gravity\":true,\"base_buoyancy\":1.0,\"big_wave_probability\":0.02999999932944775,\"big_wave_speed\":10.0,\"drag_down_on_buoyancy_removed\":0.6999999880790710,\"liquid_blocks\":[\"minecraft:water\",\"minecraft:flowing_water\"],\"simulate_waves\":false}";

public static final Vector3f PASSENGER_OFFSET = new Vector3f(-0.6f, 0, 0);
public static final Vector3f RIDER_PASSENGER_OFFSET = new Vector3f(0.2f, 0, 0);
Expand All @@ -50,7 +55,13 @@ public class EntityBoat extends EntityVehicle {
public static final double SINKING_MAX_SPEED = 0.005;

protected boolean sinking = true;

public int woodID;

protected boolean canRide = true;
protected int bubbleTime;
protected boolean bubbleColumnDown;

private boolean autoMount = true;

public EntityBoat(FullChunk chunk, CompoundTag nbt) {
Expand All @@ -70,9 +81,12 @@ protected void initEntity() {
this.setDataFlag(DATA_FLAG_STACKABLE, true, false);
this.setDataFlag(DATA_FLAG_GRAVITY, true, false);
this.dataProperties.putInt(DATA_VARIANT, woodID = this.namedTag.getByte("woodID"));
this.dataProperties.putByte(DATA_CONTROLLING_SEAT_INDEX, RIDER_INDEX);
// this.dataProperties.putByte(DATA_CONTROLLING_SEAT_INDEX, RIDER_INDEX);
this.dataProperties.putBoolean(DATA_IS_BUOYANT, true);
this.dataProperties.putString(DATA_BUOYANCY_DATA, BUOYANCY_DATA);
this.dataProperties.putFloat(DATA_PADDLE_TIME_LEFT, 0);
this.dataProperties.putFloat(DATA_PADDLE_TIME_RIGHT, 0);
// this.dataProperties.putInt(DATA_BOAT_BUBBLE_TIME, 0); //1.16.100+ do not sync deprecated actor data
}

@Override
Expand Down Expand Up @@ -164,7 +178,7 @@ public boolean onUpdate(int currentTick) {
super.onUpdate(currentTick);

double waterDiff = getWaterLevel();
if (!hasControllingPassenger()) {
if (!hasControllingPassenger() && !getDataFlag(DATA_FLAG_OUT_OF_CONTROL)) {
if (waterDiff > SINKING_DEPTH && !sinking) {
sinking = true;
} else if (waterDiff < 0.05 && sinking) {
Expand Down Expand Up @@ -216,7 +230,7 @@ public boolean onUpdate(int currentTick) {

this.motionX *= friction;

if (!hasControllingPassenger()) {
if (!hasControllingPassenger() && !getDataFlag(DATA_FLAG_OUT_OF_CONTROL)) {
if (waterDiff > SINKING_DEPTH || sinking) {
this.motionY = waterDiff > 0.5 ? this.motionY - this.getGravity() : (this.motionY - SINKING_SPEED < -SINKING_MAX_SPEED ? this.motionY : this.motionY - SINKING_SPEED);
}
Expand All @@ -233,10 +247,73 @@ public boolean onUpdate(int currentTick) {
this.getServer().getPluginManager().callEvent(new VehicleMoveEvent(this, from, to));
}

//TODO: lily pad collision
boolean aboveBubbleColumn = false;
boolean dragDown = false;
for (Block block : getCollisionBlocks()) {
if (block.is(Block.WATERLILY)) {
level.useBreakOn(block, true);
continue;
}

if (!block.is(Block.BUBBLE_COLUMN)) {
continue;
}

if (!aboveBubbleColumn) {
aboveBubbleColumn = true;

if (bubbleTime == 0) {
setDataProperty(new StringEntityData(DATA_BUOYANCY_DATA, BUBBLE_COLUMN_BUOYANCY_DATA));
}
bubbleTime++;

setDataFlag(DATA_FLAG_OUT_OF_CONTROL, true);

ThreadLocalRandom random = ThreadLocalRandom.current();
if (random.nextInt(30) == 0) {
level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_SPLASH, random.nextInt(13000000, 20000000));
}

motionY = 0;
}

if (!dragDown && block.getDamage() == BlockBubbleColumn.DRAG_DOWN_BIT) {
dragDown = true;

if (!bubbleColumnDown) {
bubbleTime = 1;
} else if (bubbleTime > 3 * 20) {
for (Entity passenger : new ArrayList<>(passengers)) {
dismountEntity(passenger);
}

setDataFlag(DATA_FLAG_OUT_OF_CONTROL, false);
setDataProperty(new ByteEntityData(DATA_IS_BUOYANT, false));
setDataProperty(new StringEntityData(DATA_BUOYANCY_DATA, ""));
canRide = false;

motionY = -0.3;
}
}
}
this.bubbleColumnDown = dragDown;
if (!aboveBubbleColumn && bubbleTime > 0) {
bubbleTime = 0;
setDataFlag(DATA_FLAG_OUT_OF_CONTROL, false);
setDataProperty(new ByteEntityData(DATA_IS_BUOYANT, true));
setDataProperty(new StringEntityData(DATA_BUOYANCY_DATA, BUOYANCY_DATA));
if (!canRide) {
move(0, 0.8, 0);
motionY = 0.04;
} else {
motionY = 0;
}
canRide = true;
}

this.updateMovement();

if (this.autoMount && this.passengers.size() < 2) {
if (this.autoMount && canRide() && this.passengers.size() < 2) {
for (Entity entity : this.level.getCollidingEntities(this.boundingBox.grow(0.2, 0, 0.2), this)) {
if (entity.riding != null || isPassenger(entity)) {
continue;
Expand All @@ -247,7 +324,11 @@ public boolean onUpdate(int currentTick) {
// continue;
// }

if (!(entity instanceof EntityLiving) || entity instanceof EntityArmorStand || entity instanceof Player || entity instanceof EntityWaterAnimal) {
if (!(entity instanceof EntityLiving) || entity instanceof EntityArmorStand || entity instanceof EntityHuman || entity instanceof EntityWaterAnimal) {
continue;
}

if (entity.getWidth() > 1.375f && !entity.getDataFlag(DATA_FLAG_BABY)) {
continue;
}

Expand Down Expand Up @@ -336,7 +417,7 @@ public double getWaterLevel() {
public void accept(int x, int y, int z) {
Block block = EntityBoat.this.level.getBlock(x, y, z);

if (block instanceof BlockWater) {
if (block.isWater() || block.is(Block.BUBBLE_COLUMN)) {
double level = block.getMaxY();

diffY = Math.min(maxY - level, diffY);
Expand Down Expand Up @@ -406,6 +487,10 @@ public boolean isControlling(Entity entity) {

@Override
public boolean onInteract(Player player, Item item, Vector3 clickedPos) {
if (!canRide()) {
return false;
}

if (this.passengers.size() >= 2) {
return false;
}
Expand Down Expand Up @@ -524,12 +609,12 @@ public boolean isFull() {

@Override
public boolean canDoInteraction(Player player) {
return !isFull();
return canRide() && !isFull();
}

@Override
public String getInteractButtonText(Player player) {
return !this.isFull() ? "action.interact.ride.boat" : "";
return canRide() && !this.isFull() ? "action.interact.ride.boat" : "";
}

@Override
Expand All @@ -549,4 +634,11 @@ public Vector3f getMountedOffset(Entity entity) {
}
return mobSeatOffset.add(0, entity.getRidingOffset(), 0);
}

protected boolean canRide() {
if (isInsideOfWater() && isInsideOfWater(1)) {
return false;
}
return canRide;
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/item/EntityBoatChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean canDoInteraction(Player player) {

@Override
public String getInteractButtonText(Player player) {
return !this.isFull() && !player.isSneaking() ? "action.interact.ride.boat" : "action.interact.opencontainer";
return canRide() && !this.isFull() && !player.isSneaking() ? "action.interact.ride.boat" : "action.interact.opencontainer";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,6 @@ public void setCurrentSpeed(double speed) {
}

protected void prepareDataProperty() {
setRollingAmplitude(0);
setRollingDirection(1);
if (namedTag.contains("CustomDisplayTile")) {
if (namedTag.getBoolean("CustomDisplayTile")) {
int display = namedTag.getInt("DisplayTile");
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/cn/nukkit/entity/item/EntityVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ public abstract class EntityVehicle extends Entity implements EntityRideable, En
public static final Vector3f MOB_SEAT_OFFSET = new Vector3f(0, -0.2f, 0);
public static final Vector3f PLAYER_SEAT_OFFSET = new Vector3f(0, 1.02001f, 0);

protected boolean rollingDirection = true;

public EntityVehicle(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}

@Override
protected void initEntity() {
super.initEntity();

this.dataProperties.putInt(DATA_HURT_TIME, 0);
this.dataProperties.putInt(DATA_HURT_DIRECTION, 1);
}

public int getRollingAmplitude() {
return this.getDataPropertyInt(DATA_HURT_TIME);
}
Expand Down Expand Up @@ -77,8 +87,6 @@ public boolean onUpdate(int currentTick) {
return true;
}

protected boolean rollingDirection = true;

protected boolean performHurtAnimation() {
setRollingAmplitude(9);
setRollingDirection(rollingDirection ? 1 : -1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/passive/EntityCamel.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public float getHeight() {
public void initEntity() {
super.initEntity();

dataProperties.putByte(DATA_CONTROLLING_SEAT_INDEX, 0);
// dataProperties.putByte(DATA_CONTROLLING_SEAT_INDEX, 0);

inventory = new HorseInventory(this);
inventory.setSize(1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/ItemBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean onActivate(Level level, Player player, Block block, Block target,
}

double y;
if (target.isWater()) {
if (target.isWater() || target.is(Block.BUBBLE_COLUMN)) {
y = block.getY() - 0.375;
} else {
AxisAlignedBB bb = target.getBoundingBox();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/cn/nukkit/item/ItemFullNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,25 @@ public interface ItemFullNames extends ItemBlockNames {
@Deprecated
String RECORD_RELIC = "minecraft:" + ItemNames.RECORD_RELIC;

String MUSIC_DISC_CREATOR = "minecraft:" + ItemNames.MUSIC_DISC_CREATOR;
/**
* @deprecated use {@link #MUSIC_DISC_CREATOR} instead
*/
@Deprecated
String RECORD_CREATOR = "minecraft:" + ItemNames.RECORD_CREATOR;
String MUSIC_DISC_CREATOR_MUSIC_BOX = "minecraft:" + ItemNames.MUSIC_DISC_CREATOR_MUSIC_BOX;
/**
* @deprecated use {@link #MUSIC_DISC_CREATOR_MUSIC_BOX} instead
*/
@Deprecated
String RECORD_CREATOR_MUSIC_BOX = "minecraft:" + ItemNames.RECORD_CREATOR_MUSIC_BOX;
String MUSIC_DISC_PRECIPICE = "minecraft:" + ItemNames.MUSIC_DISC_PRECIPICE;
/**
* @deprecated use {@link #MUSIC_DISC_PRECIPICE} instead
*/
@Deprecated
String RECORD_PRECIPICE = "minecraft:" + ItemNames.RECORD_PRECIPICE;

String SOUL_CAMPFIRE = "minecraft:" + ItemNames.SOUL_CAMPFIRE;

String GLOW_FRAME = "minecraft:" + ItemNames.GLOW_FRAME;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cn/nukkit/item/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ private static void registerSimpleAliases() {
registerAlias(ItemNames.RECORD_RELIC, ItemNames.MUSIC_DISC_RELIC, true, V1_20_0);

registerAlias(ItemNames.SCUTE, ItemNames.TURTLE_SCUTE, V1_20_60);
/*
registerAlias(ItemNames.RECORD_CREATOR, ItemNames.MUSIC_DISC_CREATOR, true, V1_21_0);
registerAlias(ItemNames.RECORD_CREATOR_MUSIC_BOX, ItemNames.MUSIC_DISC_CREATOR_MUSIC_BOX, true, V1_21_0);
registerAlias(ItemNames.RECORD_PRECIPICE, ItemNames.MUSIC_DISC_PRECIPICE, true, V1_21_0);
*/
}

private static void registerComplexAliases() {
Expand Down

0 comments on commit 86803c9

Please sign in to comment.