-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More work on documentation, add custom display fluid ingredient
- Loading branch information
1 parent
b4a4163
commit 7f94384
Showing
10 changed files
with
174 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/net/neoforged/neoforge/fluids/crafting/CustomDisplayFluidIngredient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.fluids.crafting; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.world.item.crafting.display.SlotDisplay; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.neoforged.neoforge.common.NeoForgeMod; | ||
import net.neoforged.neoforge.fluids.FluidStack; | ||
|
||
/** | ||
* FluidIngredient that wraps another fluid ingredient to override its {@link SlotDisplay}. | ||
*/ | ||
public final class CustomDisplayFluidIngredient extends FluidIngredient { | ||
public static final MapCodec<CustomDisplayFluidIngredient> CODEC = RecordCodecBuilder.mapCodec( | ||
instance -> instance | ||
.group( | ||
FluidIngredient.CODEC.fieldOf("base").forGetter(CustomDisplayFluidIngredient::base), | ||
SlotDisplay.CODEC.fieldOf("display").forGetter(CustomDisplayFluidIngredient::display)) | ||
.apply(instance, CustomDisplayFluidIngredient::new)); | ||
|
||
public static final StreamCodec<RegistryFriendlyByteBuf, CustomDisplayFluidIngredient> STREAM_CODEC = StreamCodec.composite( | ||
FluidIngredient.STREAM_CODEC, | ||
CustomDisplayFluidIngredient::base, | ||
SlotDisplay.STREAM_CODEC, | ||
CustomDisplayFluidIngredient::display, | ||
CustomDisplayFluidIngredient::new); | ||
|
||
private final FluidIngredient base; | ||
private final SlotDisplay display; | ||
|
||
public CustomDisplayFluidIngredient(FluidIngredient base, SlotDisplay display) { | ||
this.base = base; | ||
this.display = display; | ||
} | ||
|
||
public static FluidIngredient of(FluidIngredient base, SlotDisplay display) { | ||
return new CustomDisplayFluidIngredient(base, display); | ||
} | ||
|
||
@Override | ||
public boolean test(FluidStack stack) { | ||
return base.test(stack); | ||
} | ||
|
||
@Override | ||
public Stream<Holder<Fluid>> generateFluids() { | ||
return base.generateFluids(); | ||
} | ||
|
||
@Override | ||
public boolean isSimple() { | ||
return base.isSimple(); | ||
} | ||
|
||
@Override | ||
public FluidIngredientType<?> getType() { | ||
return NeoForgeMod.CUSTOM_DISPLAY_FLUID_INGREDIENT.get(); | ||
} | ||
|
||
public FluidIngredient base() { | ||
return base; | ||
} | ||
|
||
@Override | ||
public SlotDisplay display() { | ||
return display; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj instanceof CustomDisplayFluidIngredient other && | ||
Objects.equals(this.base, other.base) && | ||
Objects.equals(this.display, other.display); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(base, display); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CustomDisplayFluidIngredient[" + | ||
"base=" + base + ", " + | ||
"display=" + display + ']'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters