initial commit based on terra originum

This commit is contained in:
2026-02-14 19:46:57 +02:00
parent cbe4c328ed
commit 185522a308
321 changed files with 7427 additions and 3 deletions

View File

@@ -0,0 +1,45 @@
package com.smithy.terraoriginum;
import com.smithy.terraoriginum.blocks.CottonCropBlock;
import com.smithy.terraoriginum.blocks.Crucifix;
import com.smithy.terraoriginum.items.*;
import com.smithy.terraoriginum.registry.ModEnchantments;
import com.smithy.terraoriginum.registry.ModPowers;
import com.smithy.terraoriginum.util.LootTableModifiers;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
// import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemGroups;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TerraOriginum implements ModInitializer {
public static final String MOD_ID = "terraoriginum";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
@Override
public void onInitialize() {
Umbrella.registerItems();
IconItems.register();
ModEnchantments.register();
Crucifix.register();
CottonCropBlock.register();
CottonItems.register();
SunTotem.register();
GhostlyItems.register();
GhostlyArmourItems.register();
ModPowers.register();
LootTableModifiers.modifyLootTables();
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register((content) -> content.add(Umbrella.UMBRELLA));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register((content) -> content.add(SunTotem.SUN_TOTEM));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register((content) -> content.add(Crucifix.CRUCIFIX));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.NATURAL).register((content) -> content.add(CottonItems.COTTON_SEEDS));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register((content) -> content.add(CottonItems.COTTON_BALL));
LOGGER.info("man this Origins is " + MOD_ID);
}
}

View File

@@ -0,0 +1,49 @@
package com.smithy.terraoriginum.blocks;
import com.smithy.terraoriginum.items.CottonItems;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.CropBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemConvertible;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
public class CottonCropBlock extends CropBlock{
private static final VoxelShape[] AGE_TO_SHAPE = new VoxelShape[]{Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 3.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 5.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 7.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D),
Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D)
};
public CottonCropBlock(AbstractBlock.Settings settings) {
super(settings);
}
public ItemConvertible getSeedsItem() {
return CottonItems.COTTON_SEEDS;
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return AGE_TO_SHAPE[(Integer)state.get(this.getAgeProperty())];
}
public static final CropBlock COTTON_CROP_BLOCK = new CropBlock(AbstractBlock.Settings.create().nonOpaque().noCollision().ticksRandomly().breakInstantly().sounds(BlockSoundGroup.CROP));
public static void register() {
Registry.register(Registries.BLOCK, new Identifier("terraoriginum", "cotton_crop_block"), COTTON_CROP_BLOCK);
}
}

View File

@@ -0,0 +1,22 @@
package com.smithy.terraoriginum.blocks;
import com.smithy.terraoriginum.TerraOriginum;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
public class Crucifix {
public static final Block CRUCIFIX = new CrucifixClass(FabricBlockSettings.create().strength(5.5f, 4.8f).requiresTool());
public static void register() {
// Registry.register(Registries.BLOCK, new Identifier(TerraOriginum.MOD_ID, "crucifix"), new BlockItem(CRUCIFIX, new FabricItemSettings()));
// Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "crucifix"), CRUCIFIX);
Registry.register(Registries.BLOCK, new Identifier(TerraOriginum.MOD_ID, "crucifix"), CRUCIFIX);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "crucifix"), new BlockItem(CRUCIFIX, new Item.Settings()));
}
}

View File

@@ -0,0 +1,28 @@
package com.smithy.terraoriginum.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
public class CrucifixClass extends Block {
public CrucifixClass(Settings properties) {
super(properties);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
VoxelShape shape = VoxelShapes.empty();
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.375, 0, 0.375, 0.5625, 0.75, 0.5625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.5625, 0.375, 0.375, 0.75, 0.5625, 0.5625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.1875, 0.375, 0.375, 0.375, 0.5625, 0.5625));
return shape;
}
}

View File

@@ -0,0 +1,17 @@
package com.smithy.terraoriginum.client;
import com.smithy.terraoriginum.blocks.CottonCropBlock;
import com.smithy.terraoriginum.items.Umbrella;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.render.RenderLayer;
public class LayerRenderer implements ClientModInitializer {
@Override
public void onInitializeClient() {
Umbrella.registerRenderLayers();
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), CottonCropBlock.COTTON_CROP_BLOCK);
}
}

View File

@@ -0,0 +1,25 @@
package com.smithy.terraoriginum.client;
import io.github.apace100.apoli.ApoliClient;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import org.lwjgl.glfw.GLFW;
import java.util.List;
public class TerraKeybinds implements ClientModInitializer {
public List<String> keys = List.of("ternary","quaternary","quinary","senary","septenary","octonary","nonary","denary");
@Override
public void onInitializeClient() {
for(String key : keys) {
KeyBinding binding = new KeyBinding("key.origins."+key+"_active", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.origins");
ApoliClient.registerPowerKeybinding(binding.getTranslationKey(), binding);
ApoliClient.registerPowerKeybinding(key, binding);
KeyBindingHelper.registerKeyBinding(binding);
}
}
}

View File

@@ -0,0 +1,13 @@
package com.smithy.terraoriginum.client;
import net.fabricmc.api.ClientModInitializer;
public class TerraOriginumClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
}
}

