Skip to content

Commit

Permalink
Merge branch 'LtxProgrammer:master' into 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
耿悠博 authored Nov 20, 2024
2 parents 11d56d1 + 847c53e commit fd75b18
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 51 deletions.
41 changes: 37 additions & 4 deletions src/main/java/net/ltxprogrammer/changed/Changed.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
import net.ltxprogrammer.changed.network.ChangedPackets;
import net.ltxprogrammer.changed.network.packet.ChangedPacket;
import net.ltxprogrammer.changed.util.PatreonBenefits;
import net.ltxprogrammer.changed.world.ChangedDataFixer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.IEventBusInvokeDispatcher;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand All @@ -33,6 +37,7 @@
import org.apache.logging.log4j.Logger;

import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

Expand All @@ -46,6 +51,7 @@ public class Changed {
public static final Logger LOGGER = LogManager.getLogger(Changed.class);
public static EventHandlerClient eventHandlerClient;
public static ChangedConfig config;
public static ChangedDataFixer dataFixer;

private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel PACKET_HANDLER = NetworkRegistry.newSimpleChannel(modResource(MODID), () -> PROTOCOL_VERSION,
Expand All @@ -56,10 +62,10 @@ public class Changed {
public Changed() {
config = new ChangedConfig(ModLoadingContext.get());

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::customPacks);
MinecraftForge.EVENT_BUS.addListener(this::dataListeners);
addLoadingEventListener(this::commonSetup);
addLoadingEventListener(this::clientSetup);
addLoadingEventListener(this::customPacks);
addEventListener(this::dataListeners);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerClientEventListeners);

PACKETS.registerPackets();
Expand Down Expand Up @@ -92,6 +98,9 @@ public Changed() {
ChangedTransfurVariants.REGISTRY.register(modEventBus);
ChangedEntities.REGISTRY.register(modEventBus);
// ^^^ First to process ^^^

// Our DFU references the above registries, so they need to be initialized before the DFU is created
dataFixer = new ChangedDataFixer();
}

private void commonSetup(final FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -150,4 +159,28 @@ public static ResourceLocation modResource(String path) {
public static String modResourceStr(String path) {
return MODID + ":" + path;
}

public static <T extends Event & IModBusEvent> void addLoadingEventListener(Consumer<T> listener) {
FMLJavaModLoadingContext.get().getModEventBus().addListener(listener);
}

public static <T extends Event & IModBusEvent> boolean postModLoadingEvent(T event) {
return FMLJavaModLoadingContext.get().getModEventBus().post(event);
}

public static <T extends Event & IModBusEvent> boolean postModLoadingEvent(T event, IEventBusInvokeDispatcher dispatcher) {
return FMLJavaModLoadingContext.get().getModEventBus().post(event, dispatcher);
}

public static <T extends Event> void addEventListener(Consumer<T> listener) {
MinecraftForge.EVENT_BUS.addListener(listener);
}

public static <T extends Event> boolean postModEvent(T event) {
return MinecraftForge.EVENT_BUS.post(event);
}

public static <T extends Event> boolean postModEvent(T event, IEventBusInvokeDispatcher dispatcher) {
return MinecraftForge.EVENT_BUS.post(event, dispatcher);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static void randomTick(@NotNull BlockState state, @NotNull ServerLevel le
return;

var event = new AbstractLatexItem.CoveringBlockEvent(latexType, checkState, checkPos, level);
if (MinecraftForge.EVENT_BUS.post(event))
if (Changed.postModEvent(event))
return;
if (event.originalState == event.plannedState)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ltxprogrammer.changed.client;

import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.client.latexparticles.LatexParticleEngine;
import net.ltxprogrammer.changed.client.latexparticles.SetupContext;
import net.ltxprogrammer.changed.client.renderer.blockentity.ChangedBlockEntityWithoutLevelRenderer;
Expand Down Expand Up @@ -28,8 +29,8 @@ public class ChangedClient {
new ChangedBlockEntityWithoutLevelRenderer(minecraft.getBlockEntityRenderDispatcher(), minecraft.getEntityModels());

public static void registerEventListeners() {
MinecraftForge.EVENT_BUS.addListener(ChangedClient::afterRenderStage);
MinecraftForge.EVENT_BUS.addListener(ChangedClient::onClientTick);
Changed.addEventListener(ChangedClient::afterRenderStage);
Changed.addEventListener(ChangedClient::onClientTick);
}

public static void afterRenderStage(RenderLevelStageEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public static void onModelBake(ModelBakeEvent event) {
LOGGER.info("Gathering blocks to cover");

HashSet<RegistryElementPredicate<Block>> notCoverable = new HashSet<>();
MinecraftForge.EVENT_BUS.post(new AbstractLatexItem.GatherNonCoverableBlocksEvent(notCoverable));
Changed.postModEvent(new AbstractLatexItem.GatherNonCoverableBlocksEvent(notCoverable));

List<Block> toCover = ForgeRegistries.BLOCKS.getValues().stream().filter(block -> {
if (!block.getStateDefinition().getProperties().contains(COVERED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.entity.beast.SpecialLatex;
import net.ltxprogrammer.changed.entity.variant.TransfurVariantInstance;
import net.ltxprogrammer.changed.util.Color3;
Expand Down Expand Up @@ -133,9 +134,9 @@ public Optional<Integer> getSectionAt(int mouseX, int mouseY) {

@Override
public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ContainerScreenEvent.DrawBackground(this, ms, mouseX, mouseY));
Changed.postModEvent(new ContainerScreenEvent.DrawBackground(this, ms, mouseX, mouseY));
this.renderBackground(ms);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new ContainerScreenEvent.DrawForeground(this, ms, mouseX, mouseY));
Changed.postModEvent(new ContainerScreenEvent.DrawForeground(this, ms, mouseX, mouseY));
this.renderBg(ms, partialTicks, mouseX, mouseY);

RenderSystem.setShaderColor(1, 1, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.registries.ForgeRegistryEntry;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -321,7 +322,7 @@ public BreatheMode getBreatheMode() {

public boolean rideable() { return this.abilities.contains(ChangedAbilities.ACCESS_SADDLE); }

public static class UniversalAbilitiesEvent extends Event {
public static class UniversalAbilitiesEvent extends Event implements IModBusEvent {
private final List<Function<EntityType<?>, ? extends AbstractAbility<?>>> abilities;

public UniversalAbilitiesEvent(List<Function<EntityType<?>, ? extends AbstractAbility<?>>> abilities) {
Expand Down Expand Up @@ -378,7 +379,7 @@ public Builder(Supplier<EntityType<T>> entityType) {
.and(event.isNotOfTag(ChangedTags.EntityTypes.ARMLESS))
.and(event.isNotOfTag(ChangedTags.EntityTypes.PARTIAL_LATEX)), ChangedAbilities.GRAB_ENTITY_ABILITY);

MinecraftForge.EVENT_BUS.post(event);
Changed.postModLoadingEvent(event);
}

public void ignored() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void addNamespace(String namespace) {
public static synchronized void removeLatexCoveredStates() {
if (!removalCompleted) {
HashSet<RegistryElementPredicate<Block>> notCoverable = new HashSet<>();
MinecraftForge.EVENT_BUS.post(new AbstractLatexItem.GatherNonCoverableBlocksEvent(notCoverable));
Changed.postModEvent(new AbstractLatexItem.GatherNonCoverableBlocksEvent(notCoverable));

ForgeRegistries.BLOCKS.forEach(block -> {
if (!block.getStateDefinition().getProperties().contains(AbstractLatexBlock.COVERED))
Expand Down Expand Up @@ -184,7 +184,7 @@ public InteractionResult useOn(UseOnContext context) {
if (this.getDefaultInstance().is(type.goo.get()))
thisType = type;
var event = new CoveringBlockEvent(thisType, state, context.getClickedPos(), context.getLevel());
if (MinecraftForge.EVENT_BUS.post(event))
if (Changed.postModEvent(event))
return InteractionResult.FAIL;
if (event.originalState == event.plannedState)
return InteractionResult.FAIL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ltxprogrammer.changed.item;

import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.init.ChangedEffects;
import net.ltxprogrammer.changed.init.ChangedItems;
import net.ltxprogrammer.changed.init.ChangedSounds;
Expand Down Expand Up @@ -137,7 +138,7 @@ public UsedOnEntity(LivingEntity entity, Level level, Player player, ItemStack s
@Override
public InteractionResult useOn(UseOnContext context) {
BlockState clickedState = context.getLevel().getBlockState(context.getClickedPos());
return MinecraftForge.EVENT_BUS.post(
return Changed.postModEvent(
new UsedOnBlock(context.getClickedPos(),
clickedState,
context.getLevel(),
Expand All @@ -149,7 +150,7 @@ public InteractionResult useOn(UseOnContext context) {

@Override
public InteractionResult interactLivingEntity(ItemStack itemStack, Player player, LivingEntity livingEntity, InteractionHand hand) {
return MinecraftForge.EVENT_BUS.post(
return Changed.postModEvent(
new UsedOnEntity(livingEntity,
player.level,
player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public UsedOnEntity(LivingEntity entity, Level level, Player player, ItemStack s
@Override
public InteractionResult useOn(UseOnContext context) {
BlockState clickedState = context.getLevel().getBlockState(context.getClickedPos());
if (MinecraftForge.EVENT_BUS.post(
if (Changed.postModEvent(
new UsedOnBlock(context.getClickedPos(),
clickedState,
context.getLevel(),
Expand All @@ -226,7 +226,7 @@ public InteractionResult useOn(UseOnContext context) {

@Override
public InteractionResult interactLivingEntity(ItemStack itemStack, Player player, LivingEntity livingEntity, InteractionHand hand) {
return MinecraftForge.EVENT_BUS.post(
return Changed.postModEvent(
new UsedOnEntity(livingEntity,
player.level,
player,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/ltxprogrammer/changed/item/Syringe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.entity.variant.TransfurVariant;
import net.ltxprogrammer.changed.init.*;
import net.ltxprogrammer.changed.process.Pale;
Expand Down Expand Up @@ -202,7 +203,7 @@ public UsedOnEntity(LivingEntity entity, Level level, Player player, ItemStack s
@Override
public InteractionResult useOn(UseOnContext context) {
BlockState clickedState = context.getLevel().getBlockState(context.getClickedPos());
return MinecraftForge.EVENT_BUS.post(
return Changed.postModEvent(
new UsedOnBlock(context.getClickedPos(),
clickedState,
context.getLevel(),
Expand All @@ -219,7 +220,7 @@ public InteractionResult interactLivingEntity(ItemStack itemStack, Player player
return InteractionResult.sidedSuccess(player.level.isClientSide);
}

return MinecraftForge.EVENT_BUS.post(
return Changed.postModEvent(
new UsedOnEntity(livingEntity,
player.level,
player,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.ltxprogrammer.changed.mixin;

import com.mojang.datafixers.DataFixer;
import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.world.ChangedDataFixer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
Expand All @@ -18,11 +19,15 @@
public abstract class NbtUtilsMixin {
@Inject(method = "update(Lcom/mojang/datafixers/DataFixer;Lnet/minecraft/util/datafix/DataFixTypes;Lnet/minecraft/nbt/CompoundTag;II)Lnet/minecraft/nbt/CompoundTag;", at = @At("RETURN"))
private static void dataFixForChanged(DataFixer dataFixer, DataFixTypes types, CompoundTag tag, int taggedVersion, int loadedVersion, CallbackInfoReturnable<CompoundTag> callback) {
ChangedDataFixer.updateCompoundTag(types, tag);
if (Changed.dataFixer != null)
Changed.dataFixer.updateCompoundTag(types, tag);
}

@Redirect(method = "setValueHelper", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/properties/Property;getValue(Ljava/lang/String;)Ljava/util/Optional;"))
private static <T extends Comparable<T>> Optional<T> getValueAndUpdate(Property<T> instance, String s) {
return instance.getValue(s).or(() -> ChangedDataFixer.updateBlockState(instance, s));
if (Changed.dataFixer != null)
return instance.getValue(s).or(() -> Changed.dataFixer.updateBlockState(instance, s));
else
return instance.getValue(s);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ltxprogrammer.changed.mixin;

import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.world.ChangedDataFixer;
import net.minecraft.SharedConstants;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -23,8 +24,8 @@ public abstract class PrimaryLevelDataMixin {

@Inject(method = "updatePlayerTag", at = @At("RETURN"))
private void updateChangedTag(CallbackInfo callback) {
if (this.playerDataVersion >= SharedConstants.getCurrentVersion().getWorldVersion())
ChangedDataFixer.updateCompoundTag(DataFixTypes.PLAYER, this.loadedPlayerTag);
if (this.playerDataVersion >= SharedConstants.getCurrentVersion().getWorldVersion() && Changed.dataFixer != null)
Changed.dataFixer.updateCompoundTag(DataFixTypes.PLAYER, this.loadedPlayerTag);
}

// FORGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import eu.ha3.presencefootsteps.sound.PFIsolator;
import eu.ha3.presencefootsteps.sound.SoundEngine;
import eu.ha3.presencefootsteps.sound.generator.Locomotion;
import net.ltxprogrammer.changed.Changed;
import net.ltxprogrammer.changed.extension.presencefootsteps.ChangedPresenceFootsteps;
import net.ltxprogrammer.changed.process.ProcessTransfur;
import net.ltxprogrammer.changed.util.EntityUtil;
Expand All @@ -27,7 +28,7 @@ public void reloadEverything(ResourceManager manager, CallbackInfo callbackInfo)
event.loadBlockMap(ChangedPresenceFootsteps.BLOCK_MAP);
event.loadLocomotionMap(ChangedPresenceFootsteps.LOCOMOTION_MAP);

MinecraftForge.EVENT_BUS.post(event);
Changed.postModEvent(event);
}

@Inject(method = "getLocomotion", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ TransfurVariantInstance<?> setPlayerTransfurVariant(Player player, @Nullable Tra
boolean temporaryFromSuit) {
PlayerDataExtension playerDataExtension = (PlayerDataExtension)player;
EntityVariantAssigned event = new EntityVariantAssigned(player, ogVariant, cause);
MinecraftForge.EVENT_BUS.post(event);
Changed.postModEvent(event);
@Nullable TransfurVariant<?> variant = event.variant;

if (ChangedCompatibility.isPlayerUsedByOtherMod(player))
Expand Down Expand Up @@ -423,7 +423,7 @@ TransfurVariantInstance<?> setPlayerTransfurVariant(Player player, @Nullable Tra
}

if (variant != null && !event.isRedundant() && !instance.isTemporaryFromSuit()) {
MinecraftForge.EVENT_BUS.post(new EntityVariantAssigned.ChangedVariant(player, variant, cause));
Changed.postModEvent(new EntityVariantAssigned.ChangedVariant(player, variant, cause));
ChangedFunctionTags.ON_TRANSFUR.execute(ServerLifecycleHooks.getCurrentServer(), player);
}

Expand Down Expand Up @@ -701,7 +701,7 @@ else if (entity instanceof Player player) {
keepConscious = true;
else {
KeepConsciousEvent event = new KeepConsciousEvent(player, keepConscious);
MinecraftForge.EVENT_BUS.post(event);
Changed.postModEvent(event);
keepConscious = event.shouldKeepConscious;
}
}
Expand Down Expand Up @@ -737,7 +737,7 @@ else if (entity instanceof Player player) {

else if (!entity.level.isClientSide) {
EntityVariantAssigned event = new EntityVariantAssigned(entity, variant, context.cause);
MinecraftForge.EVENT_BUS.post(event);
Changed.postModEvent(event);
if (event.variant != null)
onReplicate.accept(event.variant.replaceEntity(entity, context.source), event.variant);
}
Expand Down Expand Up @@ -781,7 +781,7 @@ else if (!entity.level.isClientSide) {

else if (!entity.level.isClientSide) {
EntityVariantAssigned event = new EntityVariantAssigned(entity, fusion, context.cause);
MinecraftForge.EVENT_BUS.post(event);
Changed.postModEvent(event);
if (event.variant != null)
event.variant.replaceEntity(entity, context.source);
}
Expand Down
Loading

0 comments on commit fd75b18

Please sign in to comment.