Skip to content

Commit

Permalink
Add off road, refactor wheels, allow other entities to be boosted on …
Browse files Browse the repository at this point in the history
…dash panels
  • Loading branch information
FoundationGames committed Jul 4, 2021
1 parent 521b7b9 commit bdd61b1
Show file tree
Hide file tree
Showing 31 changed files with 413 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public record AutomobileFrame(
new FrameModel(
Automobility.id("textures/entity/automobile/frame/shopping_cart.png"),
ShoppingCartFrameModel::new,
WheelBase.basic(17, 12),
17,
12,
11,
7,
17
Expand All @@ -60,8 +60,8 @@ public record AutomobileFrame(
new FrameModel(
Automobility.id("textures/entity/automobile/frame/c_arr.png"),
CARRFrameModel::new,
WheelBase.basic(44.5f, 16),
44.5f,
16,
6f,
19.5f,
10.5f
Expand All @@ -76,8 +76,8 @@ public record AutomobileFrame(
new FrameModel(
Automobility.id("textures/entity/automobile/frame/dababy.png"),
DaBabyFrameModel::new,
WheelBase.basic(40, 8),
40,
8,
22,
13,
3
Expand All @@ -92,8 +92,8 @@ private static AutomobileFrame standard(String color) {
new FrameModel(
Automobility.id("textures/entity/automobile/frame/standard_"+color+".png"),
StandardFrameModel::new,
WheelBase.basic(26, 10),
26,
10,
5,
13,
3
Expand All @@ -113,8 +113,8 @@ public String getTranslationKey() {
public static record FrameModel(
Identifier texture,
Function<EntityRendererFactory.Context, Model> model,
float wheelSeparationLong,
float wheelSeparationWide,
WheelBase wheelBase,
float lengthPx,
float seatHeight,
float enginePosBack,
float enginePosUp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.foundationgames.automobility.automobile;

public class BasicWheelBase extends WheelBase {
public BasicWheelBase(float sepLong, float sepWide) {
super(
new WheelPos(sepLong / 2, sepWide / -2, 1, 0, WheelEnd.FRONT, WheelSide.LEFT),
new WheelPos(sepLong / -2, sepWide / -2, 1, 0, WheelEnd.BACK, WheelSide.LEFT),
new WheelPos(sepLong / 2, sepWide / 2, 1, 180, WheelEnd.FRONT, WheelSide.RIGHT),
new WheelPos(sepLong / -2, sepWide / 2, 1, 180, WheelEnd.BACK, WheelSide.RIGHT)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.foundationgames.automobility.automobile;

public class WheelBase {
public final WheelPos[] wheels;

public WheelBase(WheelPos ... wheels) {
this.wheels = wheels;
}

public enum WheelSide {
LEFT,
RIGHT
}

public enum WheelEnd {
FRONT,
BACK
}

public static record WheelPos(float forward, float right, float scale, float yaw, WheelEnd end, WheelSide side) {}

public static WheelBase basic(float separationLong, float separationWide) {
return new BasicWheelBase(separationLong, separationWide);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.foundationgames.automobility.automobile.AutomobileEngine;
import io.github.foundationgames.automobility.automobile.AutomobileFrame;
import io.github.foundationgames.automobility.automobile.AutomobileWheel;
import io.github.foundationgames.automobility.automobile.WheelBase;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import net.minecraft.client.model.Model;
import net.minecraft.client.render.RenderLayer;
Expand Down Expand Up @@ -88,83 +89,64 @@ public static void render(
}

var wheelBuffer = vertexConsumers.getBuffer(wheelModel.getLayer(wheels.model().texture()));
float sLong = frame.model().wheelSeparationLong() / 16;
float sWide = frame.model().wheelSeparationWide() / 16;

// WHEELS ----------------------------------------

float wheelAngle = automobile.getWheelAngle(tickDelta);
float wheelRadius = wheels.model().radius();
var wPoses = frame.model().wheelBase().wheels;

if (wheelModel != null) {
// Front left
matrices.push();
matrices.translate(-(sLong / 2), wheelRadius / 16, -(sWide / 2));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(automobile.getSteering(tickDelta) * 27));
matrices.translate(0, raise, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-wheelAngle));
matrices.translate(0, -raise, 0);
wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1);
matrices.pop();

// Rear left
matrices.push();
matrices.translate(sLong / 2, wheelRadius / 16, -(sWide / 2));
matrices.translate(0, raise, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-wheelAngle));
matrices.translate(0, -raise, 0);
wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1);
if (automobile.getDriftTimer() > 0) {
matrices.translate(0, 0, -(wheels.model().width() / 16));

for (var pos : wPoses) {
float scale = pos.scale();
float wheelRadius = wheels.model().radius() * scale;
matrices.push();
matrices.translate(-pos.forward() / 16, wheelRadius / 16, pos.right() / 16);
if (pos.end() == WheelBase.WheelEnd.FRONT) matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(automobile.getSteering(tickDelta) * 27));
matrices.translate(0, raise, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-wheelAngle));
matrices.translate(0, -raise, 0);
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(pos.yaw()));
matrices.scale(scale, scale, scale);
wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1);
matrices.pop();
}
matrices.pop();

// Rear right
matrices.push();
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180));
matrices.translate(-(sLong / 2), wheelRadius / 16, -(sWide / 2));
matrices.translate(0, raise, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(wheelAngle));
matrices.translate(0, -raise, 0);
wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1);
matrices.pop();

// Front right
matrices.push();
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180));
matrices.translate(sLong / 2, wheelRadius / 16, -(sWide / 2));
matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(automobile.getSteering(tickDelta) * 27));
matrices.translate(0, raise, 0);
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(wheelAngle));
matrices.translate(0, -raise, 0);
wheelModel.render(matrices, wheelBuffer, light, overlay, 1, 1, 1, 1);
matrices.pop();
}