View File

@@ -0,0 +1,23 @@
package com.smithy.terraoriginum.client.armour;
import com.smithy.terraoriginum.items.GhostlyArmour;
import net.minecraft.util.Identifier;
import software.bernie.geckolib.model.GeoModel;
public class GhostlyArmourModel extends GeoModel<GhostlyArmour> {
@Override
public Identifier getModelResource(GhostlyArmour animatable) {
return new Identifier("terraoriginum", "geo/ghostly_armour.geo.json");
}
@Override
public Identifier getTextureResource(GhostlyArmour animatable) {
return new Identifier("terraoriginum", "textures/models/armor/ghost_armour_model_texture");
}
@Override
public Identifier getAnimationResource(GhostlyArmour animatable) {
return null;
}
}

View File

@@ -0,0 +1,16 @@
package com.smithy.terraoriginum.client.armour;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.items.GhostlyArmour;
import net.minecraft.util.Identifier;
import software.bernie.geckolib.GeckoLib;
import software.bernie.geckolib.model.DefaultedItemGeoModel;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
public class GhostlyArmourRenderer extends GeoArmorRenderer<GhostlyArmour> {
public GhostlyArmourRenderer() {
super(new DefaultedItemGeoModel<>(new Identifier(TerraOriginum.MOD_ID, "armor/ghost_armour")));
}
}

View File

@@ -0,0 +1,89 @@
package com.smithy.terraoriginum.customMaterials;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import java.util.function.Supplier;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.items.CottonItems;
public enum RobesMaterial implements ArmorMaterial {
ROBES("robes", 42, new int[] { 4, 9, 7, 4 }, 19,
SoundEvents.ITEM_ARMOR_EQUIP_NETHERITE, 5, 0.1f, () -> Ingredient.ofItems(CottonItems.COTTON_BALL));
private final String name;
private final int durabilityMultiplier;
private final int[] protectionAmounts;
private final int enchantability;
private final SoundEvent equipSound;
private final float toughness;
private final float knockbackResistance;
private final Supplier<Ingredient> repairIngredient;
private static final int[] BASE_DURABILITY = { 11, 16, 15, 13 };
RobesMaterial(
String name,
int durabilityMultiplier,
int[] protectionAmounts,
int enchantability,
SoundEvent equipSound,
float toughness,
float knockbackResistance,
Supplier<Ingredient> repairIngredient
) {
this.name = name;
this.durabilityMultiplier = durabilityMultiplier;
this.protectionAmounts = protectionAmounts;
this.enchantability = enchantability;
this.equipSound = equipSound;
this.toughness = toughness;
this.knockbackResistance = knockbackResistance;
this.repairIngredient = repairIngredient;
}
@Override
public int getDurability(ArmorItem.Type type) {
return BASE_DURABILITY[type.ordinal()] * this.durabilityMultiplier;
}
@Override
public int getProtection(ArmorItem.Type type) {
return protectionAmounts[type.ordinal()];
}
@Override
public int getEnchantability() {
return this.enchantability;
}
@Override
public SoundEvent getEquipSound() {
return this.equipSound;
}
@Override
public Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public String getName() {
return TerraOriginum.MOD_ID + ":" + this.name;
}
@Override
public float getToughness() {
return this.toughness;
}
@Override
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}

View File

@@ -0,0 +1,39 @@
package com.smithy.terraoriginum.enchantment;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.entity.EquipmentSlot;
public class LightProtectionEnchantment extends Enchantment{
public LightProtectionEnchantment(Rarity weight, EnchantmentTarget type, EquipmentSlot[] slotTypes) {
super(weight, type, slotTypes);
}
public int getMinPower(int level) {
return 8 + level * 5;
}
public int getMaxPower(int level) {
return this.getMinPower(level) + 8;
}
public boolean isTreasure() {
return true;
}
public int getMaxLevel() {
return 1;
}
@Override
protected boolean canAccept(Enchantment other) {
if(other == this || ((other instanceof ProtectionEnchantment && !(((ProtectionEnchantment)other).protectionType == ProtectionEnchantment.Type.ALL)))) {
return false;
}
return super.canAccept(other);
}
}

View File

