ak47
This commit is contained in:
@@ -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.minecraft.client.MinecraftClient;
|
||||
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.model.EntityModelLayer;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
@@ -91,9 +92,10 @@ public class SzarClient implements ClientModInitializer {
|
||||
);
|
||||
EntityRendererRegistry.register(
|
||||
Szar.BULLET,
|
||||
BulletRenderer::new
|
||||
ctx -> new FlyingItemEntityRenderer<>(ctx)
|
||||
);
|
||||
|
||||
|
||||
EntityRendererRegistry.register(
|
||||
Szar.PoliceEntityType,
|
||||
PoliceEntityRenderer::new
|
||||
|
||||
@@ -22,19 +22,13 @@ public class AK47Item extends Item {
|
||||
if (!player.isUsingItem()) return;
|
||||
if (world.isClient) return;
|
||||
|
||||
if (player.getItemCooldownManager().isCoolingDown(this)) return;
|
||||
if (!consumeAmmo(player)) return;
|
||||
|
||||
BulletEntity bullet = new BulletEntity(world, player);
|
||||
bullet.setVelocity(
|
||||
player,
|
||||
player.getPitch(),
|
||||
player.getYaw(),
|
||||
0.0F,
|
||||
4.5F, // speed
|
||||
1.0F // spread
|
||||
);
|
||||
|
||||
bullet.setVelocity(player, player.getPitch(), player.getYaw(), 0f, 4.5f, 1.0f);
|
||||
world.spawnEntity(bullet);
|
||||
|
||||
player.getItemCooldownManager().set(this, 2); // fire rate
|
||||
}
|
||||
|
||||
|
||||
@@ -3,46 +3,29 @@ package dev.tggamesyt.szar;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileUtil;
|
||||
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BulletEntity extends ProjectileEntity {
|
||||
public class BulletEntity extends ThrownItemEntity {
|
||||
|
||||
public BulletEntity(EntityType<? extends BulletEntity> type, World world) {
|
||||
super(type, world);
|
||||
this.setNoGravity(true); // bullets fly straight
|
||||
}
|
||||
|
||||
public BulletEntity(World world, LivingEntity owner) {
|
||||
super(Szar.BULLET, world);
|
||||
this.setOwner(owner);
|
||||
this.setPosition(
|
||||
owner.getX(),
|
||||
owner.getEyeY() - 0.1,
|
||||
owner.getZ()
|
||||
);
|
||||
super(Szar.BULLET, owner, world);
|
||||
this.setNoGravity(true);
|
||||
this.setPosition(owner.getX(), owner.getEyeY() - 0.1, owner.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initDataTracker() {}
|
||||
|
||||
@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();
|
||||
protected Item getDefaultItem() {
|
||||
return Szar.AK_AMMO; // used by FlyingItemEntityRenderer
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,16 +33,13 @@ public class BulletEntity extends ProjectileEntity {
|
||||
Entity target = hit.getEntity();
|
||||
Entity owner = getOwner();
|
||||
|
||||
target.damage(
|
||||
getWorld().getDamageSources().playerAttack((PlayerEntity) owner),
|
||||
6.0F
|
||||
);
|
||||
if (owner instanceof LivingEntity livingOwner) {
|
||||
target.damage(
|
||||
getWorld().getDamageSources().mobProjectile(this, livingOwner),
|
||||
13.0F
|
||||
);
|
||||
}
|
||||
|
||||
discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCollision(HitResult hit) {
|
||||
if (!getWorld().isClient) discard();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"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