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

Add TransferVariant.getComponentMap() #4074

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Objects;

import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;

/**
* An immutable association of an immutable object instance (for example {@code Item} or {@code Fluid}) and data components.
Expand Down Expand Up @@ -47,6 +48,11 @@ public interface TransferVariant<O> {
*/
ComponentChanges getComponents();

/**
* @return The {@link ComponentMap} of this variant.
*/
ComponentMap getComponentMap();

/**
* Return true if this variant has a component changes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.ComponentMapImpl;
import net.minecraft.fluid.FlowableFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
Expand Down Expand Up @@ -63,11 +65,13 @@ public static FluidVariant of(RegistryEntry<Fluid> fluid, ComponentChanges compo

private final Fluid fluid;
private final ComponentChanges components;
private final ComponentMap componentMap;
private final int hashCode;

public FluidVariantImpl(Fluid fluid, ComponentChanges components) {
this.fluid = fluid;
this.components = components;
this.componentMap = components == ComponentChanges.EMPTY ? ComponentMap.EMPTY : ComponentMapImpl.create(ComponentMap.EMPTY, components);
this.hashCode = Objects.hash(fluid, components);
}

Expand All @@ -86,6 +90,11 @@ public Fluid getObject() {
return components;
}

@Override
public ComponentMap getComponentMap() {
return componentMap;
}

@Override
public String toString() {
return "FluidVariant{fluid=" + fluid + ", components=" + components + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jetbrains.annotations.Nullable;

import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
Expand Down Expand Up @@ -70,6 +71,11 @@ public ComponentChanges getComponents() {
return components;
}

@Override
public ComponentMap getComponentMap() {
return getCachedStack().getComponents();
}

@Override
public boolean isBlank() {
return item == Items.AIR;
Expand Down
Loading