@@ -0,0 +1,39 @@
package com.smithy.terraoriginum.enchantment;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.entity.EquipmentSlot;
public class SunProtectionEnchantment extends Enchantment {
public SunProtectionEnchantment(Rarity weight, EnchantmentTarget type, EquipmentSlot[] slotTypes) {
super(weight, type, slotTypes);
}
public int getMinPower(int level) {
return 8 + level * 5;
}
public int getMaxPower(int level) {
return this.getMinPower(level) + 8;
}
public boolean isTreasure() {
return true;
}
public int getMaxLevel() {
return 4;
}
@Override
protected boolean canAccept(Enchantment other) {
if(other == this || ((other instanceof ProtectionEnchantment && !(((ProtectionEnchantment)other).protectionType == ProtectionEnchantment.Type.ALL)))) {
return true; // true because its somehow incompatible with every other protection, except protection
}
return super.canAccept(other);
}
}

View File

@@ -0,0 +1,19 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.blocks.CottonCropBlock;
import net.minecraft.item.AliasedBlockItem;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
public class CottonItems {
public static final Item COTTON_SEEDS = new AliasedBlockItem(CottonCropBlock.COTTON_CROP_BLOCK, new Item.Settings());
public static final Item COTTON_BALL = new Item(new Item.Settings());
public static void register() {
Registry.register(Registries.ITEM, new Identifier("terraoriginum", "cotton_seeds"), COTTON_SEEDS);
Registry.register(Registries.ITEM, new Identifier("terraoriginum", "cotton_ball"), COTTON_BALL);
}
}

View File

@@ -0,0 +1,108 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.client.armour.GhostlyArmourRenderer;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import software.bernie.example.client.renderer.armor.GeckoArmorRenderer;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.client.RenderProvider;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.constant.DefaultAnimations;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.core.animation.AnimationController;
import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.renderer.GeoArmorRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class GhostlyArmour extends ArmorItem implements GeoItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private final Supplier<Object> renderProvider = GeoItem.makeRenderer(this);
public GhostlyArmour(ArmorMaterial armorMaterial, ArmorItem.Type type, Settings properties) {
super(armorMaterial, type, properties);
}
// Create our armor model/renderer for Fabric and return it
@Override
public void createRenderer(Consumer<Object> consumer) {
consumer.accept(new RenderProvider() {
private GeoArmorRenderer<?> renderer;
@Override
public BipedEntityModel<LivingEntity> getHumanoidArmorModel(LivingEntity livingEntity, ItemStack itemStack, EquipmentSlot equipmentSlot, BipedEntityModel<LivingEntity> original) {
if (this.renderer == null)
this.renderer = new GhostlyArmourRenderer();
// This prepares our GeoArmorRenderer for the current render frame.
// These parameters may be null however, so we don't do anything further with them
this.renderer.prepForRender(livingEntity, itemStack, equipmentSlot, original);
return this.renderer;
}
});
}
@Override
public Supplier<Object> getRenderProvider() {
return this.renderProvider;
}
// Let's add our animation controller
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, 20, state -> {
// Apply our generic idle animation.
// Whether it plays or not is decided down below
// Let's gather some data from the state to use below
// This is the entity that is currently wearing/holding the item
Entity entity = state.getData(DataTickets.ENTITY);
// We'll just have ArmorStands always animate, so we can return here
if (entity instanceof ArmorStandEntity)
return PlayState.CONTINUE;
// For this example, we only want the animation to play if the entity is wearing all pieces of the armor
// Let's collect the armor pieces the entity is currently wearing
Set<Item> wornArmor = new ObjectOpenHashSet<>();
for (ItemStack stack : entity.getArmorItems()) {
// We can stop immediately if any of the slots are empty
if (stack.isEmpty())
return PlayState.STOP;
wornArmor.add(stack.getItem());
}
// Check each of the pieces match our set
boolean isFullSet = wornArmor.containsAll(ObjectArrayList.of(
GhostlyArmourItems.GHOSTLY_BOOTS,
GhostlyArmourItems.GHOSTLY_LEGGING,
GhostlyArmourItems.GHOSTLY_CHESTPLATE,
GhostlyArmourItems.GHOSTLY_HELMET));
// Play the animation if the full set is being worn, otherwise stop
return isFullSet ? PlayState.CONTINUE : PlayState.STOP;
}));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
}

View File

@@ -0,0 +1,37 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.customMaterials.RobesMaterial;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
public class GhostlyArmourItems {
public static final Item GHOSTLY_HELMET = new GhostlyArmour(RobesMaterial.ROBES, ArmorItem.Type.HELMET, new FabricItemSettings().rarity(Rarity.EPIC));
public static final Item GHOSTLY_CHESTPLATE = new GhostlyArmour(RobesMaterial.ROBES, ArmorItem.Type.CHESTPLATE, new FabricItemSettings().rarity(Rarity.EPIC));
public static final Item GHOSTLY_LEGGING = new GhostlyArmour(RobesMaterial.ROBES, ArmorItem.Type.LEGGINGS, new FabricItemSettings().rarity(Rarity.EPIC));
public static final Item GHOSTLY_BOOTS = new GhostlyArmour(RobesMaterial.ROBES, ArmorItem.Type.BOOTS, new FabricItemSettings().rarity(Rarity.EPIC));
public static void register() {
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "ghostly_helmet"), GHOSTLY_HELMET);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "ghostly_chestplate"), GHOSTLY_CHESTPLATE);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "ghostly_leggings"), GHOSTLY_LEGGING);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "ghostly_boots"), GHOSTLY_BOOTS);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register((content) -> content.add(GHOSTLY_HELMET));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register((content) -> content.add(GHOSTLY_CHESTPLATE));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register((content) -> content.add(GHOSTLY_LEGGING));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.COMBAT).register((content) -> content.add(GHOSTLY_BOOTS));
}
}

