Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Oct 28, 2024
1 parent 0221b0f commit cdc33f1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/nmt/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"block.nmt.obsidian_glass": "Obsidian Glass",
"block.nmt.obsidian_glass_pane": "Obsidian Glass Pane",
"effect.nmt.burn": "Burn",
"item.nmt.lava_bottle.effect.lava": "Lava Bottle",
"item.nmt.obsidian_glass_bottle": "Obsidian Glass Bottle",
"nmt.creativetab": "No More Things"
}
17 changes: 13 additions & 4 deletions src/main/java/net/nova/nmt/data/LangProvider.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.nova.nmt.data;

import net.minecraft.core.Holder;
import net.minecraft.data.PackOutput;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.Potion;
import net.neoforged.neoforge.common.data.LanguageProvider;
import net.nova.nmt.init.CreativeTab;
import net.nova.nmt.init.NMTBlocks;
import net.nova.nmt.init.NMTEffects;
import net.nova.nmt.init.NMTItems;
import net.nova.nmt.init.*;

import java.util.function.Supplier;

import static net.nova.nmt.NoMoreThings.MODID;

Expand All @@ -22,11 +24,18 @@ protected void addTranslations() {

// Items
addItem(NMTItems.OBSIDIAN_GLASS_BOTTLE, "Obsidian Glass Bottle");
/// Obsidian Potions
/* addObsidianPotion(NMTItems.LAVA_BOTTLE, NMTPotions.LAVA, "Lava Bottle");*/
add(NMTItems.LAVA_BOTTLE.getRegisteredName(), "Lava Bottle");

// Creative Tab
add(CreativeTab.NO_MORE_THINGS_TAB_TITLE, "No More Things");

// Mob Effects
addEffect(NMTEffects.BURN::value, "Burn");
}

public void addObsidianPotion(Supplier<? extends Item> key, Holder<Potion> potionName, String name) {
add(key.get().getDescriptionId() + ".effect." + potionName.getKey().location().getPath(), name);
}
}
5 changes: 3 additions & 2 deletions src/main/java/net/nova/nmt/init/NMTItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.nova.nmt.init;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.nova.nmt.item.ObsidianBottleItem;
Expand All @@ -12,6 +14,5 @@ public class NMTItems {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MODID);

public static DeferredItem<Item> OBSIDIAN_GLASS_BOTTLE = ITEMS.register("obsidian_glass_bottle", () -> new ObsidianBottleItem(new Item.Properties().fireResistant()));
public static DeferredItem<Item> LAVA_BOTTLE = ITEMS.register("lava_bottle", () -> new ObsidianPotionItem(new Item.Properties().stacksTo(1).fireResistant()));

public static DeferredItem<Item> LAVA_BOTTLE = ITEMS.register("lava_bottle", () -> new ObsidianPotionItem(new Item.Properties().stacksTo(1).component(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA)).fireResistant()));
}
2 changes: 1 addition & 1 deletion src/main/java/net/nova/nmt/init/NMTPotions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
public class NMTPotions {
public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(Registries.POTION, MODID);

public static final Holder<Potion> BURN = POTIONS.register("lava", () -> new Potion(new MobEffectInstance(NMTEffects.BURN, 3600)));
public static final Holder<Potion> LAVA = POTIONS.register("lava", () -> new Potion(new MobEffectInstance(NMTEffects.BURN, 900)));
}
52 changes: 50 additions & 2 deletions src/main/java/net/nova/nmt/item/ObsidianPotionItem.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package net.nova.nmt.item;

import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.item.context.UseOnContext;
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.level.gameevent.GameEvent;
import net.nova.nmt.init.NMTItems;
import net.nova.nmt.init.NMTPotions;
Expand All @@ -30,7 +39,7 @@ public ObsidianPotionItem(Properties properties) {
@Override
public ItemStack getDefaultInstance() {
ItemStack itemstack = super.getDefaultInstance();
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.BURN));
itemstack.set(DataComponents.POTION_CONTENTS, new PotionContents(NMTPotions.LAVA));
return itemstack;
}

Expand Down Expand Up @@ -71,6 +80,45 @@ public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity enti
return stack;
}

@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos blockpos = context.getClickedPos();
Player player = context.getPlayer();
ItemStack itemstack = context.getItemInHand();
PotionContents potioncontents = itemstack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
BlockState blockstate = level.getBlockState(blockpos);
if (context.getClickedFace() != Direction.DOWN && blockstate.is(Blocks.NETHERRACK) && potioncontents.is(NMTPotions.LAVA)) {
level.playSound(null, blockpos, SoundEvents.LAVA_POP, SoundSource.BLOCKS, 1.0F, 1.0F);
player.setItemInHand(context.getHand(), ItemUtils.createFilledResult(itemstack, player, new ItemStack(NMTItems.OBSIDIAN_GLASS_BOTTLE.get())));
player.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
if (!level.isClientSide) {
ServerLevel serverlevel = (ServerLevel)level;

for (int i = 0; i < 5; i++) {
serverlevel.sendParticles(
ParticleTypes.LAVA,
(double)blockpos.getX() + level.random.nextDouble(),
(double)(blockpos.getY() + 1),
(double)blockpos.getZ() + level.random.nextDouble(),
1,
0.0,
0.0,
0.0,
1.0
);
}
}

level.playSound(null, blockpos, SoundEvents.BOTTLE_EMPTY, SoundSource.BLOCKS, 1.0F, 1.0F);
level.gameEvent(null, GameEvent.FLUID_PLACE, blockpos);
level.setBlockAndUpdate(blockpos, Blocks.MAGMA_BLOCK.defaultBlockState());
return InteractionResult.sidedSuccess(level.isClientSide);
} else {
return InteractionResult.PASS;
}
}

@Override
public int getUseDuration(ItemStack stack, LivingEntity entity) {
return 32;
Expand Down

0 comments on commit cdc33f1

Please sign in to comment.