Skip to content

Commit

Permalink
Merge branch 'zeta120' of https://github.com/VazkiiMods/Quark into ze…
Browse files Browse the repository at this point in the history
…ta120
  • Loading branch information
MehVahdJukaar committed Dec 29, 2023
2 parents 97f6581 + e3ae22f commit 5a80a90
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.Item;

import net.minecraft.world.phys.AABB;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZConfigChanged;
import org.violetmoon.zeta.module.ZetaLoadModule;
Expand All @@ -26,7 +26,12 @@ public final void configChanged(ZConfigChanged event) {
}

public static boolean canPlay(AbstractMinecart cart) {
return !staticEnabled || !cart.level().getBlockState(cart.blockPosition().below()).is(BlockTags.DAMPENS_VIBRATIONS);
if (!staticEnabled)
return true;

AABB bounds = cart.getBoundingBox();
bounds = bounds.move(0, bounds.minY - bounds.maxY, 0);
return cart.level().getBlockStates(bounds).noneMatch((it) -> it.is(BlockTags.DAMPENS_VIBRATIONS));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public void onTick(ZLivingTick event) {
gossips.remove(GossipType.MINOR_POSITIVE);
}

zombie.gossips = manager.store(NbtOps.INSTANCE);

zombie.getPersistentData().putBoolean(TAG_TRADES_ADJUSTED, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ItemSharingModule extends ZetaModule {

@Config(description = "In ticks.")
@Config.Min(0)
private static int cooldown = 5; //TODO: 100 ticks, it's low for testing
private static int cooldown = 100;

@Config
public static boolean renderItemsInChat = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ private boolean tryOpen(Level level, Player player, BlockState state, BlockPos o
BlockHitResult res = new BlockHitResult(new Vec3(otherPos.getX() + 0.5, otherPos.getY() + 0.5, otherPos.getZ() + 0.5), direction, otherPos, false);

if(res.getType() == HitResult.Type.BLOCK) {
boolean eventRes = Quark.ZETA.fireRightClickBlock(player, InteractionHand.MAIN_HAND, otherPos, res);

if(!eventRes) {
InteractionResult interaction = other.use(level, player, InteractionHand.MAIN_HAND, res);
return interaction != InteractionResult.PASS;
}
InteractionResult interaction = other.use(level, player, InteractionHand.MAIN_HAND, res);
return interaction != InteractionResult.PASS;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package org.violetmoon.quark.mixin.mixins.client;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.resources.sounds.MinecartSoundInstance;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.violetmoon.quark.content.client.module.WoolShutsUpMinecartsModule;

@Mixin(MinecartSoundInstance.class)
public class MinecartSoundInstanceMixin {

@Shadow
@Final
private AbstractMinecart minecart;

@ModifyExpressionValue(method = "tick()V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/resources/sounds/MinecartSoundInstance;volume:F", opcode = Opcodes.PUTFIELD))
public float muteIfOnWool(float volumeToSet) {
if (volumeToSet > 0 && !WoolShutsUpMinecartsModule.canPlay(minecart))
return 0;
return volumeToSet;
@WrapOperation(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;getDeltaMovement()Lnet/minecraft/world/phys/Vec3;"))
public Vec3 pretendThereIsNoMovementIfMuted(AbstractMinecart minecart, Operation<Vec3> original) {
if (!WoolShutsUpMinecartsModule.canPlay(minecart))
return Vec3.ZERO;
return original.call(minecart);
}

}
20 changes: 12 additions & 8 deletions src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.item.ZetaBlockItem;
import org.violetmoon.zeta.util.RegisterDynamicUtil;
Expand Down Expand Up @@ -92,8 +89,6 @@ public void registerItem(Item item, String resloc) {
public void registerBlock(Block block, ResourceLocation id, boolean hasBlockItem) {
register(block, id, Registries.BLOCK);

//TODO: this supplier is mostly a load-bearing way to defer calling groups.get(registryName),
// until after CreativeTabHandler.finalizeTabs is called
if(hasBlockItem)
defers.put(Registries.ITEM.location(), () -> createItemBlock(block));
}
Expand Down Expand Up @@ -177,7 +172,14 @@ private <T> ResourceKey<Registry<?>> erase(ResourceKey<? extends Registry<T>> we
return (ResourceKey<Registry<?>>) (Object) weeeejava;
}

//main function - allows accessing the registry, but since it's lazily created, you don't get a Holder containing the object yet...
/**
* Register something to a worldgen registry that requires a `RegistryInfoLookup` to construct.
* You might use this when constructing placed features (which require configuredfeatures), biomes (which require placedfeatures and configuredcarvers), etc.
*
* The returned Holder type is a little odd.
* - We can't return a Holder.Direct, since it's not possible to construct the object yet.
* - We can't return a Holder.Reference, since the registry we're adding the object *to* doesn't even exist yet.
*/
public <T> LateBoundHolder<T> registerDynamicF(Function<RegistryOps.RegistryInfoLookup, T> objCreator, ResourceKey<T> id, ResourceKey<? extends Registry<T>> registry) {
RegisterDynamicUtil.signup(z);

Expand All @@ -195,7 +197,9 @@ public <T> LateBoundHolder<T> registerDynamicF(Function<RegistryOps.RegistryInfo
return registerDynamicF(objCreator, newResourceLocation(regname), registry);
}

//simpler function that just takes the object directly
/**
* Register something to a worldgen registry that can be immediately constructed.
*/
public <T> Holder.Direct<T> registerDynamic(T obj, ResourceKey<T> id, ResourceKey<? extends Registry<T>> registry) {
RegisterDynamicUtil.signup(z);
dynamicDefers.computeIfAbsent(erase(registry), __ -> new ArrayList<>()).add(new DynamicEntry<>(id, __ -> obj, null));
Expand All @@ -217,7 +221,7 @@ public <T> void performDynamicRegistration(RegistryOps.RegistryInfoLookup lookup
if(entries == null || entries.isEmpty())
return;

Quark.ZETA.log.info("Dynamically registering {} thing{} into {}", entries.size(), entries.size() > 1 ? "s" : "", registryKey.location());
z.log.info("Dynamically registering {} thing{} into {}", entries.size(), entries.size() > 1 ? "s" : "", registryKey.location());

List<DynamicEntry<T>> typePun = ((List<DynamicEntry<T>>) (Object) entries);
typePun.forEach(entry -> {
Expand Down
33 changes: 33 additions & 0 deletions zeta-todo/porting-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Thanks for your interest in maintaining a Quark addon into 1.20. Please pardon our dust and let us know if there's something we missed.

## Repackaging

The source code has moved under the `org.violetmoon` organization.

## all this "zeta" stuff?

Zeta is a platform-agnostic modding platform. We are working on a Forge implementation of Zeta, and we are working on implementing Quark in terms of Zeta in order to achieve our goal of creating a Fabric port of Quark.

Zeta aims to be a big framework for writing configurable mods. It ships with a config system and config GUI system, and its event bus is designed with configurability in mind (enabling/disabling modules is baked into the "load bus"/"play bus" distinction). Most of the useful stuff that was in AutoRegLib has moved to Zeta, too.

Zeta is big, but intentionally avoids as much `static` as possible as a way of supporting multiple mods using the library simultaneously. You will not find many singletons in Zeta, and each mod is expected to create and manage their own instances of it. Quark's are under `Quark.ZETA` and `QuarkClient.ZETA_CLIENT`.

## Constructing Quark's blocks

Much like in the AutoRegLib days, Zeta leverages constructor registration for its blocks and items. This is now much more closely tied to the Zeta systems, but you can now pass `null` for any registry-name/module parameters, and Zeta just won't try to register them.

## Dealing with events

If Quark moves away from Forge, obviously we can't use its event bus. Most of the relevant Forge events have been reimplemented.

Events fired into Zeta mods are handled with code at the bottom of `ForgeZeta` that temporarily translates them into Zeta's event system.

If you want to listen to an event fired *from* a Zeta mod, you have two options:

* Engage with the Zeta event bus. You can find this in `Quark.ZETA.loadBus`/`playBus`.
* The event bus itself is very basic and doesn't require you to write "a Zeta mod".
* Zeta's `@LoadEvent` and `@PlayEvent` are the analogs of Forge's `@SubscribeEvent`.
* Subscribing to the event bus works the same as Forge, where passing a `.class` subscribes static methods, and passing an instance of something subscribes non-static methods.
* Certain events get also fired as platform-specific events. See `ForgeZeta.fireExternalEvent`.
* Usually events corresponding to a "public api" go here.
* Listen to these events using the regular platform-specific event bus system.

0 comments on commit 5a80a90

Please sign in to comment.