View File

@@ -0,0 +1,24 @@
package com.smithy.terraoriginum.items;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
public class GhostlyItems {
public static final Item GHOSTLY_CLOTH = new Item(new FabricItemSettings());
public static void register() {
Registry.register(Registries.ITEM, new Identifier("terraoriginum", "ghostly_cloth"), GHOSTLY_CLOTH);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS).register((content) -> content.add(GHOSTLY_CLOTH));
}
}

View File

@@ -0,0 +1,22 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.TerraOriginum;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
public class IconItems {
public static final Item MYNC_EYE = new Item(new Item.Settings().maxCount(1).rarity(Rarity.EPIC));
public static final Item SPIRIT = new Item(new Item.Settings().maxCount(1).rarity(Rarity.EPIC));
public static final Item TINY = new Item(new Item.Settings().maxCount(1).rarity(Rarity.EPIC));
public static void register() {
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "mync_eye"), MYNC_EYE);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "spirit"), SPIRIT);
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "tiny"), TINY);
}
}

View File

@@ -0,0 +1,17 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.TerraOriginum;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
public class SunTotem {
public static final Item SUN_TOTEM = new Item(new Item.Settings().maxCount(1).rarity(Rarity.EPIC));
public static void register() {
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "sun_totem"), SUN_TOTEM);
}
}

View File

@@ -0,0 +1,26 @@
package com.smithy.terraoriginum.items;
import com.smithy.terraoriginum.TerraOriginum;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.item.DyeableItem;
import net.minecraft.util.Identifier;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
public class Umbrella {
public static final UmbrellaDyeTest UMBRELLA = new UmbrellaDyeTest(new FabricItemSettings().maxCount(1).maxDamage(1200));
public static void registerItems() {
Registry.register(Registries.ITEM, new Identifier(TerraOriginum.MOD_ID, "umbrella"), UMBRELLA);
}
@Environment(EnvType.CLIENT)
public static void registerRenderLayers() {
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> (tintIndex > 0) ? -1 : ((DyeableItem) stack.getItem()).getColor(stack), UMBRELLA);
}
}

View File

@@ -0,0 +1,12 @@
package com.smithy.terraoriginum.items;
import net.minecraft.item.DyeableItem;
import net.minecraft.item.Item;
public class UmbrellaDyeTest extends Item implements DyeableItem {
public UmbrellaDyeTest(Settings settings) {
super(settings);
}
}

View File

@@ -0,0 +1,52 @@
package com.smithy.terraoriginum.mixin;
import com.smithy.terraoriginum.items.Umbrella;
import com.smithy.terraoriginum.power.PreventBlockSlowness;
import io.github.apace100.apoli.component.PowerHolderComponent;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow World world;
@Shadow abstract BlockPos getBlockPos();
@Shadow abstract Box getBoundingBox();
@Shadow abstract Iterable<ItemStack> getHandItems();
@Inject(method = "isBeingRainedOn", at = @At("HEAD"), cancellable = true)
private void isBeingRainedOn(CallbackInfoReturnable<Boolean> cir) {
Iterable<ItemStack> hands = this.getHandItems();
for (ItemStack stack : hands) {
if (stack.getItem() == Umbrella.UMBRELLA)
cir.setReturnValue(false);
}
}
@Inject(method = "slowMovement", at = @At("HEAD"), cancellable = true)
private void terraoriginum$preventBlockSlowness(BlockState state, Vec3d multiplier, CallbackInfo ci) {
for (PreventBlockSlowness power : PowerHolderComponent.getPowers((Entity) (Object) this, PreventBlockSlowness.class)) {
if (power.isActive()) {
ci.cancel();
return;
}
}
}
}

View File

