回滚customClientFactory
This commit is contained in:
parent
083f6bcdf2
commit
2515eff9b6
28 changed files with 127 additions and 99 deletions
|
@ -27,6 +27,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -46,6 +47,10 @@ public class BocekArrowEntity extends AbstractArrow implements ItemSupplier {
|
|||
super(TargetModEntities.BOCEK_ARROW.get(), entity, level);
|
||||
}
|
||||
|
||||
public BocekArrowEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
super(TargetModEntities.BOCEK_ARROW.get(), world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.phys.EntityHitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -46,6 +47,10 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
this.damage = damage;
|
||||
}
|
||||
|
||||
public GunGrenadeEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
this(TargetModEntities.GUN_GRENADE.get(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.mcreator.target.entity;
|
||||
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.tools.ParticleTool;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
|
@ -15,6 +16,7 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
public class MortarShellEntity extends ThrowableItemProjectile {
|
||||
private float damage = 100f;
|
||||
|
@ -36,6 +38,10 @@ public class MortarShellEntity extends ThrowableItemProjectile {
|
|||
this.damage = damage;
|
||||
}
|
||||
|
||||
public MortarShellEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
this(TargetModEntities.MORTAR_SHELL.get(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -38,6 +38,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
|||
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.entity.PartEntity;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -65,6 +66,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
|
|||
super(TargetModEntities.PROJECTILE.get(), level);
|
||||
}
|
||||
|
||||
public ProjectileEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
super(TargetModEntities.PROJECTILE.get(), world);
|
||||
}
|
||||
|
||||
public ProjectileEntity shooter(LivingEntity shooter) {
|
||||
this.shooter = shooter;
|
||||
return this;
|
||||
|
|
|
@ -27,6 +27,7 @@ import net.minecraft.world.phys.EntityHitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -46,6 +47,10 @@ public class RpgRocketEntity extends ThrowableItemProjectile {
|
|||
this.damage = damage;
|
||||
}
|
||||
|
||||
public RpgRocketEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
this(TargetModEntities.RPG_ROCKET.get(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.world.phys.EntityHitResult;
|
|||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -42,6 +43,10 @@ public class TaserBulletProjectileEntity extends ThrowableItemProjectile {
|
|||
this.damage = damage;
|
||||
}
|
||||
|
||||
public TaserBulletProjectileEntity(PlayMessages.SpawnEntity packet, Level level) {
|
||||
this(TargetModEntities.TASER_BULLET_PROJECTILE.get(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
|
|
|
@ -27,20 +27,20 @@ public class TargetModEntities {
|
|||
public static final RegistryObject<EntityType<ClaymoreEntity>> CLAYMORE = register("claymore",
|
||||
EntityType.Builder.<ClaymoreEntity>of(ClaymoreEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(ClaymoreEntity::new).fireImmune().sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<TaserBulletProjectileEntity>> TASER_BULLET_PROJECTILE = register("projectile_taser_bullet_projectile",
|
||||
EntityType.Builder.<TaserBulletProjectileEntity>of(TaserBulletProjectileEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64)
|
||||
EntityType.Builder.<TaserBulletProjectileEntity>of(TaserBulletProjectileEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setCustomClientFactory(TaserBulletProjectileEntity::new)
|
||||
.setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<GunGrenadeEntity>> GUN_GRENADE = register("projectile_gun_grenade",
|
||||
EntityType.Builder.<GunGrenadeEntity>of(GunGrenadeEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
EntityType.Builder.<GunGrenadeEntity>of(GunGrenadeEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(GunGrenadeEntity::new).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<TargetEntity>> TARGET = register("target",
|
||||
EntityType.Builder.<TargetEntity>of(TargetEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(TargetEntity::new).fireImmune().sized(0.875f, 2f));
|
||||
public static final RegistryObject<EntityType<RpgRocketEntity>> RPG_ROCKET = register("projectile_rpg_rocket",
|
||||
EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(RpgRocketEntity::new).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<MortarShellEntity>> MORTAR_SHELL = register("projectile_mortar_shell",
|
||||
EntityType.Builder.<MortarShellEntity>of(MortarShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
EntityType.Builder.<MortarShellEntity>of(MortarShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(MortarShellEntity::new).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<BocekArrowEntity>> BOCEK_ARROW = register("projectile_bocekarrow",
|
||||
EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setCustomClientFactory(BocekArrowEntity::new).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<ProjectileEntity>> PROJECTILE = register("projectile",
|
||||
EntityType.Builder.<ProjectileEntity>of(ProjectileEntity::new, MobCategory.MISC).setTrackingRange(512).sized(0.5f, 0.5f));
|
||||
EntityType.Builder.<ProjectileEntity>of(ProjectileEntity::new, MobCategory.MISC).setCustomClientFactory(ProjectileEntity::new).setTrackingRange(512).sized(0.5f, 0.5f));
|
||||
|
||||
|
||||
private static <T extends Entity> RegistryObject<EntityType<T>> register(String registryname, EntityType.Builder<T> entityTypeBuilder) {
|
||||
|
|
|
@ -43,12 +43,11 @@ public class Hammer extends SwordItem {
|
|||
|
||||
@Override
|
||||
public ItemStack getCraftingRemainingItem(ItemStack itemstack) {
|
||||
ItemStack retval = new ItemStack(this);
|
||||
retval.setDamageValue(itemstack.getDamageValue() + 1);
|
||||
if (retval.getDamageValue() >= retval.getMaxDamage()) {
|
||||
itemstack.setDamageValue(itemstack.getDamageValue() + 1);
|
||||
if (itemstack.getDamageValue() >= itemstack.getMaxDamage()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return retval;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,7 +54,7 @@ public class LightSaber extends SwordItem implements GeoItem, AnimatedItem {
|
|||
transformType = type;
|
||||
}
|
||||
|
||||
private PlayState idlePredicate(AnimationState event) {
|
||||
private PlayState idlePredicate(AnimationState<LightSaber> event) {
|
||||
if (transformType != null && transformType.firstPerson()) {
|
||||
if (this.animationProcedure.equals("empty")) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenLoop("animation.lightsaber.idle"));
|
||||
|
@ -64,7 +64,7 @@ public class LightSaber extends SwordItem implements GeoItem, AnimatedItem {
|
|||
return PlayState.STOP;
|
||||
}
|
||||
|
||||
private PlayState procedurePredicate(AnimationState event) {
|
||||
private PlayState procedurePredicate(AnimationState<LightSaber> event) {
|
||||
if (transformType != null && transformType.firstPerson()) {
|
||||
if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||
|
@ -123,4 +123,9 @@ public class LightSaber extends SwordItem implements GeoItem, AnimatedItem {
|
|||
public void setAnimationProcedure(String procedure) {
|
||||
this.animationProcedure = procedure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -200,7 +200,7 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 51) {
|
||||
|
@ -220,7 +220,7 @@ public class AK47Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ public class Aa12Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 44) {
|
||||
|
@ -220,7 +220,7 @@ public class Aa12Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SHOTGUN, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ public class Abekiri extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") == 1) {
|
||||
if (tag.getDouble("reload_time") == 83) {
|
||||
|
@ -211,7 +211,7 @@ public class Abekiri extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
GunsTool.reload(entity, GunInfo.Type.SHOTGUN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ public class Devotion extends GunItem implements GeoItem, AnimatedItem {
|
|||
itemTag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (itemTag.getDouble("reload_time") == 1 && mainHandItemTag.getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (itemTag.getBoolean("reloading") && itemTag.getInt("ammo") > 0) {
|
||||
if (itemTag.getDouble("reload_time") == 70) {
|
||||
|
@ -208,7 +208,7 @@ public class Devotion extends GunItem implements GeoItem, AnimatedItem {
|
|||
itemTag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (itemTag.getDouble("reload_time") == 1 && mainHandItemTag.getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ public class Hk416Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 53) {
|
||||
|
@ -219,7 +219,7 @@ public class Hk416Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ public class HuntingRifle extends GunItem implements GeoItem, AnimatedItem {
|
|||
itemTag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (itemTag.getDouble("reload_time") == 1 && mainHandItemTag.getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class Kraber extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 65) {
|
||||
|
@ -212,7 +212,7 @@ public class Kraber extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class M4Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 53) {
|
||||
|
@ -216,7 +216,7 @@ public class M4Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ public class M60Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 111) {
|
||||
|
@ -201,7 +201,7 @@ public class M60Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class M98bItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 57) {
|
||||
|
@ -212,7 +212,7 @@ public class M98bItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ public class Mk14Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("gj", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 45) {
|
||||
|
@ -196,7 +196,7 @@ public class Mk14Item extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class RpkItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 66) {
|
||||
|
@ -216,7 +216,7 @@ public class RpkItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ public class SentinelItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 53) {
|
||||
|
@ -221,7 +221,7 @@ public class SentinelItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
}
|
||||
}
|
||||
if (tag.getDouble("firing") > 0) {
|
||||
|
|
|
@ -195,7 +195,7 @@ public class SksItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("gj", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 51) {
|
||||
|
@ -215,7 +215,7 @@ public class SksItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.RIFLE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ public class SvdItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("gj", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 55) {
|
||||
|
@ -189,7 +189,7 @@ public class SvdItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && player.getMainHandItem().getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.SNIPER, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ public class Trachelium extends GunItem implements GeoItem, AnimatedItem {
|
|||
itemTag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (itemTag.getDouble("reload_time") == 1 && mainHandItemTag.getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.HANDGUN);
|
||||
GunsTool.reload(entity, GunInfo.Type.HANDGUN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,8 @@ import net.mcreator.target.TargetMod;
|
|||
import net.mcreator.target.client.renderer.item.VectorItemRenderer;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.item.AnimatedItem;
|
||||
import net.mcreator.target.tools.GunInfo;
|
||||
import net.mcreator.target.tools.GunReload;
|
||||
import net.mcreator.target.tools.GunsTool;
|
||||
import net.mcreator.target.tools.TooltipTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -34,8 +32,6 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
|
|||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import software.bernie.geckolib.animatable.GeoItem;
|
||||
|
@ -228,7 +224,7 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && mainHandItem.getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.HANDGUN);
|
||||
GunsTool.reload(entity, GunInfo.Type.HANDGUN);
|
||||
}
|
||||
} else if (tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
if (tag.getDouble("reload_time") == 47) {
|
||||
|
@ -249,7 +245,7 @@ public class VectorItem extends GunItem implements GeoItem, AnimatedItem {
|
|||
tag.putDouble("reload_time", 0);
|
||||
}
|
||||
if (tag.getDouble("reload_time") == 1 && mainHandItem.getOrCreateTag().getDouble("id") == id) {
|
||||
GunReload.reload(entity, GunInfo.Type.HANDGUN, true);
|
||||
GunsTool.reload(entity, GunInfo.Type.HANDGUN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package net.mcreator.target.tools;
|
||||
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public class GunReload {
|
||||
public static void reload(Entity entity, GunInfo.Type type) {
|
||||
reload(entity, type, false);
|
||||
}
|
||||
|
||||
public static void reload(Entity entity, GunInfo.Type type, boolean extraOne) {
|
||||
if (!(entity instanceof LivingEntity living)) return;
|
||||
|
||||
CompoundTag tag = living.getMainHandItem().getOrCreateTag();
|
||||
|
||||
int mag = tag.getInt("mag");
|
||||
int ammo = tag.getInt("ammo");
|
||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
||||
/*
|
||||
* 空仓换弹的栓动武器应该在换单后取消待上膛标记
|
||||
*/
|
||||
if (ammo == 0 && tag.getDouble("bolt_action_time") > 0) {
|
||||
tag.putDouble("need_bolt_action", 0);
|
||||
}
|
||||
|
||||
int playerAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> switch (type) {
|
||||
case RIFLE -> c.rifleAmmo;
|
||||
case HANDGUN -> c.handgunAmmo;
|
||||
case SHOTGUN -> c.shotgunAmmo;
|
||||
case SNIPER -> c.sniperAmmo;
|
||||
}).orElse(0);
|
||||
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
var newAmmoCount = Math.max(0, playerAmmo - ammoToAdd);
|
||||
switch (type) {
|
||||
case RIFLE -> capability.rifleAmmo = newAmmoCount;
|
||||
case HANDGUN -> capability.handgunAmmo = newAmmoCount;
|
||||
case SHOTGUN -> capability.shotgunAmmo = newAmmoCount;
|
||||
case SNIPER -> capability.sniperAmmo = newAmmoCount;
|
||||
}
|
||||
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
tag.putInt("ammo", ammo + Math.min(ammoToAdd, playerAmmo));
|
||||
|
||||
tag.putBoolean("reloading", false);
|
||||
tag.putBoolean("empty_reload", false);
|
||||
}
|
||||
}
|
|
@ -4,8 +4,11 @@ import com.google.gson.stream.JsonReader;
|
|||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.network.message.GunsDataMessage;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
@ -23,6 +26,9 @@ public class GunsTool {
|
|||
|
||||
public static HashMap<String, HashMap<String, Double>> gunsData = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 初始化数据,从data中读取数据json文件
|
||||
*/
|
||||
public static void initJsonData(ResourceManager manager) {
|
||||
for (var entry : manager.listResources("guns", file -> file.getPath().endsWith(".json")).entrySet()) {
|
||||
var id = entry.getKey();
|
||||
|
@ -87,4 +93,46 @@ public class GunsTool {
|
|||
initJsonData(event.getServer().getResourceManager());
|
||||
}
|
||||
|
||||
public static void reload(Entity entity, GunInfo.Type type) {
|
||||
reload(entity, type, false);
|
||||
}
|
||||
|
||||
public static void reload(Entity entity, GunInfo.Type type, boolean extraOne) {
|
||||
if (!(entity instanceof LivingEntity living)) return;
|
||||
|
||||
CompoundTag tag = living.getMainHandItem().getOrCreateTag();
|
||||
|
||||
int mag = tag.getInt("mag");
|
||||
int ammo = tag.getInt("ammo");
|
||||
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
|
||||
/*
|
||||
* 空仓换弹的栓动武器应该在换单后取消待上膛标记
|
||||
*/
|
||||
if (ammo == 0 && tag.getDouble("bolt_action_time") > 0) {
|
||||
tag.putDouble("need_bolt_action", 0);
|
||||
}
|
||||
|
||||
int playerAmmo = entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).map(c -> switch (type) {
|
||||
case RIFLE -> c.rifleAmmo;
|
||||
case HANDGUN -> c.handgunAmmo;
|
||||
case SHOTGUN -> c.shotgunAmmo;
|
||||
case SNIPER -> c.sniperAmmo;
|
||||
}).orElse(0);
|
||||
|
||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
var newAmmoCount = Math.max(0, playerAmmo - ammoToAdd);
|
||||
switch (type) {
|
||||
case RIFLE -> capability.rifleAmmo = newAmmoCount;
|
||||
case HANDGUN -> capability.handgunAmmo = newAmmoCount;
|
||||
case SHOTGUN -> capability.shotgunAmmo = newAmmoCount;
|
||||
case SNIPER -> capability.sniperAmmo = newAmmoCount;
|
||||
}
|
||||
|
||||
capability.syncPlayerVariables(entity);
|
||||
});
|
||||
tag.putInt("ammo", ammo + Math.min(ammoToAdd, playerAmmo));
|
||||
|
||||
tag.putBoolean("reloading", false);
|
||||
tag.putBoolean("empty_reload", false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue