优化minigun的逻辑
This commit is contained in:
parent
a180f50ce6
commit
43e5ca19a8
2 changed files with 16 additions and 23 deletions
|
@ -46,7 +46,7 @@ import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
private static final String TAG_HEAT = "heat_bar";
|
private static final String TAG_HEAT = "heat";
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
public String animationProcedure = "empty";
|
public String animationProcedure = "empty";
|
||||||
public static ItemDisplayContext transformType;
|
public static ItemDisplayContext transformType;
|
||||||
|
@ -57,17 +57,18 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBarVisible(ItemStack pStack) {
|
public boolean isBarVisible(ItemStack pStack) {
|
||||||
return ItemNBTTool.getInt(pStack, TAG_HEAT, 0) != 51;
|
return ItemNBTTool.getDouble(pStack, TAG_HEAT, 0) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarWidth(ItemStack pStack) {
|
public int getBarWidth(ItemStack pStack) {
|
||||||
return Math.round((float) ItemNBTTool.getInt(pStack, TAG_HEAT, 0) * 13.0F / 51F);
|
return Math.round((float) ItemNBTTool.getDouble(pStack, TAG_HEAT, 0) * 13.0F / 51F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarColor(ItemStack pStack) {
|
public int getBarColor(ItemStack pStack) {
|
||||||
return 0xFF0000;
|
double f = 1 - ItemNBTTool.getDouble(pStack, TAG_HEAT, 0) / 55.0F;
|
||||||
|
return Mth.hsvToRgb((float) f / 3.0F, 1.0F, 1.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,8 +83,7 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HumanoidModel.ArmPose MinigunPose = HumanoidModel.ArmPose.create("Minigun", false, (model, entity, arm) -> {
|
private static final HumanoidModel.ArmPose MinigunPose = HumanoidModel.ArmPose.create("Minigun", false, (model, entity, arm) -> {
|
||||||
if (arm == HumanoidArm.LEFT) {
|
if (arm != HumanoidArm.LEFT) {
|
||||||
} else {
|
|
||||||
model.rightArm.xRot = -0.2F + model.head.xRot;
|
model.rightArm.xRot = -0.2F + model.head.xRot;
|
||||||
model.rightArm.yRot = -0.2F;
|
model.rightArm.yRot = -0.2F;
|
||||||
model.leftArm.xRot = -1F + model.head.xRot;
|
model.leftArm.xRot = -1F + model.head.xRot;
|
||||||
|
@ -108,7 +108,7 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
transformType = type;
|
transformType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayState idlePredicate(AnimationState event) {
|
private PlayState idlePredicate(AnimationState<Minigun> event) {
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player == null) return PlayState.STOP;
|
if (player == null) return PlayState.STOP;
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
@ -128,7 +128,7 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
return PlayState.STOP;
|
return PlayState.STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayState procedurePredicate(AnimationState event) {
|
private PlayState procedurePredicate(AnimationState<Minigun> event) {
|
||||||
if (transformType != null && transformType.firstPerson()) {
|
if (transformType != null && transformType.firstPerson()) {
|
||||||
if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
if (!this.animationProcedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationProcedure));
|
||||||
|
@ -186,8 +186,6 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double cooldown = 0;
|
double cooldown = 0;
|
||||||
if (entity.wasInPowderSnow) {
|
if (entity.wasInPowderSnow) {
|
||||||
|
@ -200,11 +198,6 @@ public class Minigun extends GunItem implements GeoItem, AnimatedItem {
|
||||||
|
|
||||||
itemstack.getOrCreateTag().putDouble("heat", Mth.clamp(itemstack.getOrCreateTag().getDouble("heat") - 0.25 - cooldown, 0, 55));
|
itemstack.getOrCreateTag().putDouble("heat", Mth.clamp(itemstack.getOrCreateTag().getDouble("heat") - 0.25 - cooldown, 0, 55));
|
||||||
|
|
||||||
if (itemstack.getOrCreateTag().getDouble("heat") == 0) {
|
|
||||||
itemstack.getOrCreateTag().putDouble("heat_bar", 51);
|
|
||||||
} else {
|
|
||||||
itemstack.getOrCreateTag().putDouble("heat_bar", (itemstack.getOrCreateTag().getDouble("heat")));
|
|
||||||
}
|
|
||||||
if (itemstack.getOrCreateTag().getDouble("overheat") > 0) {
|
if (itemstack.getOrCreateTag().getDouble("overheat") > 0) {
|
||||||
itemstack.getOrCreateTag().putDouble("overheat", (itemstack.getOrCreateTag().getDouble("overheat") - 1));
|
itemstack.getOrCreateTag().putDouble("overheat", (itemstack.getOrCreateTag().getDouble("overheat") - 1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue