diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-08-29 20:16:09 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-08-29 20:16:09 +0100 |
commit | a243923a3f4c9a6ff2b87a04c14b3e305866521d (patch) | |
tree | 4092183ff71f76e20bfcc0d87c2282e0a0ee1866 /src | |
parent | 9a90ba748f11fc06662ceeb83c6a8e3efcae668e (diff) | |
download | eye-of-nether-a243923a3f4c9a6ff2b87a04c14b3e305866521d.tar.gz eye-of-nether-a243923a3f4c9a6ff2b87a04c14b3e305866521d.tar.xz eye-of-nether-a243923a3f4c9a6ff2b87a04c14b3e305866521d.zip |
Version 1.20.1+0
Diffstat (limited to 'src')
7 files changed, 175 insertions, 0 deletions
diff --git a/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNether.java b/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNether.java new file mode 100644 index 0000000..efc5b89 --- /dev/null +++ b/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNether.java @@ -0,0 +1,32 @@ +package ski.kramkow.mcmod.eyeofnether; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.fabricmc.api.ModInitializer; +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 EyeOfNether implements ModInitializer { + public static final String MOD_ID = "eye_of_nether"; + + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + public static final Item EYE_OF_NETHER = Registry.register( + Registries.ITEM, + Identifier.of(EyeOfNether.MOD_ID, "eye_of_nether"), + new EyeOfNetherItem(new Item.Settings())); + + @Override + public void onInitialize() { + LOGGER.info("Initializing"); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL) + .register((group) -> group.add(EyeOfNether.EYE_OF_NETHER)); + ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS) + .register((group) -> group.add(EyeOfNether.EYE_OF_NETHER)); + } +} diff --git a/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNetherItem.java b/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNetherItem.java new file mode 100644 index 0000000..50d85da --- /dev/null +++ b/src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNetherItem.java @@ -0,0 +1,95 @@ +package ski.kramkow.mcmod.eyeofnether; + +import com.mojang.datafixers.util.Pair; + +import net.minecraft.entity.EyeOfEnderEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.entry.RegistryEntry.Reference; +import net.minecraft.registry.entry.RegistryEntryList; +import net.minecraft.registry.entry.RegistryEntryList.Direct; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.stat.Stats; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldEvents; +import net.minecraft.world.event.GameEvent; +import net.minecraft.world.gen.structure.Structure; +import net.minecraft.world.gen.structure.StructureKeys; + +public class EyeOfNetherItem extends Item { + public EyeOfNetherItem(final Settings settings) { + super(settings); + } + + @Override + public TypedActionResult<ItemStack> use(final World world, final PlayerEntity user, final Hand hand) { + user.setCurrentHand(hand); + final ItemStack stack = user.getStackInHand(hand); + if (world instanceof final ServerWorld serverWorld) { + if (world.getRegistryKey() != World.NETHER) { + if (!user.getAbilities().creativeMode) { + // This explodes at the feet, sending you up. Accidentally very funny. + world.createExplosion(null, world.getDamageSources().explosion(user, user), null, user.getPos(), + 1.0f, true, World.ExplosionSourceType.NONE); + stack.decrement(1); + } + return TypedActionResult.consume(stack); + } + Pair<BlockPos, RegistryEntry<Structure>> pos_pair = null; + final Registry<Structure> registry = serverWorld.getRegistryManager().get(RegistryKeys.STRUCTURE); + Reference<Structure> fortress = registry.getEntry(StructureKeys.FORTRESS).orElse(null); + if (fortress != null) { + Direct<Structure> registryEntryList = RegistryEntryList.of(fortress); + pos_pair = serverWorld.getChunkManager().getChunkGenerator().locateStructure(serverWorld, + registryEntryList, + user.getBlockPos(), 100, false); + } + if (pos_pair != null) { + user.swingHand(hand, true); + if (!user.getAbilities().creativeMode) { + stack.decrement(1); + } + + // Worth changing this and the sound/event if/when that gets replaced with a + // custom entity. + final EyeOfEnderEntity entity = new EyeOfEnderEntity( + world, + user.getX(), user.getBodyY(0.5), user.getZ()); + entity.setItem(stack); + entity.initTargetPos(pos_pair.getFirst()); + world.spawnEntity(entity); + + float pitch = 0.35f + world.getRandom().nextFloat() * 0.15f; + world.playSound( + null, + user.getX(), user.getY(), user.getZ(), + SoundEvents.ENTITY_ENDER_EYE_LAUNCH, + SoundCategory.NEUTRAL, + 0.5f, pitch); + + world.syncWorldEvent( + null, + WorldEvents.EYE_OF_ENDER_LAUNCHES, + user.getBlockPos(), + 0); + world.emitGameEvent( + GameEvent.PROJECTILE_SHOOT, + entity.getPos(), + GameEvent.Emitter.of(user)); + user.incrementStat(Stats.USED.getOrCreateStat(this)); + + return TypedActionResult.success(stack); + } + } + return TypedActionResult.consume(stack); + } +} diff --git a/src/main/resources/assets/eye_of_nether/lang/en_us.json b/src/main/resources/assets/eye_of_nether/lang/en_us.json new file mode 100644 index 0000000..dcb3b5b --- /dev/null +++ b/src/main/resources/assets/eye_of_nether/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "item.eye_of_nether.eye_of_nether": "Eye of Nether" +} diff --git a/src/main/resources/assets/eye_of_nether/models/item/eye_of_nether.json b/src/main/resources/assets/eye_of_nether/models/item/eye_of_nether.json new file mode 100644 index 0000000..5e1b270 --- /dev/null +++ b/src/main/resources/assets/eye_of_nether/models/item/eye_of_nether.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "eye_of_nether:item/eye_of_nether" + } +} diff --git a/src/main/resources/assets/eye_of_nether/textures/item/eye_of_nether.png b/src/main/resources/assets/eye_of_nether/textures/item/eye_of_nether.png Binary files differnew file mode 100644 index 0000000..62f0adc --- /dev/null +++ b/src/main/resources/assets/eye_of_nether/textures/item/eye_of_nether.png diff --git a/src/main/resources/data/eye_of_nether/recipes/eye_of_nether.json b/src/main/resources/data/eye_of_nether/recipes/eye_of_nether.json new file mode 100644 index 0000000..e2e1ba8 --- /dev/null +++ b/src/main/resources/data/eye_of_nether/recipes/eye_of_nether.json @@ -0,0 +1,8 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { "item": "minecraft:ender_pearl" }, + { "item": "minecraft:ghast_tear" } + ], + "result": { "item": "eye_of_nether:eye_of_nether" } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..9cf295e --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,31 @@ +{ + "schemaVersion": 1, + "id": "eye_of_nether", + "version": "${version}", + "name": "Eye of Nether", + "description": "Add eyes of nether for locating nether fortresses", + "authors": [ + { + "name": "Tomasz Kramkowski", + "contact": { + "email": "tomasz@kramkow.ski" + } + } + ], + "contact": { + "sources": "https://the-tk.com/cgit/eye-of-nether" + }, + "license": "LGPL-3.0-or-later", + "environment": "*", + "entrypoints": { + "main": [ + "ski.kramkow.mcmod.eyeofnether.EyeOfNether" + ] + }, + "depends": { + "fabricloader": ">=0.16.3", + "minecraft": "~1.20.1", + "java": ">=17", + "fabric-api": "*" + } +} |