mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Balloons now require fuel to run
This commit is contained in:
parent
fbe444b56c
commit
3ff7466a54
1 changed files with 59 additions and 16 deletions
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.entity.mob;
|
||||||
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
|
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
|
import net.minecraft.block.entity.FurnaceBlockEntity;
|
||||||
import net.minecraft.entity.*;
|
import net.minecraft.entity.*;
|
||||||
import net.minecraft.entity.data.*;
|
import net.minecraft.entity.data.*;
|
||||||
import net.minecraft.entity.mob.MobEntity;
|
import net.minecraft.entity.mob.MobEntity;
|
||||||
|
@ -72,6 +73,9 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
private int prevInflation;
|
private int prevInflation;
|
||||||
private Vec3d manualVelocity = Vec3d.ZERO;
|
private Vec3d manualVelocity = Vec3d.ZERO;
|
||||||
|
|
||||||
|
private int maxFuel = 100;
|
||||||
|
private int fuel;
|
||||||
|
|
||||||
public AirBalloonEntity(EntityType<? extends AirBalloonEntity> type, World world) {
|
public AirBalloonEntity(EntityType<? extends AirBalloonEntity> type, World world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
intersectionChecked = true;
|
intersectionChecked = true;
|
||||||
|
@ -174,6 +178,14 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
}
|
}
|
||||||
setInflation(inflation);
|
setInflation(inflation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fuel > -6 && age % 60 == 0) {
|
||||||
|
fuel -= boosting ? 10 : 1;
|
||||||
|
if (fuel <= -6) {
|
||||||
|
setBoostTicks(0);
|
||||||
|
setAscending(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (inflation < getMaxInflation() && inflation > 0) {
|
if (inflation < getMaxInflation() && inflation > 0) {
|
||||||
setInflation(--inflation);
|
setInflation(--inflation);
|
||||||
|
@ -196,15 +208,16 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
if (hasBurner() && isAscending()) {
|
if (hasBurner() && isAscending()) {
|
||||||
Vec3d burnerPos = getPos().add(0, 3, 0);
|
Vec3d burnerPos = getPos().add(0, 3, 0);
|
||||||
for (int i = 0; i < (boosting ? 6 : 1); i++) {
|
for (int i = 0; i < (boosting ? 6 : 1); i++) {
|
||||||
getWorld().addParticle(
|
getWorld().addParticle(fuel <= 0
|
||||||
getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN)
|
? ParticleTypes.SMOKE
|
||||||
|
: getStackInHand(Hand.MAIN_HAND).isOf(Items.SOUL_LANTERN)
|
||||||
? ParticleTypes.SOUL_FIRE_FLAME
|
? ParticleTypes.SOUL_FIRE_FLAME
|
||||||
: ParticleTypes.FLAME,
|
: ParticleTypes.FLAME,
|
||||||
rng.nextTriangular(burnerPos.x, 0.25),
|
rng.nextTriangular(burnerPos.x, 0.25),
|
||||||
rng.nextTriangular(burnerPos.y, 1),
|
rng.nextTriangular(burnerPos.y, 1),
|
||||||
rng.nextTriangular(burnerPos.z, 0.25),
|
rng.nextTriangular(burnerPos.z, 0.25),
|
||||||
0,
|
0,
|
||||||
Math.max(0, getVelocity().y + (boosting ? 0.1 : 0)),
|
(boosting ? 0.1 : 0),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +249,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
if (leashPost.distanceTo(pos) >= 5) {
|
if (leashPost.distanceTo(pos) >= 5) {
|
||||||
Vec3d newVel = leashPost.subtract(pos).multiply(0.01);
|
Vec3d newVel = leashPost.subtract(pos).multiply(0.01);
|
||||||
if (isAirworthy()) {
|
if (isAirworthy()) {
|
||||||
setVelocity(newVel.lengthSquared() < 0.03 ? Vec3d.ZERO : newVel);
|
setVelocity(newVel.lengthSquared() < 0.0001 ? Vec3d.ZERO : newVel);
|
||||||
} else {
|
} else {
|
||||||
setVelocity(getVelocity().multiply(0.9).add(newVel));
|
setVelocity(getVelocity().multiply(0.9).add(newVel));
|
||||||
}
|
}
|
||||||
|
@ -277,11 +290,20 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
if (!getWorld().isClient) {
|
if (!getWorld().isClient) {
|
||||||
manualVelocity = manualVelocity.add(0.3 * xPush, 0, 0.3 * zPush);
|
manualVelocity = manualVelocity.add(0.3 * xPush, 0, 0.3 * zPush);
|
||||||
}
|
}
|
||||||
} else if (stack.isEmpty() && isAscending()) {
|
getWorld().playSound(null, getX() + hitPos.getX(), getY() + hitPos.getY(), getZ() + hitPos.getZ(), USounds.Vanilla.ENTITY_LEASH_KNOT_PLACE, getSoundCategory(), 1, 1);
|
||||||
setBoostTicks(50);
|
|
||||||
if (!player.isSneaky()) {
|
if (!player.isSneaky()) {
|
||||||
getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos());
|
getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos());
|
||||||
}
|
}
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.isEmpty() && isAscending()) {
|
||||||
|
setBoostTicks(50);
|
||||||
|
playSound(USounds.ENTITY_HOT_AIR_BALLOON_BOOST, 1, 1);
|
||||||
|
if (!player.isSneaky()) {
|
||||||
|
getWorld().emitGameEvent(player, GameEvent.ENTITY_INTERACT, getBlockPos());
|
||||||
|
}
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,9 +331,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack.isIn(ConventionalItemTags.SHEARS) && hasBalloon()) {
|
if (stack.isIn(ConventionalItemTags.SHEARS) && hasBalloon()) {
|
||||||
if (!player.getAbilities().creativeMode) {
|
stack.damage(1, player, p -> p.sendToolBreakStatus(hand));
|
||||||
stack.damage(1, player, p -> p.sendToolBreakStatus(hand));
|
|
||||||
}
|
|
||||||
setDesign(BalloonDesign.NONE);
|
setDesign(BalloonDesign.NONE);
|
||||||
dropItem(UItems.GIANT_BALLOON);
|
dropItem(UItems.GIANT_BALLOON);
|
||||||
playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY, 1, 1);
|
playSound(USounds.ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY, 1, 1);
|
||||||
|
@ -336,6 +356,25 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasBurner()) {
|
||||||
|
int fuel = FurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0);
|
||||||
|
if (fuel > 0) {
|
||||||
|
if (this.fuel < maxFuel) {
|
||||||
|
if (this.fuel < 0) {
|
||||||
|
this.fuel = fuel;
|
||||||
|
} else {
|
||||||
|
this.fuel += fuel;
|
||||||
|
}
|
||||||
|
if (!player.getAbilities().creativeMode) {
|
||||||
|
stack.decrement(1);
|
||||||
|
}
|
||||||
|
playSound(USounds.Vanilla.ENTITY_VILLAGER_YES, 1, 1);
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
return ActionResult.FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,13 +513,15 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
public List<Box> getGravityZoneBoxes() {
|
public List<Box> getGravityZoneBoxes() {
|
||||||
Box balloon = getBalloonBoundingBox().expand(0.001);
|
Box balloon = getBalloonBoundingBox().expand(0.001);
|
||||||
Box interior = getInteriorBoundingBox().expand(0.001);
|
Box interior = getInteriorBoundingBox().expand(0.001);
|
||||||
return List.of(
|
if (hasBalloon() && getInflation(1) > 0.999F) {
|
||||||
// interior - basket to top of balloon
|
return List.of(
|
||||||
interior.withMaxY(balloon.minY).withMinY(interior.maxY),
|
// interior - basket to top of balloon
|
||||||
// balloon
|
interior.withMaxY(balloon.minY).withMinY(interior.maxY),
|
||||||
balloon.withMaxY(balloon.maxY + 0.5).withMinY(balloon.maxY)
|
// balloon
|
||||||
);
|
balloon.withMaxY(balloon.maxY + 0.5).withMinY(balloon.maxY)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return List.of(interior.withMaxY(balloon.minY).withMinY(interior.maxY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -570,6 +611,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
setBoostTicks(compound.getInt("boostTicks"));
|
setBoostTicks(compound.getInt("boostTicks"));
|
||||||
prevInflation = compound.getInt("inflationAmount");
|
prevInflation = compound.getInt("inflationAmount");
|
||||||
setInflation(prevInflation);
|
setInflation(prevInflation);
|
||||||
|
fuel = MathHelper.clamp(compound.getInt("fuel"), 0, maxFuel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -580,6 +622,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp
|
||||||
compound.putBoolean("burnerActive", isAscending());
|
compound.putBoolean("burnerActive", isAscending());
|
||||||
compound.putInt("boostTicks", getBoostTicks());
|
compound.putInt("boostTicks", getBoostTicks());
|
||||||
compound.putInt("inflationAmount", getInflation());
|
compound.putInt("inflationAmount", getInflation());
|
||||||
|
compound.putInt("fuel", fuel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isBetween(double value, double min, double max) {
|
static boolean isBetween(double value, double min, double max) {
|
||||||
|
|
Loading…
Reference in a new issue