Skip to content

Commit

Permalink
Fire ball (affecting both blocks and entities) and levio (food item w…
Browse files Browse the repository at this point in the history
…ith effects) added
  • Loading branch information
AnanasikDev committed Apr 9, 2024
1 parent 7b2ef23 commit 5668fbf
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ModCreativeModeTabs {
output.accept(ModItems.SAPPHIRE.get());
output.accept(ModItems.RAW_SAPPHIRE.get());
output.accept(ModItems.METAL_DETECTOR.get());
output.accept(ModItems.LEVIO.get());
output.accept(ModItems.FIRE_BALL.get());
output.accept(ModBlocks.RAW_SAPPHIRE_BLOCK.get());
output.accept(ModBlocks.SAPPHIRE_BLOCK.get());
output.accept(ModBlocks.SAPPHIRE_ORE.get());
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/ananaseek/tutorialmod/item/ModFoods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.ananaseek.tutorialmod.item;

import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.food.FoodProperties;

public class ModFoods {
public static final FoodProperties LEVIO = new FoodProperties.Builder()
.nutrition(1)
.saturationMod(0.2f)
.effect(() -> new MobEffectInstance(MobEffects.LEVITATION, 35), 1f)
.effect(() -> new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 20), 0.4f).build();
}
5 changes: 5 additions & 0 deletions src/main/java/net/ananaseek/tutorialmod/item/ModItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.ananaseek.tutorialmod.item;

import net.ananaseek.tutorialmod.TutorialMod;
import net.ananaseek.tutorialmod.item.custom.FireBallItem;
import net.ananaseek.tutorialmod.item.custom.MetalDetectorItem;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
Expand All @@ -18,6 +19,10 @@ public class ModItems {
() -> new Item(new Item.Properties()));
public static final RegistryObject<Item> METAL_DETECTOR = ITEMS.register("metal_detector",
() -> new MetalDetectorItem(new Item.Properties().durability(50)));
public static final RegistryObject<Item> LEVIO = ITEMS.register("levio",
() -> new Item(new Item.Properties().food(ModFoods.LEVIO).stacksTo(32)));
public static final RegistryObject<Item> FIRE_BALL = ITEMS.register("fire_ball",
() -> new FireBallItem(new Item.Properties()));

public static void register(IEventBus eventBus){
ITEMS.register(eventBus);
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/net/ananaseek/tutorialmod/item/custom/FireBall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.ananaseek.tutorialmod.item.custom;

import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Blaze;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;

public class FireBall extends ThrowableItemProjectile {
public FireBall(EntityType<? extends FireBall> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}

public FireBall(Level pLevel, LivingEntity pShooter) {
super(EntityType.SNOWBALL, pShooter, pLevel);
}

public FireBall(Level pLevel, double pX, double pY, double pZ) {
super(EntityType.SNOWBALL, pX, pY, pZ, pLevel);
}

protected Item getDefaultItem() {
return Items.SNOWBALL;
}

private ParticleOptions getParticle() {
ItemStack itemstack = this.getItemRaw();
return (ParticleOptions)(itemstack.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleOption(ParticleTypes.ITEM, itemstack));
}

/**
* Handles an entity event received from a {@link net.minecraft.network.protocol.game.ClientboundEntityEventPacket}.
*/
public void handleEntityEvent(byte pId) {
if (pId == 3) {
ParticleOptions particleoptions = this.getParticle();

for(int i = 0; i < 8; ++i) {
this.level().addParticle(particleoptions, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
}
}

}

/**
* Called when the arrow hits an entity
*/
protected void onHitEntity(EntityHitResult pResult) {
super.onHitEntity(pResult);
Entity entity = pResult.getEntity();
int i = entity instanceof Blaze ? 3 : 0;
entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float)i);
}

/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onHit(HitResult pResult) {
super.onHit(pResult);
if (!this.level().isClientSide) {
this.level().broadcastEntityEvent(this, (byte)3);
this.discard();

var pos = pResult.getLocation();
this.level().explode(this, pos.x, pos.y, pos.z, 2.7F, Level.ExplosionInteraction.TNT);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.ananaseek.tutorialmod.item.custom;

import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Snowball;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public class FireBallItem extends Item {
public FireBallItem(Item.Properties pProperties) {
super(pProperties);
}

public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pHand) {
ItemStack itemstack = pPlayer.getItemInHand(pHand);
pLevel.playSound((Player)null, pPlayer.getX(), pPlayer.getY(), pPlayer.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (pLevel.getRandom().nextFloat() * 0.4F + 0.8F));
if (!pLevel.isClientSide) {
FireBall fireball = new FireBall(pLevel, pPlayer);
fireball.setItem(itemstack);
fireball.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 1.5F, 1.0F);
pLevel.addFreshEntity(fireball);
}

pPlayer.awardStat(Stats.ITEM_USED.get(this));
if (!pPlayer.getAbilities().instabuild) {
itemstack.shrink(1);
}

return InteractionResultHolder.sidedSuccess(itemstack, pLevel.isClientSide());
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/tutorialmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"item.tutorialmod.sapphire": "Sapphire",
"item.tutorialmod.raw_sapphire": "Raw Sapphire",
"item.tutorialmod.metal_detector": "Metal Detector",
"item.tutorialmod.levio": "Levio",
"item.tutorialmod.fire_ball": "Fire Ball",

"creativetab.tutorial_tab": "My mod tab!",

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "tutorialmod:item/fire_ball"
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/tutorialmod/models/item/levio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "tutorialmod:item/levio"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/main/resources/data/tutorialmod/recipes/levio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "minecraft:popped_chorus_fruit"
},
{
"item": "minecraft:phantom_membrane"
}
],
"result": {
"item": "tutorialmod:levio",
"count": 4
}
}

0 comments on commit 5668fbf

Please sign in to comment.