@@ -0,0 +1,47 @@
package com.smithy.terraoriginum.mixin;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.smithy.terraoriginum.power.WingsPower;
import dev.cammiescorner.icarus.api.IcarusPlayerValues;
import dev.cammiescorner.icarus.util.IcarusHelper;
import io.github.apace100.apoli.component.PowerHolderComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import java.util.function.Function;
import java.util.function.Predicate;
@Mixin(value = IcarusHelper.class, remap = false)
public class IcarusHelperMixin {
@ModifyReturnValue(method = "getConfigValues", at = @At("RETURN"))
private static IcarusPlayerValues injectPowerConfigValues(IcarusPlayerValues original, LivingEntity entity) {
var list = PowerHolderComponent.getPowers(entity, WingsPower.class);
if(!list.isEmpty()) {
var power = list.get(0);
power.updateFallback(original);
return power;
}
return original;
}
@WrapOperation(method = "hasWings", at = @At(value = "INVOKE", target = "Ljava/util/function/Predicate;test(Ljava/lang/Object;)Z"))
private static boolean originHasWings(Predicate<LivingEntity> instance, Object entity, Operation<Boolean> original) {
return PowerHolderComponent.hasPower((LivingEntity) entity, WingsPower.class) || original.call(instance, entity);
}
@WrapOperation(method = "getEquippedWings", at = @At(value = "INVOKE", target = "Ljava/util/function/Function;apply(Ljava/lang/Object;)Ljava/lang/Object;"))
private static Object originGetWings(Function<LivingEntity, ItemStack> instance, Object entity, Operation<ItemStack> original) {
if (PowerHolderComponent.hasPower((LivingEntity) entity, WingsPower.class)) {
// null is special case
return null;
}
return original.call(instance, entity);
}
}

View File

@@ -0,0 +1,35 @@
package com.smithy.terraoriginum.mixin;
import io.github.apace100.apoli.power.factory.condition.EntityConditions;
import io.github.apace100.calio.data.SerializableData;
import com.smithy.terraoriginum.items.Umbrella;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(EntityConditions.class)
public class PlayerConditionsMixin {
@Inject(method = { "lambda$register$10" }, at = { @At("HEAD") }, cancellable = true)
private static void sunDamagePrevention(SerializableData.Instance data, Entity player, CallbackInfoReturnable<Boolean> cir) {
for (ItemStack stack : player.getHandItems()) {
if (stack.getItem().equals(Umbrella.UMBRELLA) && stack.getDamage() < stack.getMaxDamage() - 1) {
cir.setReturnValue(false);
}
}
}
@Inject(method = { "lambda$register$11" }, at = { @At("HEAD") }, cancellable = true)
private static void umbrellaRainedOn(SerializableData.Instance data, Entity player, CallbackInfoReturnable<Boolean> cir) {
for (ItemStack stack : player.getHandItems()) {
if (stack.getItem().equals(Umbrella.UMBRELLA) && stack.getDamage() < stack.getMaxDamage() - 1) {
cir.setReturnValue(false);
}
}
}
}

View File

@@ -0,0 +1,73 @@
package com.smithy.terraoriginum.mixin;
import io.github.apace100.apoli.mixin.EntityAccessor;
import com.smithy.terraoriginum.items.Umbrella;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends Entity {
@Shadow
public abstract ItemStack getEquippedStack(EquipmentSlot slot);
@Shadow
public abstract Iterable<ItemStack> getHandItems();
@Shadow
public abstract PlayerInventory getInventory();
protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world) {
super(entityType, world);
}
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
private void tick(CallbackInfo ci) {
boolean isBeingRainedOn = ((EntityAccessor) this).callIsBeingRainedOn();
if (isBeingRainedOn && this.age % 10 == 0) {
for (ItemStack stack : this.getHandItems()) {
if (stack.getItem().equals(Umbrella.UMBRELLA) && stack.getDamage() < stack.getMaxDamage() - 1) {
// Set damage instead of calling stack.damage, otherwise an animation is
// triggered for each damage tick.
stack.setDamage(stack.getDamage() + 1);
}
}
} else if (!isBeingRainedOn && this.age % 20 == 0) {
ItemStack offHand = this.getEquippedStack(EquipmentSlot.OFFHAND);
boolean isHot = getWorld().getBiome(this.getBlockPos()).value().isCold(this.getBlockPos());
// Repair off-hand umbrella.
this.repairStack(offHand, isHot, true);
// Repair any umbrellas in the player's inventory.
for (int i = 0; i < 36; i++) {
this.repairStack(this.getInventory().getStack(i), isHot, this.getInventory().selectedSlot == i);
}
}
}
private void repairStack(ItemStack stack, boolean isHot, boolean isExposed) {
if (stack.getItem().equals(Umbrella.UMBRELLA) && stack.isDamaged()) {
stack.setDamage(stack.getDamage() - 1);
if (isHot) {
// Umbrellas dry faster in hot climates.
stack.setDamage(stack.getDamage() - 1);
}
if (isExposed) {
// Umbrellas dry faster if they're exposed (not tucked away in inventory).
stack.setDamage(stack.getDamage() - 1);
}
}
}
}

View File

