Skip to content

Commit

Permalink
Halfass a bunch of Forge events
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 30, 2023
1 parent c4026dc commit 3f6a268
Show file tree
Hide file tree
Showing 40 changed files with 497 additions and 197 deletions.
3 changes: 1 addition & 2 deletions src/main/java/vazkii/quark/base/client/config/QButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import vazkii.quark.base.QuarkClient;
import vazkii.zeta.client.TopLayerTooltipHandler;
import vazkii.quark.base.handler.ContributorRewardHandler;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.quark.base.handler.MiscUtil;
Expand Down Expand Up @@ -157,7 +156,7 @@ public void renderButton(@Nonnull PoseStack mstack, int mouseX, int mouseY, floa
if(QuarkClient.ticker.total % 20 > 10)
cy++;

MiscUtil.drawChatBubble(mstack, x + 16, cy, font, I18n.get("quark.misc.configure_quark_here"), alpha, true);
MiscUtil.Client.drawChatBubble(mstack, x + 16, cy, font, I18n.get("quark.misc.configure_quark_here"), alpha, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.resources.language.I18n;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.zeta.client.event.ZScreenInit;
import vazkii.zeta.event.bus.PlayEvent;

public class QButtonHandler {

@SubscribeEvent
public static void onGuiInit(ScreenEvent.Init event) {
@PlayEvent
public static void onGuiInit(ZScreenInit.Pre event) {
Screen gui = event.getScreen();

if(GeneralConfig.enableQButton && (gui instanceof TitleScreen || gui instanceof PauseScreen)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.Slot;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.addons.oddities.client.screen.BackpackInventoryScreen;
import vazkii.quark.api.IQuarkButtonAllowed;
import vazkii.quark.base.Quark;
import vazkii.quark.base.QuarkClient;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.quark.base.handler.InventoryTransferHandler;
import vazkii.zeta.client.event.ZScreenInit;
import vazkii.zeta.client.event.ZScreenKeyPressed;
import vazkii.zeta.client.event.ZScreenMousePressed;
import vazkii.zeta.event.bus.PlayEvent;
import vazkii.zeta.module.ZetaModule;
import vazkii.zeta.client.event.ZKeyMapping;

Expand All @@ -43,8 +45,8 @@ public final class InventoryButtonHandler {
private static final Multimap<ButtonTargetType, ButtonProviderHolder> providers = Multimaps.newSetMultimap(new HashMap<>(), TreeSet::new);
private static final Multimap<ButtonTargetType, Button> currentButtons = Multimaps.newSetMultimap(new HashMap<>(), LinkedHashSet::new);

@SubscribeEvent
public static void initGui(ScreenEvent.Init.Post event) {
@PlayEvent
public static void initGui(ZScreenInit.Post event) {
Minecraft mc = Minecraft.getInstance();
Screen screen = event.getScreen();
if(GeneralConfig.printScreenClassnames) {
Expand Down Expand Up @@ -88,8 +90,8 @@ private static Collection<ButtonProviderHolder> forGui(Screen gui) {
return holders;
}

@SubscribeEvent
public static void mouseInputEvent(ScreenEvent.MouseButtonPressed.Pre pressed) {
@PlayEvent
public static void mouseInputEvent(ZScreenMousePressed.Pre pressed) {
Screen gui = pressed.getScreen();
if (gui instanceof AbstractContainerScreen<?> screen) {
if(!GeneralConfig.isScreenAllowed(screen))
Expand All @@ -108,8 +110,8 @@ public static void mouseInputEvent(ScreenEvent.MouseButtonPressed.Pre pressed) {
}
}

@SubscribeEvent
public static void keyboardInputEvent(ScreenEvent.KeyPressed.Post pressed) {
@PlayEvent
public static void keyboardInputEvent(ZScreenKeyPressed.Pre pressed) {
Screen gui = pressed.getScreen();
if (gui instanceof AbstractContainerScreen<?> screen) {
if(!GeneralConfig.isScreenAllowed(screen))
Expand All @@ -129,7 +131,7 @@ public static void keyboardInputEvent(ScreenEvent.KeyPressed.Post pressed) {

}

private static void applyProviders(ScreenEvent.Init.Post event, ButtonTargetType type, AbstractContainerScreen<?> screen, Predicate<Slot> slotPred) {
private static void applyProviders(ZScreenInit.Post event, ButtonTargetType type, AbstractContainerScreen<?> screen, Predicate<Slot> slotPred) {
Collection<ButtonProviderHolder> holders = providers.get(type);
if(!holders.isEmpty()) {
for(Slot slot : screen.getMenu().slots)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.addons.oddities.client.model.BackpackModel;
import vazkii.quark.base.Quark;
import vazkii.quark.base.client.render.QuarkArmorModel;
Expand All @@ -29,7 +27,10 @@
import vazkii.quark.content.mobs.client.model.StonelingModel;
import vazkii.quark.content.mobs.client.model.ToretoiseModel;
import vazkii.quark.content.mobs.client.model.WraithModel;
import vazkii.zeta.client.event.ZRegisterLayerDefinitions;
import vazkii.zeta.event.bus.LoadEvent;

//TODO ZETA: Move into respective modules so it's not a singleton
public class ModelHandler {

private static final Map<ModelLayerLocation, Layer> layers = new HashMap<>();
Expand Down Expand Up @@ -84,8 +85,8 @@ private static ModelLayerLocation addLayer(String name, Layer layer) {
return loc;
}

@SubscribeEvent
public static void registerLayer(EntityRenderersEvent.RegisterLayerDefinitions event) {
@LoadEvent
public static void registerLayer(ZRegisterLayerDefinitions event) {
initModels();

for(ModelLayerLocation location : layers.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import java.util.Map;

import net.minecraft.ChatFormatting;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.zeta.client.event.ZCustomizeDebugText;
import vazkii.zeta.event.bus.PlayEvent;

public class NetworkProfilingHandler {

Expand All @@ -24,9 +22,8 @@ public static void receive(String name) {
}
}

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void showF3(CustomizeGuiOverlayEvent.DebugText event) {
@PlayEvent
public static void showF3(ZCustomizeDebugText event) {
if(GeneralConfig.enableNetworkProfiling) {
event.getLeft().add("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
import vazkii.quark.base.handler.GeneralConfig;
import vazkii.zeta.Zeta;
import vazkii.zeta.event.ZItemTooltip;
import vazkii.zeta.event.bus.PlayEvent;

public class RequiredModTooltipHandler {

Expand All @@ -40,20 +39,28 @@ public static List<ItemStack> disabledItems() {
.toList();
}

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void onTooltip(ItemTooltipEvent event) {
if(!BLOCKS.isEmpty() && event.getEntity() != null && event.getEntity().level != null) {
for(Block b : BLOCKS.keySet())
ITEMS.put(b.asItem(), BLOCKS.get(b));
BLOCKS.clear();
public static class Client {
private final Zeta z;

public Client(Zeta z) {
this.z = z;
z.playBus.subscribe(this);
}

Item item = event.getItemStack().getItem();
if(ITEMS.containsKey(item)) {
String mod = ITEMS.get(item);
if (!ModList.get().isLoaded(mod)) {
event.getToolTip().add(Component.translatable("quark.misc.mod_disabled", mod).withStyle(ChatFormatting.GRAY));
@PlayEvent
public void onTooltip(ZItemTooltip event) {
if(!BLOCKS.isEmpty() && event.getEntity() != null && event.getEntity().level != null) {
for(Block b : BLOCKS.keySet())
ITEMS.put(b.asItem(), BLOCKS.get(b));
BLOCKS.clear();
}

Item item = event.getItemStack().getItem();
if(ITEMS.containsKey(item)) {
String mod = ITEMS.get(item);
if (!z.isModLoaded(mod)) {
event.getToolTip().add(Component.translatable("quark.misc.mod_disabled", mod).withStyle(ChatFormatting.GRAY));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.Quark;
import vazkii.zeta.client.event.ZRenderPlayer;
import vazkii.zeta.event.ZCommonSetup;
import vazkii.zeta.event.ZPlayerLoggedIn;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.event.bus.PlayEvent;

public class ContributorRewardHandler {

Expand All @@ -55,9 +54,8 @@ public static void init(ZCommonSetup event) {
init();
}

@SubscribeEvent
@OnlyIn(Dist.DEDICATED_SERVER)
public static void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
@PlayEvent
public static void onPlayerJoin(ZPlayerLoggedIn event) {
//refresh the contributor list on login
init();
}
Expand Down Expand Up @@ -131,9 +129,8 @@ public static void getLocalName(ZCommonSetup event) {
name = Minecraft.getInstance().getUser().getName().toLowerCase(Locale.ROOT);
}

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void onRenderPlayer(RenderPlayerEvent.Post event) {
@PlayEvent
public static void onRenderPlayer(ZRenderPlayer.Post event) {
Player player = event.getEntity();
String uuid = player.getUUID().toString();
if(player instanceof AbstractClientPlayer clientPlayer && DEV_UUID.contains(uuid) && !done.contains(uuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier.Builder;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.zeta.event.ZEntityAttributeCreation;
import vazkii.zeta.event.bus.LoadEvent;

public final class EntityAttributeHandler {

Expand All @@ -18,8 +18,8 @@ public static void put(EntityType<? extends LivingEntity> type, Supplier<Builder
attributeSuppliers.put(type, attrSupplier);
}

@SubscribeEvent
public static void onAttributeCreation(EntityAttributeCreationEvent event) {
@LoadEvent
public static void onAttributeCreation(ZEntityAttributeCreation event) {
for(EntityType<? extends LivingEntity> type : attributeSuppliers.keySet()) {
Supplier<Builder> supplier = attributeSuppliers.get(type);
event.put(type, supplier.get().build());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/vazkii/quark/base/handler/FuelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.Quark;
import vazkii.quark.content.building.block.VerticalSlabBlock;
import vazkii.zeta.event.ZFurnaceFuelBurnTime;
import vazkii.zeta.event.ZLoadComplete;
import vazkii.zeta.event.bus.LoadEvent;
import vazkii.zeta.event.bus.PlayEvent;

public class FuelHandler {

Expand Down Expand Up @@ -48,8 +49,8 @@ public static void addAllWoods(ZLoadComplete event) {
}
}

@SubscribeEvent
public static void getFuel(FurnaceFuelBurnTimeEvent event) {
@PlayEvent
public static void getFuel(ZFurnaceFuelBurnTime event) {
Item item = event.getItemStack().getItem();
if(fuelValues.containsKey(item))
event.setBurnTime(fuelValues.get(item));
Expand Down
Loading

0 comments on commit 3f6a268

Please sign in to comment.