ak47
This commit is contained in:
@@ -6,7 +6,7 @@ minecraft_version=1.20.1
|
|||||||
yarn_mappings=1.20.1+build.10
|
yarn_mappings=1.20.1+build.10
|
||||||
loader_version=0.18.3
|
loader_version=0.18.3
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=26.2.5
|
mod_version=26.2.5.1
|
||||||
maven_group=dev.tggamesyt
|
maven_group=dev.tggamesyt
|
||||||
archives_base_name=szar
|
archives_base_name=szar
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
|||||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
|
||||||
import net.minecraft.client.render.entity.animation.Animation;
|
import net.minecraft.client.render.entity.animation.Animation;
|
||||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.client.util.InputUtil;
|
||||||
@@ -91,9 +92,10 @@ public class SzarClient implements ClientModInitializer {
|
|||||||
);
|
);
|
||||||
EntityRendererRegistry.register(
|
EntityRendererRegistry.register(
|
||||||
Szar.BULLET,
|
Szar.BULLET,
|
||||||
BulletRenderer::new
|
ctx -> new FlyingItemEntityRenderer<>(ctx)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
EntityRendererRegistry.register(
|
EntityRendererRegistry.register(
|
||||||
Szar.PoliceEntityType,
|
Szar.PoliceEntityType,
|
||||||
PoliceEntityRenderer::new
|
PoliceEntityRenderer::new
|
||||||
|
|||||||
@@ -22,19 +22,13 @@ public class AK47Item extends Item {
|
|||||||
if (!player.isUsingItem()) return;
|
if (!player.isUsingItem()) return;
|
||||||
if (world.isClient) return;
|
if (world.isClient) return;
|
||||||
|
|
||||||
|
if (player.getItemCooldownManager().isCoolingDown(this)) return;
|
||||||
if (!consumeAmmo(player)) return;
|
if (!consumeAmmo(player)) return;
|
||||||
|
|
||||||
BulletEntity bullet = new BulletEntity(world, player);
|
BulletEntity bullet = new BulletEntity(world, player);
|
||||||
bullet.setVelocity(
|
bullet.setVelocity(player, player.getPitch(), player.getYaw(), 0f, 4.5f, 1.0f);
|
||||||
player,
|
|
||||||
player.getPitch(),
|
|
||||||
player.getYaw(),
|
|
||||||
0.0F,
|
|
||||||
4.5F, // speed
|
|
||||||
1.0F // spread
|
|
||||||
);
|
|
||||||
|
|
||||||
world.spawnEntity(bullet);
|
world.spawnEntity(bullet);
|
||||||
|
|
||||||
player.getItemCooldownManager().set(this, 2); // fire rate
|
player.getItemCooldownManager().set(this, 2); // fire rate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,46 +3,29 @@ package dev.tggamesyt.szar;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
|
||||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.entity.projectile.ProjectileUtil;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.hit.EntityHitResult;
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
import net.minecraft.util.hit.HitResult;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class BulletEntity extends ProjectileEntity {
|
public class BulletEntity extends ThrownItemEntity {
|
||||||
|
|
||||||
public BulletEntity(EntityType<? extends BulletEntity> type, World world) {
|
public BulletEntity(EntityType<? extends BulletEntity> type, World world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
|
this.setNoGravity(true); // bullets fly straight
|
||||||
}
|
}
|
||||||
|
|
||||||
public BulletEntity(World world, LivingEntity owner) {
|
public BulletEntity(World world, LivingEntity owner) {
|
||||||
super(Szar.BULLET, world);
|
super(Szar.BULLET, owner, world);
|
||||||
this.setOwner(owner);
|
this.setNoGravity(true);
|
||||||
this.setPosition(
|
this.setPosition(owner.getX(), owner.getEyeY() - 0.1, owner.getZ());
|
||||||
owner.getX(),
|
|
||||||
owner.getEyeY() - 0.1,
|
|
||||||
owner.getZ()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initDataTracker() {}
|
protected Item getDefaultItem() {
|
||||||
|
return Szar.AK_AMMO; // used by FlyingItemEntityRenderer
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
|
|
||||||
Vec3d velocity = this.getVelocity();
|
|
||||||
this.setVelocity(velocity.multiply(1.02)); // fast
|
|
||||||
|
|
||||||
HitResult hit = ProjectileUtil.getCollision(this, this::canHit);
|
|
||||||
if (hit.getType() != HitResult.Type.MISS) {
|
|
||||||
onCollision(hit);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.age > 60) discard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,16 +33,13 @@ public class BulletEntity extends ProjectileEntity {
|
|||||||
Entity target = hit.getEntity();
|
Entity target = hit.getEntity();
|
||||||
Entity owner = getOwner();
|
Entity owner = getOwner();
|
||||||
|
|
||||||
target.damage(
|
if (owner instanceof LivingEntity livingOwner) {
|
||||||
getWorld().getDamageSources().playerAttack((PlayerEntity) owner),
|
target.damage(
|
||||||
6.0F
|
getWorld().getDamageSources().mobProjectile(this, livingOwner),
|
||||||
);
|
13.0F
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
discard();
|
discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCollision(HitResult hit) {
|
|
||||||
if (!getWorld().isClient) discard();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"parent": "minecraft:item/generated",
|
"parent": "minecraft:item/generated",
|
||||||
"textures": {
|
"textures": {
|
||||||
"layer0": "szar:entity/bullet"
|
"layer0": "szar:item/bullet"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/main/resources/assets/szar/textures/item/bullet.png
Normal file
BIN
src/main/resources/assets/szar/textures/item/bullet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 B |
20
src/main/resources/data/szar/recipes/bullet.json
Normal file
20
src/main/resources/data/szar/recipes/bullet.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
" M ",
|
||||||
|
" B ",
|
||||||
|
"B B"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"M": {
|
||||||
|
"item": "minecraft:milk_bucket"
|
||||||
|
},
|
||||||
|
"B": {
|
||||||
|
"item": "minecraft:beef"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "szar:bullet",
|
||||||
|
"count": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user