@@ -0,0 +1,24 @@
package com.smithy.terraoriginum.mixin;
import io.github.apace100.apoli.component.PowerHolderComponent;
import net.minecraft.block.PowderSnowBlock;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.smithy.terraoriginum.power.CanStandOnPowderSnow;
@Mixin(PowderSnowBlock.class)
public class PowderSnowBlockMixin {
@Inject(method = "canWalkOnPowderSnow", at = @At("HEAD"), cancellable = true)
private static void terraoriginum$canStandOnPowderSnow(Entity entity, CallbackInfoReturnable<Boolean> cir) {
for (CanStandOnPowderSnow canStandOnPowderSnowPower : PowerHolderComponent.getPowers(entity, CanStandOnPowderSnow.class)) {
if (canStandOnPowderSnowPower.isActive()) {
cir.setReturnValue(true);
return;
}
}
}
}

View File

@@ -0,0 +1,26 @@
package com.smithy.terraoriginum.mixin.client;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.smithy.terraoriginum.power.WingsPower;
import dev.cammiescorner.icarus.client.IcarusClient;
import io.github.apace100.apoli.component.PowerHolderComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(value = IcarusClient.class, remap = false)
public class IcarusClientMixin {
@ModifyReturnValue(method = "getWingsForRendering", at = @At(value = "RETURN"))
private static ItemStack injectOriginWings(ItemStack original, LivingEntity entity) {
if(original.isEmpty()) {
var list = PowerHolderComponent.getPowers(entity, WingsPower.class);
if (!list.isEmpty()) {
return list.get(0).getWingsType();
}
}
return original;
}
}

View File

@@ -0,0 +1,11 @@
package com.smithy.terraoriginum.power;
import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import net.minecraft.entity.LivingEntity;
public class CanStandOnPowderSnow extends Power {
public CanStandOnPowderSnow(PowerType<?> type, LivingEntity entity) {
super(type, entity);
}
}

View File

@@ -0,0 +1,11 @@
package com.smithy.terraoriginum.power;
import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import net.minecraft.entity.LivingEntity;
public class PreventBlockSlowness extends Power {
public PreventBlockSlowness(PowerType<?> type, LivingEntity entity) {
super(type, entity);
}
}

View File

@@ -0,0 +1,113 @@
package com.smithy.terraoriginum.power;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.util.CustomDataTypes;
import com.smithy.terraoriginum.util.OptionalBool;
import dev.cammiescorner.icarus.api.IcarusPlayerValues;
import dev.cammiescorner.icarus.util.ServerPlayerFallbackValues;
import io.github.apace100.apoli.power.Power;
import io.github.apace100.apoli.power.PowerType;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.calio.data.SerializableData;
import net.minecraft.util.Identifier;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import java.util.OptionalDouble;
import java.util.OptionalInt;
public class WingsPower extends Power implements IcarusPlayerValues {
public static final Identifier POWER_TYPE_ID = new Identifier(TerraOriginum.MOD_ID, "wings");
private final ItemStack wingsType;
private final OptionalBool armorSlows;
private final OptionalDouble maxSlowedMultiplier;
private final OptionalDouble wingsSpeed;
private final OptionalDouble exhaustionAmount;
private final OptionalInt maxHeightAboveWorld;
private IcarusPlayerValues fallback = new ServerPlayerFallbackValues();
public WingsPower(PowerType<?> type, LivingEntity entity, ItemStack wingsType, OptionalBool armorSlows, OptionalDouble maxSlowedMultiplier, OptionalDouble wingsSpeed, OptionalDouble exhaustionAmount, OptionalInt maxHeightAboveWorld) {
super(type, entity);
this.wingsType = wingsType;
this.armorSlows = armorSlows;
this.maxSlowedMultiplier = maxSlowedMultiplier;
this.wingsSpeed = wingsSpeed;
this.exhaustionAmount = exhaustionAmount;
this.maxHeightAboveWorld = maxHeightAboveWorld;
}
public ItemStack getWingsType() {
return wingsType;
}
public void updateFallback(IcarusPlayerValues fallback) {
this.fallback = fallback;
}
@Override
public float wingsSpeed() {
return (float) wingsSpeed.orElseGet(fallback::wingsSpeed);
}
@Override
public float maxSlowedMultiplier() {
return (float) maxSlowedMultiplier.orElseGet(fallback::maxSlowedMultiplier);
}
@Override
public boolean armorSlows() {
return armorSlows.orElseGet(fallback::armorSlows);
}
@Override
public boolean canLoopDeLoop() {
return fallback.canLoopDeLoop();
}
@Override
public boolean canSlowFall() {
return fallback.canSlowFall();
}
@Override
public float exhaustionAmount() {
return (float) exhaustionAmount.orElseGet(fallback::exhaustionAmount);
}
@Override
public int maxHeightAboveWorld() {
return maxHeightAboveWorld.orElseGet(fallback::maxHeightAboveWorld);
}
@Override
public boolean maxHeightEnabled() {
return maxHeightAboveWorld.isPresent() || fallback.maxHeightEnabled();
}
public static PowerFactory<WingsPower> createFactory() {
return new PowerFactory<>(POWER_TYPE_ID,
new SerializableData()
.add("wings_type", CustomDataTypes.STACK_OR_ITEM_NAME)
.add("armor_slows", CustomDataTypes.OPTIONAL_BOOL, OptionalBool.DEFAULT)
.add("max_slowed_multiplier", CustomDataTypes.OPTIONAL_DOUBLE, OptionalDouble.empty())
.add("wings_speed", CustomDataTypes.OPTIONAL_DOUBLE, OptionalDouble.empty())
.add("exhaustion_amount", CustomDataTypes.OPTIONAL_DOUBLE, OptionalDouble.empty())
.add("max_height_above_world", CustomDataTypes.OPTIONAL_INT, OptionalInt.empty()),
data -> (type, owner) -> {
ItemStack wingsType = data.get("wings_type");
OptionalBool armorSlows = data.get("armor_slows");
OptionalDouble maxSlowedMultiplier = data.get("max_slowed_multiplier");
OptionalDouble wingsSpeed = data.get("wings_speed");
OptionalDouble exhaustionAmount = data.get("exhaustion_amount");
OptionalInt maxHeightAboveWorld = data.get("max_height_above_world");
return new WingsPower(type, owner, wingsType, armorSlows, maxSlowedMultiplier, wingsSpeed, exhaustionAmount, maxHeightAboveWorld);
}
);
}
}

