aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/ski/kramkow
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ski/kramkow')
-rw-r--r--src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNether.java32
-rw-r--r--src/main/java/ski/kramkow/mcmod/eyeofnether/EyeOfNetherItem.java95
2 files changed, 127 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);
+ }
+}