Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of AttachCapabilitiesEvent #9718

Draft
wants to merge 63 commits into
base: 1.20.x
Choose a base branch
from

Conversation

RealMangorage
Copy link
Contributor

@RealMangorage RealMangorage commented Sep 20, 2023

PR for reworking the AttachCapabillitiesEvent.

Currently in a prototype/testing stage.
What is currently made is not final product. Changes may occur.

Documentation: Proposal (WIP)

We add a new class which handles all event posts for AttachCapabilitiesEvent (Which now extends Event, and not GenericEvent)

> CapabilitySystem.java

CapabilitySystem.addListener(Class<T> yourClassToListenFor, Consumer<AttachCapabilitiesEvent<T>> eventConsumer);

CapabilitySystem.addWrappedListener(Class<T> yourClassToListenFor, Class<W> classYourActuallyGonnaGet Consumer<AttachCapabilitiesEvent<W>> eventConsumer);

Examples:

CapabilitySystem.addListener(Player.class, e -> {}); // This will only be called and supplied with objects that are Player.class or extend Player.class.
 CapabilitySystem.addWrappedListener(ItemStack.class, BlockItem.class, ItemStack::getItem,  (event, item) -> {}); // This will only be called and supplied with objects who use BlockItem.class or extend BlockItem.class, and the objects it returns in this case will be ItemStack. Use .getItem() to get the item or use "item" to get it without needing to cast it.

@autoforge autoforge bot added Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. 1.20 labels Sep 20, 2023
@autoforge autoforge bot requested a review from a team September 20, 2023 07:18
@RealMangorage RealMangorage marked this pull request as draft September 20, 2023 14:09
@Jonathing
Copy link
Member

Relevant conversation from Discord.

protected final BlockPos f_58858_;
protected boolean f_58859_;
private BlockState f_58856_;
-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch change looks wrong to me, looks like this PR added a trivial whitespace change to the patch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Please remove it so we can keep the patch surface as low as possible.

@autoforge autoforge bot added the Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). label Sep 21, 2023
@autoforge
Copy link

autoforge bot commented Sep 21, 2023

@RealMangorage, this pull request has conflicts, please resolve them for this PR to move forward.

@autoforge autoforge bot removed the Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). label Sep 22, 2023
Copy link
Member

@Jonathing Jonathing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

public class CapabilitySystem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bracket on new line, please

public static <T, W> void addWrappedListener(Class<T> type, Class<W> wrappedClass, BiConsumer<AttachCapabilitiesEvent<T>, W> eventConsumer)
{
if (!Item.class.isAssignableFrom(type)) throw new IllegalStateException("Unable to add Listener for Items. Use CapabilitySystem.addListener(Class, Consumer) for non Item related stuff");
LISTENER_LIST.computeIfAbsent(type, (e) -> new ArrayList<>()).add((cls) -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember if lambda brackets also go on new line. @LexManos?

@@ -448,4 +448,4 @@ default boolean shouldUpdateFluidWhileBoating(FluidState state, Boat boat)
{
return boat.shouldUpdateFluidWhileRiding(state, self());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace edit

@@ -10,4 +10,4 @@
public interface IForgeLevelChunk extends ICapabilityProvider
{

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace edit

@@ -1250,5 +1250,4 @@ public static void handleClientConfigurationComplete(Connection connection) {
} else
LOGGER.info("Connected to a modded server.");
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace edit

@@ -174,4 +174,4 @@ public <T> LazyOptional<T> getCapability(@NotNull Capability<T> capability, @Nul
{
return ForgeCapabilities.FLUID_HANDLER_ITEM.orEmpty(capability, holder);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace edit

Comment on lines 56 to 57
if (caps.containsKey(key))
throw new IllegalStateException("Duplicate Capability Key: " + key + " " + cap);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary whitespace edit (unless this is an intentional part of the refactor)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar formatting issues to CapabilitySystem.java. Inconsistent usage of new-line brackets.

Comment on lines 7 to 13
[[mods]]
modId="captest"

[[mods]]
modId="creative_mode_tab_test"

[[mods]]
modId="captest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test mod only needs to be declared in this file once.

@@ -40,26 +42,44 @@ public class CapabilitiesTest
{
public static final String MODID = "capabilities_test";

private static final boolean ENABLED = false;
private static final boolean ENABLED = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to disable this after the PR is out of draft state

Copy link
Member

@Jonathing Jonathing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shit so far. It works a lot better than the horse shit we had before, especially with the explicit class listening. Obviously it needs a lot more testing, but it's headed in the right direction. Like I said in VC, I am happy to help with remedial shit like javadocs and the primer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs javadocs, especially since it looks like modders are going to be interfacing with this.

{
public static final String MOD_ID = "captest";
private static final ConcurrentHashMap<Class<?>, AtomicInteger> TRACK = new ConcurrentHashMap<>();
private static final boolean ENABLED = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to set this to false before marking the PR as ready!

@autoforge autoforge bot added the Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). label Oct 7, 2023
@autoforge
Copy link

autoforge bot commented Oct 7, 2023

@RealMangorage, this pull request has conflicts, please resolve them for this PR to move forward.

@autoforge autoforge bot removed the Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). label Oct 8, 2023
@autoforge autoforge bot added the Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). label Oct 8, 2023
@autoforge
Copy link

autoforge bot commented Oct 8, 2023

@RealMangorage, this pull request has conflicts, please resolve them for this PR to move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.20 Needs Rebase This PR requires a rebase to implement upstream changes (usually to fix merge conflicts). Triage This request requires the active attention of the Triage Team. Requires labelling or reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants