From 4e89ddb44826e345c6fdc825984299a408d8245d Mon Sep 17 00:00:00 2001 From: xkball <45330674+xkball@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:34:36 +0800 Subject: [PATCH] Fix a fatal bug. Bump to 1.4.29 Took 40 minutes --- gradle.properties | 2 +- .../teacon/powertool/client/ClientEvents.java | 4 +- .../powertool/entity/MartingCarEntity.java | 47 +++++++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2d65591..27d742f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,7 +34,7 @@ mod_name=Power Tool # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPL-3.0 # The mod version. See https://semver.org/ -mod_version=1.4.28 +mod_version=1.4.29 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/org/teacon/powertool/client/ClientEvents.java b/src/main/java/org/teacon/powertool/client/ClientEvents.java index 8c2adc3..ee0222c 100644 --- a/src/main/java/org/teacon/powertool/client/ClientEvents.java +++ b/src/main/java/org/teacon/powertool/client/ClientEvents.java @@ -169,14 +169,14 @@ public static void renderers(EntityRenderersEvent.RegisterRenderers event) { } @SubscribeEvent - public static void on(EntityRenderersEvent.RegisterLayerDefinitions event) { + public static void onRegModelLayerDef(EntityRenderersEvent.RegisterLayerDefinitions event) { for (var v : MartingCarEntity.Variant.values()) { event.registerLayerDefinition(v.getModelLayer(), MartingCarEntityModel::createBodyLayer); } } @SubscribeEvent - public static void on(RegisterGuiLayersEvent event) { + public static void onRegGuiLayerDef(RegisterGuiLayersEvent event) { event.registerAbove(VanillaGuiLayers.CROSSHAIR, ResourceLocation.fromNamespaceAndPath(PowerTool.MODID, "cashier_hud"), (guiGraphics, partialTicks) -> { Minecraft mc = Minecraft.getInstance(); HitResult res = mc.hitResult; diff --git a/src/main/java/org/teacon/powertool/entity/MartingCarEntity.java b/src/main/java/org/teacon/powertool/entity/MartingCarEntity.java index 1e27011..368de0b 100644 --- a/src/main/java/org/teacon/powertool/entity/MartingCarEntity.java +++ b/src/main/java/org/teacon/powertool/entity/MartingCarEntity.java @@ -21,6 +21,10 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.common.NeoForgeMod; +import net.neoforged.neoforge.common.data.fixes.NeoForgeEntityLegacyAttributesFix; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.teacon.powertool.PowerTool; @@ -43,6 +47,8 @@ public class MartingCarEntity extends LivingEntity { public static final EntityDataAccessor DATA_ID_STEERING_WHEEL_ROTATE_DEGREE = SynchedEntityData.defineId(MartingCarEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor DATA_ID_DAMAGE = SynchedEntityData.defineId(MartingCarEntity.class, EntityDataSerializers.FLOAT); + + public static final EntityDataAccessor VARIANT = SynchedEntityData.defineId(MartingCarEntity.class, EntityDataSerializers.INT); // Todo: wheel speed should depends on velocity. public static final double WHEEL_ROTATE_DEGREE_PER_TICK = 18; // 360 / 20 @@ -50,8 +56,7 @@ public class MartingCarEntity extends LivingEntity { public static final int MAX_REMAINING_LIFE_TIME_TICKS = 120 * 20; // 2 minutes // - - private Variant variant = Variant.RED; + private int remainingLifeTimeTicks = MAX_REMAINING_LIFE_TIME_TICKS; private AttributeMap attributeMap; @@ -68,11 +73,11 @@ public MartingCarEntity(EntityType entityType, Level level) { } public void setVariant(Variant variant) { - this.variant = variant; + this.entityData.set(VARIANT,variant.ordinal()); } public Variant getVariant() { - return variant; + return Variant.from(this.entityData.get(VARIANT)); } // @@ -188,7 +193,7 @@ public boolean showVehicleHealth() { } protected @NotNull Item getDropItem() { - return variant.getItemSupplier().get(); + return getVariant().getItemSupplier().get(); } protected void updateWheelsAnimation() { @@ -231,7 +236,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { @Override public void addAdditionalSaveData(@NotNull CompoundTag compound) { - compound.putString("variant", variant.getName()); + compound.putString("variant", getVariant().getName()); compound.putInt("lifetimeRemain", remainingLifeTimeTicks); } @@ -240,6 +245,7 @@ protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) { super.defineSynchedData(builder); builder.define(DATA_ID_STEERING_WHEEL_ROTATE_DEGREE, 0F); builder.define(DATA_ID_DAMAGE, 0F); + builder.define(VARIANT,0); } public float getDamage() { @@ -267,6 +273,8 @@ public static AttributeSupplier createAttributes() { .add(Attributes.SCALE) .add(Attributes.GRAVITY) .add(Attributes.MOVEMENT_EFFICIENCY) + .add(NeoForgeMod.SWIM_SPEED) + .add(Attributes.WATER_MOVEMENT_EFFICIENCY) .add(Attributes.SAFE_FALL_DISTANCE, 30) .add(Attributes.FALL_DAMAGE_MULTIPLIER) .build(); @@ -295,23 +303,22 @@ public void setHealth(float health) { // public enum Variant { - RED("marting_red", PowerToolItems.MARTING_RED, MartingCarEntityModel.LAYER_RED), - GREEN("marting_green", PowerToolItems.MARTING_GREEN, MartingCarEntityModel.LAYER_GREEN), - BLUE("marting_blue", PowerToolItems.MARTING_BLUE, MartingCarEntityModel.LAYER_BLUE), + RED("marting_red", PowerToolItems.MARTING_RED), + GREEN("marting_green", PowerToolItems.MARTING_GREEN), + BLUE("marting_blue", PowerToolItems.MARTING_BLUE), ; private final String name; private final Supplier itemSupplier; private final ResourceLocation id; private final ResourceLocation texture; - private final ModelLayerLocation layer; + - Variant(String name, Supplier itemSupplier, ModelLayerLocation layer) { + Variant(String name, Supplier itemSupplier) { this.name = name; this.itemSupplier = itemSupplier; this.id = ResourceLocation.fromNamespaceAndPath(PowerTool.MODID, name); this.texture = ResourceLocation.fromNamespaceAndPath(PowerTool.MODID, "textures/item/" + name + ".png"); - this.layer = layer; } public static Variant from(String name) { @@ -320,9 +327,16 @@ public static Variant from(String name) { return v; } } - return RED; } + + public static Variant from(int ordinal){ + return switch (ordinal){ + case 1 -> GREEN; + case 2 -> BLUE; + default -> RED; + }; + } public String getName() { return name; @@ -340,8 +354,13 @@ public ResourceLocation getTexture() { return texture; } + @OnlyIn(Dist.CLIENT) public ModelLayerLocation getModelLayer() { - return layer; + return switch (this){ + case RED -> MartingCarEntityModel.LAYER_RED; + case GREEN -> MartingCarEntityModel.LAYER_GREEN; + case BLUE -> MartingCarEntityModel.LAYER_BLUE; + }; } } }