// Skid effects
if (automobile.getDriftTimer() > 0 && automobile.automobileOnGround()) {
if ((automobile.getDriftTimer() > 0 || automobile.debris()) && automobile.automobileOnGround()) {
var skidTexes = SkidEffectModel.SMOKE_TEXTURES;
boolean bright = false;
float r = 1;
float g = 1;
float b = 1;
if (automobile.getDriftTimer() > AutomobileEntity.DRIFT_TURBO_TIME) {
skidTexes = SkidEffectModel.FLAME_TEXTURES;
bright = true;
} else if (automobile.debris()) {
skidTexes = SkidEffectModel.DEBRIS_TEXTURES;
var c = automobile.debrisColor();
r = c.getX() * 0.85f;
g = c.getY() * 0.85f;
b = c.getZ() * 0.85f;
} else if (automobile.getDriftTimer() > AutomobileEntity.DRIFT_TURBO_TIME - 20) {
skidTexes = SkidEffectModel.SPARK_TEXTURES;
}
int index = (int)Math.floor(((automobile.getWorldTime() + tickDelta) / 1.5f) % skidTexes.length);
var skidEffectBuffer = vertexConsumers.getBuffer(bright ? RenderLayer.getEyes(skidTexes[index]) : RenderLayer.getEntityTranslucent(skidTexes[index]));

matrices.push();
float back = (wheelRadius / 16) - Math.max(0, ((wheelRadius / 16) - (3f / 16)) * 0.75f);
matrices.translate((sLong / 2) + back, wheelRadius / 16, -((sWide / 2) + (wheels.model().width() / 16)));
skidEffectModel.render(matrices, skidEffectBuffer, light, overlay, 1, 1, 1, 0.6f);
matrices.pop();
matrices.push();
matrices.scale(1, 1, -1);
matrices.translate((sLong / 2) + back, wheelRadius / 16, -((sWide / 2) + (wheels.model().width() / 16)));
skidEffectModel.render(matrices, skidEffectBuffer, light, overlay, 1, 1, 1, 0.6f);
matrices.pop();
var skidEffectBuffer = vertexConsumers.getBuffer(bright ? RenderLayer.getEyes(skidTexes[index]) : RenderLayer.getEntityCutout(skidTexes[index]));

for (var pos : wPoses) {
if (pos.end() == WheelBase.WheelEnd.BACK) {
float scale = pos.scale();
float wheelRadius = wheels.model().radius() * scale;
float wheelWidth = (wheels.model().width() / 16) * scale;
float back = (wheelRadius / 16) - Math.max(0, ((wheelRadius / 16) - (3f / 16)) * 0.75f);
matrices.push();
matrices.translate((-pos.forward() / 16) + back, wheelRadius / 16, (pos.right() / 16) + (wheelWidth * (pos.side() == WheelBase.WheelSide.RIGHT ? 1 : -1)));
matrices.scale(1, 1, pos.side() == WheelBase.WheelSide.RIGHT ? -1 : 1);
skidEffectModel.render(matrices, skidEffectBuffer, light, overlay, r, g, b, 0.6f);
matrices.pop();
}
}
}

// -----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.math.Vec3f;

public interface RenderableAutomobile {
Model getFrameModel(EntityRendererFactory.Context ctx);
Expand Down Expand Up @@ -29,4 +30,8 @@ public interface RenderableAutomobile {
long getWorldTime();

boolean automobileOnGround();

boolean debris();

Vec3f debrisColor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class SkidEffectModel extends Model {
Automobility.id("textures/entity/automobile/skid_effect/skid_flames_1.png"),
Automobility.id("textures/entity/automobile/skid_effect/skid_flames_2.png")
};
public static final Identifier[] DEBRIS_TEXTURES = new Identifier[] {
Automobility.id("textures/entity/automobile/skid_effect/skid_debris_0.png"),
Automobility.id("textures/entity/automobile/skid_effect/skid_debris_1.png"),
Automobility.id("textures/entity/automobile/skid_effect/skid_debris_2.png")
};

private final ModelPart main;
private final ModelPart side;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.model.Model;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3f;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -92,4 +93,14 @@ public long getWorldTime() {
public boolean automobileOnGround() {
return true;
}

@Override
public boolean debris() {
return false;
}

@Override
public Vec3f debrisColor() {
return new Vec3f();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@
import io.github.foundationgames.automobility.item.SlopeBlockItem;
import io.github.foundationgames.automobility.item.SteepSlopeBlockItem;
import io.github.foundationgames.automobility.resource.AutomobilityAssets;
import io.github.foundationgames.automobility.util.AUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.level.ColorResolver;

public enum AutomobilityBlocks {;
public static final Block AUTO_MECHANIC_TABLE = register("auto_mechanic_table", new AutoMechanicTableBlock(FabricBlockSettings.copyOf(Blocks.COPPER_BLOCK)), Automobility.GROUP);
public static final Block GRASS_OFF_ROAD = register("grass_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.GRASS_BLOCK).noCollision(), AUtils.colorFromInt(0x406918)), Automobility.GROUP);
public static final Block DIRT_OFF_ROAD = register("dirt_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.DIRT).noCollision(), AUtils.colorFromInt(0x594227)), Automobility.GROUP);
public static final Block SAND_OFF_ROAD = register("sand_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SAND).noCollision(), AUtils.colorFromInt(0xC2B185)), Automobility.GROUP);
public static final Block SNOW_OFF_ROAD = register("snow_off_road", new OffRoadBlock(FabricBlockSettings.copyOf(Blocks.SNOW).noCollision(), AUtils.colorFromInt(0xD0E7ED)), Automobility.GROUP);

public static final Block DASH_PANEL = register("dash_panel", new DashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true).noCollision()), Automobility.GROUP);
public static final Block SLOPED_DASH_PANEL = register("sloped_dash_panel", new SlopedDashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true)));
public static final Block STEEP_SLOPED_DASH_PANEL = register("steep_sloped_dash_panel", new SteepSlopedDashPanelBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).luminance(1).emissiveLighting((state, world, pos) -> true)));
Expand All @@ -29,6 +40,8 @@ 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.ITEM.register((stack, tintIndex) -> GrassColors.getColor(0.5D, 1.0D), GRASS_OFF_ROAD.asItem());
}

public static Block register(String name, Block block) {
Expand All @@ -51,7 +64,7 @@ public static void registerSlopes(String namespace) {
Registry.register(Registry.ITEM, Automobility.id(path), new SlopeBlockItem(base, block, new Item.Settings().group(Automobility.GROUP)));
block = register(steepPath, new SteepSlopeBlock(FabricBlockSettings.copyOf(base)));
Registry.register(Registry.ITEM, Automobility.id(steepPath), new SteepSlopeBlockItem(base, block, new Item.Settings().group(Automobility.GROUP)));
AutomobilityAssets.addProcessor(pack -> AutomobilityAssets.addSlope(path, namespace+":block/"+id.getPath()));
AutomobilityAssets.addProcessor(pack -> AutomobilityAssets.addMinecraftSlope(path, id.getPath()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package io.github.foundationgames.automobility.block;

import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.entity.AutomobilityEntities;
import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
Expand All @@ -11,6 +16,7 @@
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
Expand Down Expand Up @@ -64,13 +70,25 @@ public FluidState getFluidState(BlockState state) {
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);
if (entity instanceof AutomobileEntity auto) {
auto.boost(0.45f, 50);
}
onCollideWithDashPanel(entity);
}

@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}

public static void onCollideWithDashPanel(Entity entity) {
if (entity instanceof AutomobileEntity auto) {
auto.boost(0.45f, 50);
} else if (AutomobilityEntities.DASH_PANEL_BOOSTABLES.contains(entity.getType())) {
if (entity instanceof LivingEntity living) {
living.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, 50, 20, true, false, false));
}
Vec3d vel;
double yaw = Math.toRadians(entity.getYaw() + 180);
vel = new Vec3d(Math.sin(yaw), 0, Math.cos(yaw));
entity.addVelocity(vel.x, vel.y, vel.z);
}
}
}
Loading

0 comments on commit bdd61b1

Please sign in to comment.