forked from Kittycraft/Psychedelicraft
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
571 additions
and
252 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
24 changes: 24 additions & 0 deletions
24
src/main/java/ivorius/psychedelicraft/client/item/AgeProperty.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,24 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
|
||
import net.minecraft.client.render.item.property.numeric.NumericProperty; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public record AgeProperty() implements NumericProperty { | ||
public static final MapCodec<AgeProperty> CODEC = MapCodec.unit(new AgeProperty()); | ||
|
||
@Override | ||
public float getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity holder, int seed) { | ||
return stack.getDamage() / 10F; | ||
} | ||
|
||
@Override | ||
public MapCodec<AgeProperty> getCodec() { | ||
return CODEC; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/ivorius/psychedelicraft/client/item/FilledProperty.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,58 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import java.util.Locale; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
|
||
import ivorius.psychedelicraft.item.BongItem; | ||
import ivorius.psychedelicraft.item.PaperBagItem; | ||
import ivorius.psychedelicraft.item.component.BagContentsComponent; | ||
import ivorius.psychedelicraft.item.component.ItemFluids; | ||
import net.minecraft.client.render.item.property.select.SelectProperty; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
import net.minecraft.util.StringIdentifiable; | ||
|
||
public record FilledProperty() implements SelectProperty<FilledProperty.FillPercentage> { | ||
public static final SelectProperty.Type<FilledProperty, FillPercentage> TYPE = SelectProperty.Type.create(MapCodec.unit(new FilledProperty()), FillPercentage.CODEC); | ||
|
||
@Override | ||
public FillPercentage getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed, ModelTransformationMode modelTransformationMode) { | ||
if (stack.getItem() instanceof PaperBagItem) { | ||
BagContentsComponent contents = BagContentsComponent.get(stack); | ||
return contents.isEmpty() ? FillPercentage.EMPTY : contents.count() > BagContentsComponent.FULL_COUNT | ||
? (contents.count() > BagContentsComponent.FULL_COUNT * 2F ? FillPercentage.FULL : FillPercentage.THREE_QUARTER) : FillPercentage.HALF; | ||
} | ||
if (stack.getItem() instanceof BongItem item) { | ||
return item.hasUsableConsumable(user) ? FillPercentage.FULL : FillPercentage.EMPTY; | ||
} | ||
return ItemFluids.of(stack).isEmpty() ? FillPercentage.EMPTY : FillPercentage.FULL; | ||
} | ||
|
||
@Override | ||
public SelectProperty.Type<FilledProperty, FillPercentage> getType() { | ||
return TYPE; | ||
} | ||
|
||
public enum FillPercentage implements StringIdentifiable { | ||
EMPTY, | ||
ONE_QUARTER, | ||
HALF, | ||
THREE_QUARTER, | ||
FULL; | ||
|
||
public static final Codec<FillPercentage> CODEC = StringIdentifiable.createCodec(FillPercentage::values); | ||
|
||
private final String name = name().toLowerCase(Locale.ROOT); | ||
|
||
@Override | ||
public String asString() { | ||
return name; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/ivorius/psychedelicraft/client/item/FilledWithLavaProperty.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,27 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
|
||
import ivorius.psychedelicraft.item.component.ItemFluids; | ||
import net.minecraft.client.render.item.property.bool.BooleanProperty; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
import net.minecraft.registry.tag.FluidTags; | ||
|
||
public record FilledWithLavaProperty() implements BooleanProperty { | ||
public static final MapCodec<FilledWithLavaProperty> CODEC = MapCodec.unit(new FilledWithLavaProperty()); | ||
|
||
@Override | ||
public boolean getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed, ModelTransformationMode modelTransformationMode) { | ||
return ItemFluids.of(stack).isIn(FluidTags.LAVA); | ||
} | ||
|
||
@Override | ||
public MapCodec<FilledWithLavaProperty> getCodec() { | ||
return CODEC; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/ivorius/psychedelicraft/client/item/FluidTintSource.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,31 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import ivorius.psychedelicraft.client.render.FluidBoxRenderer; | ||
import ivorius.psychedelicraft.item.component.ItemFluids; | ||
import net.minecraft.client.render.item.tint.TintSource; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.dynamic.Codecs; | ||
|
||
public record FluidTintSource(int defaultColor) implements TintSource { | ||
public static final MapCodec<FluidTintSource> CODEC = RecordCodecBuilder.mapCodec( | ||
instance -> instance.group(Codecs.RGB.fieldOf("default").forGetter(FluidTintSource::defaultColor)).apply(instance, FluidTintSource::new) | ||
); | ||
|
||
@Override | ||
public int getTint(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user) { | ||
ItemFluids fluids = ItemFluids.of(stack); | ||
return fluids.isEmpty() ? defaultColor : FluidBoxRenderer.FluidAppearance.getItemColor(fluids); | ||
} | ||
|
||
@Override | ||
public MapCodec<FluidTintSource> getCodec() { | ||
return CODEC; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/ivorius/psychedelicraft/client/item/FlyingProperty.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,26 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
|
||
import ivorius.psychedelicraft.entity.MolotovCocktailEntity; | ||
import net.minecraft.client.render.item.property.bool.BooleanProperty; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
|
||
public record FlyingProperty() implements BooleanProperty { | ||
public static final MapCodec<FlyingProperty> CODEC = MapCodec.unit(new FlyingProperty()); | ||
|
||
@Override | ||
public boolean getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed, ModelTransformationMode modelTransformationMode) { | ||
return stack.getHolder() instanceof MolotovCocktailEntity; | ||
} | ||
|
||
@Override | ||
public MapCodec<FlyingProperty> getCodec() { | ||
return CODEC; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/ivorius/psychedelicraft/client/item/HallucinatedItemModel.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,45 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import ivorius.psychedelicraft.item.SuspiciousItem; | ||
import net.minecraft.client.item.ItemModelManager; | ||
import net.minecraft.client.render.item.ItemRenderState; | ||
import net.minecraft.client.render.item.model.ItemModel; | ||
import net.minecraft.client.render.model.ResolvableModel; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
|
||
public class HallucinatedItemModel implements ItemModel { | ||
public static final ItemModel INSTANCE = new HallucinatedItemModel(); | ||
@Override | ||
public void update(ItemRenderState state, ItemStack stack, ItemModelManager resolver, ModelTransformationMode mode, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed) { | ||
if (stack.getItem() instanceof SuspiciousItem sus) { | ||
sus.getHallucinatedItem().map(Item::getDefaultStack).ifPresent(replacement -> { | ||
resolver.update(state, replacement, mode, world, user, seed); | ||
}); | ||
} | ||
} | ||
|
||
public static record Unbaked() implements ItemModel.Unbaked { | ||
public static final MapCodec<Unbaked> CODEC = MapCodec.unit(Unbaked::new); | ||
|
||
@Override | ||
public void resolve(ResolvableModel.Resolver resolver) { | ||
} | ||
|
||
@Override | ||
public ItemModel bake(ItemModel.BakeContext context) { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public MapCodec<Unbaked> getCodec() { | ||
return CODEC; | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/ivorius/psychedelicraft/client/item/PSItemProperties.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,96 @@ | ||
package ivorius.psychedelicraft.client.item; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
|
||
import ivorius.psychedelicraft.Psychedelicraft; | ||
import net.minecraft.client.render.item.model.ItemModel; | ||
import net.minecraft.client.render.item.model.ItemModelTypes; | ||
import net.minecraft.client.render.item.model.special.SpecialModelRenderer; | ||
import net.minecraft.client.render.item.model.special.SpecialModelTypes; | ||
import net.minecraft.client.render.item.property.bool.BooleanProperties; | ||
import net.minecraft.client.render.item.property.bool.BooleanProperty; | ||
import net.minecraft.client.render.item.property.numeric.NumericProperties; | ||
import net.minecraft.client.render.item.property.numeric.NumericProperty; | ||
import net.minecraft.client.render.item.property.select.SelectProperties; | ||
import net.minecraft.client.render.item.property.select.SelectProperty; | ||
import net.minecraft.client.render.item.tint.TintSource; | ||
import net.minecraft.client.render.item.tint.TintSourceTypes; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ModelTransformationMode; | ||
|
||
public interface PSItemProperties { | ||
|
||
private static <P extends SelectProperty<T>, T> void option(String name, SelectProperty.Type<P, T> codec) { | ||
SelectProperties.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
private static void flag(String name, MapCodec<? extends BooleanProperty> codec) { | ||
BooleanProperties.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
private static void range(String name, MapCodec<? extends NumericProperty> codec) { | ||
NumericProperties.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
private static void tint(String name, MapCodec<? extends TintSource> codec) { | ||
TintSourceTypes.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
private static void model(String name, MapCodec<? extends ItemModel.Unbaked> codec) { | ||
ItemModelTypes.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
private static void specialModel(String name, MapCodec<? extends SpecialModelRenderer.Unbaked> codec) { | ||
SpecialModelTypes.ID_MAPPER.put(Psychedelicraft.id(name), codec); | ||
} | ||
|
||
static void bootstrap() { | ||
flag("tripping", TrippingProperty.CODEC); | ||
flag("flying", FlyingProperty.CODEC); | ||
flag("using", UsingProperty.CODEC); | ||
option("filled", FilledProperty.TYPE); | ||
flag("filled_with_lava", FilledWithLavaProperty.CODEC); | ||
range("age", AgeProperty.CODEC); | ||
|
||
tint("fluid", FluidTintSource.CODEC); | ||
|
||
model("hallucination", HallucinatedItemModel.Unbaked.CODEC); | ||
specialModel("rift_jar", RiftJarItemModelRenderer.Unbaked.CODEC); | ||
|
||
// layer 1,2,3,etc -> minecraft:dye | ||
// ColorProviderRegistry.ITEM.register((stack, layer) -> layer > 0 ? -1 : DyedColorComponent.getColor(stack, Colors.RED), PSItems.HARMONIUM); | ||
|
||
// layer0 -> minecraft:dye (default is white) | ||
// layer1 -> psychedelicraft:fluid (default is white) | ||
/*ColorProviderRegistry.ITEM.register((stack, layer) -> { | ||
if (layer == 0) { | ||
return DyedColorComponent.getColor(stack, Colors.WHITE); | ||
} | ||
if (layer == 1) { | ||
ItemFluids fluids = ItemFluids.of(stack); | ||
if (!fluids.isEmpty()) { | ||
return FluidBoxRenderer.FluidAppearance.getItemColor(fluids); | ||
} | ||
} | ||
return Colors.WHITE; | ||
}, PSItems.BOTTLE, PSItems.MOLOTOV_COCKTAIL, PSItems.GLASS_CHALICE, PSItems.STONE_CUP, PSItems.WOODEN_MUG, PSItems.FILLED_BUCKET, PSItems.FILLED_BOWL, PSItems.SYRINGE);*/ | ||
// layer0 -> psychedelicraft:fluid (default is white) | ||
/*ColorProviderRegistry.ITEM.register((stack, layer) -> { | ||
if (layer == 0) { | ||
ItemFluids fluids = ItemFluids.of(stack); | ||
if (!fluids.isEmpty()) { | ||
return FluidBoxRenderer.FluidAppearance.getItemColor(fluids); | ||
} | ||
} | ||
return Colors.WHITE; | ||
}, PSItems.FILLED_GLASS_BOTTLE);*/ | ||
} | ||
|
||
interface ValueSupplier<T> { | ||
T getValue(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity user, int seed, ModelTransformationMode modelTransformationMode); | ||
} | ||
} |
Oops, something went wrong.