Added the spectral clock for tracking the zap apple tree's season and make the zap apple tree cyce faster

This commit is contained in:
Sollace 2024-02-01 21:47:05 +00:00
parent e1f4d77580
commit 8804fa0aba
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
51 changed files with 264 additions and 28 deletions

BIN
assets/spectral_clock_0.xcf Normal file

Binary file not shown.

View file

@ -116,6 +116,7 @@ public interface URenderers {
PolearmRenderer.register(UItems.WOODEN_POLEARM, UItems.STONE_POLEARM, UItems.IRON_POLEARM, UItems.GOLDEN_POLEARM, UItems.DIAMOND_POLEARM, UItems.NETHERITE_POLEARM);
ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("affinity"), (stack, world, entity, seed) -> EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getAffinity().getAlignment() : 0);
ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, new Identifier("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount());
ModelPredicateProviderRegistry.register(Unicopia.id("zap_cycle"), (stack, world, entity, seed) -> UnicopiaClient.getInstance().getZapStageDelta());
ColorProviderRegistry.BLOCK.register(URenderers::getTintedBlockColor, TintedBlock.REGISTRY.stream().toArray(Block[]::new));
ColorProviderRegistry.ITEM.register((stack, i) -> getTintedBlockColor(Block.getBlockFromItem(stack.getItem()).getDefaultState(), null, null, i), TintedBlock.REGISTRY.stream().map(Block::asItem).filter(i -> i != Items.AIR).toArray(Item[]::new));

View file

@ -22,6 +22,7 @@ import com.minelittlepony.unicopia.entity.player.PlayerCamera;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.network.handler.ClientNetworkHandlerImpl;
import com.minelittlepony.unicopia.server.world.WeatherConditions;
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
import com.minelittlepony.unicopia.util.Lerp;
import net.fabricmc.api.ClientModInitializer;
@ -53,6 +54,9 @@ public class UnicopiaClient implements ClientModInitializer {
public final Lerp tangentalSkyAngle = new Lerp(0, true);
public final Lerp skyAngle = new Lerp(0, true);
private ZapAppleStageStore.Stage zapAppleStage = ZapAppleStageStore.Stage.HIBERNATING;
private long zapStageTime;
public static Optional<PlayerCamera> getCamera() {
PlayerEntity player = MinecraftClient.getInstance().player;
@ -84,6 +88,15 @@ public class UnicopiaClient implements ClientModInitializer {
instance = this;
}
public void setZapAppleStage(ZapAppleStageStore.Stage stage, long delta) {
zapAppleStage = stage;
zapStageTime = delta;
}
public float getZapStageDelta() {
return zapAppleStage.getCycleProgress(zapStageTime);
}
public float getSkyAngleDelta(float tickDelta) {
if (MinecraftClient.getInstance().world == null) {
return 0;
@ -135,6 +148,8 @@ public class UnicopiaClient implements ClientModInitializer {
world.setRainGradient(gradient);
world.setThunderGradient(gradient);
}
zapStageTime++;
}
private Float getTargetRainGradient(ClientWorld world, BlockPos pos, float tickDelta) {

View file

@ -56,7 +56,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
dirty = false;
MsgServerResources msg = new MsgServerResources();
server.getWorlds().forEach(world -> {
Channel.SERVER_RESOURCES_SEND.sendToAllPlayers(msg, world);
Channel.SERVER_RESOURCES.sendToAllPlayers(msg, world);
});
}
}

View file

@ -164,6 +164,7 @@ public interface UItems {
Item PALM_BASKET = register("palm_basket", new BasketItem(AirBalloonEntity.BasketType.of(UWoodTypes.PALM_BOAT_TYPE), new Item.Settings().maxCount(1)), ItemGroups.TOOLS);
Item GIANT_BALLOON = register("giant_balloon", new HotAirBalloonItem(new Item.Settings().maxCount(1)), ItemGroups.TOOLS);
Item SPECTRAL_CLOCK = register("spectral_clock", new Item(new Item.Settings()), ItemGroups.TOOLS);
Item LIGHT_GRAY_BED_SHEETS = register(CloudBedBlock.SheetPattern.LIGHT_GRAY);
Item GRAY_BED_SHEETS = register(CloudBedBlock.SheetPattern.GRAY);

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.network;
import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
import com.sollace.fabwork.api.packets.*;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
@ -29,11 +30,12 @@ public interface Channel {
S2CPacketType<MsgSpellbookStateChanged<PlayerEntity>> SERVER_SPELLBOOK_UPDATE = SimpleNetworking.serverToClient(Unicopia.id("server_spellbook_update"), MsgSpellbookStateChanged::new);
C2SPacketType<MsgSpellbookStateChanged<ServerPlayerEntity>> CLIENT_SPELLBOOK_UPDATE = SimpleNetworking.clientToServer(Unicopia.id("client_spellbook_update"), MsgSpellbookStateChanged::new);
S2CPacketType<MsgServerResources> SERVER_RESOURCES_SEND = SimpleNetworking.serverToClient(Unicopia.id("resources_send"), MsgServerResources::new);
S2CPacketType<MsgServerResources> SERVER_RESOURCES = SimpleNetworking.serverToClient(Unicopia.id("resources"), MsgServerResources::new);
S2CPacketType<MsgOtherPlayerCapabilities> SERVER_OTHER_PLAYER_CAPABILITIES = SimpleNetworking.serverToClient(Unicopia.id("other_player_capabilities"), MsgOtherPlayerCapabilities::new);
S2CPacketType<MsgPlayerAnimationChange> SERVER_PLAYER_ANIMATION_CHANGE = SimpleNetworking.serverToClient(Unicopia.id("other_player_animation_change"), MsgPlayerAnimationChange::new);
S2CPacketType<MsgSkyAngle> SERVER_SKY_ANGLE = SimpleNetworking.serverToClient(Unicopia.id("sky_angle"), MsgSkyAngle::new);
S2CPacketType<MsgZapAppleStage> SERVER_ZAP_STAGE = SimpleNetworking.serverToClient(Unicopia.id("zap_stage"), MsgZapAppleStage::new);
static void bootstrap() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
@ -50,8 +52,10 @@ public interface Channel {
Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString());
}
}
sender.sendPacket(SERVER_RESOURCES_SEND.id(), new MsgServerResources().toBuffer());
sender.sendPacket(SERVER_RESOURCES.id(), new MsgServerResources().toBuffer());
sender.sendPacket(SERVER_SKY_ANGLE.id(), new MsgSkyAngle(UnicopiaWorldProperties.forWorld(handler.getPlayer().getServerWorld()).getTangentalSkyAngle()).toBuffer());
ZapAppleStageStore store = ZapAppleStageStore.get(handler.player.getServerWorld());
sender.sendPacket(SERVER_ZAP_STAGE.id(), new MsgZapAppleStage(store.getStage(), store.getStageDelta()).toBuffer());
});
}
}

