generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
cb34a79
commit 32ed9b2
Showing
14 changed files
with
102 additions
and
124 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
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
4 changes: 0 additions & 4 deletions
4
src/main/java/com/portingdeadmods/nautec/content/augments/LeapAugment.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
6 changes: 0 additions & 6 deletions
6
src/main/java/com/portingdeadmods/nautec/content/augments/ThrowBouncingTridentAugment.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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/portingdeadmods/nautec/events/helper/ItemEtching.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,85 @@ | ||
package com.portingdeadmods.nautec.events.helper; | ||
|
||
import com.portingdeadmods.nautec.Nautec; | ||
import com.portingdeadmods.nautec.content.recipes.ItemEtchingRecipe; | ||
import com.portingdeadmods.nautec.registries.NTBlocks; | ||
import com.portingdeadmods.nautec.utils.ParticleUtils; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.component.DataComponentType; | ||
import net.minecraft.core.component.DataComponents; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.component.ItemContainerContents; | ||
import net.minecraft.world.item.component.SeededContainerLoot; | ||
import net.minecraft.world.item.crafting.RecipeHolder; | ||
import net.minecraft.world.item.crafting.SingleRecipeInput; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.Optional; | ||
|
||
public class ItemEtching { | ||
private static final Object2IntMap<ItemEntity> activeEtching = new Object2IntOpenHashMap<>(); | ||
|
||
public static void processItemEtching(ItemEntity itemEntity, Level level) { | ||
ItemStack stack = itemEntity.getItem(); | ||
|
||
if (!activeEtching.containsKey(itemEntity)) { | ||
Optional<ItemEtchingRecipe> optionalRecipe = getEtchingRecipe(stack, level); | ||
if (optionalRecipe.isPresent()) { | ||
activeEtching.put(itemEntity, 0); | ||
} | ||
} else { | ||
int etchingTime = activeEtching.getInt(itemEntity); | ||
|
||
if (etchingTime >= 100) { | ||
Optional<ItemEtchingRecipe> optionalRecipe = getEtchingRecipe(stack, level); | ||
if (optionalRecipe.isPresent()) { | ||
transformItem(itemEntity, optionalRecipe.get(), level); | ||
} | ||
activeEtching.removeInt(itemEntity); | ||
} else { | ||
activeEtching.put(itemEntity, etchingTime + 1); | ||
// Optionally spawn particles while etching | ||
ParticleUtils.spawnParticlesAroundItem(itemEntity, level, ParticleTypes.FLAME); | ||
} | ||
} | ||
} | ||
|
||
private static Optional<ItemEtchingRecipe> getEtchingRecipe(ItemStack stack, Level level) { | ||
return level.getRecipeManager() | ||
.getRecipeFor(ItemEtchingRecipe.Type.INSTANCE, new SingleRecipeInput(stack), level) | ||
.map(RecipeHolder::value); | ||
} | ||
|
||
private static void transformItem(ItemEntity itemEntity, ItemEtchingRecipe recipe, Level level) { | ||
BlockPos position = itemEntity.getOnPos(); | ||
ItemStack inputStack = itemEntity.getItem(); | ||
ItemStack resultStack = recipe.getResultItem(level.registryAccess()).copy(); | ||
resultStack.setCount(itemEntity.getItem().getCount()); | ||
|
||
if (inputStack.is(NTBlocks.RUSTY_CRATE.asItem()) && resultStack.is(NTBlocks.CRATE.asItem())) { | ||
ItemContainerContents value = itemEntity.getItem().copy().get(DataComponents.CONTAINER); | ||
resultStack.set(DataComponents.CONTAINER, value); | ||
SeededContainerLoot value1 = itemEntity.getItem().copy().get(DataComponents.CONTAINER_LOOT); | ||
resultStack.set(DataComponents.CONTAINER_LOOT, value1); | ||
} | ||
|
||
itemEntity.discard(); | ||
|
||
int rand = level.random.nextInt(0, 3); | ||
if (rand == 2) { | ||
level.setBlock(itemEntity.getOnPos(), Blocks.AIR.defaultBlockState(), 11); | ||
} | ||
|
||
ItemEntity newItemEntity = new ItemEntity(level, position.getX(), position.getY(), position.getZ(), resultStack); | ||
level.addFreshEntity(newItemEntity); | ||
} | ||
|
||
} |
Oops, something went wrong.