-
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.
- Loading branch information
1 parent
f4e68b6
commit b052605
Showing
14 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
common/src/main/java/abeshutt/staracademy/entity/SlingshotEntity.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,49 @@ | ||
package abeshutt.staracademy.entity; | ||
|
||
import abeshutt.staracademy.init.ModEntities; | ||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.projectile.thrown.ThrownItemEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.util.hit.HitResult; | ||
import net.minecraft.world.World; | ||
|
||
public class SlingshotEntity extends ThrownItemEntity { | ||
|
||
public SlingshotEntity(EntityType<SlingshotEntity> type, World world) { | ||
super(type, world); | ||
} | ||
|
||
public SlingshotEntity(World world, LivingEntity thrower, ItemStack stack) { | ||
super(ModEntities.SLINGSHOT.get(), thrower, world); | ||
this.getDataTracker().set(ITEM, stack); | ||
} | ||
|
||
@Override | ||
protected Item getDefaultItem() { | ||
return Items.AIR; | ||
} | ||
|
||
protected void onEntityHit(EntityHitResult result) { | ||
super.onEntityHit(result); | ||
|
||
if(result.getEntity() instanceof PokemonEntity entity) { | ||
entity.takeKnockback(2.0D, -this.getVelocity().x, -this.getVelocity().z); | ||
this.getWorld().playSound(null, entity.getX(), entity.getY(), entity.getZ(), | ||
SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1.0F, 1.2F); | ||
entity.kill(); | ||
} | ||
} | ||
|
||
protected void onCollision(HitResult result) { | ||
super.onCollision(result); | ||
this.discard(); | ||
} | ||
|
||
} |
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
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
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
84 changes: 84 additions & 0 deletions
84
common/src/main/java/abeshutt/staracademy/item/SlingshotItem.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,84 @@ | ||
package abeshutt.staracademy.item; | ||
|
||
import abeshutt.staracademy.entity.SlingshotEntity; | ||
import abeshutt.staracademy.init.ModItems; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.item.RangedWeaponItem; | ||
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.UseAction; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class SlingshotItem extends RangedWeaponItem { | ||
|
||
public SlingshotItem() { | ||
super(new Settings()); | ||
} | ||
|
||
@Override | ||
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) { | ||
if(user instanceof PlayerEntity player) { | ||
float progress = getPullProgress(this.getMaxUseTime(stack) - remainingUseTicks) / 2.0F; | ||
|
||
if(progress < 0.1D) { | ||
return; | ||
} | ||
|
||
if(!world.isClient) { | ||
SlingshotEntity entity = new SlingshotEntity(world, player, new ItemStack(Items.FIRE_CHARGE)); | ||
entity.setVelocity(entity, player.getPitch(), player.getYaw(), 0.0F, progress, 1.0F); | ||
world.spawnEntity(entity); | ||
} | ||
|
||
world.playSound(null, player.getX(), player.getY(), player.getZ(), | ||
SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, | ||
1.0F / (world.getRandom().nextFloat() * 0.4F + 1.2F) + progress * 0.5F); | ||
player.incrementStat(Stats.USED.getOrCreateStat(this)); | ||
} | ||
} | ||
|
||
public static float getPullProgress(int useTicks) { | ||
float f = (float)useTicks / 20.0F; | ||
f = (f * f + f * 2.0F) / 3.0F; | ||
if (f > 1.0F) { | ||
f = 1.0F; | ||
} | ||
|
||
return f; | ||
} | ||
|
||
@Override | ||
public int getMaxUseTime(ItemStack stack) { | ||
return 72000; | ||
} | ||
|
||
@Override | ||
public UseAction getUseAction(ItemStack stack) { | ||
return UseAction.BOW; | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
user.setCurrentHand(hand); | ||
return TypedActionResult.consume(user.getStackInHand(hand)); | ||
} | ||
|
||
@Override | ||
public Predicate<ItemStack> getProjectiles() { | ||
return ItemStack::isEmpty; | ||
} | ||
|
||
@Override | ||
public int getRange() { | ||
return 15; | ||
} | ||
|
||
} |
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
50 changes: 50 additions & 0 deletions
50
common/src/main/resources/assets/academy/models/item/slingshot.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,50 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "academy:item/slingshot" | ||
}, | ||
"display": { | ||
"thirdperson_righthand": { | ||
"rotation": [ -80, 260, -40 ], | ||
"translation": [ -1, -2, 2.5 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [ -80, -280, 40 ], | ||
"translation": [ -1, -2, 2.5 ], | ||
"scale": [ 0.9, 0.9, 0.9 ] | ||
}, | ||
"firstperson_righthand": { | ||
"rotation": [ 0, -90, 25 ], | ||
"translation": [ 1.13, 3.2, 1.13], | ||
"scale": [ 0.68, 0.68, 0.68 ] | ||
}, | ||
"firstperson_lefthand": { | ||
"rotation": [ 0, 90, -25 ], | ||
"translation": [ 1.13, 3.2, 1.13], | ||
"scale": [ 0.68, 0.68, 0.68 ] | ||
} | ||
}, | ||
"overrides": [ | ||
{ | ||
"predicate": { | ||
"pulling": 1 | ||
}, | ||
"model": "academy:item/slingshot_pulling_0" | ||
}, | ||
{ | ||
"predicate": { | ||
"pulling": 1, | ||
"pull": 0.65 | ||
}, | ||
"model": "academy:item/slingshot_pulling_1" | ||
}, | ||
{ | ||
"predicate": { | ||
"pulling": 1, | ||
"pull": 0.9 | ||
}, | ||
"model": "academy:item/slingshot_pulling_2" | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/slingshot_pulling_0.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": "academy:item/dueling_glove", | ||
"textures": { | ||
"layer0": "academy:item/slingshot_pulling_0" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/slingshot_pulling_1.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": "academy:item/dueling_glove", | ||
"textures": { | ||
"layer0": "academy:item/slingshot_pulling_1" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/academy/models/item/slingshot_pulling_2.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": "academy:item/dueling_glove", | ||
"textures": { | ||
"layer0": "academy:item/slingshot_pulling_2" | ||
} | ||
} |
Binary file added
BIN
+297 Bytes
common/src/main/resources/assets/academy/textures/item/slingshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+297 Bytes
common/src/main/resources/assets/academy/textures/item/slingshot_pulling_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+333 Bytes
common/src/main/resources/assets/academy/textures/item/slingshot_pulling_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+289 Bytes
common/src/main/resources/assets/academy/textures/item/slingshot_pulling_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.