View file

@ -0,0 +1,23 @@
package com.minelittlepony.unicopia.network;
import com.minelittlepony.unicopia.server.world.ZapAppleStageStore;
import com.sollace.fabwork.api.packets.Packet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
public record MsgZapAppleStage (
ZapAppleStageStore.Stage stage,
long delta
) implements Packet<PlayerEntity> {
public MsgZapAppleStage(PacketByteBuf buffer) {
this(buffer.readEnumConstant(ZapAppleStageStore.Stage.class), buffer.readLong());
}
@Override
public void toBuffer(PacketByteBuf buffer) {
buffer.writeEnumConstant(stage);
buffer.writeLong(delta);
}
}

View file

@ -36,8 +36,9 @@ public class ClientNetworkHandlerImpl {
Channel.SERVER_BLOCK_DESTRUCTION.receiver().addPersistentListener(this::handleBlockDestruction);
Channel.CANCEL_PLAYER_ABILITY.receiver().addPersistentListener(this::handleCancelAbility);
Channel.UNLOCK_TRAITS.receiver().addPersistentListener(this::handleUnlockTraits);
Channel.SERVER_RESOURCES_SEND.receiver().addPersistentListener(this::handleServerResources);
Channel.SERVER_RESOURCES.receiver().addPersistentListener(this::handleServerResources);
Channel.SERVER_SKY_ANGLE.receiver().addPersistentListener(this::handleSkyAngle);
Channel.SERVER_ZAP_STAGE.receiver().addPersistentListener(this::handleZapStage);
Channel.SERVER_PLAYER_ANIMATION_CHANGE.receiver().addPersistentListener(this::handlePlayerAnimation);
Channel.SERVER_REQUEST_PLAYER_LOOK.receiver().addPersistentListener(this::handleCasterLookRequest);
}
@ -93,6 +94,10 @@ public class ClientNetworkHandlerImpl {
UnicopiaClient.getInstance().tangentalSkyAngle.update(packet.tangentalSkyAngle(), 200);
}
private void handleZapStage(PlayerEntity sender, MsgZapAppleStage packet) {
UnicopiaClient.getInstance().setZapAppleStage(packet.stage(), packet.delta());
}
@SuppressWarnings("unchecked")
private void handleServerResources(PlayerEntity sender, MsgServerResources packet) {
SpellTraits.load(packet.traits());

View file

@ -5,6 +5,8 @@ import java.util.stream.StreamSupport;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.MsgZapAppleStage;
import com.minelittlepony.unicopia.particle.LightningBoltParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.util.Tickable;
@ -20,10 +22,13 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.event.GameEvent;
public class ZapAppleStageStore extends PersistentState implements Tickable {
private static final Identifier ID = Unicopia.id("zap_apple_stage");
static final long DAY_LENGTH = World.field_30969;
static final long MOON_PHASES = DimensionType.MOON_SIZES.length;
public static ZapAppleStageStore get(World world) {
return WorldOverlay.getPersistableStorage(world, ID, ZapAppleStageStore::new, ZapAppleStageStore::new);
@ -32,7 +37,9 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
private final World world;
private Stage lastStage = Stage.HIBERNATING;
private int countdown;
private long stageDelta;
private long lastTime;
private boolean stageChanged;
private boolean playedMoonEffect;
private int nextLightningEvent = 1200;
@ -40,8 +47,8 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
ZapAppleStageStore(World world, NbtCompound compound) {
this(world);
lastStage = Stage.VALUES[Math.max(0, compound.getInt("stage")) % Stage.VALUES.length];
stageDelta = compound.getLong("stageDelta");
stageChanged = compound.getBoolean("stageChanged");
countdown = compound.getInt("countdown");
playedMoonEffect = compound.getBoolean("playedMoonEffect");
nextLightningEvent = compound.getInt("nextLightningEvent");
}
@ -55,32 +62,38 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
if (!world.isDay()) {
if (nextLightningEvent > 0) {
nextLightningEvent--;
markDirty();
}
if (!stageChanged && (lastStage != Stage.HIBERNATING || (world.getMoonPhase() == 0))) {
stageChanged = true;
if (countDay()) {
lastStage = lastStage.getNext();
countdown = 1;
stageDelta = 0;
playedMoonEffect = false;
markDirty();
onStageChanged();
}
sendUpdate();
}
} else if (stageChanged) {
stageChanged = false;
markDirty();
}
}
private boolean countDay() {
long timeOfDay = world.getTimeOfDay();
if (stageDelta != 0 && (timeOfDay < lastTime || timeOfDay > lastTime + 10)) {
long timeDifference = timeOfDay - lastTime;
Unicopia.LOGGER.info("Times a changing {}!", timeDifference);
while (timeDifference < 0) {
timeDifference += DAY_LENGTH;
}
stageDelta += timeDifference;
sendUpdate();
}
lastTime = timeOfDay;
stageDelta++;
markDirty();
return countdown-- <= 0;
}
protected void onStageChanged() {
//world.setRainGradient(0.5F);
protected void sendUpdate() {
Channel.SERVER_ZAP_STAGE.sendToAllPlayers(new MsgZapAppleStage(getStage(), stageDelta), world);
}
public void playMoonEffect(BlockPos pos) {
@ -112,7 +125,6 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
/**
* Returns true during nights that the zap apples must change their states.
* @return
*/
public boolean hasStageChanged() {
return stageChanged;
@ -125,30 +137,60 @@ public class ZapAppleStageStore extends PersistentState implements Tickable {
return lastStage;
}
public long getStageDelta() {
return stageDelta;
}
public float getStageProgress() {
return getStage().getStageProgress(getStageDelta());
}
public float getCycleProgress() {
return getStage().getCycleProgress(getStageDelta());
}
@Override
public NbtCompound writeNbt(NbtCompound compound) {
compound.putInt("stage", lastStage.ordinal());
compound.putLong("stageDelta", stageDelta);
compound.putBoolean("stageChanged", stageChanged);
compound.putInt("countdown", countdown);
compound.putBoolean("playedMoonEffect", playedMoonEffect);
compound.putInt("nextLightningEvent", nextLightningEvent);
return compound;
}
public enum Stage implements StringIdentifiable {
HIBERNATING,
GREENING,
FLOWERING,
FRUITING,
RIPE;
HIBERNATING(MOON_PHASES * DAY_LENGTH),
GREENING(DAY_LENGTH),
FLOWERING(DAY_LENGTH),
FRUITING(DAY_LENGTH),
RIPE(DAY_LENGTH);
static final long DAY_LENGTH = 24000;
static final Stage[] VALUES = values();
private final long duration;
Stage(long duration) {
this.duration = duration;
}
public Stage getNext() {
return byId((ordinal() + 1) % VALUES.length);
}
public Stage getPrevious() {
return byId(((ordinal() - 1) + VALUES.length) % VALUES.length);
}
public float getStageProgress(long time) {
return (time % duration) / (float)duration;
}
public float getCycleProgress(long time) {
float ordinal = ordinal();
return MathHelper.lerp(getStageProgress(time), ordinal, ordinal + 1) / 5F;
}
public static Stage byId(int id) {
return VALUES[MathHelper.clamp(id, 0, VALUES.length)];
}

View file

@ -44,6 +44,8 @@
"item.unicopia.palm_chest_boat": "Palm Boat with Chest",
"item.unicopia.spellbook": "Spellbook",
"item.unicopia.spectral_clock": "Spectral Clock",
"emi.category.unicopia.spellbook": "Spellbook",
"emi.category.unicopia.cloud_shaping": "Shaping",
"emi.category.unicopia.growing": "Growing",

View file

@ -0,0 +1,29 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_0"
},
"overrides": [
{ "predicate": { "unicopia:zap_cycle": 0.00}, "model": "unicopia:item/spectral_clock" },
{ "predicate": { "unicopia:zap_cycle": 0.05}, "model": "unicopia:item/spectral_clock_1" },
{ "predicate": { "unicopia:zap_cycle": 0.10}, "model": "unicopia:item/spectral_clock_2" },
{ "predicate": { "unicopia:zap_cycle": 0.15}, "model": "unicopia:item/spectral_clock_3" },
{ "predicate": { "unicopia:zap_cycle": 0.20}, "model": "unicopia:item/spectral_clock_greening_0" },
{ "predicate": { "unicopia:zap_cycle": 0.25}, "model": "unicopia:item/spectral_clock_greening_1" },
{ "predicate": { "unicopia:zap_cycle": 0.30}, "model": "unicopia:item/spectral_clock_greening_2" },
{ "predicate": { "unicopia:zap_cycle": 0.35}, "model": "unicopia:item/spectral_clock_greening_3" },
{ "predicate": { "unicopia:zap_cycle": 0.40}, "model": "unicopia:item/spectral_clock_flowering_0" },
{ "predicate": { "unicopia:zap_cycle": 0.45}, "model": "unicopia:item/spectral_clock_flowering_1" },
{ "predicate": { "unicopia:zap_cycle": 0.50}, "model": "unicopia:item/spectral_clock_flowering_2" },
{ "predicate": { "unicopia:zap_cycle": 0.55}, "model": "unicopia:item/spectral_clock_flowering_3" },
{ "predicate": { "unicopia:zap_cycle": 0.60}, "model": "unicopia:item/spectral_clock_fruiting_0" },
{ "predicate": { "unicopia:zap_cycle": 0.65}, "model": "unicopia:item/spectral_clock_fruiting_1" },
{ "predicate": { "unicopia:zap_cycle": 0.70}, "model": "unicopia:item/spectral_clock_fruiting_2" },
{ "predicate": { "unicopia:zap_cycle": 0.75}, "model": "unicopia:item/spectral_clock_fruiting_3" },
{ "predicate": { "unicopia:zap_cycle": 0.80}, "model": "unicopia:item/spectral_clock_ripe_0" },
{ "predicate": { "unicopia:zap_cycle": 0.85}, "model": "unicopia:item/spectral_clock_ripe_1" },
{ "predicate": { "unicopia:zap_cycle": 0.90}, "model": "unicopia:item/spectral_clock_ripe_2" },
{ "predicate": { "unicopia:zap_cycle": 0.95}, "model": "unicopia:item/spectral_clock_ripe_3" },
{ "predicate": { "unicopia:zap_cycle": 1.00}, "model": "unicopia:item/spectral_clock" }
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_3"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_flowering_0"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_flowering_1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_flowering_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_flowering_3"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_fruiting_0"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_fruiting_1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_fruiting_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_fruiting_3"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_greening_0"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_greening_1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_greening_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_greening_3"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_ripe_0"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_ripe_1"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_ripe_2"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:item/spectral_clock_ripe_3"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB