diff --git a/src/generated/resources/.cache/5db5b310cf1abc4c7f33d2d565e2a2290a7f6c4d b/src/generated/resources/.cache/5db5b310cf1abc4c7f33d2d565e2a2290a7f6c4d index 86f253a2..ab9af2ee 100644 --- a/src/generated/resources/.cache/5db5b310cf1abc4c7f33d2d565e2a2290a7f6c4d +++ b/src/generated/resources/.cache/5db5b310cf1abc4c7f33d2d565e2a2290a7f6c4d @@ -1,10 +1,10 @@ -// 1.21.1 2024-09-07T19:25:16.955058691 Item Models: modjam +// 1.21.1 2024-09-08T11:01:34.5874471 Item Models: modjam 207e815e9b4c9ebca4f444f877e2488a5ce9b1c5 assets/modjam/models/item/aquarine_steel.json 51765874ad3111adf69684269ad9a422bfbaac4a assets/modjam/models/item/aquarine_steel_block.json dd0c37deb1f33fb0844da4a540706681887fc3d4 assets/modjam/models/item/aquatic_catalyst.json 246cda7a0fca8b278dd6ed5392d0ce745d9fa097 assets/modjam/models/item/chiseled_dark_prismarine.json 5dd5fd7a7c348bbaf51df14605c5241bf75e18ae assets/modjam/models/item/dark_prismarine_pillar.json +4d48047a9639345841262719f87f57c3494e4a55 assets/modjam/models/item/deep_sea_drain.json 5b6b9e8621c065cb4167e4b6dfdfaecb0fd7186d assets/modjam/models/item/eas_vial.json f0f9891cd57b3a66f7440a71b925348bb8ea745b assets/modjam/models/item/glass_vial.json dab337d602d93b0a4930b69e652b1155300c6502 assets/modjam/models/item/prism_monocle.json -c01b567bc1c1fdc5563e08b663fa59595f3efed8 assets/modjam/models/item/prismarine_crucible.json diff --git a/src/generated/resources/.cache/7383b985a2cdbb3a068dc5fd3ae4ba545545c370 b/src/generated/resources/.cache/7383b985a2cdbb3a068dc5fd3ae4ba545545c370 index f114257f..85dbb50a 100644 --- a/src/generated/resources/.cache/7383b985a2cdbb3a068dc5fd3ae4ba545545c370 +++ b/src/generated/resources/.cache/7383b985a2cdbb3a068dc5fd3ae4ba545545c370 @@ -1,9 +1,8 @@ -// 1.21.1 2024-09-07T19:25:16.970839509 Block States: modjam +// 1.21.1 2024-09-08T11:01:34.5904385 Block States: modjam af3ef9c17c60ced537516e8aa1215fcb76e3683e assets/modjam/blockstates/aquarine_steel_block.json 865a45a4d022b56bc54dc32dae4b666af2df7d6f assets/modjam/blockstates/aquatic_catalyst.json 6e42254717fc67a953282f50517eb06c02193129 assets/modjam/blockstates/chiseled_dark_prismarine.json 791da2d01b6b33bb1ce175d5c9c1fa5b737c9dfc assets/modjam/blockstates/dark_prismarine_pillar.json -02c24ce3baaa9c5e8e571090695486c7be860fc5 assets/modjam/blockstates/prismarine_crucible.json 5ca1917566d04d2f7fefbfa648958c06d3238f67 assets/modjam/models/block/aquarine_steel_block.json 4d2484ce030aeac9f86e39b1dffd193afb69271f assets/modjam/models/block/aquatic_catalyst.json 7dac030be8fd8eb7409ecb588476b3379d53142f assets/modjam/models/block/aquatic_catalyst_down.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 5d12b8f0..b89e5b66 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1 +1,2 @@ -// 1.21.1 2024-09-06T15:44:54.651739 Recipes +// 1.21.1 2024-09-08T11:01:34.5914309 Recipes +7ee5f7bbf9d978b4b659502cf6c42314dbe3678b data/modjam/recipe/aquarine_steel.json diff --git a/src/generated/resources/assets/modjam/models/item/deep_sea_drain.json b/src/generated/resources/assets/modjam/models/item/deep_sea_drain.json new file mode 100644 index 00000000..90dde8c5 --- /dev/null +++ b/src/generated/resources/assets/modjam/models/item/deep_sea_drain.json @@ -0,0 +1,3 @@ +{ + "parent": "modjam:block/deep_sea_drain" +} \ No newline at end of file diff --git a/src/generated/resources/data/modjam/recipe/aquarine_steel.json b/src/generated/resources/data/modjam/recipe/aquarine_steel.json new file mode 100644 index 00000000..0a3201d0 --- /dev/null +++ b/src/generated/resources/data/modjam/recipe/aquarine_steel.json @@ -0,0 +1,12 @@ +{ + "type": "modjam:item_transformation", + "ingredients": [ + { + "item": "minecraft:iron_ingot" + } + ], + "result": { + "count": 1, + "id": "modjam:aquarine_steel" + } +} \ No newline at end of file diff --git a/src/main/java/com/portingdeadmods/modjam/ModJam.java b/src/main/java/com/portingdeadmods/modjam/ModJam.java index d6ddbf9a..811dccaf 100644 --- a/src/main/java/com/portingdeadmods/modjam/ModJam.java +++ b/src/main/java/com/portingdeadmods/modjam/ModJam.java @@ -1,5 +1,9 @@ package com.portingdeadmods.modjam; +import com.portingdeadmods.modjam.content.augments.AugmentHelper; +import com.portingdeadmods.modjam.content.augments.DisallowBreakingAugment; +import com.portingdeadmods.modjam.content.augments.GiveDiamondAugment; +import com.portingdeadmods.modjam.content.augments.ThrowSnowballAugment; import com.portingdeadmods.modjam.content.items.PrismMonocleItem; import com.portingdeadmods.modjam.data.MJDataComponents; import com.portingdeadmods.modjam.registries.*; @@ -23,14 +27,19 @@ public final class ModJam { public ModJam(IEventBus modEventBus, ModContainer modContainer) { modEventBus.addListener(NewRegistryEvent.class, event -> event.register(MJRegistries.MULTIBLOCK)); + AugmentHelper.AddAugment(new DisallowBreakingAugment(), 1); + AugmentHelper.AddAugment(new GiveDiamondAugment(), 2); + AugmentHelper.AddAugment(new ThrowSnowballAugment(), 3); + MJItems.ITEMS.register(modEventBus); - MJBlocks.BLOCKS.register(modEventBus); - MJDataAttachments.ATTACHMENTS.register(modEventBus); MJFluids.FLUIDS.register(modEventBus); + MJBlocks.BLOCKS.register(modEventBus); + MJRecipes.SERIALIZERS.register(modEventBus); MJFluidTypes.FLUID_TYPES.register(modEventBus); + MJDataAttachments.ATTACHMENTS.register(modEventBus); + MJBlockEntityTypes.BLOCK_ENTITIES.register(modEventBus); MJCreativeTabs.CREATIVE_MODE_TABS.register(modEventBus); MJDataComponents.DATA_COMPONENT_TYPES.register(modEventBus); - MJBlockEntityTypes.BLOCK_ENTITIES.register(modEventBus); modEventBus.addListener(PrismMonocleItem::registerCapabilities); diff --git a/src/main/java/com/portingdeadmods/modjam/api/blockentities/LaserBlockEntity.java b/src/main/java/com/portingdeadmods/modjam/api/blockentities/LaserBlockEntity.java index 80eac754..a2994f55 100644 --- a/src/main/java/com/portingdeadmods/modjam/api/blockentities/LaserBlockEntity.java +++ b/src/main/java/com/portingdeadmods/modjam/api/blockentities/LaserBlockEntity.java @@ -1,6 +1,8 @@ package com.portingdeadmods.modjam.api.blockentities; import com.portingdeadmods.modjam.api.blocks.blockentities.LaserBlock; +import com.portingdeadmods.modjam.recipes.ItemTransformationRecipe; +import com.portingdeadmods.modjam.recipes.MJRecipeInput; import com.portingdeadmods.modjam.registries.MJItems; import com.portingdeadmods.modjam.utils.ParticlesUtils; import it.unimi.dsi.fastutil.objects.Object2IntMap; @@ -13,15 +15,14 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.items.ItemStackHandler; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public abstract class LaserBlockEntity extends ContainerBlockEntity { private static final int MAX_DISTANCE = 16; @@ -83,6 +84,58 @@ private void transmitPower() { private ItemEntity cookingItem = null; private int cookTime = 0; + private void damageLivingEntities(AABB box) { + List livingEntities = level.getEntitiesOfClass(LivingEntity.class, box); + for (LivingEntity livingEntity : livingEntities) { + livingEntity.hurt(level.damageSources().inFire(), 3); + } + } + + private void processItemCrafting(AABB box) { + assert level != null; + List itemEntities = level.getEntitiesOfClass(ItemEntity.class, box); + if (cookingItem == null) { + for (ItemEntity itemEntity : itemEntities) { + if (itemEntity.getItem().is(Items.IRON_INGOT)) { + cookingItem = itemEntity; + cookTime = 0; + break; + } + } + } else { + if (cookTime >= 40) { + int stackSize = cookingItem.getItem().getCount(); + BlockPos spawnPos = cookingItem.blockPosition(); + cookingItem.discard(); + ItemStack newStack = new ItemStack(MJItems.AQUARINE_STEEL.get(), stackSize); + ItemEntity newItemEntity = new ItemEntity(level, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), newStack); + level.addFreshEntity(newItemEntity); + cookingItem = null; + cookTime = 0; + } else { + cookTime++; + ParticlesUtils.spawnParticles(cookingItem, level, ParticleTypes.END_ROD); + } + } + + if (cookingItem != null && (!cookingItem.isAlive() || !cookingItem.getItem().is(Items.IRON_INGOT))) { + cookingItem = null; + cookTime = 0; + } + } + + + private Optional> getCurrentRecipe() { + ItemStackHandler stackHandler = this.getItemStackHandler(); + List itemStacks = new ArrayList<>(stackHandler.getSlots()); + for (int i = 0; i < stackHandler.getSlots() - 1; i++) { + itemStacks.add(stackHandler.getStackInSlot(i)); + } + MJRecipeInput recipeInput = new MJRecipeInput(itemStacks); + return this.level.getRecipeManager().getRecipeFor(ItemTransformationRecipe.Type.INSTANCE, recipeInput, level); + } + + private void damageLiving() { for (Direction direction : getLaserOutputs()) { int distance = this.laserDistances.getInt(direction); @@ -93,38 +146,14 @@ private void damageLiving() { this.box = box; assert level != null; - List livingEntities = level.getEntitiesOfClass(LivingEntity.class, box); - for (LivingEntity livingEntity : livingEntities) { - livingEntity.hurt(level.damageSources().inFire(), 3); - } - List itemEntities = level.getEntitiesOfClass(ItemEntity.class, box); - if (cookingItem == null) { - for (ItemEntity itemEntity : itemEntities) { - if (itemEntity.getItem().is(Items.IRON_INGOT)) { - cookingItem = itemEntity; - cookTime = 0; - break; - } - } - } else { - if (cookTime >= 40) { - cookingItem.setItem(new ItemStack(MJItems.AQUARINE_STEEL.get())); - cookingItem = null; - cookTime = 0; - } else { - cookTime++; - ParticlesUtils.spawnParticles(cookingItem,level,ParticleTypes.END_ROD); - } - } + damageLivingEntities(box); - if (cookingItem != null && (!cookingItem.isAlive() || !cookingItem.getItem().is(Items.IRON_INGOT))) { - cookingItem = null; - cookTime = 0; - } + processItemCrafting(box); } } + private void checkConnections() { for (Direction direction : getLaserOutputs()) { for (int i = 1; i < MAX_DISTANCE; i++) { diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/AugmentHelper.java b/src/main/java/com/portingdeadmods/modjam/content/augments/AugmentHelper.java index 4b2aaef3..64482d60 100644 --- a/src/main/java/com/portingdeadmods/modjam/content/augments/AugmentHelper.java +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/AugmentHelper.java @@ -7,9 +7,20 @@ import net.minecraft.world.entity.player.Player; import net.neoforged.neoforge.attachment.AttachmentType; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.function.Supplier; public class AugmentHelper { + private static HashMap augmentHashMap = new HashMap<>(); + public static void AddAugment(StaticAugment augment, int id){ + augmentHashMap.put(id, augment); + } + public static StaticAugment getAugment(Player player, Slot slot){ + int id = getId(player, slot); + return augmentHashMap.get(id); + } private static Supplier> getAttachment(Slot slot){ switch (slot){ case HEAD -> { @@ -51,4 +62,14 @@ public static boolean playerHasAugment(Player player, Slot slot, Augments augmen return getId(player, slot) == augment.id; } + public static StaticAugment[] getAugments(Player player) { + List augments = new ArrayList(); + augments.add(getAugment(player, Slot.HEAD)); + augments.add(getAugment(player, Slot.BODY)); + augments.add(getAugment(player, Slot.ARMS)); + augments.add(getAugment(player, Slot.LEGS)); + augments.add(getAugment(player, Slot.HEART)); + + return augments.toArray(new StaticAugment[0]); + } } diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/Augments.java b/src/main/java/com/portingdeadmods/modjam/content/augments/Augments.java index 000573a2..5cc12263 100644 --- a/src/main/java/com/portingdeadmods/modjam/content/augments/Augments.java +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/Augments.java @@ -1,7 +1,7 @@ package com.portingdeadmods.modjam.content.augments; public enum Augments { - TEST_AUGMENT(69); + TEST_AUGMENT(1); public final int id; Augments(int id){ diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/DisallowBreakingAugment.java b/src/main/java/com/portingdeadmods/modjam/content/augments/DisallowBreakingAugment.java new file mode 100644 index 00000000..396a2088 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/DisallowBreakingAugment.java @@ -0,0 +1,24 @@ +package com.portingdeadmods.modjam.content.augments; + +import com.mojang.blaze3d.platform.InputConstants; +import com.portingdeadmods.modjam.utils.InputUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; + +public class DisallowBreakingAugment implements StaticAugment{ + @Override + public void breakBlock(BlockEvent.BreakEvent event) { + // Player player = event.getPlayer(); + event.setCanceled(true); + } + + @Override + public void tick(PlayerTickEvent.Post event) { + if (InputUtils.isKeyDown(InputConstants.KEY_Y)){ + event.getEntity().addItem(Items.EMERALD.getDefaultInstance()); + } + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/GiveDiamondAugment.java b/src/main/java/com/portingdeadmods/modjam/content/augments/GiveDiamondAugment.java new file mode 100644 index 00000000..934f0b04 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/GiveDiamondAugment.java @@ -0,0 +1,24 @@ +package com.portingdeadmods.modjam.content.augments; + +import com.mojang.blaze3d.platform.InputConstants; +import com.portingdeadmods.modjam.utils.InputUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; +import org.lwjgl.system.linux.Stat; + +public class GiveDiamondAugment implements StaticAugment { + @Override + public void breakBlock(BlockEvent.BreakEvent event) { + + } + + @Override + public void tick(PlayerTickEvent.Post event) { + if (InputUtils.isKeyDown(InputConstants.KEY_Y)) { + event.getEntity().addItem(Items.DIAMOND.getDefaultInstance()); + } + + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/StaticAugment.java b/src/main/java/com/portingdeadmods/modjam/content/augments/StaticAugment.java new file mode 100644 index 00000000..701e68bc --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/StaticAugment.java @@ -0,0 +1,10 @@ +package com.portingdeadmods.modjam.content.augments; + +import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; + +public interface StaticAugment { + void breakBlock(BlockEvent.BreakEvent event); + + void tick(PlayerTickEvent.Post event); +} diff --git a/src/main/java/com/portingdeadmods/modjam/content/augments/ThrowSnowballAugment.java b/src/main/java/com/portingdeadmods/modjam/content/augments/ThrowSnowballAugment.java new file mode 100644 index 00000000..38865e95 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/content/augments/ThrowSnowballAugment.java @@ -0,0 +1,29 @@ +package com.portingdeadmods.modjam.content.augments; + +import com.mojang.blaze3d.platform.InputConstants; +import com.portingdeadmods.modjam.ModJam; +import com.portingdeadmods.modjam.utils.InputUtils; +import net.minecraft.world.entity.projectile.Snowball; +import net.minecraft.world.item.Items; +import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; + +public class ThrowSnowballAugment implements StaticAugment { + @Override + public void breakBlock(BlockEvent.BreakEvent event) { + + } + + @Override + public void tick(PlayerTickEvent.Post event) { + if (InputUtils.isKeyDown(InputConstants.KEY_Y)) { + ModJam.LOGGER.info("Snow"); + if (!event.getEntity().level().isClientSide) { + Snowball snowball = new Snowball(event.getEntity().level(), event.getEntity()); + snowball.setItem(Items.SNOWBALL.getDefaultInstance()); + snowball.shootFromRotation(event.getEntity(), event.getEntity().getXRot(), event.getEntity().getYRot(), 0.0F, 1.5F, 1.0F); + event.getEntity().level().addFreshEntity(snowball); + } + } + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/content/items/AugmentDebugItem.java b/src/main/java/com/portingdeadmods/modjam/content/items/AugmentDebugItem.java index 31e7cddb..d86c7119 100644 --- a/src/main/java/com/portingdeadmods/modjam/content/items/AugmentDebugItem.java +++ b/src/main/java/com/portingdeadmods/modjam/content/items/AugmentDebugItem.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.platform.InputConstants; import com.portingdeadmods.modjam.capabilities.augmentation.Slot; import com.portingdeadmods.modjam.content.augments.AugmentHelper; +import com.portingdeadmods.modjam.utils.InputUtils; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; @@ -33,21 +34,15 @@ public boolean onDroppedByPlayer(@NotNull ItemStack item, Player player) { Player player = context.getPlayer(); Block clickedBlock = level.getBlockState(context.getClickedPos()).getBlock(); if (level.isClientSide) return InteractionResult.SUCCESS; - if (clickedBlock == Blocks.DIRT){ - if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),InputConstants.KEY_LSHIFT)){ - AugmentHelper.decId(player, Slot.HEAD); - } else { - AugmentHelper.incId(player, Slot.HEAD); - } - } else if (clickedBlock == Blocks.STONE){ - if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),InputConstants.KEY_LSHIFT)){ - AugmentHelper.decId(player, Slot.BODY); - } else { - AugmentHelper.incId(player, Slot.BODY); - } + if (InputUtils.isKeyDown(InputConstants.KEY_LSHIFT)){ + if (clickedBlock == Blocks.DIRT) AugmentHelper.decId(player,Slot.HEAD); + else if (clickedBlock == Blocks.STONE) AugmentHelper.decId(player, Slot.BODY); + } else if (InputUtils.isKeyDown(InputConstants.KEY_LCONTROL)){ + onDroppedByPlayer(context.getItemInHand(),player); + } else { + if (clickedBlock == Blocks.DIRT) AugmentHelper.incId(player,Slot.HEAD); + else if (clickedBlock == Blocks.STONE) AugmentHelper.incId(player, Slot.BODY); } - - return super.useOn(context); } } diff --git a/src/main/java/com/portingdeadmods/modjam/datagen/RecipesProvider.java b/src/main/java/com/portingdeadmods/modjam/datagen/RecipesProvider.java index 05ee0c2a..54392a70 100644 --- a/src/main/java/com/portingdeadmods/modjam/datagen/RecipesProvider.java +++ b/src/main/java/com/portingdeadmods/modjam/datagen/RecipesProvider.java @@ -1,8 +1,13 @@ package com.portingdeadmods.modjam.datagen; +import com.portingdeadmods.modjam.datagen.recipe_builder.ItemTransformationRecipeBuilder; +import com.portingdeadmods.modjam.registries.MJItems; import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.*; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.CompletableFuture; @@ -12,7 +17,9 @@ public RecipesProvider(PackOutput pOutput, CompletableFuture ingredients; + @NotNull private final ItemStack result; + + private ItemTransformationRecipeBuilder(ItemStack result) { + this.ingredients = new ArrayList<>(); + this.result = result; + } + + public static ItemTransformationRecipeBuilder newRecipe(ItemStack result) { + return new ItemTransformationRecipeBuilder(result); + } + + @Override + public @NotNull ItemTransformationRecipeBuilder unlockedBy(String s, Criterion criterion) { + return this; + } + + public ItemTransformationRecipeBuilder ingredients(IngredientWithCount... ingredients) { + this.ingredients.addAll(Arrays.stream(ingredients).toList()); + return this; + } + public ItemTransformationRecipeBuilder ingredients(ItemStack... items) { + this.ingredients.addAll(Arrays.stream(items).map(IngredientWithCount::fromItemStack).toList()); + return this; + } + + public ItemTransformationRecipeBuilder ingredients(ItemLike... items) { + this.ingredients.addAll(Arrays.stream(items).map(IngredientWithCount::fromItemLike).toList()); + return this; + } + + @SafeVarargs + public final ItemTransformationRecipeBuilder ingredients(TagKey... items) { + this.ingredients.addAll(Arrays.stream(items).map(IngredientWithCount::fromItemTag).toList()); + return this; + } + + @Override + public @NotNull ItemTransformationRecipeBuilder group(@Nullable String group) { + return this; + } + + @Override + public @NotNull Item getResult() { + return result.getItem(); + } + + @Override + public void save(RecipeOutput recipeOutput, ResourceLocation resourceLocation) { + ItemTransformationRecipe recipe = new ItemTransformationRecipe(this.ingredients, this.result); + recipeOutput.accept(resourceLocation, recipe, null); + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/events/AugmentEvents.java b/src/main/java/com/portingdeadmods/modjam/events/AugmentEvents.java index 7e6f24cf..ad0add49 100644 --- a/src/main/java/com/portingdeadmods/modjam/events/AugmentEvents.java +++ b/src/main/java/com/portingdeadmods/modjam/events/AugmentEvents.java @@ -1,46 +1,33 @@ package com.portingdeadmods.modjam.events; import com.portingdeadmods.modjam.ModJam; -import com.portingdeadmods.modjam.capabilities.augmentation.Slot; -import com.portingdeadmods.modjam.content.augments.Augment; import com.portingdeadmods.modjam.content.augments.AugmentHelper; -import com.portingdeadmods.modjam.content.augments.Augments; -import net.minecraft.world.entity.player.Player; +import com.portingdeadmods.modjam.content.augments.StaticAugment; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.event.entity.player.PlayerEvent; -import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; @SuppressWarnings("unused") @EventBusSubscriber(modid = ModJam.MODID) public class AugmentEvents { @SubscribeEvent public static void breakEvent(BlockEvent.BreakEvent event){ - Player player = event.getPlayer(); - if(AugmentHelper.playerHasAugment(player, Slot.HEAD, Augments.TEST_AUGMENT)){ - Augment.onBreak(event); - } - } - @SubscribeEvent - public static void breakSpeedEvent(PlayerEvent.BreakSpeed event){ - Player player = event.getEntity(); - if(AugmentHelper.playerHasAugment(player, Slot.HEAD, Augments.TEST_AUGMENT)){ - ModJam.LOGGER.info("break speed with augment"); - Augment.onBreakSpeed(event); + StaticAugment[] augments = AugmentHelper.getAugments(event.getPlayer()); + for (int i = 0; i < augments.length; i++) { + if (augments[i] != null){ + augments[i].breakBlock(event); + } } } + @SubscribeEvent - public static void blockInteractionEvent(PlayerInteractEvent.LeftClickBlock event){ - Player player = event.getEntity(); - if(AugmentHelper.playerHasAugment(player, Slot.HEAD, Augments.TEST_AUGMENT)){ - ModJam.LOGGER.info("interact with augment"); - Augment.onBlockLeftClick(event); + public static void playerTick(PlayerTickEvent.Post event){ + StaticAugment[] augments = AugmentHelper.getAugments(event.getEntity()); + for (int i = 0; i < augments.length; i++) { + if (augments[i] != null){ + augments[i].tick(event); + } } } - @SubscribeEvent - public static void loggedIn(PlayerEvent.PlayerLoggedInEvent event){ - ModJam.LOGGER.info("Id on logged in: "+AugmentHelper.getId(event.getEntity(),Slot.HEAD)); - } - } diff --git a/src/main/java/com/portingdeadmods/modjam/events/MJEvents.java b/src/main/java/com/portingdeadmods/modjam/events/MJEvents.java deleted file mode 100644 index 7eacecdc..00000000 --- a/src/main/java/com/portingdeadmods/modjam/events/MJEvents.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.portingdeadmods.modjam.events; - -import static net.minecraft.world.item.Item.getPlayerPOVHitResult; - -//@EventBusSubscriber(modid = ModJam.MODID, bus = EventBusSubscriber.Bus.GAME) -public class MJEvents { - - //Fuck events, im gonna mixin vanilla - -} diff --git a/src/main/java/com/portingdeadmods/modjam/recipes/ItemTransformationRecipe.java b/src/main/java/com/portingdeadmods/modjam/recipes/ItemTransformationRecipe.java new file mode 100644 index 00000000..21fce526 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/recipes/ItemTransformationRecipe.java @@ -0,0 +1,101 @@ +package com.portingdeadmods.modjam.recipes; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.portingdeadmods.modjam.recipes.utils.IngredientWithCount; +import com.portingdeadmods.modjam.recipes.utils.RecipeUtils; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.NonNullList; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.*; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public record ItemTransformationRecipe(List ingredients, ItemStack result) implements Recipe { + public static final String NAME = "item_transformation"; + + @Override + public boolean matches(@NotNull MJRecipeInput recipeInput, @NotNull Level level) { + List inputItems = recipeInput.items().stream().filter(input -> !input.isEmpty()).toList(); + return RecipeUtils.compareItems(inputItems, ingredients); + } + + @Override + public @NotNull ItemStack assemble(@NotNull MJRecipeInput input, HolderLookup.@NotNull Provider registries) { + return result.copy(); + } + + @Override + public boolean canCraftInDimensions(int width, int height) { + return true; + } + + @Override + public @NotNull ItemStack getResultItem(HolderLookup.@NotNull Provider registries) { + return result.copy(); + } + + @Override + public @NotNull RecipeSerializer getSerializer() { + return Serializer.INSTANCE; + } + + @Override + public @NotNull RecipeType getType() { + return Type.INSTANCE; + } + + @Override + public @NotNull NonNullList getIngredients() { + return RecipeUtils.listToNonNullList(RecipeUtils.iWCToIngredientsSaveCount(ingredients)); + } + + public @NotNull NonNullList getIngredientsWithCount() { + return RecipeUtils.listToNonNullList(ingredients); + } + + public static class Serializer implements RecipeSerializer { + public static final ItemTransformationRecipe.Serializer INSTANCE = new ItemTransformationRecipe.Serializer(); + private static final MapCodec MAP_CODEC = RecordCodecBuilder.mapCodec((builder) -> builder.group( + IngredientWithCount.CODEC.listOf().fieldOf("ingredients").forGetter(ItemTransformationRecipe::ingredients), + ItemStack.OPTIONAL_CODEC.fieldOf("result").forGetter(ItemTransformationRecipe::result) + ).apply(builder, ItemTransformationRecipe::new)); + private static final StreamCodec STREAM_CODEC = StreamCodec.composite( + IngredientWithCount.STREAM_CODEC.apply(ByteBufCodecs.list()), + ItemTransformationRecipe::ingredients, + ItemStack.OPTIONAL_STREAM_CODEC, + ItemTransformationRecipe::result, + ItemTransformationRecipe::new + ); + + private Serializer() { + } + + @Override + public @NotNull MapCodec codec() { + return MAP_CODEC; + } + + @Override + public @NotNull StreamCodec streamCodec() { + return STREAM_CODEC; + } + } + + public static class Type implements RecipeType { + public static final ItemTransformationRecipe.Type INSTANCE = new ItemTransformationRecipe.Type(); + + private Type() { + } + + @Override + public String toString() { + return ItemTransformationRecipe.NAME; + } + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/recipes/MJRecipeInput.java b/src/main/java/com/portingdeadmods/modjam/recipes/MJRecipeInput.java new file mode 100644 index 00000000..55250902 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/recipes/MJRecipeInput.java @@ -0,0 +1,25 @@ +package com.portingdeadmods.modjam.recipes; + + +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeInput; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public record MJRecipeInput(List items) implements RecipeInput { + + public MJRecipeInput(ItemStack ...items) { + this(List.of(items)); + } + + @Override + public @NotNull ItemStack getItem(int i) { + return items.get(i); + } + + @Override + public int size() { + return items.size(); + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/recipes/utils/IngredientWithCount.java b/src/main/java/com/portingdeadmods/modjam/recipes/utils/IngredientWithCount.java new file mode 100644 index 00000000..95ed5938 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/recipes/utils/IngredientWithCount.java @@ -0,0 +1,56 @@ +package com.portingdeadmods.modjam.recipes.utils; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.ItemLike; + +public record IngredientWithCount(Ingredient ingredient, int count) { + public static final IngredientWithCount EMPTY = new IngredientWithCount(Ingredient.EMPTY, -1); + // Note: for implementation reasons count has to be above ingredient, otherwise we will get a JSON Null issue thingy + private static final Codec> PAIR_CODEC = Codec.pair( + Codec.INT.optionalFieldOf("count", 1).codec(), + Ingredient.CODEC + ); + + public static final Codec CODEC = PAIR_CODEC.xmap(pair -> new IngredientWithCount(pair.getSecond(), pair.getFirst()), + iwc -> new Pair<>(iwc.count, iwc.ingredient)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + Ingredient.CONTENTS_STREAM_CODEC, + IngredientWithCount::ingredient, + ByteBufCodecs.INT, + IngredientWithCount::count, + IngredientWithCount::new + ); + + public boolean test(ItemStack itemStack) { + return ingredient.test(itemStack) && itemStack.getCount() >= count; + } + + public static IngredientWithCount fromItemStack(ItemStack itemStack) { + return new IngredientWithCount(Ingredient.of(itemStack), itemStack.getCount()); + } + + public static IngredientWithCount fromItemTag(TagKey itemTagKey) { + return new IngredientWithCount(Ingredient.of(itemTagKey), 1); + } + + public static IngredientWithCount fromItemTag(TagKey itemTagKey, int count) { + return new IngredientWithCount(Ingredient.of(itemTagKey), count); + } + + public static IngredientWithCount fromItemLike(ItemLike itemLike) { + return new IngredientWithCount(Ingredient.of(itemLike), 1); + } + + public static IngredientWithCount fromItemLike(ItemLike itemLike, int count) { + return new IngredientWithCount(Ingredient.of(itemLike), count); + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/recipes/utils/RecipeUtils.java b/src/main/java/com/portingdeadmods/modjam/recipes/utils/RecipeUtils.java new file mode 100644 index 00000000..2c774a42 --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/recipes/utils/RecipeUtils.java @@ -0,0 +1,141 @@ +package com.portingdeadmods.modjam.recipes.utils; + +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +public final class RecipeUtils { + public static List ingredientsToIWC(List ingredients) { + return ingredients.stream().map(ingredient -> new IngredientWithCount(ingredient, 1)).toList(); + } + + public static List iWCToIngredients(List ingredientsWithCount) { + return ingredientsWithCount.stream().map(IngredientWithCount::ingredient).toList(); + } + + public static List iWCToIngredientsSaveCount(List ingredientsWithCount) { + return ingredientsWithCount.stream().map(RecipeUtils::iWCToIngredientSaveCount).toList(); + } + + public static @NotNull Ingredient iWCToIngredientSaveCount(IngredientWithCount ingredientWithCount) { + Ingredient ingredient = ingredientWithCount.ingredient(); + for (ItemStack itemStack : ingredient.getItems()) { + itemStack.setCount(ingredientWithCount.count()); + } + return ingredient; + } + + public static NonNullList listToNonNullList(List list) { + NonNullList nnl = NonNullList.create(); + nnl.addAll(list); + return nnl; + } + + public static boolean compareItems(List inputs, List ingredients) { + int elements = inputs.size(); + if (elements != ingredients.size()) { + return false; + } else { + int[] ret = new int[elements]; + + Arrays.fill(ret, -1); + + BitSet data = new BitSet((elements + 2) * elements); + + for (int x = 0; x < elements; ++x) { + int matched = 0; + int offset = (x + 2) * elements; + IngredientWithCount test = ingredients.get(x); + + for (int y = 0; y < elements; ++y) { + if (!data.get(y) && test.test(inputs.get(y))) { + data.set(offset + y); + ++matched; + } + } + + if (matched == 0) { + return false; + } + + if (matched == 1 && !claim(ret, data, x, elements)) { + return false; + } + } + + if (data.nextClearBit(0) >= elements) { + return true; + } else return backtrack(data, ret, 0, elements); + } + } + + private static boolean claim(int[] ret, BitSet data, int claimed, int elements) { + Queue pending = new LinkedList<>(); + pending.add(claimed); + + while (pending.peek() != null) { + int test = (Integer) pending.poll(); + int offset = (test + 2) * elements; + int used = data.nextSetBit(offset) - offset; + if (used >= elements || used < 0) { + throw new IllegalStateException("What? We matched something, but it wasn't set in the range of this test! Test: " + test + " Used: " + used); + } + + data.set(used); + data.set(elements + test); + ret[used] = test; + + for (int x = 0; x < elements; ++x) { + offset = (x + 2) * elements; + if (data.get(offset + used) && !data.get(elements + x)) { + data.clear(offset + used); + int count = 0; + + for (int y = offset; y < offset + elements; ++y) { + if (data.get(y)) { + ++count; + } + } + + if (count == 0) { + return false; + } + + if (count == 1) { + pending.add(x); + } + } + } + } + + return true; + } + + private static boolean backtrack(BitSet data, int[] ret, int start, int elements) { + int test = data.nextClearBit(elements + start) - elements; + if (test >= elements) { + return true; + } else if (test < 0) { + throw new IllegalStateException("This should never happen, negative test in backtrack!"); + } else { + int offset = (test + 2) * elements; + + for (int x = 0; x < elements; ++x) { + if (data.get(offset + x) && !data.get(x)) { + data.set(x); + if (backtrack(data, ret, test + 1, elements)) { + ret[x] = test; + return true; + } + + data.clear(x); + } + } + + return false; + } + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/registries/MJRecipes.java b/src/main/java/com/portingdeadmods/modjam/registries/MJRecipes.java new file mode 100644 index 00000000..80cf6b0f --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/registries/MJRecipes.java @@ -0,0 +1,17 @@ +package com.portingdeadmods.modjam.registries; + +import com.portingdeadmods.modjam.ModJam; +import com.portingdeadmods.modjam.recipes.ItemTransformationRecipe; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.neoforged.neoforge.registries.DeferredRegister; + +public class MJRecipes { + public static final DeferredRegister> SERIALIZERS = + DeferredRegister.create(BuiltInRegistries.RECIPE_SERIALIZER, ModJam.MODID); + + static { + SERIALIZERS.register(ItemTransformationRecipe.NAME, () -> ItemTransformationRecipe.Serializer.INSTANCE); + } + +} diff --git a/src/main/java/com/portingdeadmods/modjam/utils/InputUtils.java b/src/main/java/com/portingdeadmods/modjam/utils/InputUtils.java new file mode 100644 index 00000000..785ed48e --- /dev/null +++ b/src/main/java/com/portingdeadmods/modjam/utils/InputUtils.java @@ -0,0 +1,10 @@ +package com.portingdeadmods.modjam.utils; + +import com.mojang.blaze3d.platform.InputConstants; +import net.minecraft.client.Minecraft; + +public class InputUtils { + public static boolean isKeyDown(int key){ + return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(),key); + } +} diff --git a/src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java b/src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java index b6670ccf..51ad8e15 100644 --- a/src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java +++ b/src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java @@ -1,7 +1,6 @@ package com.portingdeadmods.modjam.utils; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.level.Level; diff --git a/src/main/resources/data/modjam/recipe/item_transformation/balls.json b/src/main/resources/data/modjam/recipe/item_transformation/balls.json new file mode 100644 index 00000000..e69de29b