Skip to content

Commit

Permalink
Fix a fatal bug. Bump to 1.4.29
Browse files Browse the repository at this point in the history
Took 40 minutes
  • Loading branch information
xkball committed Nov 18, 2024
1 parent 84efcb4 commit 4e89ddb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/teacon/powertool/client/ClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 33 additions & 14 deletions src/main/java/org/teacon/powertool/entity/MartingCarEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,15 +47,16 @@ public class MartingCarEntity extends LivingEntity {
public static final EntityDataAccessor<Float> DATA_ID_STEERING_WHEEL_ROTATE_DEGREE = SynchedEntityData.defineId(MartingCarEntity.class, EntityDataSerializers.FLOAT);

public static final EntityDataAccessor<Float> DATA_ID_DAMAGE = SynchedEntityData.defineId(MartingCarEntity.class, EntityDataSerializers.FLOAT);

public static final EntityDataAccessor<Integer> 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

public static final int MAX_REMAINING_LIFE_TIME_TICKS = 120 * 20; // 2 minutes

// <editor-fold desc="Persistent states.">

private Variant variant = Variant.RED;

private int remainingLifeTimeTicks = MAX_REMAINING_LIFE_TIME_TICKS;
private AttributeMap attributeMap;

Expand All @@ -68,11 +73,11 @@ public MartingCarEntity(EntityType<MartingCarEntity> 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));
}

// <editor-fold desc="Living entity staff.">
Expand Down Expand Up @@ -188,7 +193,7 @@ public boolean showVehicleHealth() {
}

protected @NotNull Item getDropItem() {
return variant.getItemSupplier().get();
return getVariant().getItemSupplier().get();
}

protected void updateWheelsAnimation() {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -295,23 +303,22 @@ public void setHealth(float health) {
// </editor-fold>

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<Item> itemSupplier;
private final ResourceLocation id;
private final ResourceLocation texture;
private final ModelLayerLocation layer;


Variant(String name, Supplier<Item> itemSupplier, ModelLayerLocation layer) {
Variant(String name, Supplier<Item> 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) {
Expand All @@ -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;
Expand All @@ -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;
};
}
}
}

0 comments on commit 4e89ddb

Please sign in to comment.