Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/zeta120' into zeta120
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Dec 29, 2023
2 parents 8d79ce1 + 5a80a90 commit e4faec4
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void tick() {
//convert old pipes
if(convert) {
convert = false;
refreshAllConnections();
refreshVisualConnections();
}
boolean enabled = isPipeEnabled();
if(!enabled && level.getGameTime() % 10 == 0 && level instanceof ServerLevel serverLevel)
Expand Down Expand Up @@ -385,11 +385,11 @@ public void sync() {
MiscUtil.syncTE(this);
}

public void refreshAllConnections() {
public void refreshVisualConnections() {
Arrays.stream(Direction.values()).forEach(this::updateConnection);
}

protected ConnectionType updateConnection(Direction facing) {
public ConnectionType updateConnection(Direction facing) {
var c = computeConnectionTo(level, worldPosition, facing);
connectionsCache[facing.ordinal()] = c;
return c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ public boolean allowsFullConnection(PipeBlockEntity.ConnectionType conn) {
return conn.isSolid;
}

@NotNull
@Override
public InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn, @NotNull BlockPos pos, Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) {
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
ItemStack stack = player.getItemInHand(handIn);

// fix pipes if they're ruined
Expand Down Expand Up @@ -153,10 +152,17 @@ public BlockState mirror(@NotNull BlockState state, @NotNull Mirror mirror) {

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighbor, LevelAccessor level, BlockPos pos, BlockPos neighborPos) {
PipeBlockEntity.ConnectionType type = PipeBlockEntity.computeConnectionTo(level, pos, direction);
state = state.setValue(directionProperty(direction), allowsFullConnection(type));
return state;
}

@Override
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block p_60512_, BlockPos p_60513_, boolean p_60514_) {
super.neighborChanged(state, level, pos, p_60512_, p_60513_, p_60514_);
if(level.getBlockEntity(pos) instanceof PipeBlockEntity tile) {
tile.refreshAllConnections();
tile.refreshVisualConnections();
}
return getTargetState(level, pos);
}

@Override
Expand All @@ -167,11 +173,12 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
if(level.getBlockEntity(pos) instanceof PipeBlockEntity tile) {
tile.refreshAllConnections();
tile.refreshVisualConnections();
}
super.setPlacedBy(level, pos, state, entity, stack);
}

// Update all connections in blockstate
protected BlockState getTargetState(LevelAccessor level, BlockPos pos) {
BlockState newState = defaultBlockState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

import static org.violetmoon.quark.base.handler.MiscUtil.directionProperty;

public class PipeBlock extends BasePipeBlock implements SimpleWaterloggedBlock {
public class CopperPipeBlock extends BasePipeBlock implements SimpleWaterloggedBlock {

private static final VoxelShape CENTER_SHAPE = Shapes.box(0.3125, 0.3125, 0.3125, 0.6875, 0.6875, 0.6875);

Expand All @@ -57,7 +57,7 @@ public class PipeBlock extends BasePipeBlock implements SimpleWaterloggedBlock {

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public PipeBlock(@Nullable ZetaModule module) {
public CopperPipeBlock(@Nullable ZetaModule module) {
super("pipe", module);
}

Expand All @@ -75,7 +75,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play
worldIn.updateNeighborsAt(pos, PipesModule.encasedPipe);

BlockEntity newBe = worldIn.getBlockEntity(pos);
newBe.load(cmp);
if(newBe != null) newBe.load(cmp);
}

SoundType type = Blocks.GLASS.defaultBlockState().getSoundType(worldIn, pos, player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.violetmoon.quark.addons.oddities.block.be.PipeBlockEntity;
import org.violetmoon.quark.addons.oddities.block.pipe.EncasedPipeBlock;
import org.violetmoon.quark.addons.oddities.block.pipe.PipeBlock;
import org.violetmoon.quark.addons.oddities.block.pipe.CopperPipeBlock;
import org.violetmoon.quark.addons.oddities.client.render.be.PipeRenderer;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.config.Config;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class PipesModule extends ZetaModule {

@LoadEvent
public final void register(ZRegister event) {
pipe = new PipeBlock(this);
pipe = new CopperPipeBlock(this);
encasedPipe = new EncasedPipeBlock(this);

blockEntityType = BlockEntityType.Builder.of(PipeBlockEntity::new, pipe, encasedPipe).build(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.violetmoon.quark.content.automation.block.be;

import com.mojang.authlib.GameProfile;

import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.particles.ItemParticleOption;
Expand All @@ -13,31 +11,27 @@
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.DispenserMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;

import org.jetbrains.annotations.NotNull;

import org.jetbrains.annotations.Nullable;
import org.violetmoon.quark.addons.oddities.block.pipe.CopperPipeBlock;
import org.violetmoon.quark.base.handler.MiscUtil;
import org.violetmoon.quark.content.automation.block.FeedingTroughBlock;
import org.violetmoon.quark.content.automation.module.FeedingTroughModule;

import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
* @author WireSegal
Expand Down
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
@@ -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 e4faec4

Please sign in to comment.