View File

@@ -0,0 +1,27 @@
package com.smithy.terraoriginum.registry;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.enchantment.LightProtectionEnchantment;
import com.smithy.terraoriginum.enchantment.SunProtectionEnchantment;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.registry.Registry;
public class ModEnchantments {
public static final Enchantment SUN_PROTECTION = new SunProtectionEnchantment(Enchantment.Rarity.RARE, EnchantmentTarget.ARMOR, new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET});
public static final Enchantment LIGHT_PROTECTION = new LightProtectionEnchantment(Enchantment.Rarity.RARE, EnchantmentTarget.ARMOR_CHEST, new EquipmentSlot[]{EquipmentSlot.CHEST});
public static void register() {
register("sun_protection", SUN_PROTECTION);
register("light_protection", LIGHT_PROTECTION);
}
private static Enchantment register(String path, Enchantment enchantment) {
Registry.register(Registries.ENCHANTMENT, new Identifier(TerraOriginum.MOD_ID, path), enchantment);
return enchantment;
}
}

View File

@@ -0,0 +1,27 @@
package com.smithy.terraoriginum.registry;
import com.smithy.terraoriginum.TerraOriginum;
import com.smithy.terraoriginum.power.CanStandOnPowderSnow;
import com.smithy.terraoriginum.power.PreventBlockSlowness;
import com.smithy.terraoriginum.power.WingsPower;
import io.github.apace100.apoli.power.factory.PowerFactory;
import io.github.apace100.apoli.registry.ApoliRegistries;
import io.github.apace100.calio.data.SerializableData;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
public class ModPowers {
public static final PowerFactory<?> CAN_WALK_ON_POWDER_SNOW = new PowerFactory<>( new Identifier(TerraOriginum.MOD_ID, "can_walk_on_powder_snow"), new SerializableData(), data -> (type, entity) -> new CanStandOnPowderSnow(type, entity)).allowCondition();
public static final PowerFactory<?> PREVENT_BLOCK_SLOWNESS = new PowerFactory<>(new Identifier(TerraOriginum.MOD_ID, "prevent_block_slowness"), new SerializableData(), data -> (type, entity) -> new PreventBlockSlowness(type, entity)).allowCondition();
public static final PowerFactory<?> WINGS_POWER = WingsPower.createFactory().allowCondition();
public static void register() {
Registry.register(ApoliRegistries.POWER_FACTORY, CAN_WALK_ON_POWDER_SNOW.getSerializerId(), CAN_WALK_ON_POWDER_SNOW);
Registry.register(ApoliRegistries.POWER_FACTORY, PREVENT_BLOCK_SLOWNESS.getSerializerId(), PREVENT_BLOCK_SLOWNESS);
Registry.register(ApoliRegistries.POWER_FACTORY, WingsPower.POWER_TYPE_ID, WINGS_POWER);
}
}

View File

@@ -0,0 +1,13 @@
package com.smithy.terraoriginum.util;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import net.minecraft.registry.Registries;
import net.minecraft.item.ItemStack;
import java.util.function.UnaryOperator;
public class CodecHelper {
public static final Codec<ItemStack> STACK_OR_ITEM_NAME = Codec.either(ItemStack.CODEC, Registries.ITEM.getCodec()).xmap(either -> either.map(UnaryOperator.identity(), ItemStack::new), Either::left);
}

View File

