mirror of
https://github.com/FabricMC/fabric.git
synced 2025-02-27 17:04:30 -05:00
Add TransferVariant.getComponentMap() (#4074)
* Add TransferVariant.getComponentMap() * used the cached stack * Even better
This commit is contained in:
parent
4854df7166
commit
0771530439
3 changed files with 21 additions and 0 deletions
fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric
api/transfer/v1/storage
impl/transfer
|
@ -19,6 +19,7 @@ package net.fabricmc.fabric.api.transfer.v1.storage;
|
|||
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.
|
||||
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.Objects;
|
|||
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;
|
||||
|
@ -63,11 +65,13 @@ public class FluidVariantImpl implements FluidVariant {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -86,6 +90,11 @@ public class FluidVariantImpl implements FluidVariant {
|
|||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentMap getComponentMap() {
|
||||
return componentMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FluidVariant{fluid=" + fluid + ", components=" + components + '}';
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Objects;
|
|||
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;
|
||||
|
@ -70,6 +71,11 @@ public class ItemVariantImpl implements ItemVariant {
|
|||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentMap getComponentMap() {
|
||||
return getCachedStack().getComponents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlank() {
|
||||
return item == Items.AIR;
|
||||
|
|
Loading…
Reference in a new issue