Skip to content

Commit

Permalink
Make work on dedicated servers, fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Jul 4, 2021
1 parent 36488a9 commit b685377
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lambdacontrols_version=1.7.1+1.17
myron_version=1.6.0
arrp_version=0.4.3

mod_version = 0.0.1+1.17
mod_version = 0.0.2+1.17
maven_group = io.github.foundationgames
archives_base_name = automobility

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.foundationgames.automobility.util.network.PayloadPackets;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.entity.AutomobilityEntities;
import io.github.foundationgames.automobility.item.AutomobilityItems;
import io.github.foundationgames.automobility.render.AutomobilityModels;
import io.github.foundationgames.automobility.resource.AutomobilityAssets;
import io.github.foundationgames.automobility.util.AUtils;
import io.github.foundationgames.automobility.util.network.PayloadPackets;
Expand All @@ -16,6 +17,7 @@
public class AutomobilityClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
AutomobilityModels.init();
AutomobilityBlocks.initClient();
AutomobilityItems.initClient();
AutomobilityEntities.initClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel;
import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel;
import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel;
import io.github.foundationgames.automobility.render.AutomobilityModels;
import io.github.foundationgames.automobility.util.SimpleMapContentRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;
Expand All @@ -25,7 +28,7 @@ public record AutomobileEngine(
public static final AutomobileEngine IRON = REGISTRY.register(
new AutomobileEngine(Automobility.id("iron"), 0.5f, 1,
new EngineModel(
Automobility.id("textures/entity/automobile/engine/iron.png"), IronEngineModel::new,
Automobility.id("textures/entity/automobile/engine/iron.png"), Automobility.id("engine_iron"),
new AutomobileEngine.ExhaustPos(-3.5f, 5.4f, -8, 26, 0),
new AutomobileEngine.ExhaustPos(3.5f, 5.4f, -8, 26, 0)
)
Expand All @@ -35,7 +38,7 @@ public record AutomobileEngine(
public static final AutomobileEngine COPPER = REGISTRY.register(
new AutomobileEngine(Automobility.id("copper"), 0.375f, 0.8f,
new EngineModel(
Automobility.id("textures/entity/automobile/engine/copper.png"), CopperEngineModel::new,
Automobility.id("textures/entity/automobile/engine/copper.png"), Automobility.id("engine_copper"),
new AutomobileEngine.ExhaustPos(2, 1.625f, -8.95f, 26, 0)
)
)
Expand All @@ -44,7 +47,7 @@ public record AutomobileEngine(
public static final AutomobileEngine GOLD = REGISTRY.register(
new AutomobileEngine(Automobility.id("gold"), 0.7f, 0.75f,
new EngineModel(
Automobility.id("textures/entity/automobile/engine/gold.png"), GoldEngineModel::new,
Automobility.id("textures/entity/automobile/engine/gold.png"), Automobility.id("engine_gold"),
new AutomobileEngine.ExhaustPos(4, 9.3f, -7.75f, 26, 0),
new AutomobileEngine.ExhaustPos(-4, 9.3f, -7.75f, 26, 0)
)
Expand All @@ -54,7 +57,7 @@ public record AutomobileEngine(
public static final AutomobileEngine CREATIVE = REGISTRY.register(
new AutomobileEngine(Automobility.id("creative"), 1f, 2f,
new EngineModel(
Automobility.id("textures/entity/automobile/engine/creative.png"), CreativeEngineModel::new,
Automobility.id("textures/entity/automobile/engine/creative.png"), Automobility.id("engine_creative"),
new AutomobileEngine.ExhaustPos(0, 7, -7, 90, 0)
)
)
Expand All @@ -71,9 +74,14 @@ public String getTranslationKey() {

public static record EngineModel(
Identifier texture,
Function<EntityRendererFactory.Context, Model> model,
Identifier modelId,
ExhaustPos ... exhausts
) {}
) {
@Environment(EnvType.CLIENT)
public Function<EntityRendererFactory.Context, Model> model() {
return AutomobilityModels.MODELS.get(modelId);
}
}

public static record ExhaustPos(
float x, float y, float z,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.render.frame.*;
import io.github.foundationgames.automobility.render.AutomobilityModels;
import io.github.foundationgames.automobility.util.SimpleMapContentRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -45,7 +48,7 @@ public record AutomobileFrame(
0.25f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/shopping_cart.png"),
ShoppingCartFrameModel::new,
Automobility.id("frame_shopping_cart"),
WheelBase.basic(17, 12),
17,
11,
Expand All @@ -61,7 +64,7 @@ public record AutomobileFrame(
0.85f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/c_arr.png"),
CARRFrameModel::new,
Automobility.id("frame_c_arr"),
WheelBase.basic(44.5f, 16),
44.5f,
6f,
Expand All @@ -77,7 +80,7 @@ public record AutomobileFrame(
0.75f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/pineapple.png"),
PineappleFrameModel::new,
Automobility.id("frame_pineapple"),
WheelBase.basic(10, 18),
12,
16,
Expand All @@ -93,7 +96,7 @@ public record AutomobileFrame(
0.93f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/dababy.png"),
DaBabyFrameModel::new,
Automobility.id("frame_dababy"),
WheelBase.basic(40, 8),
40,
22,
Expand All @@ -109,7 +112,7 @@ private static AutomobileFrame standard(String color) {
0.6f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/standard_"+color+".png"),
StandardFrameModel::new,
Automobility.id("frame_standard"),
WheelBase.basic(26, 10),
26,
5,
Expand All @@ -125,7 +128,7 @@ private static AutomobileFrame tractor(String color) {
0.9f,
new FrameModel(
Automobility.id("textures/entity/automobile/frame/"+color+"_tractor.png"),
TractorFrameModel::new,
Automobility.id("frame_tractor"),
new WheelBase(
new WheelBase.WheelPos(-2, -7, 1.8f, 0, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.LEFT),
new WheelBase.WheelPos(-2, 7, 1.8f, 180, WheelBase.WheelEnd.BACK, WheelBase.WheelSide.RIGHT),
Expand All @@ -151,11 +154,16 @@ public String getTranslationKey() {

public static record FrameModel(
Identifier texture,
Function<EntityRendererFactory.Context, Model> model,
Identifier modelId,
WheelBase wheelBase,
float lengthPx,
float seatHeight,
float enginePosBack,
float enginePosUp
) {}
) {
@Environment(EnvType.CLIENT)
public Function<EntityRendererFactory.Context, Model> model() {
return AutomobilityModels.MODELS.get(modelId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.render.wheel.*;
import io.github.foundationgames.automobility.render.AutomobilityModels;
import io.github.foundationgames.automobility.util.SimpleMapContentRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;
Expand All @@ -20,27 +23,23 @@ public record AutomobileWheel(
public static final SimpleMapContentRegistry<AutomobileWheel> REGISTRY = new SimpleMapContentRegistry<>();

public static final AutomobileWheel STANDARD = REGISTRY.register(
new AutomobileWheel(Automobility.id("standard"), 0.6f, 0.5f, new WheelModel(3, 3, Automobility.id("textures/entity/automobile/wheel/standard.png"), StandardWheelModel::new))
new AutomobileWheel(Automobility.id("standard"), 0.6f, 0.5f, new WheelModel(3, 3, Automobility.id("textures/entity/automobile/wheel/standard.png"), Automobility.id("wheel_standard")))
);

public static final AutomobileWheel OFF_ROAD = REGISTRY.register(
new AutomobileWheel(Automobility.id("off_road"), 1.1f, 0.8f, new WheelModel(8.4f, 5, Automobility.id("textures/entity/automobile/wheel/off_road.png"), OffRoadWheelModel::new))
new AutomobileWheel(Automobility.id("off_road"), 1.1f, 0.8f, new WheelModel(8.4f, 5, Automobility.id("textures/entity/automobile/wheel/off_road.png"), Automobility.id("wheel_off_road")))
);

public static final AutomobileWheel STEEL = REGISTRY.register(
new AutomobileWheel(Automobility.id("steel"), 0.69f, 0.4f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/steel.png"), SteelWheelModel::new))
new AutomobileWheel(Automobility.id("steel"), 0.69f, 0.4f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/steel.png"), Automobility.id("wheel_steel")))
);

public static final AutomobileWheel TRACTOR = REGISTRY.register(
new AutomobileWheel(Automobility.id("tractor"), 1.05f, 0.69f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/tractor.png"), TractorWheelModel::new))
new AutomobileWheel(Automobility.id("tractor"), 1.05f, 0.69f, new WheelModel(3.625f, 3, Automobility.id("textures/entity/automobile/wheel/tractor.png"), Automobility.id("wheel_tractor")))
);

// public static final AutomobileWheel INFLATABLE = REGISTRY.register(
// new AutomobileWheel(Automobility.id("inflatable"), 0.75f, new WheelModel(4, 4, TEMP_ID, EmptyModel::new), Ability.HYDROPLANE)
// );

public static final AutomobileWheel CONVERTIBLE = REGISTRY.register(
new AutomobileWheel(Automobility.id("convertible"), 0.75f, 0.45f, new WheelModel(5.2f, 4.1f, Automobility.id("textures/entity/automobile/frame/dababy.png"), ConvertibleWheelModel::new))
new AutomobileWheel(Automobility.id("convertible"), 0.75f, 0.45f, new WheelModel(5.2f, 4.1f, Automobility.id("textures/entity/automobile/frame/dababy.png"), Automobility.id("wheel_convertible")))
);

@Override
Expand All @@ -53,13 +52,17 @@ public String getTranslationKey() {
}

public enum Ability {
// HYDROPLANE;
}

public static record WheelModel(
float radius,
float width,
Identifier texture,
Function<EntityRendererFactory.Context, Model> model
) {}
Identifier modelId
) {
@Environment(EnvType.CLIENT)
public Function<EntityRendererFactory.Context, Model> model() {
return AutomobilityModels.MODELS.get(modelId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void init() {

@Environment(EnvType.CLIENT)
public static void initClient() {
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD);
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD.asItem());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public void readCustomDataFromNbt(NbtCompound nbt) {
inLeft = nbt.getBoolean("steeringLeft");
inRight = nbt.getBoolean("steeringRight");
inSpace = nbt.getBoolean("holdingDrift");
groundSlopeX = nbt.getFloat("angleX");
groundSlopeZ = nbt.getFloat("angleZ");

updateModels = true;
}
Expand Down Expand Up @@ -161,6 +163,8 @@ public void writeCustomDataToNbt(NbtCompound nbt) {
nbt.putBoolean("steeringLeft", inLeft);
nbt.putBoolean("steeringRight", inRight);
nbt.putBoolean("holdingDrift", inSpace);
nbt.putFloat("angleX", groundSlopeX);
nbt.putFloat("angleZ", groundSlopeZ);
}

private boolean inFwd = false;
Expand Down Expand Up @@ -292,9 +296,9 @@ public void baseTick() {
sync(player);
}
}
} else {
slopeAngleTick();
}

slopeAngleTick();
}

private void sync(ServerPlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public static void init() {
);
}

@Environment(EnvType.CLIENT)
private static EntityRendererFactory.Context cachedCtx;
private static final AutomobileData reader = new AutomobileData();
private static final ItemRenderableAutomobile itemAutomobile = new ItemRenderableAutomobile(reader);

@Environment(EnvType.CLIENT)
public static void initClient() {
var itemAutomobile = new ItemRenderableAutomobile(reader);
EntityRenderHelper.registerContextListener(ctx -> cachedCtx = ctx);
BuiltinItemRendererRegistry.INSTANCE.register(AUTOMOBILE, (stack, mode, matrices, vertexConsumers, light, overlay) -> {
if (cachedCtx != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.github.foundationgames.automobility.render;

import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.render.engine.CopperEngineModel;
import io.github.foundationgames.automobility.automobile.render.engine.CreativeEngineModel;
import io.github.foundationgames.automobility.automobile.render.engine.GoldEngineModel;
import io.github.foundationgames.automobility.automobile.render.engine.IronEngineModel;
import io.github.foundationgames.automobility.automobile.render.frame.*;
import io.github.foundationgames.automobility.automobile.render.wheel.*;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

@Environment(EnvType.CLIENT)
public enum AutomobilityModels {;
public static final Map<Identifier, Function<EntityRendererFactory.Context, Model>> MODELS = new HashMap<>();

@Environment(EnvType.CLIENT)
public static void init() {
MODELS.put(Automobility.id("frame_standard"), StandardFrameModel::new);
MODELS.put(Automobility.id("frame_tractor"), TractorFrameModel::new);
MODELS.put(Automobility.id("frame_shopping_cart"), ShoppingCartFrameModel::new);
MODELS.put(Automobility.id("frame_c_arr"), CARRFrameModel::new);
MODELS.put(Automobility.id("frame_pineapple"), PineappleFrameModel::new);
MODELS.put(Automobility.id("frame_dababy"), DaBabyFrameModel::new);

MODELS.put(Automobility.id("wheel_standard"), StandardWheelModel::new);
MODELS.put(Automobility.id("wheel_off_road"), OffRoadWheelModel::new);
MODELS.put(Automobility.id("wheel_steel"), SteelWheelModel::new);
MODELS.put(Automobility.id("wheel_tractor"), TractorWheelModel::new);
MODELS.put(Automobility.id("wheel_convertible"), ConvertibleWheelModel::new);

MODELS.put(Automobility.id("engine_iron"), IronEngineModel::new);
MODELS.put(Automobility.id("engine_copper"), CopperEngineModel::new);
MODELS.put(Automobility.id("engine_gold"), GoldEngineModel::new);
MODELS.put(Automobility.id("engine_creative"), CreativeEngineModel::new);
}
}

0 comments on commit b685377

Please sign in to comment.