-
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.
Fire ball (affecting both blocks and entities) and levio (food item w…
…ith effects) added
- Loading branch information
1 parent
7b2ef23
commit 5668fbf
Showing
11 changed files
with
164 additions
and
0 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
13 changes: 13 additions & 0 deletions
13
src/main/java/net/ananaseek/tutorialmod/item/ModFoods.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,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(); | ||
} |
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
78 changes: 78 additions & 0 deletions
78
src/main/java/net/ananaseek/tutorialmod/item/custom/FireBall.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,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); | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/net/ananaseek/tutorialmod/item/custom/FireBallItem.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,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()); | ||
} | ||
} |
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: 6 additions & 0 deletions
6
src/main/resources/assets/tutorialmod/models/item/fire_ball.json
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,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "tutorialmod:item/fire_ball" | ||
} | ||
} |
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,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.
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,16 @@ | ||
{ | ||
"type": "minecraft:crafting_shapeless", | ||
"category": "misc", | ||
"ingredients": [ | ||
{ | ||
"item": "minecraft:popped_chorus_fruit" | ||
}, | ||
{ | ||
"item": "minecraft:phantom_membrane" | ||
} | ||
], | ||
"result": { | ||
"item": "tutorialmod:levio", | ||
"count": 4 | ||
} | ||
} |