@@ -0,0 +1,78 @@
package com.smithy.terraoriginum.util;
import com.google.gson.JsonParseException;
import com.mojang.serialization.JsonOps;
import io.github.apace100.calio.data.SerializableDataType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import java.util.OptionalDouble;
import java.util.OptionalInt;
public class CustomDataTypes {
public static final SerializableDataType<ItemStack> STACK_OR_ITEM_NAME = new SerializableDataType<>(
ItemStack.class,
PacketByteBuf::writeItemStack,
PacketByteBuf::readItemStack,
jsonElement -> CodecHelper.STACK_OR_ITEM_NAME.decode(JsonOps.INSTANCE, jsonElement).result().orElseThrow(() -> new JsonParseException("Could not parse ItemStack from JSON.")).getFirst()
);
/*new SerializableDataType<>(ItemStack.class,
PacketByteBuf::writeItem,
PacketByteBuf::readItem,
jsonElement -> CodecHelper.STACK_OR_ITEM_NAME.decode(JsonOps.INSTANCE, jsonElement).result().orElseThrow(() -> new JsonParseException("Could not parse ItemStack from JSON.")).getFirst()
);*/
public static final SerializableDataType<OptionalBool> OPTIONAL_BOOL = new SerializableDataType<>(OptionalBool.class,
PacketByteBuf::writeEnumConstant,
buf -> buf.readEnumConstant(OptionalBool.class),
jsonElement -> {
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isBoolean()) {
return OptionalBool.of(jsonElement.getAsBoolean());
}
return OptionalBool.DEFAULT;
}
);
public static final SerializableDataType<OptionalDouble> OPTIONAL_DOUBLE = new SerializableDataType<>(OptionalDouble.class,
(buf, optionalDouble) -> {
buf.writeBoolean(optionalDouble.isPresent());
if (optionalDouble.isPresent()) {
buf.writeDouble(optionalDouble.getAsDouble());
}
},
buf -> {
if (buf.readBoolean()) {
return OptionalDouble.of(buf.readDouble());
}
return OptionalDouble.empty();
},
jsonElement -> {
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
return OptionalDouble.of(jsonElement.getAsDouble());
}
return OptionalDouble.empty();
}
);
public static final SerializableDataType<OptionalInt> OPTIONAL_INT = new SerializableDataType<>(OptionalInt.class,
(buf, optionalInt) -> {
buf.writeBoolean(optionalInt.isPresent());
if (optionalInt.isPresent()) {
buf.writeInt(optionalInt.getAsInt());
}
},
buf -> {
if (buf.readBoolean()) {
return OptionalInt.of(buf.readInt());
}
return OptionalInt.empty();
},
jsonElement -> {
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
return OptionalInt.of(jsonElement.getAsInt());
}
return OptionalInt.empty();
}
);
}

View File

@@ -0,0 +1,30 @@
package com.smithy.terraoriginum.util;
import com.smithy.terraoriginum.items.CottonItems;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.condition.RandomChanceLootCondition;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;
import net.minecraft.util.Identifier;
public class LootTableModifiers {
private static final Identifier GRASS_ID =
new Identifier("minecraft", "blocks/grass");
public static void modifyLootTables() {
LootTableEvents.MODIFY.register((resourceManager, lootManager, id, tableBuilder, source) -> {
if(GRASS_ID.equals(id)) {
LootPool.Builder poolBuilder = LootPool.builder()
.rolls(ConstantLootNumberProvider.create(1))
.conditionally(RandomChanceLootCondition.builder(0.08f))
.with(ItemEntry.builder(CottonItems.COTTON_SEEDS))
.apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(1.0f, 1.0f)).build());
tableBuilder.pool(poolBuilder.build());
}
});
}
}

View File

@@ -0,0 +1,38 @@
package com.smithy.terraoriginum.util;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import java.util.Optional;
import java.util.function.BooleanSupplier;
public enum OptionalBool {
TRUE,
FALSE,
DEFAULT;
public static OptionalBool of(Boolean value) {
return value == null ? DEFAULT : value ? TRUE : FALSE;
}
public boolean isTrue() {
return this == TRUE;
}
public boolean orElse(boolean defaultValue) {
return this == TRUE || (this == DEFAULT && defaultValue);
}
public boolean orElseGet(BooleanSupplier defaultValue) {
return this == TRUE || (this == DEFAULT && defaultValue.getAsBoolean());
}
public Optional<Boolean> asOptional() {
return this == DEFAULT ? Optional.empty() : Optional.of(isTrue());
}
public static MapCodec<OptionalBool> codecFieldOf(String fieldName) {
return Codec.BOOL.optionalFieldOf(fieldName).xmap(opt -> opt.map(aBoolean -> aBoolean ? TRUE : FALSE).orElse(DEFAULT), OptionalBool::asOptional);
}
}

View File

@@ -0,0 +1,10 @@
package com.smithy.terraoriginum.util;
import net.minecraft.entity.Entity;
public class TerraHelper {
public static boolean isWet(Entity entity) {
return entity.isWet();
}
}